Chapter 12: Cash Drawer Interface 12-13
// close the file handle
m_bPortDrvr = FALSE;
g_nPortDrvr=0; // Dec to zero using and close handle
CloseHandle(g_hPortDrvr);
g_hPortDrvr = NULL;
}
m_bInitialized = FALSE;
ReleaseMutex( g_hSharedMemoryMutex );
}
}
/////////////////////////////////////////////////////////
long OpenPort()
{
CString sData;
long RetStatus;
CString Result;
static TCHAR szIOPort[] = _T("Port");
// Get the IO H/W Configuration to set IOPORT addresses
// If other of same type exists then use same IOPort addresses
QueryConf(); // Sets IOPORT addresses based on H/W configuration
// initialize state
DWORD sBytes=0;
DWORD bMask = ~(CD7402DRWR1SOLENOID | CD7402DRWR2SOLENOID); // Set
Solenoid bits LOW
bMask = bMask | CD7402ARM_OFF; // set solenoid bits low and arm bit high
// **program solenoid bits as inputs to start
if ( !ReadIOPort(&sBytes, m_nIOPort_select) )
{
// Error logged in ReadIOPort
RetStatus = CDD_E_IOFAILURE;
Result = _T("I/O read operation failed");
}
else if ( !WriteIOPort( sBytes | CD7402SELECT_GPI,
m_nIOPort_select)) // Darlington 1 = select input
{
// Error logged in WriteIOPort
RetStatus = CDD_E_IOFAILURE;
Result = _T("I/O write operation failed");
}
//** set solenoid bits de-activated, even though they are supposed to be
inputs now
if ( !ReadIOPort(&sBytes, m_nIOPort) )