Monday, March 30, 2009

Vault-OS : IPC and Shared Memory

Embedded programming under Windows operating systems is a closed shop. The correct way to approach the problem is a trade secret and those who know are on the inside. I know because as an outsider I have followed the Microsoft recommended methods and have been chasing my own tail in a circle for months. Every single scheme I have come up with to monitor I2C in real-time has started to slow down when I began loading more devices and sharing the data with more applications. Ask the pros how it is "really done" for all these SCADA systems running Windows NT in factories and for assembly line machines and they'll give you the shifty eyes and weird smirks. It's a secret and it's not widely available to newbies.

This is what I have figured out with the help of some articles on the Code Project.

1. You must run your I2C driver as a Windows service on startup. OWFS or OWHTTP are best in the background.

2. Use IPC (Inter Process Communication) to share the data with all other applications in a general pool. Don't use named pipes. They're ridiculously slow and they crash on a dime.

3. Use a shared memory data structure available through a mutex to make the Windows Service data available to all running applications.

4. Your applications will have to access the shared memory structure without conflicts, which is best done through semaphores and raising events.

If you get this running correctly, it will fly like a bat out of hell and you will have a real-time operating system under Windows monitoring a network of I2C sensors and never missing a beat in reaction time or data updates.

With 12 devices, this is the first arrangement I have had with no slowdown. It entails a rewrite of some of my applications in their interfacing to the data but they are all basically zero-lag now and can look into the shared memory structure at any time.

The first "application" I am trying to get running on top of this service is a totally independent marquee scroller, an adjustable window band, that displays configured sensors in real time all the time with no lags or hitches. I want to make it configurable with things like ...


... scrolling by on the marquee band day and night.


Anonymous said...

Tex, I do not kid >>> have something to show at the end of april. Im dying to see even what you describe working it would be very useful to everybody. I can guess where youre going with this. If you make it open source others can work on it and help you with it. Good job and keep it up. End of april post what you have.

Anonymous said...

The Christmas travel plans of thousands of are in disarray after snow left Heathrow Airport all but shut. Thousands have been forced to sleep overnight in airports and there is disruption to road and rail travel with the Met Office warning of more snow ...