這是采用C#開發的一個USB庫,使您可以管理USB設備的連接和分離事件,探測自己的設備。可以運行在Windows XP和Windows7 64位系統下。
01
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
}