modbus_add_rw_signal(IP, slave_number, read_address, read_register_count, write_address, write_register_count, signal_name, sequential_mode=False)
Adds a new modbus signal for the controller to supervise. This function will use the function code 23. The read and write addresses can overlap. Until the first set_output_register() command the function code will be 3, after the call it will switch to 23.
>>> modbus_add_rw_signal("172.140.17.11", 255, 5, 10, 15, 10, "output1")
>>> modbus_add_rw_signal("localhost:1122", 255, 5, 10, 15, 10, "output1")
Parameters
IP: A string specifying the IP address / hostname of the Modbus unit to which the Modbus signal is connected. The IP can not be empty. Optionally, the target port number can be specified by using ':'. The default port is 502.
slave_number: An integer normally not used and set to 255, but is a free choice between 0 and 255.
read_address: An integer specifying the address of the first register that this new signal should read from.
read_register_count: Number of registers to read [1-123].
write_address: An integer specifying the address of the first register that this new signal should write to.
write_register_count: Number of registers to write [1-123].
signal_name: A string uniquely identifying the signal. If a string is supplied which is equal to an already added signal, the new signal will replace the old one. The length of the string can not exceed 20 characters. The signal name cannot be empty.
sequential_mode: Setting to True forces the Modbus client to wait for a response before sending the next request. This mode is required by some fieldbus units (Optional).
Example command: modbus_add_rw_signal("172.140.17.11", 255, 5, 10, 15, 10 "output1")
This example will create a signal that cyclically reads 10 registers from addresses 5-14, an writes 10 registers to addresses 10-19 Signal will use Function Code 3 to read register until first time modbus_set_register_output(...) is called. Afterwards Function Code 23 will be used to both read and write registers in remote device.
- Example Parameters:
- IP address = 172.140.17.11
- Slave number = 255
- Signal read address = 5
- Signal read register count = 10
- Signal write address = 15
- Signal write register count = 10
- Signal name = output 1