这是采用C#开发的一个USB库,使您可以管理USB设备的连接和分离事件,探测自己的设备。可以运行在Windows XP和Windows7 64位系统下。
01
class="keyword">private
void
USBPort_USBDeviceAttached(
object
sender,
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
15
private
void
USBPort_USBDeviceRemoved(
object
sender,
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
}