bohdan-s/SungrowModbusWebClient

SH8.0RT "write holding register" supported?

Opened this issue · 6 comments

olili commented

I tried to write to to holding register via SungrowModbusWebClient 0.3.2 and modified Modbus4mqtt.
Reading input and holding registers is working like a sharm
But writing to holding registers throws an error like attached.
Any hint? O.

2023-05-14 13:37:54 ERROR Failed to write to modbus device: cannot access local variable 'param_type' where it is not associated with a value
Traceback (most recent call last):
File "/modbus4mqtt/modbus_interface.py", line 234, in _process_writes
self._mb.write_register(addr, value, unit=0x01)
File "/usr/local/lib/python3.11/site-packages/pymodbus/client/common.py", line 92, in write_register
return self.execute(request)
^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/pymodbus/client/sync.py", line 109, in execute
return self.transaction.execute(request)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/pymodbus/transaction.py", line 174, in execute
response, last_exception = self._transact(
^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/pymodbus/transaction.py", line 274, in _transact
size = self._send(packet)
^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/pymodbus/transaction.py", line 309, in _send
return self.client.framer.sendPacket(packet)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/pymodbus/framer/init.py", line 41, in sendPacket
return self.client.send(message)
^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/pymodbus/client/sync.py", line 78, in send
return self._send(request)
^^^^^^^^^^^^^^^^^^^
File "/modbus4mqtt/SungrowModbusWebClient_patched.py", line 136, in _send
logging.debug("param_type: " + str(param_type) + ", start_address: " + str(address) + ", count: " + str(count) + ", dev_id: " +str(dev_id))
^^^^^^^^^^
UnboundLocalError: cannot access local variable 'param_type' where it is not associated with a value

olili commented

in addition to my post before.
With the following sample script you can comprehend the bahaviour:

from pymodbus.client.sync import ModbusTcpClient, ModbusSocketFramer
from SungrowModbusWebClient import SungrowModbusWebClient
#import my_SungrowModbusWebClient as SungrowModbusWebClient
import logging
logging.basicConfig()
logging.getLogger().setLevel(logging.DEBUG)

client`` = SungrowModbusWebClient.SungrowModbusWebClient(host="172.23.23.31", port=8082, framer=ModbusSocketFramer, timeout=3, RetryOnEmpty=True, retries=1)
success = client.connect()
client.write_register( 13003, 1, unit=1 )

As told before wrt to Reading Holding Registers:

read = client.read_holding_registers( 13003, 1, unit=1 )
print( read.registers[0] )

is working perfectly.

Sorry. No idea my current client does not support writing registers. Without knowing what you have patched to make it work I am not sure?
I have write ability coming in a release I’m working on.

olili commented

Thx. I used your original verison.

" No idea my current client does not support writing registers."

Does this mean that your WebClient does not support "write_register" at all?

This information I have not found/read before. I was not aware.

Sorry,
Yes the http layer is overriding the pymodbus package to pretend to be modbus.
It's really just logging into the web interface as admin and using the general parameters page.
The writing component on the webui is on a different page so wasn't implemented originally.
I currently have an alpha build with write ability I am playing with before pushing.

olili commented
olili commented

@bohdan-s is there any news on a WebClient with Write-Support? I'm stll eger to alpha test.