这是采用C#开发的一个USB库,使您可以管理USB设备的连接和分离事件,探测自己的设备。可以运行在Windows XP和Windows7 64位系统下。

检测 USB 设备拨插的 C# 类库:USBClassLibrary-LMLPHP

01private void USBPort_USBDeviceAttached(objectsender,
02             USBClass.USBDeviceEventArgs e)
03{
04   if (!MyUSBDeviceConnected)
05   {
06      if(USBClass.GetUSBDevice(MyDeviceVID, MyDevicePID,
07                                ref USBDeviceProperties, false))
08      {
09         //My Device is connected
10         MyUSBDeviceConnected = true;
11      }
12   }
13}
14 
15private void USBPort_USBDeviceRemoved(objectsender,
16             USBClass.USBDeviceEventArgs e)
17{
18   if(!USBClass.GetUSBDevice(MyDeviceVID, MyDevicePID,
19                              ref USBDeviceProperties, false))
20   {
21      //My Device is removed
22      MyUSBDeviceConnected = false;
23   }
24}
05-10 20:44