LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

liaison Rs-232

Solved!
Go to solution

Hi everyone,

 

I would like to communicate with a device with a liaison RS-232. I wrote a little computer program on CVI for it. 

On the technical documentation of the device, it is notticed that " Each command issued should be followed by  a <CR> and/ or <LF>". 

 

I programmed this : 

 

length = strlen(tableau);
tableau[length] = 'CR';

tableau[length + 1] = '\0';
length = strlen(tableau);
ComWrt (1, tableau, length);

 

where "tableau" is my string that i would like to send to the device. I would like to know if it's good or if i'm supposed to write something else like : 

 

length = strlen(tableau);
tableau[length] = '<CR>';

 

I apologize if my english isn't very good, i'm a french student ... 🙂 !

Thanks you very much !

 

 

 

0 Kudos
Message 1 of 4
(1,085 Views)
Solution
Accepted by topic author Armando1223

<CR> and <LF> are not to be taken literally in this case! They are placeholders for carriage return and linefeed characters respectively.

To correctly create your string use '\r' for CR and '\n' for linefeed, so if your command is "1234" you can use strcpy (tableau, "1234\r") and send tableau to the external device (5 characters in this case). No need to terminate the string since strcpy will do it for you.

 

If on the contrary the command is in binary format you can use (same characters as above):

 

tableau[0] = 48;
tableau[1] = 49;
tableau[2] = 50;
tableau[3] = 51;
tableau[4] = 13;    // Line terminator: <CR>
tableau[5] = 0;     // Not really needed but useful

 

and issue the same ComWrt (comPort, tableau, 5);

 



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
(1,080 Views)

There is also noticed for the answer : "Each response will be followed by a <CR> and <LF> terminators", so, to read the response, should i write something like this ? : 

 

ComRdTerm (1, valeur, 256, '\r\n');

 

where valeur is the response, 1 the COM, 256 the number of bite to read and '\r\n' the termination byte. 

0 Kudos
Message 3 of 4
(1,069 Views)
Solution
Accepted by topic author Armando1223

You must set one single character as a terminator in ComRdTerm: use either '\n' or 10.



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
(1,061 Views)