modbus-tk
modbus-tk copied to clipboard
Poor quality of communications
I am using modbus tk to simulate a slave on a raspberry pi with the following code: `import modbus_tk import modbus_tk.defines as cst from modbus_tk import modbus_rtu import serial import time
PORT = "/dev/ttyUSB0"
def main(): """main""" #Create the server server = modbus_rtu.RtuServer(serial.Serial(PORT,baudrate=9600,bytesize=8,parity='N', stopbits=1)) t = 32
try:
server.start()
slave = server.add_slave(8)
slave.add_block('0', cst.HOLDING_REGISTERS, 0, 10)
slave.set_values('0', 0, [t, 87, 255, 0, 1, 0, 1, 1,22])
while True:
values = slave.get_values('0', 0, 10)
print('values read: %s\r\n' % (str(values)))
print("wait for a while...")
time.sleep(1)
finally:
server.stop()
if name == "main":
main()
Use modbus poll at the PC to simulate the master reading and writing to the slave registers.
However, the quality of communications has been poor, with a ratio of successful communications to communications timeouts of about 2 to 1.
Please point out my problem or include it in the next version of the upgrade!