How to write to PLC input registers using pymodbus

。_饼干妹妹 提交于 2019-12-05 21:33:39

Input registers are read-only. You can write to holding registers, using Modbus functions Write Single Register or Write Multiple Registers (ModbusTcpClient.write_register or ModbusTcpClient.write_registers in pymodbus).

Example using a Festo MODBUS/TCP:

# First digital input address
address = 40003
# Written value
value = 255

# It will send '11111111' to the output 
client.write_register(address, value)

According to the documentation:
http://pymodbus.readthedocs.org/en/latest/library/sync-client.html

// function
write_register(address, value)
// Parameters
address – The starting address to write to
value – The value to write to the specified address

PLC's have a dedicated set of registers for you to read and a set for you to write to. The set of write registers differ by PLC. You read registers, for instance could start on register "1". You read from "1" but not write. You'll have to look up the modbus register mapping for your PLC.

My knowledge of Python is low, but it appears that you are trying to read up to 5 registers, starting with 1? To write, you probably need to use

reg = client.write_output_registers(?,??)

I usually use a Wago 880. I can write to registers 0-999 and read from 1000-1999. I am assuming Python would take care of the function code for you.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!