All Forums
 Microsoft Windows CE
 CE Sample Applications and Utilities
 eVC - NotificationMonitor.exe
 Forum Locked
 Send Topic to a Friend
 Printer Friendly
Author Topic  

bsamuels

53 Posts

Posted - 06 Mar 2006 :  10:52:47  Show Profile  Email Poster
NotificationMonitor.exe

NotificationMonitor is a sample application that demonstrates how to detect when your device has come out of ("awakened") from suspend/sleep mode or when any storage device has been inserted or removed.

The code looks for the PBT_RESUME event from the PowerEventWaitQueue and for device status changes (fAttached) in the StorageEventWaitQueue.

The included sample application displays a message on the debug port after wakeup (power notifications) and for insertion and ejection/removal of "cards" (USB, SD/MMC, PCMCIA, CompactFlash, etc).

Key APIs Used

CreateMsgQueue

Lines of Code: 650


Source Download
Rev. 1 - March 2, 2006 (zip 6 kB)


Related topics: CE power management


Edited by akidder 17-Aug-2006: Add link to CE power management.

mcmalburg

28 Posts

Posted - 02 Aug 2008 :  08:06:27  Show Profile  Email Poster
Has this been ported to C#? If not, is there any advice on how to perform these functions in C#?
Go to Top of Page

ctacke

877 Posts

Posted - 02 Aug 2008 :  10:13:38  Show Profile  Email Poster
Not been ported that I'm aware, but it's based on Point to Point message queues, which OpenNETCF has already wrapped in their Smart Device Framework, so if you use that as a base, it would be pretty simple to implement.
Go to Top of Page

mcmalburg

28 Posts

Posted - 02 Aug 2008 :  11:17:15  Show Profile  Email Poster
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.)?
Go to Top of Page

ctacke

877 Posts

Posted - 02 Aug 2008 :  12:47:19  Show Profile  Email Poster
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);
Go to Top of Page

mcmalburg

28 Posts

Posted - 03 Aug 2008 :  14:47:09  Show Profile  Email Poster
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
Go to Top of Page

ctacke

877 Posts

Posted - 03 Aug 2008 :  15:09:20  Show Profile  Email Poster
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.
Go to Top of Page

mcmalburg

28 Posts

Posted - 04 Aug 2008 :  08:45:03  Show Profile  Email Poster
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?
Go to Top of Page

ctacke

877 Posts

Posted - 04 Aug 2008 :  10:07:18  Show Profile  Email Poster
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.
Go to Top of Page

mcmalburg

28 Posts

Posted - 04 Aug 2008 :  11:16:35  Show Profile  Email Poster
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).
Go to Top of Page

ctacke

877 Posts

Posted - 04 Aug 2008 :  11:34:26  Show Profile  Email Poster
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.
Go to Top of Page
  Topic  
 Forum Locked
 Send Topic to a Friend
 Printer Friendly
Jump To:
Eurotech Support Forums © Eurotech Inc. Go To Top Of Page
This page was generated in 0.03 seconds. Snitz Forums 2000