UsbRegisterDeviceNotification: Difference between revisions
Appearance
added example code |
|||
| (4 intermediate revisions by the same user not shown) | |||
| Line 4: | Line 4: | ||
==Syntax== | ==Syntax== | ||
<pre> | <pre> | ||
ulrc = UsbRegisterDeviceNotification(pNotifyID,hDeviceAdded,hDeviceRemoved,usVendor,usProduct, | ulrc = UsbRegisterDeviceNotification(pNotifyID,hDeviceAdded,hDeviceRemoved,usVendor,usProduct,usBCDDevice) | ||
</pre> | </pre> | ||
| Line 18: | Line 18: | ||
; usProduct : the Product Identifier (ProductID) from the device descriptor. | ; usProduct : the Product Identifier (ProductID) from the device descriptor. | ||
; | ; usBCDDevice : the Device Release Number from the device descriptor. | ||
==Return Code== | ==Return Code== | ||
| Line 50: | Line 50: | ||
ULONG ulTimeout = 8000; | ULONG ulTimeout = 8000; | ||
USBNOTIFY NotifyID; | USBNOTIFY NotifyID; | ||
USHORT | USHORT usBCDDevice = 0x0101; | ||
USHORT usProduct = 0x602D; | USHORT usProduct = 0x602D; | ||
USHORT usVendor = 0x0C45; | USHORT usVendor = 0x0C45; | ||
| Line 57: | Line 57: | ||
phDeviceAdded = &hDeviceAdded; | phDeviceAdded = &hDeviceAdded; | ||
ulrc = DosCreateEventSem(NULL,phDeviceAdded,DC_SEM_SHARED,FALSE); | ulrc = DosCreateEventSem(NULL,phDeviceAdded,DC_SEM_SHARED,FALSE); | ||
printf("\nDosCreateEventSem - ulrc: | printf("\nDosCreateEventSem - ulrc: 0x%04X (%hu)",ulrc,ulrc); | ||
phDeviceRemoved = &hDeviceRemoved; | phDeviceRemoved = &hDeviceRemoved; | ||
ulrc = DosCreateEventSem(NULL,phDeviceRemoved,DC_SEM_SHARED,FALSE); | ulrc = DosCreateEventSem(NULL,phDeviceRemoved,DC_SEM_SHARED,FALSE); | ||
printf("\nDosCreateEventSem - ulrc: | printf("\nDosCreateEventSem - ulrc: 0x%04X (%hu)",ulrc,ulrc); | ||
pNotifyID = &NotifyID; | pNotifyID = &NotifyID; | ||
ulrc = UsbRegisterDeviceNotification(pNotifyID,hDeviceAdded,hDeviceRemoved,usVendor,usProduct, | ulrc = UsbRegisterDeviceNotification(pNotifyID,hDeviceAdded,hDeviceRemoved,usVendor,usProduct,usBCDDevice); | ||
printf("\nUsbRegisterDeviceNotification - ulrc: | printf("\nUsbRegisterDeviceNotification - ulrc: 0x%04X (%hu)",ulrc,ulrc); | ||
//await attach device event | //await attach device event | ||
ulrc = DosWaitEventSem(hDeviceAdded,ulTimeout); | ulrc = DosWaitEventSem(hDeviceAdded,ulTimeout); | ||
printf("\nDosWaitEventSem - ulrc: | printf("\nDosWaitEventSem - ulrc: 0x%04X (%hu)",ulrc,ulrc); | ||
if (!ulrc) //success | if (!ulrc) //success | ||
{ | { | ||
| Line 76: | Line 76: | ||
//await detach device event | //await detach device event | ||
ulrc = DosWaitEventSem(hDeviceRemoved,ulTimeout); | ulrc = DosWaitEventSem(hDeviceRemoved,ulTimeout); | ||
printf("\nDosWaitEventSem - ulrc: | printf("\nDosWaitEventSem - ulrc: 0x%04X (%hu)",ulrc,ulrc); | ||
if (!ulrc) //success | if (!ulrc) //success | ||
{ | { | ||
| Line 82: | Line 82: | ||
} | } | ||
} | } | ||
</pre> | </pre> | ||
==Related Functions== | ==Related Functions== | ||
* [[UsbRegisterChangeNotification]] | |||
* [[UsbDeregisterNotification]] | |||
* [[UsbOpen]] | |||
[[Category:USBCalls]] | [[Category:USBCalls]] | ||
Latest revision as of 17:25, 12 February 2017
Description
Registers semaphores for attach/detach notification of specific USB devices.
Syntax
ulrc = UsbRegisterDeviceNotification(pNotifyID,hDeviceAdded,hDeviceRemoved,usVendor,usProduct,usBCDDevice)
Parameters
- pNotifyID
- the address of the variable to receive the Notification Identifier.
- hDeviceAdded
- the handle of the event semaphore to be posted on device attach.
- hDeviceRemoved
- the handle of the event semaphore to be posted on device detach.
- usVendor
- the Vendor Identifier (VendorID) from the device descriptor.
- usProduct
- the Product Identifier (ProductID) from the device descriptor.
- usBCDDevice
- the Device Release Number from the device descriptor.
Return Code
0x0000 - NO_ERROR
Errors
0x0000 - NO_ERROR 0x0006 - ERROR_INVALID_HANDLE 0x0057 - ERROR_INVALID_PARAMETER 0x005F - ERROR_INTERRUPT 0x0064 - ERROR_TOO_MANY_SEMAPHORES 0x0067 - ERROR_TOO_MANY_SEM_REQUESTS 0x0069 - ERROR_SEM_OWNER_DIED 0x1B58 - USB_NOT_INIT 0x1B59 - USB_ERROR_NO_MORE_NOTIFICATTIONS
Remarks
Example Code
//Code Snippet - UsbRegisterDeviceNotification
{
APIRET ulrc;
HEV hDeviceAdded;
HEV hDeviceRemoved;
PHEV phDeviceAdded;
PHEV phDeviceRemoved;
PUSBNOTIFY pNotifyID;
ULONG ulTimeout = 8000;
USBNOTIFY NotifyID;
USHORT usBCDDevice = 0x0101;
USHORT usProduct = 0x602D;
USHORT usVendor = 0x0C45;
//acquire semaphores
phDeviceAdded = &hDeviceAdded;
ulrc = DosCreateEventSem(NULL,phDeviceAdded,DC_SEM_SHARED,FALSE);
printf("\nDosCreateEventSem - ulrc: 0x%04X (%hu)",ulrc,ulrc);
phDeviceRemoved = &hDeviceRemoved;
ulrc = DosCreateEventSem(NULL,phDeviceRemoved,DC_SEM_SHARED,FALSE);
printf("\nDosCreateEventSem - ulrc: 0x%04X (%hu)",ulrc,ulrc);
pNotifyID = &NotifyID;
ulrc = UsbRegisterDeviceNotification(pNotifyID,hDeviceAdded,hDeviceRemoved,usVendor,usProduct,usBCDDevice);
printf("\nUsbRegisterDeviceNotification - ulrc: 0x%04X (%hu)",ulrc,ulrc);
//await attach device event
ulrc = DosWaitEventSem(hDeviceAdded,ulTimeout);
printf("\nDosWaitEventSem - ulrc: 0x%04X (%hu)",ulrc,ulrc);
if (!ulrc) //success
{
printf(" - obtained Attach Notification");
}
//await detach device event
ulrc = DosWaitEventSem(hDeviceRemoved,ulTimeout);
printf("\nDosWaitEventSem - ulrc: 0x%04X (%hu)",ulrc,ulrc);
if (!ulrc) //success
{
printf(" - obtained Detach Notification");
}
}