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 b79b1fa175 - Show all commits
+22 -14
View File
@@ -1,17 +1,15 @@
/*
* scan.c - Phase 1 barcode diagnostic: minimal TTY:D barcode-driver read.
* scan.c - Phase 1 barcode diagnostic: software-triggered scan over TTY:D.
*
* TTY:D is the top-slot bar code interface (I/O Devices Reference, HC
* Intelligent Bar Code Reader chapter). Opening it powers the interface and
* the scanner; by default the scanner is enabled and in auto-read mode, and it
* transmits each decoded label as ASCII text terminated by a carriage return.
* TTY:D is the top-slot bar code interface. It did not auto-transmit on a scan,
* so this build uses the documented escape-sequence trigger (I/O Devices
* Reference, HC Intelligent Bar Code Reader chapter):
* <Esc>-y1J enable single-read mode
* <Esc>-y1K "read next scan" - arms the reader for one label
* After each decoded label (terminated by CR) it re-arms with another K.
* Every received byte is streamed as a decimal value.
*
* Earlier attempts failed for self-inflicted reasons: a P_FSET forced 9600/8/1
* (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).
* <Esc>=0x1b, '-'=0x2d, 'y'=0x79. Escape sequences carry no embedded spaces.
*/
#include <plib.h>
@@ -21,6 +19,9 @@ GLDEF_C INT main(VOID)
UBYTE b;
INT err, n, c;
static TEXT cmdJ[5] = { 0x1b, '-', 'y', '1', 'J' }; /* single-read mode on */
static TEXT cmdK[5] = { 0x1b, '-', 'y', '1', 'K' }; /* trigger one scan */
err = p_open(&chan, "TTY:D", (UINT)-1);
p_printf("open TTY:D: %d\n", err);
if (err < 0) {
@@ -29,10 +30,15 @@ GLDEF_C INT main(VOID)
return 1;
}
p_printf("Scan now. Streaming bytes:\n\n");
err = p_write(chan, cmdJ, 5);
p_printf("single-read mode (Esc-y1J): %d\n", err);
err = p_write(chan, cmdK, 5);
p_printf("trigger (Esc-y1K): %d\n", err);
p_printf("\nPoint at a barcode. Streaming bytes:\n\n");
for (;;) {
n = p_read(chan, &b, 1); /* one byte; no reconfiguration at all */
n = p_read(chan, &b, 1);
if (n < 0) {
p_printf("<e%d>", n);
continue;
@@ -41,7 +47,9 @@ GLDEF_C INT main(VOID)
continue;
c = b;
p_printf(" %d", c);
if (c == 13 || c == 10)
if (c == 13 || c == 10) {
p_printf(" <EOL>\n");
p_write(chan, cmdK, 5); /* re-arm for the next scan */
}
}
}