LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

ComWrite in labwindows

Solved!
Go to solution

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.

 

 

0 Kudos
Message 1 of 4
(3,955 Views)

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.



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 2 of 4
(3,954 Views)

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?

0 Kudos
Message 3 of 4
(3,947 Views)
Solution
Accepted by topic author ammukrish

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.



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 4 of 4
(3,945 Views)