简体   繁体   English

设备在C#中连接到底座Windows ce opennetcf时处理事件

[英]Handle the event when device connect to cradle windows ce opennetcf in C#

I develop an application on windowCE 5.0 with opennetcf library. 我在带有opennetcf库的windowCE 5.0上开发了一个应用程序。 I want to check WHEN my Device is connected to Cradle. 我想检查我的设备何时连接到通讯座。 It means I want to handle the event of plugged the device to cradle or other similar. 这意味着我想处理将设备插入通讯座或其他类似设备的事件。

My purpose is that when Device is connected to Cradle, I disable all forms of my application, and when it is removed from cradle, all the forms are enabled. 我的目的是当Device连接到Cradle时,我会禁用我的应用程序的所有表格,并且当将其从Cradle中删除时,会启用所有表格。

I search much. 我搜索很多。 But the answer is not matched to my expect. 但是答案与我的期望不符。

Please help me. 请帮我。


After reading reference of opennetcf, I found out the two events: ACPowerApplied and ACPowerRemoved 阅读了opennetcf的参考资料之后,我发现了两个事件:ACPowerApplied和ACPowerRemoved

Here is my code: 这是我的代码:

public static event DeviceNotification ACPowerApplied;
public static event DeviceNotification ACPowerRemoved;

void Form1_ACPowerRemoved()
{
MessageBox.Show("Un-cradle");
}

void Form1_ACPowerApplied()
{
MessageBox.Show("Cradle");
}

private void Form1_Load(object sender, EventArgs e)
{
ACPowerApplied += new DeviceNotification(Form1_ACPowerApplied);
ACPowerRemoved += new DeviceNotification(Form1_ACPowerRemoved);
}

But the process did not step into Form1_ACPowerRemoved() and Form1_ACPowerApplied(). 但是该过程并未进入Form1_ACPowerRemoved()和Form1_ACPowerApplied()。

Is there any idea for that? 有什么想法吗? Sorry for my poor English. 对不起,我的英语不好。 Thank you in advance. 先感谢您。

Your code is wrong. 您的代码是错误的。 You've subscribed to the form's event, and nobody raise it. 您已订阅表单的活动,没有人提出。 Documentation doesn't show how-to-use code, I think. 我认为文档没有显示如何使用代码。 It shows declaraion. 它显示声明。

Maybe it will work (not tested): 也许可以使用(未​​经测试):

OpenNETCF.WindowsCE.DeviceManagement.ACPowerApplied += Form1_ACPowerApplied
OpenNETCF.WindowsCE.DeviceManagement.ACPowerRemoved += Form1_ACPowerRemoved

Also you can try to use WinAPI calls: http://blogs.msdn.com/b/davidklinems/archive/2005/02/10/370591.aspx 您也可以尝试使用WinAPI调用: http : //blogs.msdn.com/b/davidklinems/archive/2005/02/10/370591.aspx

If you want, I have complete code, but there are a lot of waste and "OnRs232Connect" event. 如果您愿意,我有完整的代码,但是有很多浪费和“ OnRs232Connect”事件。 By the way, what does "craddled" mean for you? 顺便说一下,“拥抱”对您意味着什么? Craddle can be disconneted from both AC and PC. 摇篮可以从AC和PC上断开。 I mean, do you want to handle when your device started to get electricity power, or when it started connecting to the PC via Active Sync? 我的意思是,您要处理设备何时开始通电,还是设备开始通过Active Sync连接到PC? If the second, you want to catch "OnRs232Connect" event 如果是第二个,则要捕获“ OnRs232Connect”事件

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM