c#检测usb设备拨插类库USBClassLibrary分享
程序员文章站
2023-12-19 13:07:04
复制代码 代码如下:private void usbport_usbdeviceattached(objectsender,usbclass.usbdeviceeventa...
复制代码 代码如下:
private void usbport_usbdeviceattached(objectsender,
usbclass.usbdeviceeventargs e)
{
if (!myusbdeviceconnected)
{
if(usbclass.getusbdevice(mydevicevid, mydevicepid,
ref usbdeviceproperties, false))
{
//my device is connected
myusbdeviceconnected = true;
}
}
}
private void usbport_usbdeviceremoved(objectsender,
usbclass.usbdeviceeventargs e)
{
if(!usbclass.getusbdevice(mydevicevid, mydevicepid,
ref usbdeviceproperties, false))
{
//my device is removed
myusbdeviceconnected = false;
}
}