I'm hoping someone here can share a sample of Python code showing how to handle events from a Digital Input on an interface kit. My application is pretty basic - I want to log time/date when a digital input changes state. I've looked at the sample code ("Interface kit-simple.py") but my Python skills are not sufficient to figure out how to make it work.
I'm a bit new to both phidgets and python, but have recently thrown myself into it so I'll try at an answer....
The key process handling the change events of the input in the sample code is with the function interfaceKitInputChanged. That function was setup as an event handler in the main program code with:
@pmpaq,
Thanks. This is a big help. I made good progress over the weekend, and will post back here when I have something working. I've run into a glitch handling signals (for example, a Ctrl-C, to exit from an endless loop). I'm going to report it in another thread so as not to hijack this one...
@freshmeat,
Attached is the little Python program I wrote (my first).
It monitors the operation of a dual-stage furnace and records outdoor temperature by reading 2 digital inputs and 1 analog input from a Phidgets I/O card.
The program is very simple, and is based on the Phidgets InterfaceKit sample from the website. Instead of using event handlers (i.e., interrupt-driven operation), I structured the program as an endless loop (while True:…) which sleeps for 60 seconds, checks the two inputs, logs any changes, then goes back to sleep.
The only problem I ran into was getting a ctrl-C to cleanly break out of the endless loop so the log files could be closed, etc. Ms. Google indicated I could do this using signals, but my first attempts were unsuccessful. I reached out to Phidgets for help. Patrick there recommended putting the signal.signal call (which hooks the SIGINT ctrl-C handler) after the call to waitForAttach. Initially, I had positioned it up near the top of the program, but that didn’t work.
I always intended to go back and re-write the program using the event handlers, but never did. The program works fine - it's been running 7x24 for many many months on an old Mac mini.
Good luck with your Phidgets project!
You do not have the required permissions to view the files attached to this post.