python-can icon indicating copy to clipboard operation
python-can copied to clipboard

Handling cantimeout exception

Open Onizuka09 opened this issue 2 years ago • 2 comments

I have written a code that receives a message for certain timeout, if the timeout exceeds and no message was sent it raises the CanTimeoutError flag. when i ran the program, the exception doesn't get executed. this is the code i wrote

import can

with can.Bus(interface="socketcan", channel="vcan0") as bus:
    try:
        msg=bus.recv(1)
        print(msg)
    except can.CanTimeoutError:
        print("timeout exceeded")

Does someone have any idea how to resolve this issue ?

Onizuka09 avatar Mar 30 '23 15:03 Onizuka09

i have read the docs, I know that the message returns None when it times out or if no messages were sent,
does returning none mean i can't raise a CanTimeoutError exception. i just want to know how to use the CanTimeoutError.

Onizuka09 avatar Mar 30 '23 15:03 Onizuka09