Skip to main content

RS485

Hardware

One RS485/RS422 bus is integrated into the AutomatePro with a max data rate of 500kbs. A 120ohm termination resistor should be placed between RS485P and RS485N at both ends of the RS485 network.

Connector Pinout

RS485 Specifications

ParameterValue
TransceiverTHVD1400DR
Data Rate500 kbps
RS485 StandardTIA/EIA-485A
DuplexHalf

Software

Serial Port

/dev/ttyTHS1 is the serial port used for RS485 communication. RTS pin is used to control the direction of the transceiver. RTS is inverted and active low, RTS high enables the receiver and RTS low enables the transmitter.

Example

  import serial
import serial.rs485
import time

# Configure the serial connections
ser = serial.rs485.RS485(
port='/dev/ttyTHS1',
baudrate=115200, # Set your baud rate
parity=serial.PARITY_NONE,
stopbits=serial.STOPBITS_ONE,
bytesize=serial.EIGHTBITS,
timeout=0.1 # Timeout for read operations
)

ser.rs485_mode = serial.rs485.RS485Settings(
rts_level_for_tx=False,
rts_level_for_rx=True,
)
def send_data(data):
ser.write(data.encode())
print("Sent:", data)

def receive_data():
incoming_data = ser.read(100) # Read up to 100 bytes or until timeout
if incoming_data:
print("Received:", incoming_data.decode()) # Decode bytes to string

if __name__ == '__main__':
try:
while True:
send_data("Hello RS485")
time.sleep(1) # Wait a bit for a response
receive_data()
except Exception as e:
print("An error occurred:", str(e))
finally:
ser.close() # Always close the serial port

Troubleshooting

  • No data is being sent or received: Check the wiring and termination resistors. Check the user permissions and serial port parameters such as baudrate, etc.
  • Data is being sent but not received: Check whether the RTS pin is toggled correctly. RTS should be high to recieve data.
  • Data is being received but not sent: Check whether the RTS pin is toggled correctly. RTS should be low to send data.

If you are using terminal emulators such as picocom, toggle the RTS pin manually using the commands offered by the terminal emulator.