User's Manual
ACG RF PC Handheld Reader Modules, Version 0.2
ACG Identification Technologies AT Page 6
3.4 Writing your own Application in Visual C++
This example illustrates the access to a com port of a handheld. A handheld normally
sets the serial port of the CF slot to 4, 5, or 6.
// set the appropriate com port
CString m_Serial = "com4";
bool m_contReceiveMode = false;
HANDLE hComm;
// Open communication
hComm = CreateFile(m_Serial.GetBuffer(), GENERIC_READ |
GENERIC_WRITE, 0, NULL, OPEN_EXISTING,
FILE_FLAG_WRITE_THROUGH, NULL);
if (hComm == INVALID_HANDLE_VALUE)
{
printf("error\n");
hComm = NULL;
}
else
{
COMMTIMEOUTS noblock;
DCB dcb;
// set communication timeout
GetCommTimeouts(hComm, &noblock); // get communication
timeouts
if (m_contReceiveMode == false)
{
// get answer (ReadFile waits for answer until timeout)
// use timeouts, because it is easier to handle
noblock.ReadTotalTimeoutConstant = 2000; // 2 seconds
timeout
noblock.ReadTotalTimeoutMultiplier = MAXDWORD;
noblock.ReadIntervalTimeout = MAXDWORD;
}
else
{
// get answer for polling (immediate return from ReadFile)
noblock.ReadTotalTimeoutConstant = 0;
noblock.ReadTotalTimeoutMultiplier = 0;
noblock.ReadIntervalTimeout = MAXDWORD;
}
if (SetCommTimeouts(hComm, &noblock) == 0) // set
communication timeouts
printf("error\n");
// set communication state
GetCommState(hComm, & dcb);
dcb.BaudRate = 9600;
dcb.ByteSize = 8;
dcb.fParity = FALSE;