How to verify if the bus is shut down properly. Because the bus.shutdown() method of the python-can library returns None.
I am using python-can version 4.4.0 on my windows 11 machine.
The latest python-can library contains only three states for a bus those are ACTIVE, PASSIVE and ERROR.
Hence I don’t know if I can use the state of the bus to identify if the bus is shutdown or not.
I verified the state of the bus after it was shut down the state was still ACTIVE as the bus was initialized earlier at the beginning with an active state with the following python statement:
from can import * bus = interface.Bus(interface='pcan', channel=USBChannel, bitrate=BaudRate, state=bus.BusState.ACTIVE)
I have embedded python code in c code which is making the bus shutdown and I want to ensure that the bus is shutdown then only I can continue with my next code.
Is there a way to ensure that a bus is shutdown or not in python-can library?
Hello @JamesParrott that’s what I want to know. Because bus.shutdown() method does not return any value which would give me an indication. Earlier there used to be an OFF state in the bus.state now that is also not there hence I am confused what to look for?
Asking the general python community here is probably not going to lead to helpful answers unless a domain expert happens to stumble across this question. Better ask the maintainers of python-can, or maybe over on stackoverflow.
@JamesParrott secondly the state of the bus remains ACTIVE even after shutting it down it does not change to PASSIVE. I have confirmed that. Because originally it has been set to ACTIVE.
There is no general way to check if a Bus object is shut down in python-can, because python-can is a wrapper around several drivers which handle this differently. Some drivers provide no feedback on device state after a shutdown command.
For the specific case of PCAN devices, bus shutdown can be verified with
import can
bus = can.Bus(interface="pcan")
bus.shutdown()
assert bus.status & can.interfaces.pcan.basic.PCAN_ERROR_BUSOFF