Showing results for 
Search instead for 
Did you mean: 

Read data from RS232 (Serial) port



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

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.

LV 7.1, 2011, 2017, 2019
0 Kudos
Message 2 of 8


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

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?

There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
0 Kudos
Message 4 of 8

I think it wont accept any command.

0 Kudos
Message 5 of 8

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.

LV 7.1, 2011, 2017, 2019
0 Kudos
Message 6 of 8

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

0 Kudos
Message 7 of 8

You are not lucky. See crossrulz's answer.

LV 7.1, 2011, 2017, 2019
0 Kudos
Message 8 of 8