Quantcast
Channel: LabWindows/CVI topics
Viewing all articles
Browse latest Browse all 5339

Assembling a packet from a mixture of chars arrays and an int using Fmt

$
0
0

Hi,

I need to assemble a packet containing 2 qualifier bytes, 2 length bytes big endian, and variable length command bytes.

I can do this in one line and this is what I have come up with:

 

int Send((unsigned char *command,int port,int length) 

unsigned char qualifiers[] = {0xAA,0x55,0}; 

unsigned char packet[0x10005];

//length is length of command array and stored as little endian on my machine.

Fmt(packet,"%s%c[b2o1]%c%s[t-w*]",qualifiers,length,length,length,command);

 

To get the 2 length bytes in place with high order byte first i'm using the byte order modifier. Since i'm printing to a string I need to use %c because I don't want the int length converted to ascii. But i need length to appear twice as an argument to fill in the 2 length bytes in my packet.

Is there anyway to get the length in the packet correctly with 1 less length argument?

 

Thank you


Viewing all articles
Browse latest Browse all 5339

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>