pikapython/test/python/modbus/rtu_master.py

22 lines
510 B
Python
Raw Normal View History

2022-09-19 13:27:20 +08:00
import modbus
mb_tcp = modbus.ModBusRTU(128, 128)
mb_tcp.setSlave(1)
send_buff = mb_tcp.serializeReadRegisters(0, 10)
2022-09-19 14:38:12 +08:00
print(send_buff)
2022-09-19 13:27:20 +08:00
host_regists = mb_tcp.deserializeReadRegisters(
b'\x01\x03\x14\x00\x00\x00\x00\x04\xD2\x00\x00\x00\x00\x00\x7B\x00\x00\x00\x00\x00\x00\x00\x00\xE5\x0B'
)
2022-09-19 14:38:12 +08:00
print(host_regists)
2022-09-19 13:27:20 +08:00
2022-09-19 14:38:12 +08:00
2023-02-10 11:07:25 +08:00
mb_tcp.serializeReadInputRegisters(0, 2)
mb_tcp.deserializeReadInputRegisters(b'\x01\x04\x04\x00\x00\x08\xE6\x7D\xCE')
2022-09-19 14:38:12 +08:00
send_buff = mb_tcp.serializeWriteRegister(0, 0x1234)
2022-09-19 13:27:20 +08:00
print(send_buff)