serial-portpyserialnvidia-jetsonrs485

Serial Port Connection Fails on Subsequent Attempts (Jetson Orin Nano - RS485)


I am experiencing an issue with a serial port connection on my Seeed Studio reComputer J30 (Jetson Orin Nano Industrial). When I reboot the device, the serial port connection works fine on the first attempt. However, if I try to establish the connection a second time without rebooting, it fails with the following error:

Error opening the port: Could not configure port: (5, 'Input/output error')

I am trying to communicate with a display using RS485. The Jetson has a DB9 port configured for RS485. I can send data once (without the ACK), but subsequent attempts fail.

I do this before running my script

sudo su
echo 460 > /sys/class/gpio/export
echo out > /sys/class/gpio/PR.04/direction
sudo python test_serial.py

Here is a minimal script (test_serial.py) I am using to test the connection:

import serial

try:
    ser = serial.Serial(
        port='/dev/ttyTHS0',
        baudrate=1200,
        bytesize=serial.SEVENBITS,
        parity=serial.PARITY_EVEN,
        stopbits=serial.STOPBITS_ONE,
        timeout=0.5
    )
    print("Port opened successfully.")
    ser.close()
    print("Port closed.")
except serial.SerialException as e:
    print(f"Error opening the port: {e}")

I found this documentation available, but I don't have the adapter to test it exactly as described.

Additional Information:

Could someone please help me understand why this is happening and how I can resolve this issue?

Thank you in advance!

EDIT:


Solution

  • TL;DR: This Jetson may not support certain baud rates like 1200. Try using a supported baud rate (e.g., 9600, 19200 or 4800) for your serial connection.

    Unfortunately, it seems like this is a issue with this Seeed Studio Jetson, which sometimes has trouble handling certain baud rates, including 1200. To troubleshoot and see which baud rates are supported, you can use the stty command to test different rates. Here's what I did (with the reComputer J30):

    sudo stty -F /dev/ttyTHS0 speed #show 9600 (default)
    
    sudo stty -F /dev/ttyTHS0 19200
    sudo stty -F /dev/ttyTHS0 speed #show 19200
    
    sudo stty -F /dev/ttyTHS0 4800
    sudo stty -F /dev/ttyTHS0 speed #show 4800
    
    sudo stty -F /dev/ttyTHS0 2400
    sudo stty -F /dev/ttyTHS0 speed #show Input/output error
    

    In my case, 19200, 9600 and 4800 worked fine, but 2400 and 1200 resulted in an input/output error. This suggests that not all baud rates are supported equally on this platform.

    A potential solution would be to use a different baud rate that is supported by your device. If possible, try adjusting your display or peripheral to match one of the supported baud rates.

    If you need further assistance or have additional details to share, feel free to provide more information!

    Best regards