Python-CAN correct way to remove bus instances

108 views Asked by At

I'll preface by saying I'm not strong with python, but have familiarity with CAN libraries in other languages.

I have a thread watching for various devices being plugged in to the host, for example:

        from can.interfaces.ixxat import get_ixxat_hwids
        newHwids = get_ixxat_hwids()
        for hwid in self.deviceIds:
            if (hwid not in newHwids):
                # Clear any hwids that are no longer present
                self.deviceIds.remove(hwid)
                bus = self.activeBuses[0]
                bus.shutdown()
        for hwid in newHwids:
            if (hwid not in self.deviceIds):
                # Add new hwids
                self.deviceIds.append(hwid)
                bus = IXXATBus(0, unique_hardware_id=hwid)
                self.activeBuses.append(bus)

The line bus.shutdown, throws the error: function canControlStart failed (Attempt to send a message to a disconnected communication port.) I can understand that when the device is disconnected from the host, the shutdown function must fail for some reason, the issue is, if I instead try to delete the instance from the list, then the del function of the bus object is called, and within that function the warning LOG.warning("%s was not properly shut down", self.__class__.__name__) is raised and the object attempts to call shutdown() anyways, which also fails.

What is the correct way to remove the bus instance when the device is unplugged?

0

There are 0 answers