11-12-2020 02:36 AM
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 !
Solved! Go to Solution.
11-12-2020 02:51 AM - edited 11-12-2020 02:56 AM
<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);
11-12-2020 02:58 AM
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.
11-12-2020 03:12 AM
You must set one single character as a terminator in ComRdTerm: use either '\n' or 10.