设备检测:DBT_DEVICEARRIVAL无法正常工作 [英] Device Detection : DBT_DEVICEARRIVAL not working

查看:482
本文介绍了设备检测:DBT_DEVICEARRIVAL无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我正在检测新端口是否已到达COM端口.我在检测新设备到货时遇到问题.请帮忙.

我已实现如下:

注册设备

Hi,

I am working on detecting the new device arrival on the COM Port. I having problems in detecting new device arrival. please help.

I have implemented as below:

Register the device

DEV_BROADCAST_DEVICEINTERFACE notificationFilter = { 0 };
notificationFilter.dbcc_size = sizeof(notificationFilter);
notificationFilter.dbcc_devicetype =  DBT_DEVTYP_DEVICEINTERFACE;
notificationFilter.dbcc_classguid = GUID;

::RegisterDeviceNotification(
  hwnd, &notificationFilter, DEVICE_NOTIFY_WINDOW_HANDLE);


等待消息


Wait for Message

while( ::PeekMessage(&msg, hwnd, NULL, NULL, PM_REMOVE ) )
{
   ::TranslateMessage( &msg );
   ::DispatchMessage( &msg );
   if( WM_DEVICECHANGE == msg.message )
   {
      if( DBT_DEVICEARRIVAL == msg.wParam )
      {
         // process
      }


if( DBT_DEVNODES_CHANGED == msg.wParam  )
   {
   }
  }
}



我没有得到任何DVT_DEVICEARRIVAL,但即使在插入设备时也只有DBT_DEVNODES_CHANGED.请帮忙.



I am not getting any DVT_DEVICEARRIVAL but only get DBT_DEVNODES_CHANGED even on inserting the device. Please help.

推荐答案

通常不适用于串行设备.

您需要一个封装设备的设备驱动程序,配置为使用com端口.

由于它是com端口,因此驱动程序有责任检测com端口上发生的情况.

通常,这不是通用"串行设备的工作方式.可以使用SerialPort组件对其进行访问.

问候
Espen Harlinn
Normally doesn''t work that way for serial devices.

You''ll need a device driver that encapsulates the device, configured to use the com port.

Since it''s the com port it will be the drivers responsibility to detect what happens on the com port.

This is usually not how "general" serial devices work. They can be accessed using the SerialPort component.

Regards
Espen Harlinn


[更新]

我发现了问题所在.显然,只有主窗口[顶层]才能接收消息.子窗口以及某些窗口类型根本无法接收消息.

这应该起作用:
[ ^ ]

如果它不起作用,那么我建议您检查是否正在创建窗口.一旦您注册了消息,它就有可能失败. [它依次调用NCCreate和NCDestroy].我不知道如何使它工作[我有一个链接,该链接有同样的问题,但是在那里死胡同],但是一种解决方法是使用主窗口.

希望能在某处帮助某人并节省一天:-D
[Update]

I found out what the problem is. Apparently, ONLY main windows[top level] would be able to receive the messages. Child windows and apparently some windows types simply don''t have the ability to receive messages.

This should work :
[^]

If it is not working, then I would suggest you check if the window is getting created. Chances are it is failing once you register for the messages. [It calls NCCreate followed by NCDestroy]. I dunno how to make it work [I got a link which had same issue but hit a dead end there] but a way around is using the main window.

Hope that helps someone, somewhere and saves a day :-D


这篇关于设备检测:DBT_DEVICEARRIVAL无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆