RxUsbRegisterDeviceNotification
From EDM2
Contents
Description
Registers semaphores for attach/detach notification of specific USB devices.
Syntax
To register semaphores for attach/detach notification of specific USB devices use:
rc = RxUsbRegisterDeviceNotification(NotifyID,hDevAdd,hDevRem,idVendor,idProduct)
To register semaphores for attach/detach notification of even more specific USB devices use:
rc = RxUsbRegisterDeviceNotification(NotifyID,hDevAdd,hDevRem,idVendor,idProduct,bcdDevice)
Parameters
- NotifyID
- the name of the variable to receive the Notification Identifier.
- hDevAdd
- the handle of the event semaphore to be posted on device attach.
- hDevRem
- the handle of the event semaphore to be posted on device detach.
- idVendor
- the Vendor Identifier (VendorID) from the device descriptor.
- idProduct
- the Product Identifier (ProductID) from the device descriptor.
- bcdDevice
- the Device Release Number from the device descriptor.
Return Code
0x0000 - NO_ERROR
Errors
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
Device attach/detach notifications may be obtained by registering event semaphores to be posted upon attach/detach of USB devices. The RexxUtil library provides functions to work with event semaphores. Some of these are used in the example code.
Example Code
/* add SysCreateEventSem */ rc = RxFuncAdd('SysCreateEventSem','RexxUtil','SysCreateEventSem') say '+SysCreateEventSem(),RC=0x'd2x(rc) /* invoke SysCreateEventSem() */ hSemAttach = SysCreateEventSem() say '*SysCreateEventSem(),RC=0x'd2x(rc) hSemDetach = SysCreateEventSem() say '*SysCreateEventSem(),RC=0x'd2x(rc) /* drop SysCreateEventSem */ rc = RxFuncDrop('SysCreateEventSem') say '-SysCreateEventSem(),RC=0x'd2x(rc) /* add RxUsbRegisterDeviceNotification */ rc = RxFuncAdd('RxUsbRegisterDeviceNotification','usbcalls','RxUsbRegisterDeviceNotification') say '+RxUsbRegisterDeviceNotification(),RC=0x'd2x(rc) /* invoke RxUsbRegisterDeviceNotification */ idVendor=x2d(046D) /* vendor identifier */ idProduct=x2d(0804) /* product identifier */ bcdDevice=x2d(0009) /* device release number */ hDevAdd = hSemAttach; /* attach semaphore handle */ hDevRem = hSemDetach; /* detach semaphore handle */ drop NotifyID /* to receive the notification identifier */ rc = RxUsbRegisterDeviceNotification(NotifyID,hDevAdd,hDevRem,idVendor,idProduct,bcdDevice) say '*RxUsbRegisterDeviceNotification(),RC=0x'd2x(rc) /* drop RxUsbRegisterDeviceNotification */ rc = RxFuncDrop('RxUsbRegisterDeviceNotification') say '-RxUsbRegisterDeviceNotification(),RC=0x'd2x(rc) /* add SysWaitEventSem */ rc = RxFuncAdd('SysWaitEventSem','RexxUtil','SysWaitEventSem') say '+SysWaitEventSem(),RC=0x'd2x(rc) /* invoke SysWaitEventSem() */ timeout = 8000; /* await 8 seconds */ rc = SysWaitEventSem(hSemAttach,timeout) say '*SysWaitEventSem(),RC=0x'd2x(rc) if (rc=0) then say 'obtained Attach Notification' rc = SysWaitEventSem(hSemDetach,timeout) say '*SysWaitEventSem(),RC=0x'd2x(rc) if (rc=0) then say 'obtained Detach Notification' /* drop SysWaitEventSem */ rc = RxFuncDrop('SysWaitEventSem') say '-SysWaitEventSem(),RC=0x'd2x(rc)