Detecting insertion into/removal from cradle.

  • Thread starter Thread starter BLUE
  • Start date Start date
B

BLUE

Are there events that are fired when I insert the handheld into or I remove
it from the cradle?

*OpenNETCF.Desktop.Communication.ActiveSync* class has *Active* (indicates
that a connection is established between
the client application and the connection manager) and *Inactive* (indicates
a disconnection, or disconnected state, between the
desktop computer and the Windows CE-based device) events, but I don't know
if I can use them:
"the OpenNETCF.Desktop.Communication namespace contains classes for working
remotely with devices through ActiveSync and RAPI" so I can use ActiveSync
class on an handheld to detect communication with a PC or only on a PC to
detect communication with the handheld?


Thanks,
Luigi.
 
Luigi,

Well, does the documentation for the classes that you are using indicate
that there are events that are being fired?
 
The RAPI API is for code running on the PC side. That's why it's separate
from the OpenNETCF Smart Device Framework which runs on the device. You can
use some network calls on the device side to see if there's an ActiveSync
connection. If you try to resolve "ppp_peer" from the device, that should
only resolve if ActiveSync is connected (or maybe if the unit is dialed into
a network over a modem, but that doesn't show up very often). I'm sure that
we've discussed this in the Compact Framework group previously. Use
GoogleGroups to search microsoft.public.dotnet.framework.compactframework on
suitable key words and I'm sure you'll find something useful...

Paul T.
 
Hi,

Post in the Compactframework NG, you will get answers there from the very
same people that wrote OpenNetCF :)
 
using OpenNETCF.Win32

// ...
string key = "Comm\\tcpip\\hosts\\ppp_peer";

regKey = Registry.LocalMachine;

regKey = regKey.OpenSubKey(key, false);

if (regKey == null)
{
// NO ActiveSync connection available
}
else
{
// we do have an ActiveSync connection.
}


But the problem is: since there is no event, it's right to use a timer to
check it continuously or there is a better solution?


Thanks,
Luigi.
 
Check it just before you need it to be connected, if you're trying to decide
if it's OK to go ahead with some operation. If you're waiting for the
cradle to be connected and if the device is a Windows Mobile 5 device, you
could wait for the USB 'network' to indicate a change of state using the
AdapterStatusMonitor class, maybe, in SDF. Since you haven't really told us
*what* you're trying to do, just how you've been trying to do it, we don't
have much of a picture of what the right solution might be.

Paul T.
 
But the problem is: since there is no event, it's right to use a timer to
Check it just before you need it to be connected, if you're trying to
decide if it's OK to go ahead with some operation. If you're waiting for
the cradle to be connected and if the device is a Windows Mobile 5 device,
you could wait for the USB 'network' to indicate a change of state using
the AdapterStatusMonitor class, maybe, in SDF. Since you haven't really
told us *what* you're trying to do, just how you've been trying to do it,
we don't have much of a picture of what the right solution might be.

Since I asked if there was an event it's obvious I do not want to do a check
before doing an operation: an event is used to react to some change.

BTW I have a method I call from time to time with a timer to send data to a
server and I want to disable the timer and send data immediately as soon as
the handheld is inserted into the cradle.
Moreover I want to roll back operation as soon as the handheld is removed
from the cradle if this happens before the end of the operation itself.

I've WinCE 4.2.


Thanks,
Luigi.
 
That sounds like you're implementing what MSMQ does automatically, but OK,
if you prefer to do it yourself to avoid having to add that component to the
OS or avoid learning another new API, you can still try the
AdapterStatusMonitor scheme. My guess is that whether this will work or not
will depend on what version of ActiveSync is on the other end of the cradle
connection, etc., but you might be able to get it to work with both 3.8 and
4.x and it would notify you when the network connection was created in
response to a cradle event.

You could also try asking for notification from the Notification Manager of
events like RS232 connection or whatever corresponds to a cradle event
(CeRunAppAtEvent). I'm sure that's how ActiveSync is getting notified of a
connect event, so it should work for you, too, although you might have to do
some checking, once you're notified, to make sure that the connection is
really ready; it won't be instantaneous. You wouldn't have to poll for
cradle connection, though.

Paul T.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top