network.py Network.disconnect() functions calls the bus.shutdown() then dumps the bus instance (assigns None).
The problem is that in case a PCAN error happens (e.g. you disconnect the bus - but you would like to be robust against disconnected bus) then notifier thread will throw a PcanError exception, in case you would like your code to recover from this situation this could be done like:
while True:
try:
print node.sdo['item']['subitem'].raw
except:
network.bus.reset()
network.disconnect()
network.connect(....)
The problem with this is that if your bus interruption takes longer than the bus reset, reconnect then the connect will fail without exception and in the next cycle the bus.reset() will report "None" type object has no member reset.
Currently my only workaround is:
while True:
try:
print node.sdo['item']['subitem'].raw
except:
try:
network.bus.reset()
except:
pass
try:
network.disconnect()
except:
pass
try:
network.connect(....)
except:
pass
I also tried to just reset the bus using network.bus.reset() but I was not able to (although with PCAN-View it is possible to bring out the device from the
Bus error: an error counter reached the 'heavy'/'warning' limit
I personally would remove either the python self.bus = None or make it part of the connect() function that in case the item exists we could either throw an exception or just simply replace it with the new instace.
network.py
Network.disconnect()functions calls the bus.shutdown() then dumps the bus instance (assigns None).The problem is that in case a PCAN error happens (e.g. you disconnect the bus - but you would like to be robust against disconnected bus) then notifier thread will throw a PcanError exception, in case you would like your code to recover from this situation this could be done like:
The problem with this is that if your bus interruption takes longer than the bus reset, reconnect then the connect will fail without exception and in the next cycle the
bus.reset()will report "None" type object has no memberreset.Currently my only workaround is:
I also tried to just reset the bus using
network.bus.reset()but I was not able to (although with PCAN-View it is possible to bring out the device from theI personally would remove either the
python self.bus = Noneor make it part of theconnect()function that in case the item exists we could either throw an exception or just simply replace it with the new instace.