I'm reading from an object the correct registers value
from pymodbus.payload import BinaryPayloadDecoder
from pymodbus.payload import BinaryPayloadBuilder
from pymodbus.client.sync import ModbusSerialClient as ModbusClient
class modbusRW(object):
def init(self):
self.client = ModbusClient(
method=self.method,
port=self.port,
parity='N',
stopbits=self.stopbits,
bytesize=self.bytesize,
baudrate=self.baudrate,
timeout=self.timeout)
def read(self):
modbus_address = 41023
modbus_count = 10
modbus_unit = 1
e = 0
time.sleep(constant.modbus_connection_delay)
self.connect()
result = self.client.read_holding_registers(
modbus_address,
count=modbus_count,
unit=modbus_unit)
decoder = BinaryPayloadDecoder.fromRegisters(
result.registers, wordorder=Endian.Little, byteorder = Endian.Big)
self.close()
e = { 'Counter 1': decoder.decode_32bit_float(),
'Counter 2': decoder.decode_32bit_float(),
'Counter 3': decoder.decode_32bit_float(),
'Counter 4': decoder.decode_32bit_float(),
'Counter 5': decoder.decode_32bit_float()}
now I'm trying to write a value (0.0) on the same address (only counter 1)
def write(self):
modbus_address_reset = 41023
modbus_count = 2
modbus_unit = 1
modbus_reset_value = 0.0
builder_reset = BinaryPayloadBuilder(wordorder=Endian.Little, byteorder = Endian.Big)
builder_reset.add_32bit_float(modbus_reset_value)
payload_reset = builder_reset.build()
time.sleep(constant.modbus_connection_delay)
self.connect()
result_reset = self.client.write_registers(
address= modbus_address_reset,
values= payload_reset,
count = modbus_count,
unit = modbus_unit)
self.close()
but the code goes to error...
**required argument is not an integer**
what wrote I wrong?
thank for your help
I'm expecting to write the same holding register. On the code I wrote only the highlights of the object class
To test, I got the same error also if I try to execute the code below (write a single register)
result_reset = self.client.write_register(41023, 0, unit=1)
If I add skip_encode = True like parameter on write registers function, everything working fine
result_reset = self.client.write_registers(
address= modbus_address_reset,
values = payload_reset,
count = modbus_count,
unit = modbus_unit,
skip_encode = True)