Closed jmmgenerac closed 2 years ago
On further exploration, it appears there may be another issue: if this is fixed in the way that I proposed, each subsequent call to scan() adds an additional instance of each model to the Device's models
dict.
I think a possible fix is to create a delete_models() function in the Device class that clears models and model_list, and on a scan in the Modbus client, delete_models() should be called and base_addr set to None before starting the scan. In the file client, delete_models() should be called before starting the scan.
When calling scan() a second time, there is no modbus traffic and the following exception arises:
This appears to be related to the assumption that the the
data
variable has been populated during the base_addr search. However, ifself.base_addr
has been found on the previous call toscan()
, thedata
variable contains the empty string on the subsequent call. This causesstruct.unpack()
to throw the exception. This might be resolved easily by simply performing the base_addr search regardless of the pre-existing value ofself.base_addr
. I.e., removing this optimization.