feat(inventory): Phase 1 - scan and validate UPC barcodes #1

Open
lyrathorpe wants to merge 54 commits from feat/inventory-phase1-scan into main
Showing only changes of commit 724b5a11eb - Show all commits
+28 -40
View File
@@ -1,59 +1,47 @@
/* /*
* scan.c - Phase 1 barcode diagnostic: pin down the BAR: device. * scan.c - Phase 1 barcode diagnostic: minimal TTY:D barcode-driver read.
* *
* The scan key is keycode 368 (a Window Server key event an app catches to * TTY:D is the top-slot bar code interface (I/O Devices Reference, HC
* trigger a scan); the working demo draws the decode itself, so it uses a * Intelligent Bar Code Reader chapter). Opening it powers the interface and
* scanner API - and the only barcode software path in this SDK is the bar*.ldd * the scanner; by default the scanner is enabled and in auto-read mode, and it
* decoder device "BAR:". Our BAR: open has been failing but its exact error * transmits each decoded label as ASCII text terminated by a carriage return.
* kept scrolling away. This build loads BAREAN, opens BAR:A (then BAR:B), *
* reports each result and HOLDS the screen. If a channel opens, it issues * Earlier attempts failed for self-inflicted reasons: a P_FSET forced 9600/8/1
* p_iow(P_FREAD) - which should arm the laser - and dumps the decode. * (wrong if the scanner uses another rate, which garbles the data) and a
* 64-byte read blocked forever with no terminator set. This build does NEITHER:
* it opens TTY:D, changes nothing, and reads ONE byte at a time, streaming each
* value. Scan during the brief active window after launch (re-trigger with the
* scan key if needed).
*/ */
#include <plib.h> #include <plib.h>
#include "bcode.h"
GLDEF_C INT main(VOID) GLDEF_C INT main(VOID)
{ {
VOID *chan; VOID *chan;
UBYTE buf[256]; UBYTE b;
INT ld, ra, rb, r, i, cnt; INT err, n, c;
ld = p_loadldd(BCODE_LDD); err = p_open(&chan, "TTY:D", (UINT)-1);
ra = p_open(&chan, "BAR:A", (UINT)-1); p_printf("open TTY:D: %d\n", err);
if (ra < 0) if (err < 0) {
rb = p_open(&chan, "BAR:B", (UINT)-1); p_printf("Press a key to exit.\n");
else
rb = 0;
p_printf("load %s: %d\n", BCODE_LDD, ld);
p_printf("open BAR:A: %d\n", ra);
if (ra < 0)
p_printf("open BAR:B: %d\n", rb);
if (ra < 0 && rb < 0) {
p_printf("\nNo BAR channel opened. Press a key.\n");
p_getch(); p_getch();
return 1; return 1;
} }
p_printf("\nOpen. A read should arm the laser - scan now.\n\n"); p_printf("Scan now. Streaming bytes:\n\n");
for (;;) { for (;;) {
r = p_iow(chan, P_FREAD, buf); /* arms laser, blocks for a decode */ n = p_read(chan, &b, 1); /* one byte; no reconfiguration at all */
if (r < 0) { if (n < 0) {
p_printf("read status %d\n", r); p_printf("<e%d>", n);
continue; continue;
} }
cnt = buf[0]; if (n == 0)
if (cnt <= 0) {
p_printf("(empty read)\n");
continue; continue;
} c = b;
p_printf("cnt=%d type=%d:", cnt, buf[1]); p_printf(" %d", c);
for (i = 1; i <= cnt && i < 256; i++) if (c == 13 || c == 10)
p_printf(" %d", buf[i]); p_printf(" <EOL>\n");
p_printf(" \"");
for (i = 1; i <= cnt && i < 256; i++)
p_putch(buf[i] >= ' ' ? buf[i] : '.');
p_printf("\"\n");
} }
} }