feat(inventory): Phase 1 - scan and validate UPC barcodes #1
+22
-14
@@ -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
|
* TTY:D is the top-slot bar code interface. It did not auto-transmit on a scan,
|
||||||
* Intelligent Bar Code Reader chapter). Opening it powers the interface and
|
* so this build uses the documented escape-sequence trigger (I/O Devices
|
||||||
* the scanner; by default the scanner is enabled and in auto-read mode, and it
|
* Reference, HC Intelligent Bar Code Reader chapter):
|
||||||
* transmits each decoded label as ASCII text terminated by a carriage return.
|
* <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
|
* <Esc>=0x1b, '-'=0x2d, 'y'=0x79. Escape sequences carry no embedded spaces.
|
||||||
* (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>
|
||||||
|
|
||||||
@@ -21,6 +19,9 @@ GLDEF_C INT main(VOID)
|
|||||||
UBYTE b;
|
UBYTE b;
|
||||||
INT err, n, c;
|
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);
|
err = p_open(&chan, "TTY:D", (UINT)-1);
|
||||||
p_printf("open TTY:D: %d\n", err);
|
p_printf("open TTY:D: %d\n", err);
|
||||||
if (err < 0) {
|
if (err < 0) {
|
||||||
@@ -29,10 +30,15 @@ GLDEF_C INT main(VOID)
|
|||||||
return 1;
|
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 (;;) {
|
for (;;) {
|
||||||
n = p_read(chan, &b, 1); /* one byte; no reconfiguration at all */
|
n = p_read(chan, &b, 1);
|
||||||
if (n < 0) {
|
if (n < 0) {
|
||||||
p_printf("<e%d>", n);
|
p_printf("<e%d>", n);
|
||||||
continue;
|
continue;
|
||||||
@@ -41,7 +47,9 @@ GLDEF_C INT main(VOID)
|
|||||||
continue;
|
continue;
|
||||||
c = b;
|
c = b;
|
||||||
p_printf(" %d", c);
|
p_printf(" %d", c);
|
||||||
if (c == 13 || c == 10)
|
if (c == 13 || c == 10) {
|
||||||
p_printf(" <EOL>\n");
|
p_printf(" <EOL>\n");
|
||||||
|
p_write(chan, cmdK, 5); /* re-arm for the next scan */
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user