4.2.14 Modbus
slave_addr=0x0A
starting_address=0x00
register_quantity=100
signed=True
register_value = modbus_obj.read_input_registers(slave_addr, starting_address, registe
r_quantity, signed)
print('Input register value: ' + ' '.join('{:d}'.format(x) for x in register_value))
Write Single Coil
This function code is used to write the state of a discrete coil on a remote device. A value of
means the coil should be set to ON, while a value of
0xFF00
be set to OFF. The Python sample code to set the coil at address
shown below.
slave_addr=0x0A
output_address=0x00
output_value=0xFF00
return_flag = modbus_obj.write_single_coil(slave_addr, output_address, output_value)
output_flag = 'Success' if return_flag else 'Failure'
print('Writing single coil status: ' + output_flag)
Write Single Register
This command is used to write the contents of an analog output holding register on a remote
device. The slave address, the register address, the register value, and the signature of the
data must be specified. As for all the other commands, the register addresses start from 0.
slave_addr=0x0A
register_address=0x01
register_value=-32768
signed=True
return_flag = modbus_obj.write_single_register(slave_addr, register_address, register_
value, signed)
output_flag = 'Success' if return_flag else 'Failure'
print('Writing single coil status: ' + output_flag)
Write Multiple Coils
means the coil should
0x0000
, to an ON state is
0x00
187
Need help?
Do you have a question about the WiPy 3.0 and is the answer not in the manual?
Questions and answers