C-6 Scanner API
MX3-CE Reference Guide E-EQ-MX3CERG-A-ARC
Detecting Presence Of Internal Scanner
The internal scanner is reliably detected via a 2-stage process.
First, RTS is toggled, and the software looks for a response coming back. Note that the sense of
RTS is reversed in this case, so it must be cleared to be made active:
static BOOL CheckScanner1(HANDLE port, LPCTSTR portname)
{
int tim=0;
if (wcscmp(portname, L"COM3:") != 0)
// only COM3 can be scanner
return FALSE;
if (!CommSetup(port, CBR_9600, 8, NOPARITY, ONESTOPBIT))
return FALSE;
if (!CommSetLine(port, linename, SETRTS))
return FALSE;
if (!CommSetLine(port, linename, CLRRTS))
// IMPORTANT-scanner is negative active
return FALSE;
while (1)
{
DWORD flags;
GetCommModemStatus(port, &flags);
if (!(flags & MS_CTS_ON))
// IMPORTANT-scanner is negative active
break;
if (++tim > 100L) // timeout
return FALSE;
Sleep(1);
}
return TRUE;
}
Second, a Symbol Revision Request command is sent to the scanner, and the software looks for the
correct response:
static BOOL ScanCommandSend(HANDLE port, unsigned char *ptr, int length)
{
int i, cksm;
DWORD cnt;
unsigned char buf[100];
// build checksum for packet
length -= 2; // skip checksum
for (i=0, cksm=0; i<length; i++)
cksm -= (int) ptr[i]; // 2's complement
ptr[i++] = (cksm >> 8);
ptr[i] = (cksm & 0xFF);
length += 2; // include checksum
if (!WriteFile(port, ptr, length, &cnt, 0)) return FALSE;
if (!ReadFile(port, buf, 100, &cnt, 0)) return FALSE;
if (buf[1] != REPLY_REVISION) return FALSE;
return TRUE; // we don’t really care what response was
}
static BOOL CheckScanner2(HANDLE port)
{
static unsigned char cmd[] = {
0x04, // length
REQUEST_REVISION, // opcode
HOST_SOURCE, // source of message
STATUS_IS_OK, // initialize status
0,0 // checksum
};
return ScanCommandSend(port, cmd, sizeof(cmd));
}