How to control(on/off) the relay in Modbus RTU on the RS-485 model using python

499 views Asked by At

I am the begginer for python and rs-485. Currently I'm working on Modbus RTU protocol in RS-485, and I read and write data from read_holding_resister using python. Also, I need to control rs-485 relay using a python script. Thank you

Sample code

import serial
conn = serial.Serial(
port='/dev/ttyUSB0',
baudrate=9600,
parity=serial.PARITY_NONE,
stopbits=serial.STOPBITS_ONE,
bytesize=serial.EIGHTBITS,
timeout=1,
rtscts=False, 
dsrdtr=False)
while True:
   dataline = conn.readline();
   serialcmd = b'\x08';
   conn.write(serialcmd)
0

There are 0 answers