读写Modbus RTU

问题描述 投票:0回答:1

我正在使用minimalmodbus进行读写。我有USB到Rs485的连接。

我正在尝试将此“ 02 05 0000 ff11”写入python中的RTU寄存器,但出现错误。这是我的代码。

设备地址: 02

功能代码: 05

注册地址: 0000

值: ff00

 import minimalmodbus
 instrument = minimalmodbus.Instrument('COM4', 1)
 instrument.write_register(02, 05, 0000, ff00)

[我需要使用python在上面的代码中具有相同的功能!

I need this functionality in Python script

python-3.x iot modbus
1个回答
0
投票

您正在混合一些设置。

Modbus从站地址(在您的情况下为2)应包含在仪器的实例中:

instrument = minimalmodbus.Instrument('COM4', 2)

并且您用于write_register函数的参数也是错误的,它们应该是:

instrument.write_register(0, 0xff00)

如您所见,write_register仅采用两个参数:寄存器号和要在其中读取的值。

[the code和/或some examples可能是个好主意。

© www.soinside.com 2019 - 2024. All rights reserved.