About the timeout error in `system.serial.readLine`

Hello
I have a question about system.serial.readLine.

I'm new to Ignition. Currently, I'm using system.serial to connect to a serial communication device.
Connection tests confirmed the device connection and data retrieval worked, but when I try to retrieve data after a timeout with system.serial.readLine, it throws an error.

Even when I create if statements or Try / catch blocks to handle cases where the value is NULL, the error still occurs.
How should I handle this situation? Should I change the settings on the device side?

data = system.serial.readLine("COM3", 20000)

I would post the config and the errors you get, we aren't mind readers.

1 Like

Understood, that's correct! My apologies.
The script I created is as follows.
The error details are contained within the JSON file.
This file was generated when the error occurred.

■code:

try:
        #Definition of Connected Devices
        system.serial.configureSerialPort(port="COM3",
        bitRate=system.serial.BIT_RATE_9600,
        dataBits=system.serial.DATA_BITS_8,
        handshake=system.serial.HANDSHAKE_NONE,
        hardwareFlowControl=False,
        parity=system.serial.PARITY_NONE,
        stopBits=system.serial.STOP_BITS_1)
        
        #Connection
        system.serial.openSerialPort("COM3")
        
        #Data acquisition
        data = system.serial.readLine("COM3", 50000)
        
        if data is None:
           data = "Timeout occurred"
        
        system.serial.closeSerialPort("COM3")

        return data
     #The returned data is being used by each component.

■Error Details:

NonResponsiveEdt-2025-08-29_193604 (1).json (65.4 KB)

The problem is that you are running this script directly in the foreground UI thread, which is not allowed to wait. You need to use system.util.invokeAsynchronous() to launch a background thread to do all of the serial line work. The background thread would report results by writing to client tags or using a shared jython variable, as background threads are not permitted to directly access windows and components.

1 Like

Thank you! I'll try running a connection test using that method!

You should study this old topic if you wish to manipulate your UI from the background:

1 Like