From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Read data from RS232 (Serial) port

Hi,

In one of my project, I need to take data from a serial device. 

I will initialize the serial port connection once and i will continuously monitor bytes at port. If I get the bytes then i will go and read the data in the serial port. I will open the connection only once.

This is working fine in normal condition. Once after opening the connection, if the cable got disconnected or removed, i wont  get any error.

Any method is there to check whether the connection is alive or not?  

Please provide if there is any other way to ensure the connection is alive

0 Kudos
Message 1 of 8
(4,372 Views)

There are timeouts for this purpose. If you don't get any data within a given time limit, the connection is bad.

The actual timeout value will depend on the frequency of the data output.

Be careful in using Bytes at port, because it may report a partial packet length (further characters may be received immediately afterwards).

If the device packet has a fixed termination character, it would be better to enable it in the VISA Configure serial port.

Set a proper timeout and use a single Read, specifying a number of characters to read bigger than the expected packet length.

If the Read does not return the packet, there is a problem.

Paolo
-------------------
LV 7.1, 2011, 2017, 2019, 2021
0 Kudos
Message 2 of 8
(4,358 Views)

Hi,

In my project, i will get always bytes at port value is zero. I will get great than zero once the instrument done its work. In between if cable got removed also, the bytes at port property wont give any error.  

0 Kudos
Message 3 of 8
(4,346 Views)

The only way to see if a device is still connected through and RS-232 port is to attempt to talk to it.  Does the instrument accept commands so that you can verify it is still there every so often?


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 4 of 8
(4,332 Views)

I think it wont accept any command.

0 Kudos
Message 5 of 8
(4,328 Views)

Typically a serial port will not report anything about the cable plugged/unplugged status.

So you will never get a VISA error about this.

What's your device and what hardware protocol is used (none, hardware)? Is the cable a minimal RX, TX, GROUND?

You may use a VISA property node of type Serial Settings -> Modem Line Settings -> Break State (and similar) to monitor the state of various serial pins and see if anything changes connecting and disconnecting the cable. However, as expressed by the property names, those lines are (were?) typically used by serial modems; it's not likely that they can be used for this purpose with another type of device.

Paolo
-------------------
LV 7.1, 2011, 2017, 2019, 2021
0 Kudos
Message 6 of 8
(4,327 Views)

Yes, the cable have only RX,TX,GND.

0 Kudos
Message 7 of 8
(4,320 Views)

You are not lucky. See crossrulz's answer.

Paolo
-------------------
LV 7.1, 2011, 2017, 2019, 2021
0 Kudos
Message 8 of 8
(4,314 Views)