Python Forum

Full Version: Guidance for how to monitor for a change in a bit state from a hex value
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello,
I am starting to learn Python, but i come from a controls background.
I have a Beaglebone and just for fun i am using a CanOpen interface with a small servo motor.
I have everything working fine but now i am finding i have to code all the normal features i find as standard in a motion controller ! so its getting interesting

The Problem i am working on :

when you start a servo motor for the first time you "send it home" to find zero, during the homing cycle a 'status word' is sent back continually to the control, in my case the beaglebone.

This statusword HEX value has bit 12 and bit 10 set as 0 or 1 dependent on the condition.

bit 12 and bit 10 both = 0 when the homing operation has started. so i cant move forward in the main program, i must Wait until :-
bit 12 and bit 10 are both = 1 when the homing operation has completed successfully. now i can move forward in the program.

for example i might have the following initially Hex = 4227 Dec = 16935 = bin = 100001000100111
on completion of homing it could change to this Hex = 5627 Dec = 22055 = bin = 101011000100111

I am interested to get opinion on how i might best achieve this type of monitoring as i dont need to change any values, only monitor for change.

while this might be totally obvious solution for people, with my current experience level i want to be sure i follow the best methods.
thank you for all guidance / help
There's a pretty good write up of various event systems here: https://stackoverflow.com/a/16192256
I don't like pointing to another forum, but this looks like it has good coverage.
Thank you for this interesting link.

I have also been looking at 'bitflags' would you have any comments on this ?

https://pypi.org/project/bitflag/
It's not anything that I have needed to use, so can't be of much help.