我正在尝试使用 Python 将 1 位从我的电脑(192.168.0.2)发送到西门子网络输入(IP:192.168.0.11:504)。但我无法让它工作。目标是通过 modbus 连接发送位来触发 BO31 条件。
我的 Python 代码:
import socket
from umodbus import conf
from umodbus.client import tcp
# Enable values to be signed (default is False).
conf.SIGNED_VALUES = True
### Creating connection
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.connect(('192.168.0.11', 504))
message = tcp.write_multiple_coils(slave_id=1, starting_address=1, values=[1, 0, 0, 0])
# Response depends on Modbus function code. This particular returns the
# amount of coils written, in this case it is.
response = tcp.send_message(message, sock)
print(response)
sock.close()
print("Transfer finished")