pyhys / minimalmodbus

Easy-to-use Modbus RTU and Modbus ASCII implementation for Python.
Apache License 2.0
309 stars 145 forks source link

No answer #96

Closed Grandpa-G closed 1 year ago

Grandpa-G commented 1 year ago

I am getting this error on both read and writes periodically, but almost always. Using a Rpi4 bullseye. I know the device works fine on a windows application. Where do I go from here?

  self.box.write_register(registeraddress=switchChange-1, value=1, number_of_decimals= 0, functioncode= 16, signed= False)
  File "/usr/local/lib/python3.9/dist-packages/minimalmodbus.py", line 550, in write_register
    self.box.write_register(registeraddress=switchChange-1, value=1, number_of_decimals= 0, functioncode= 16, signed= False)
  File "/usr/local/lib/python3.9/dist-packages/minimalmodbus.py", line 550, in write_register
    self._generic_command(
  File "/usr/local/lib/python3.9/dist-packages/minimalmodbus.py", line 1245, in _generic_command
    self._generic_command(
  File "/usr/local/lib/python3.9/dist-packages/minimalmodbus.py", line 1245, in _generic_command
    payload_from_slave = self._perform_command(functioncode, payload_to_slave)
  File "/usr/local/lib/python3.9/dist-packages/minimalmodbus.py", line 1322, in _perform_command
    payload_from_slave = self._perform_command(functioncode, payload_to_slave)
  File "/usr/local/lib/python3.9/dist-packages/minimalmodbus.py", line 1322, in _perform_command
    response_bytes = self._communicate(request_bytes, number_of_bytes_to_read)
  File "/usr/local/lib/python3.9/dist-packages/minimalmodbus.py", line 1490, in _communicate
    response_bytes = self._communicate(request_bytes, number_of_bytes_to_read)
  File "/usr/local/lib/python3.9/dist-packages/minimalmodbus.py", line 1490, in _communicate
    raise NoResponseError("No communication with the instrument (no answer)")
minimalmodbus.NoResponseError: No communication with the instrument (no answer)
    raise NoResponseError("No communication with the instrument (no answer)")
minimalmodbus.NoResponseError: No communication with the instrument (no answer)
ccall48 commented 1 year ago

I periodically got that error but never dug too deep into it.

There are a few things you can try, you could add your code to try except block with a pass so your code ignores this exception and continues (obviously not best practice) if you wish use the logging module to log the error/exception however iirc that is the exception No communication with the instrument (no answer).

For me it might have been triggered a few times a day to maybe once or twice a week on the few devices that I was polling every 5~10 minutes.

you could also try closing the serial port after each call to true if you're not already and see if this helps you a little.

on a physical level you could double check your cabling, device and or ttl adaptor you're using one for correct setup.

Grandpa-G commented 1 year ago

Thanks, but this happens almost every time after the first success. I am using the same cables as windows. I done the debug, and that is what I got as I posted. Ignoring is not an option.

So far I have moved to pyModBus and it is working.

pyhys commented 1 year ago

Closing due to inactivity Please reopen if necessary