corbinbs / solarshed

A Python library to help monitor solar charge controllers typically used in off the grid applications.
MIT License
86 stars 25 forks source link

Removed minimalmodbus constants, added default constructor arguments #10

Closed limweichiang closed 3 years ago

limweichiang commented 4 years ago

Removed unsupported module-level constants for BAUDRATE and TIMEOUT, instead using default arguments in the constructor to initialize the values for use on the pyserial object.

This change took effect as of MinimalModbus 1.0 which the RenogyRover class inherits, refer to https://minimalmodbus.readthedocs.io/en/stable/usage.html#default-values

Before fixing, the following error was encountered:

$ python3 renogy_rover.py 
Traceback (most recent call last):
  File "renogy_rover.py", line 185, in <module>
    print('Model: ', rover.model())
  File "renogy_rover.py", line 41, in model
    return self.read_string(12, number_of_registers=8)
  File "/home/ubuntu/.local/lib/python3.8/site-packages/minimalmodbus.py", line 751, in read_string
    return self._generic_command(
  File "/home/ubuntu/.local/lib/python3.8/site-packages/minimalmodbus.py", line 1170, in _generic_command
    payload_from_slave = self._perform_command(functioncode, payload_to_slave)
  File "/home/ubuntu/.local/lib/python3.8/site-packages/minimalmodbus.py", line 1240, in _perform_command
    response = self._communicate(request, number_of_bytes_to_read)
  File "/home/ubuntu/.local/lib/python3.8/site-packages/minimalmodbus.py", line 1406, in _communicate
    raise NoResponseError("No communication with the instrument (no answer)")
minimalmodbus.NoResponseError: No communication with the instrument (no answer)
limweichiang commented 4 years ago

Sorry for the messy PRs, I'm kinda getting used to collaborating on code using git, and should keep my branches cleaner. Please do review https://github.com/corbinbs/solarshed/pull/9 first, as the fix there should precede this.