Created
April 30, 2025 16:07
-
-
Save sourceperl/a56f3e0760022526938f438a2fefc86a to your computer and use it in GitHub Desktop.
Test of the RevPi Connect 4 RS485 interface with python serial.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
from serial import Serial | |
from serial.rs485 import RS485Settings | |
# Configure the serial port with RS485 settings (with RTS level set for tx and rx) | |
s = Serial(port='/dev/ttyRS485', baudrate=9600, bytesize=8, parity='N', stopbits=1) | |
s.rs485_mode = RS485Settings(rts_level_for_tx=False, rts_level_for_rx=True) | |
try: | |
while True: | |
c = s.read(1) | |
if c: | |
print(c) | |
msg = b'rx: ' + c.upper() + b'\r\n' | |
s.write(msg) | |
except KeyboardInterrupt: | |
pass |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment