Catch the event when device connect using ActiveSync
-
mercredi 25 février 2009 10:36I have the application which can update data from the internet. I want to built a new functionality - application updates data automatically when the device connects to PC using ActiveSync. I found CeRunAppAtEvent function - so I can register my application using this function and NOTIFICATION_EVENT_RS232_DETECTED flag. But what happens when the device connects and the application is not running? It starts the application? Because I don't want to start the application when it connects. I only want to catch the event, when my application is running.
thanks much
Toutes les réponses
-
vendredi 27 février 2009 06:35Modérateur
Hi zbynda,
OpennetCF provide a way to monitor activesync connection status. Like the code below:
private void connectAsync_Click(object sender, System.EventArgs e)
{
m_rapi.RAPIConnected += new RAPIConnectedHandler(m_rapi_RAPIConnected);
m_rapi.RAPIDisconnected += new RAPIConnectedHandler(m_rapi_RAPIDisconnected);
m_rapi.Connect(false, -1);
}
private void m_rapi_RAPIConnected()
{
this.Invoke(textUpdate, new object[] { this, new TextArgs(connectStatus, "Connected") });
this.Invoke(enableUpdate, new object[] { this, new EnableArgs(connectAsync, false) });
this.Invoke(enableUpdate, new object[] { this, new EnableArgs(connectSync, false) });
}
private void m_rapi_RAPIDisconnected()
{
this.Invoke(textUpdate, new object[] { this, new TextArgs(connectStatus, "Not Connected") });
this.Invoke(enableUpdate, new object[] { this, new EnableArgs(connectAsync, false) });
this.Invoke(enableUpdate, new object[] { this, new EnableArgs(connectAsync, false) });
}
private void copyFrom_Click(object sender, System.EventArgs e)
{
if(! m_rapi.Connected)
{
MessageBox.Show("Not connected!");
return;
}
m_rapi.CopyFileFromDevice("f:\\1.jpg", "\\My Documents\\1.jpg", true);
}
While detecting it is connection, it will change the status as "connected".
For more information:
http://social.msdn.microsoft.com/forums/en-US/vssmartdevicesvbcs/thread/44e50105-a0ec-4906-86f8-42c8215b6993/Best regards,
Guang-Ming Bian - MSFT
Please remember to mark the replies as answers if they help and unmark them if they provide no help -
samedi 28 février 2009 13:13Hello,
thanks for your answer, but I use native C++ MFC code not .NET Compact Framework. I think that your code is for .NET Compact Framework only. -
mercredi 4 mars 2009 18:31
Take a look at the MSDN Description of CeRunAppAtEvent. : http://msdn.microsoft.com/en-us/library/aa932775.aspx
The pwszAppName Param can also handle a named event.
So jou can create an Even (CreateEvent Function) an register that event for NOTIFICATION_EVENT_RNDIS_FN_DETECTED & NOTIFICATION_EVENT_RS232_DETECTED.
So you app won´t be started but you event will be fired. Just wait for it with WaitForSingleObject.- Proposé comme réponse Patrick Getzmann vendredi 6 mars 2009 10:51
-
mardi 8 novembre 2011 04:26
There is also the registry setting
HKLM\System\State\Hardware\Cradled which is a subkey string which will be "1" if ActiveSync is communicating.
My problem is that I also want to detect if the WM6 device is connected either by ActiveSync (USB), a network cradle or wireless.
What I'm trying to do is exchange data with a SOAP gateway, however over ActiveSync (USB) it takes substantially longer to instantiate the network adapter on the PC and ActiveSync to launch and connect and I don't want my users to waste time polling and timing out a gateway which may not be present when wireless or network cradle connected just because the device has some kind of connection and been allocated an IP.
-
mardi 8 novembre 2011 15:03
Please start a new thread for your question, rather than resurrecting an old one.
The key you refer to is part of the State and Notification Broker. You don't need to poll it, you can register for an event or callback to be signaled when it changes.
see: snapi http://msdn.microsoft.com/en-us/library/bb154498.aspx
and snapi.h SN_CRADLEPRESENT_*That will, however, only work for ActiveSync connections. You will need a separate method for determining when you're connected via IP (WLAN, WWAN, or LAN).
I'd recommend browsing snapi.h for useful items. Other SNAPI keys will notify your application when a new network connection is added/removed. see SN_CONNECTIONNETWORKCOUNT_*
You can use the iphelper api to enumerate all present network connections and their addresses, gateway, etc... If you know the network you're looking for, then you can use this to find it without polling. see GetAdaptersInfo: http://msdn.microsoft.com/en-us/library/aa916102.aspx
-PaulH

