47 lines
1.2 KiB
C
47 lines
1.2 KiB
C
/*
|
|||
|
|
* bcode.c - barcode scanner serial channel (see bcode.h).
|
||
|
|
*/
|
||
|
|
#include "bcode.h"
|
||
|
|
|
||
|
|
GLDEF_C INT bcodeOpen(VOID **pChan)
|
||
|
|
{
|
||
|
|
/*
|
||
|
|
* TTY:D = the top internal slot's serial port, where the barcode module
|
||
|
|
* sits. mode -1 asks the driver for its default open mode.
|
||
|
|
*
|
||
|
|
* If the scanner needs specific line settings (baud rate, parity, stop
|
||
|
|
* bits), configure the channel after opening with
|
||
|
|
* p_iow(*pChan, P_FSET, &config);
|
||
|
|
* where config is an E_CONFIG struct from p_config.h. See the RS232
|
||
|
|
* section of the PLIB Reference. The module runs at up to 9600 baud.
|
||
|
|
*/
|
||
|
|
return p_open(pChan, "TTY:D", (UINT)-1);
|
||
|
|
}
|
||
|
|
|
||
|
|
GLDEF_C VOID bcodeClose(VOID *chan)
|
||
|
|
{
|
||
|
|
if (chan != NULL)
|
||
|
|
p_close(chan);
|
||
|
|
}
|
||
|
|
|
||
|
|
GLDEF_C INT bcodeAssemble(UBYTE *raw, INT n, TEXT *line, INT *pLen, INT max)
|
||
|
|
{
|
||
|
|
INT i;
|
||
|
|
|
||
|
|
for (i = 0; i < n; i++) {
|
||
|
|
UBYTE c = raw[i];
|
||
|
|
|
||
|
|
if (c == BCODE_TERM) {
|
||
|
|
line[*pLen] = '\0';
|
||
|
|
*pLen = 0;
|
||
|
|
return 1;
|
||
|
|
}
|
||
|
|
if (c < ' ') /* skip LF, NULs and other control bytes */
|
||
|
|
continue;
|
||
|
|
if (*pLen < max - 1)
|
||
|
|
line[(*pLen)++] = (TEXT)c;
|
||
|
|
/* else: overflow - drop until the next terminator */
|
||
|
|
}
|
||
|
|
return 0;
|
||
|
|
}
|