How to write PLC input registers using pymodbus
I want to write to PLC input registers using pymodbus. I can read them:
from pymodbus.client.sync import ModbusTcpClient
client = ModbusTcpClient('10.10.10.32')
client.connect()
reg = client.read_input_registers(1,5)
print(reg.registers)
But I still haven't found a way to write them any value. I appreciate any help. Thank you.
The PLC has a special set of registers for reading and a set for writing. The set of write registers is different from that of a PLC. You are reading registers, for example, may start with register "1". You read "1" but you don't write. You will need to match the Modbus register for your PLC.
My knowledge of Python is low, but it seems like you are trying to read up to 5 registers starting at 1? To write, you probably need to use
reg = client.write_output_registers (?, ??)
I usually use Wago 880. I can write to registers 0-999 and read from 1000-1999. I am assuming Python will take care of the functional code for you.
source to share
Example of using 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 - starting address for writing to
value - Value for writing to the specified address
source to share