02-03-2021 07:10 AM
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
Solved! Go to Solution.
02-03-2021 10:21 AM
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?
02-03-2021 11:49 AM
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.
02-03-2021 11:56 AM
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.
02-03-2021 11:57 AM
Hi Wolfgang,
Unfortunately I am working with RS232 communication.
02-03-2021 12:06 PM
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
02-03-2021 12:15 PM
Perfect!
The code is not complicated at all, so i will try with VISA library.
02-04-2021 02:00 AM
@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"?
02-04-2021 07:05 AM
Hi Roberto,
How can I schedule that every time I send a command visualize its response in a texbox? The examples t
02-04-2021 05:41 PM - edited 02-04-2021 05:46 PM
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.