Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
olili opened this issue May 14, 2023 · 6 comments
Open

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

olili opened this issue May 14, 2023 · 6 comments

Comments

@olili
Copy link

olili commented May 14, 2023

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
Copy link
Author

olili commented May 16, 2023

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
Copy link
Owner

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
Copy link
Author

olili commented May 16, 2023

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
Copy link
Owner

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
Copy link
Author

olili commented May 16, 2023 via email

@olili
Copy link
Author

olili commented Sep 17, 2023

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants