bohdan-s / SungrowModbusWebClient

Access Modbus RTU via API call to Sungrow WiNet-S
GNU General Public License v3.0
17 stars 6 forks source link

SH8.0RT "write holding register" supported? #4

Open olili opened 1 year ago

olili commented 1 year ago

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 1 year ago

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.

bohdan-s commented 1 year ago

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 1 year ago

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.

bohdan-s commented 1 year ago

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 1 year ago

Thx for information and your great work in the WebClient.

If you need an alpha tester for Web Client with "write support", I'm ready.

O.

Am 2023-05-16 10:23, schrieb bohdan-s:

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.

-- Reply to this email directly, view it on GitHub [1], or unsubscribe [2]. You are receiving this because you authored the thread.Message ID: @.***>

Links:

[1] https://github.com/bohdan-s/SungrowModbusWebClient/issues/4#issuecomment-1549218616 [2] https://github.com/notifications/unsubscribe-auth/AJ5KIIZQSIM7PHOAGAGXPRTXGM2OTANCNFSM6AAAAAAYBFQYA4

olili commented 9 months ago

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