Author |
Topic |
|
bsamuels
53 Posts |
|
mcmalburg
28 Posts |
Posted - 02 Aug 2008 : 08:06:27
|
Has this been ported to C#? If not, is there any advice on how to perform these functions in C#? |
|
|
ctacke
877 Posts |
|
mcmalburg
28 Posts |
Posted - 02 Aug 2008 : 11:17:15
|
OK - I'm already using a little bit of OpenNetCF in the app. What do I need to do for catching these particular device messages (wake-up, storage device insertion, etc.)? |
|
|
ctacke
877 Posts |
Posted - 02 Aug 2008 : 12:47:19
|
Taking a look at the source (NotificaionMonitor.cpp) is the clearest way to see how to proceed. Queues are created - I don't think the name makes any difference - for receiving the messages like so:
m_storageQueue = CreateMsgQueue(_T("StorageEventWaitQueue"), &options);
The to get storage notifications for example (the power notifications are actually already implemented in the SDF) a call to RequestDeviceNotifications with the queue handle created above is is made providing the storage GUID:
HANDLE notificationHandle = RequestDeviceNotifications(&STORAGE_GUID, instance->m_storageQueue, TRUE);
This you would have to manually P/Invoke this (I don't think it's in the SDF, though I'm not certain).
Once you have that, notifications will come into the queue automagically, so you could do a polling read or use the eventing in the P2PMessageQueue class.
When you're done, be sure to shut down the notifications like the sample does:
StopDeviceNotifications(notificationHandle);
|
|
|
mcmalburg
28 Posts |
Posted - 03 Aug 2008 : 14:47:09
|
OK, I've been digging into this and came across what looks like a simple solution with OpenNETCF. (I just love that OpenNETCF stuff!)
OpenNETCF.WindowsCE.PowerManagement.PowerDown += new OpenNETCF.WindowsCE.DeviceNotification(MyPowerDownFunction); OpenNETCF.WindowsCE.PowerManagement.PowerUp += new OpenNETCF.WindowsCE.DeviceNotification(MyPowerUpFunction);
However, when I look inside the SDF.dll that I downloaded from EuroTech Topic 2164 (DLL version 1.0.2391.23951) I don't see a "WindowsCE" section, nor do I see anything called "DeviceNotification". Are these functions available in a newer SDF.dll (perhaps from the OpenNETCF website)? If so, can I simply use the newer SDF.dll with a BitsyXb?
Thanks,
|
Edited by - mcmalburg on 03 Aug 2008 14:47:29 |
|
|
ctacke
877 Posts |
Posted - 03 Aug 2008 : 15:09:20
|
Yes, the SDF stuff in Topic 2164 is quite dated. I'd recommend getting the latest from the link above - it will work fine with your target device. |
|
|
mcmalburg
28 Posts |
Posted - 04 Aug 2008 : 08:45:03
|
I thought this might be "too good to be true". I've added the above lines (handling the notifications), but my functions aren't getting called. My BistyXb registry has set: VddPwrOffByApps = 1 PowerOffByGPIO1 = 1
What am I missing? Is there a prerequisite function call that "turns on" this OpenNETCF functionality? Or do I just add the two handlers? |
|
|
ctacke
877 Posts |
Posted - 04 Aug 2008 : 10:07:18
|
You're mixing technologies. The OpenNETCF code taps into the OS's power management queue to receive notifications of power state changes. It will not allow you to prevent the device from going to sleep - that's a Eurotech-specific feature (and a really useful one). You need to catch the named system event that the Eurotech driver is spitting out when the PWROFF GPIO is grounded. Unfortunately the CF has no buit-in mechanism for named system events. The SDF does in the form of the EventWaitHandle. You can create it with the name your platform uses for that event and then call WaitOne() on it. |
|
|
mcmalburg
28 Posts |
Posted - 04 Aug 2008 : 11:16:35
|
OK, I really appreciate the time you are spending working me through this.
Here's the bottom line: I'm using a BistyXb, I need to intercept the power button so that I can shutdown a couple of subsystems. When the power button is pressed again (bringing the system back to life), I need to capture this so that I can re-power the subsystems and restore communications with them.
What C# (.NET) approach is recommended for catching the user pusing the red button "turning off the system" and what approach is recommended for the user pushing the red button "turning on the system"?
I like the simple functionality of "OpenNETCF.WindowsCE.PowerManagement.PowerDown" and "OpenNETCF.WindowsCE.PowerManagement.PowerUp". However, these functions don't seem to be working (i.e. not getting called by my system).
|
|
|
ctacke
877 Posts |
Posted - 04 Aug 2008 : 11:34:26
|
The OpenNETCF functions should be working, but you would likely only get both events at power up. This is becasue the power down event gets queued, but the device suspends before your software has any opportunity to run a handler. When you resume, the handler continues running and processing it. The OS requirement for this to work is the power manager, which IIRC all off-the-shelf Eurotech images have (if it's not there, the DeviceManagement class has another notification that might work as well).
If you want to prevent the shutdown until after you've done some work, you need to use the Eurotech feature you've described above and an EventWaitHandle. This would give you the hook into that piece. Your handler would do the work, then call the system API to actually suspend. For capturing wake, you would just use the OpenNETCF function.
To be any more detailed, I'd have to get my BitsyXb development system out and write some code. If you're interested in that, feel free to contact me offline. |
|
|
|
Topic |
|