09-11-2015 03:40 AM
Hi,
I am facing problem in writing hex data to com port using ComWrite. How i will make sure that whatever data sent is written to my target properly because i am not seeing any changes in my target.
Whenever i am trying to read data from my target which is continously sending some response i can read through comRead successfully but write doesnt goes well. I cross verified the same message with other termnial where i can write hex data. but in CVI i cant. your feedbacks are much appreciated.
int no_of_bytes=0;
char comdata[100] = {0x28,0x00,0x02,0x00,0x01,0x00,0x01,0x00,0x00,0x00,0x29};
no_of_bytes = ComWrt (COM_PORT, comdata, strlen(comdata));
thanks.
Solved! Go to Solution.
09-11-2015 03:49 AM
The proble is in the use of strlen () to calculate the number of bytes to send: strlen treats c-like strings, that is it will return the position of the first NUL bite in the string: in your case it will return 2 bytes instead of 11 you are expecting.
The only solution is to calculate this number in a different way.
09-11-2015 04:01 AM
Thank u very much.
now i have written my code as
no_of_bytes = ComWrt (COM_PORT, comdata, 11); and it works.
instead of couting the number of bytes manually is there any way where we can get count of number of bytes?
09-11-2015 04:16 AM
Since you are dealing with raw data, there is no way to discriminate the number of bytes to send: each byte could theretically assume ever value fro 0x00 to 0xFF.
Unless your protocol has some characteristics you can leverage on (e.g. some end-of-transmission character or 7-byte protocol) I see no way other than counting bytes while you are preparing the message to send.