LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Visualize COM Port data

Solved!
Go to solution

Hi,

 

I am working with a device connected by a COM port and I'm interested in seeing the port data. My intention is that when I send a command to the device I can see the answer. I only want to see the command's momentary response, not all the port data.

 

Thank you for helping,

 

Mikel

0 Kudos
Message 1 of 11
(2,050 Views)

I must admit that I don't understand your goal: can you clarify your question, possibly with an example of what you are trying to achieve?



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 11
(2,011 Views)

Hi,

 

it sounds as if you are looking for a tool such NI I/O Trace which records all input parameters passed to a function and all output parameters that the function returns, including the return value of the function. Unfortunately this tool does not support the RS232 driver but if I remember correctly it works with VISA calls -  so if you happen to talk to your COM port via VISA it should work.

0 Kudos
Message 3 of 11
(2,002 Views)

Hi Roberto,

 

Imagine sending an "sm" command to my device. This one will answer me with "mote 5 is still alive". What I intend is to visualize this response in a texbox. And so with any command I send. I hope you undertand it this  time.

 

 

0 Kudos
Message 4 of 11
(1,999 Views)

Hi Wolfgang,

 

Unfortunately I am working with RS232 communication.

0 Kudos
Message 5 of 11
(1,998 Views)

Hi Mikel,

 

it is not about RS232 communication but about NI's RS232 driver library, VISA also support serial communication and in general it is much superior to the rather simple RS232 library. So if your code is not too complex this might be an opportunity to switch from RS232 to VISA

0 Kudos
Message 6 of 11
(1,994 Views)

Perfect!

 

The code is not complicated at all, so i will try with VISA library. 

0 Kudos
Message 7 of 11
(1,989 Views)

@mikelmujika  ha scritto:

Hi Roberto,

 

Imagine sending an "sm" command to my device. This one will answer me with "mote 5 is still alive". What I intend is to visualize this response in a texbox. And so with any command I send. I hope you undertand it this  time.

 

 


That's the basic of serial communication: query a device and read response! I was puzzled by this sentence of yours: "I only want to see the command's momentary response, not all the port data", but in this scenario use ComWrt to poll your device and ComRd with an appropriate timeout to read the response back. Or am I missing something? What do you mean with "all the port data"?



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 8 of 11
(1,966 Views)

Hi Roberto,

 

How can I schedule that every time I send a command visualize its response in a texbox? The examples t

0 Kudos
Message 9 of 11
(1,952 Views)
Solution
Accepted by topic author mikelmujika

Mikel, it's easy if you think of it!

Someting along these lines...

 

1. Open the port and set an appropriate timeout

 

OpenComConfig (comPort...);
SetComTime (comPort, 0.5);   // Timeout depends on your hardware

 

 

2. Poll the device

 

ComWrt (comPort, ....);
ComRd (comPort, buffer, expectedLenght);
strcat (buffer, "\n");    // Add each response in a new line
SetCtrlVal (panelHandle, PANEL_TEXTBOX, buffer);

 

 

That's all!

 

It's up to you to complete or accomodate the code according to your setup (e.g. using ComRdTerm if the device sends messages with specific termination).

 

And be sure to add a robust error checking in order to be warned in case of errors.



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 10 of 11
(1,943 Views)