We tried to implement the write/set functionality in the intermediary, however, the following line of code fails to write the values to the register. After numerous attempts to solve the issue on our own, we still couldn't succeed. We had also applied @robin-schoch's changes, which didn't make any difference as well.
Current code and its output:
# Code
builder = PayloadBuilder(byteorder=order, wordorder=order)
print(f"Value to be written: {value} {data_type}")
builder.encode(value, data_type, rounding=RoundingScheme.floor)
print("PayloadBuilder state before writing to registers:", builder)
self.client.write_registers(address=addr, values=builder.to_registers(), unit=slave_id)
# Output:
Setting value for 1.EMS_Current_Limit.EMSCurrentLimit: 5.9
Value to be written: 5.9 float32
ERROR:root:An unexpected error occurred while writing value to register: PayloadBuilder.encode() missing 3 required positional arguments: 'value', 'modbus_type', and 'rounding'
Traceback (most recent call last):
File "/home/dmytro/documents/projects/SGrIntermediary/sgr/sgr_library/modbus_client.py", line 107, in value_encoder
print("PayloadBuilder state before writing to registers:", builder)
File "/home/dmytro/documents/projects/SGrIntermediary/venv/lib/python3.11/site-packages/pymodbus/payload.py", line 91, in __str__
return self.encode().decode("utf-8")
^^^^^^^^^^^^^
TypeError: PayloadBuilder.encode() missing 3 required positional arguments: 'value', 'modbus_type', and 'rounding'
Description
We tried to implement the write/set functionality in the intermediary, however, the following line of code fails to write the values to the register. After numerous attempts to solve the issue on our own, we still couldn't succeed. We had also applied @robin-schoch's changes, which didn't make any difference as well.
Current code and its output:
Link to the line in the latest version on github:
https://github.com/SmartGridready/SGrPython/blob/71f51ed8f5d92a6c5212029bec74d214be8e2f73/sgr_library/modbus_client.py#L103
How to reproduce
or
sgr-write
python main.py
(Venv used) (instructions)Create Instance
request 3.2 Write it withWrite Instance Data
The usage of the SGrPython
write
in the set endpoint: https://github.com/SmartGridready/SGrIntermediary/blob/6c81bf994d4aec57ce24b976cd9046d6f2ca615a/main.py#L173Postman collection: SGrIntermediary.postman_collection.json