Skip to main content
Version: 1.0.2

RS485

Hardware​

One RS485/RS422 bus is integrated into AutomatePro with a max data rate of 500 kbps.

Connector Pinout​

RS485 Specifications​

ParameterValue
TransceiverTHVD1400DR
Data Rate500 kbps
RS485 StandardTIA/EIA-485A
DuplexHalf
Integrated 120 Ω termination resistorYes

Software​

Serial Port​

/dev/ttyTHS1 is the serial port used for RS485 communication.

Example​

This example sends a two-byte counter every second with rs485_sender and prints what rs485_receiver reads, on /dev/ttyTHS1 at 9600 baud, 8 data bits, no parity, 1 stop bit, and no flow control. The programs are in the misc folder of the AutomatePro tutorials repository, and its README explains how to build and run them. Run the receiver and the sender in separate terminals, one at each end of the bus. On a PC with a USB-RS485 adapter, pass the adapter's device as the only argument, for example python3 rs485_sender.py /dev/ttyUSB0; on AutomatePro, the /dev/ttyUSB* ports belong to the 5G modem. The Python programs need pyserial, and the user needs to be a member of the dialout group.

Sender: rs485_sender.py

import serial
import time
import signal
import sys

running = True


def signal_handler(sig, frame):
global running
print("\n[Sender] Stopping...")
running = False


signal.signal(signal.SIGINT, signal_handler)


def main():
port = sys.argv[1] if len(sys.argv) > 1 else '/dev/ttyTHS1'
baudrate = 9600

print(f"[Sender] Opening serial port: {port}")
try:
ser = serial.Serial(port, baudrate=baudrate, bytesize=serial.EIGHTBITS,
parity=serial.PARITY_NONE, stopbits=serial.STOPBITS_ONE,
timeout=1)
except serial.SerialException as e:
print(f"[Sender] Failed to open serial port: {e}")
sys.exit(1)

print("[Sender] Serial port ready. Press Ctrl+C to stop.")

counter = 0
while running:
data = bytearray([counter & 0xFF, (counter >> 8) & 0xFF])
ser.write(data)
print(f"[Sender] Sent Data: {data[0]} {data[1]}")
counter += 1
time.sleep(1)

ser.close()
print("[Sender] Closed.")


if __name__ == "__main__":
main()
python3 rs485_sender.py

Receiver: rs485_receiver.py

import serial
import time
import signal
import sys

running = True


def signal_handler(sig, frame):
global running
print("\n[Receiver] Stopping...")
running = False


signal.signal(signal.SIGINT, signal_handler)


def main():
port = sys.argv[1] if len(sys.argv) > 1 else '/dev/ttyTHS1'
baudrate = 9600

print(f"[Receiver] Opening serial port: {port}")
try:
ser = serial.Serial(port, baudrate=baudrate, bytesize=serial.EIGHTBITS,
parity=serial.PARITY_NONE, stopbits=serial.STOPBITS_ONE,
timeout=2)
except serial.SerialException as e:
print(f"[Receiver] Failed to open serial port: {e}")
sys.exit(1)

print("[Receiver] Serial port ready. Press Ctrl+C to stop.")

while running:
data = ser.read(2)
if len(data) == 2:
print(f"[Receiver] Received Data: {data[0]} {data[1]}")
elif len(data) > 0:
print(f"[Receiver] Partial Data: {list(data)}")
else:
print("[Receiver] Timeout - no data")
time.sleep(0.5)

ser.close()
print("[Receiver] Closed.")


if __name__ == "__main__":
main()
python3 rs485_receiver.py

Troubleshooting​

  • No data is being sent or received: Check the wiring and termination resistors. Check the user permissions and serial port parameters such as baud rate, etc.