10-18-2005 09:27 AM
10-18-2005 09:40 AM - edited 10-18-2005 09:40 AM
Do you need to format a string exactly as you wrote, including the '0x' prefix? Then you can use sprintf (msg, "%#X\r", value); and output the string with ComWrt (comPort, msg, strlen (msg));
If '0x' prefix is not necessary, simply omit the '#' flag.
I added final '\r' as a termination character: it may be unnecessary or dangerous depending on your device communication protocol.
If you use 'x' operator you will have literal part of the string written in lowercase (e.g. 0x12ab), if you use 'X' it will be written in uppercase (0X12AB).
Message Edited by Roberto Bozzolo on 10-18-2005 04:44 PM
10-19-2005 02:38 PM
10-19-2005 03:22 PM - edited 10-19-2005 03:22 PM
Some other ways to send binary data are:
Send it byte by byte
ComWrtByte(1, 0x02);
ComWrtByte(1, 0x22);
ComWrtByte(1, 0x08);
…
or load a buffer and send the buffer, you can load the array up any way you like,
unsigned char dataBuffer[10]={0x02, 0x22, 0x08, 0x01, 0x20, 0x64, 0xD4, 0x03};
ComWrt(1, dataBuffer, 8);
or this is another way, the data is sent as the octal representation directly from inside a string.
ComWrt(1, "\002\042\010\001\040\144\324\003", 8);
that is \042 = 0x22. The calculator in windows can do hex to octal conversion for you if you ever need to do it this way.
Reading the data back is also strait forward: ComRdByte() reads a single byte. ComRd() reads as many bytes as you ask for I would assume that the instrument sends back something like 0x02, 0x22, then maybe the number of bytes it will send. You can use ComRdByte() to get all the bytes up to and including the length, then you know how many more bytes to get with ComRd() into an array of type char or unsigned char. You can do with the results what you wish. Good Luck
Message Edited by mvr on 10-19-2005 03:24 PM
05-26-2017 06:02 PM
How to send a Hex format command to TCP port using LabWindows CVI?
i need to send this command : A5 00 00 00 50 5E 00 00 11 D0
i sent unsigned char transmitBuf[11]={0xA5, 0x00, 0x00, 0x00, 0x50, 0x5E, 0x00, 0x00, 0x11, 0xD0};
, just send A5 to the server, WHY ?
05-28-2017 12:37 PM
Which functions did you use to send the string? If you happen to use any text-related command (strcpy, strcat, strlen...) they will terminate on the first NUL byte found. That's the most probable cause for your program to send only the first part of the string.
Having said this, I urge you to open a new discussion thread instead of reviving a 12-years old thread that only partially covers your problem.