Files
sibo-playground/code/inventory/scan.c
T

68 lines
1.9 KiB
C
Raw Normal View History

/*
* scan.c - Phase 1 barcode diagnostic for the Workabout MX integral laser.
*
* The EAN/UPC decoder LDD (BAREAN.LDD) is loaded, then the decoder device is
* opened. The exact device-name form and open mode are not documented in the
* available manuals (they live in the I/O Devices Reference), so this build
* tries several candidates in one run and reports which one opens - most
* likely "BAR:D" (the decoder over port D, like TTY:D), since bare "BAR:"
* returns E_FILE_NAME (-38). Once open, it dumps every byte of each read so
* the decoded UPC format can be seen.
*
* Blocking I/O; exit via the System screen.
*/
#include <plib.h>
#include "bcode.h"
#define NCAND 5
GLDEF_C INT main(VOID)
{
VOID *chan;
UBYTE buf[64];
INT loadErr, r, n, i, opened;
UINT k;
static TEXT *names[NCAND] = { "BAR:D", "BAR:D", "BAR:", "BAR:E", "BAR:A" };
static UINT modes[NCAND] = { (UINT)-1, 0, 0, (UINT)-1, (UINT)-1 };
loadErr = bcodeLoad();
p_printf("load %s.LDD: %d\n\n", BCODE_LDD, loadErr);
opened = 0;
for (k = 0; k < NCAND; k++) {
r = p_open(&chan, names[k], modes[k]);
p_printf("open \"%s\" mode %u: %d\n", names[k], modes[k], r);
if (r >= 0) {
opened = 1;
break;
}
}
if (opened == 0) {
p_printf("\nNothing opened. Press a key to exit.\n");
p_getch();
return 1;
}
p_printf("\nOpened \"%s\". Scan a barcode. System screen to exit.\n\n",
names[k]);
for (;;) {
n = p_read(chan, buf, sizeof(buf));
if (n < 0) {
p_printf("read err %d\n", n);
continue;
}
if (n == 0)
continue;
p_printf("n=%d:", n);
for (i = 0; i < n; i++)
p_printf(" %d", buf[i]);
p_printf(" \"");
for (i = 0; i < n; i++)
p_putch(buf[i] >= ' ' ? buf[i] : '.');
p_printf("\"\n");
}
}