©
2007,
UTC RETAIL
15
11473012 Rev B
Below is a code snipit that shows how to get the status of the cash drawer
(assuming hDev is already open as shown above):
...SNIP...
BOOLEAN boolReadBuffer;
ULONG ulRetLen;
if (!DeviceIoControl(hDev,
IOCTL_UTC RETAIL_CASHDRAWER_STATUS,
NULL, 0, &boolReadBuffer,
sizeof(boolReadBuffer), &ulRetLen, 0))
{
printf("DeviceIoControl failed with error 0x%x\n", GetLastError());
return;
}
printf("Status = %s\n",(boolReadBuffer==STATUS_OPEN?"Open":"Closed"));
...SNIP...
The following code snipit shows how to register for and monitor status change
events (assuming hDev is already open as shown above):
...SNIP...
hEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
if ( !hEvent ) {
printf("CreateEvent error = %d\n", GetLastError() );
return;
}
bStatus = DeviceIoControl(
hDev, // Handle to device
IOCTL_UTC RETAIL_CASHDRAWER_REGISTER_EVENT,
&hEvent, sizeof(PHANDLE), NULL,
0, &ulRetLen, NULL);
if ( !bStatus ) {
printf("Ioctl failed with code %d\n", GetLastError() );
} else {
printf("Waiting for event, open or close drawer...\n");
WaitForSingleObject(hEvent, INFINITE);
printf("status: %s\n",getStatusString(hDev));
// If we want to keep receiving events, uncomment ResetEvent()
//ResetEvent( hEvent);
}
CloseHandle(hEvent);
...SNIP...