LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

проблема передачи команды через RS232

Есть такой код:

Fmt (send_data, "%s", SET 1 3 5 7 8 2 4 6\n");

if(err_code=ComWrt (10, send_data, 20)!=20){

RS232Error_Disp();

return 0;

}else{

SetCtrlVal(panel_handle, PANEL_TEXTBOX, send_data);

byte_count=ComRd(10, read_data, 19);

if(byte_count!=19)

RS232Error_Disp();

else{

SetCtrlVal(panel_handle, PANEL_TEXTBOX_2, read_data);

 

Как сделать так, чтобы последовательность ("SET 1 3 5 7 8 2 4 6\n") я вводил не в коде, а в самом текстовом поле при запуске программы, соответственно последовательность цифр может меняться и на конце нужно учесть символ '\n'? Заранее спасибо.

 

 

There is such a code:

Fmt (send_data, "%s", SET 1 3 5 7 8 2 4 6\n");

if(err_code=Com Wrt (10, send_data, 20)!=20){

RS 232 Error_Disp();

return 0;

}else{

SetCtrlVal(panel_handle, PANEL_TEXTBOX, send_data);

byte_count=ComRd(10, read_data, 19);

if(byte_count!=19)

RS 232 Error_Disp();

else{

SetCtrlVal(panel_handle, PANEL_TEXTBOX_2, read_data);

 

How to make the sequence ("SET 1 3 5 7 8 2 4 6\n") I did not enter it in the code, but in the text field itself when starting the program, respectively, the sequence of numbers may change and the character '\n ' must be taken into account at the end? Thank you in advance.

0 Kudos
Message 1 of 4
(1,186 Views)

Hello, I'm not sure I understand you correctly, because this seems quite a basic task:

  1. Read from a text control on a panel (GetCtrlVal into a string variable)
  2. (Opt.) add a new line character (strcat command)
  3. Send to serial line (like you already do)

There must be something unclear to me for you to ask: may you clarify better your situation? Is this somewhat related to your other discussion?

Additionally, I may add that I have rarely found a device that needs a linefeed as a termination character: a carriage return is most common, followed by a CR-LF pair.



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,180 Views)

Извиняюсь..просто трудно сформулировать. В общем ошибка заключается в чтении, в переменную read_data ничего не приходит. Хотя по количеству байт если выводить последовательность программно через SetCtrlVal всё получается

 

Apologize..it's just hard to formulate. In general, the error is in reading, nothing comes to the read_data variable. Although by the number of bytes if you output the sequence programmatically via SetCtrlVal everything turns out

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

Just a guess: what if the message has simply gone out of sight?

I mean, if the returning string terminates with a newline or carriage return character and your textbox is single-line the visible part of the message may be simply scrolled off!

You can test it by clicking on the control and pressing the Up key, or by setting the textbox to show 2 lines.



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,140 Views)