Page 1 of 1

How do I make sense of constant's lookup numbers

Posted: Wed Apr 06, 2022 12:35 am
by ilium007
Not sure if I have worded this correctly but I am not sure how to look up constant's values. ie.

Code: Select all

>>>
>>> can1.state()
2
>>>
>>>
>>> can1.
any             send            BUS_OFF         ERROR_ACTIVE
ERROR_PASSIVE   ERROR_WARNING   LIST16          LIST32
LOOPBACK        MASK16          MASK32          NORMAL
SILENT          SILENT_LOOPBACK                 STOPPED
clearfilter     deinit          info            init
initfilterbanks                 recv            restart
rxcallback      setfilter       state
>>>
>>>
>>>
In the CAN class CAN.state() returns a value relating to the bus state. These state values are constants that relate to a one of 5 states

CAN.STOPPED
CAN.ERROR_ACTIVE
CAN.ERROR_PASSIVE
CAN.ERROR_WARNING
CAN.BUS_OFF

How do I know which state relates to the integer return from CAN.state()?

Re: How do I make sense of constant's lookup numbers

Posted: Wed Apr 06, 2022 11:31 am
by Shards
You can simply print the constants to find their values. However, it's not something you would normally need to do. Presumably you are examining the state to take appropriate action, so you will do something like:

Code: Select all

If can1.state() == CAN.STOPPED :
    Do something
If can1.state() == CAN.ERROR_PASSIVE:
    Do something else
It's then clear what you are doing and should the implementation change it won't fall over. Odd that all the states are in the 'bad things category' but then I have no idea what CAN does.

Re: How do I make sense of constant's lookup numbers

Posted: Wed Apr 06, 2022 12:29 pm
by ilium007
ahh ok, got it. I was looking at it all from the wrong side!

Re: How do I make sense of constant's lookup numbers

Posted: Wed Apr 06, 2022 12:33 pm
by ilium007
Shards wrote:
Wed Apr 06, 2022 11:31 am
I have no idea what CAN does.
CANbus is a physical layer protocol for communications between microcontrollers / devices. It's widely used in automotive applications / industrial applications to allow devices to talk in 'noisy' environments over just two wires.

I am building a project to allow microcontrollers to talk between themselves using a simple messaging protocol. The end goal is to control a model railway and have all the control panel inputs communicating with speed controllers, railway points, lights etc all over CANbus.
camphoto_579758561.JPG
camphoto_579758561.JPG (187.97 KiB) Viewed 2698 times

Re: How do I make sense of constant's lookup numbers

Posted: Wed Apr 06, 2022 5:06 pm
by scruss
ilium007 wrote:
Wed Apr 06, 2022 12:33 pm
... The end goal is to control a model railway and have all the control panel inputs communicating with speed controllers, railway points, lights etc all over CANbus.
That sounds like a really impressive project. CAN would be the perfect networking technology for this: cheap and robust.

Re: How do I make sense of constant's lookup numbers

Posted: Sun May 08, 2022 8:06 pm
by Le fond du garage
super project.

i will make a project to talk with theVESC over CAN.

can you post part of your code please to see how you make simple com between µc in CAN?

regards.