feat(inventory): Phase 1 - scan and validate UPC barcodes #1
+25
-61
@@ -1,75 +1,39 @@
|
|||||||
/*
|
/*
|
||||||
* scan.c - Phase 1 barcode diagnostic: decoded laser over the serial port.
|
* scan.c - Phase 1 barcode diagnostic: keyboard / scan-key route.
|
||||||
*
|
*
|
||||||
* The Workabout MX integral laser powered up and gave a good-read LED on
|
* A working on-device demo triggers the laser from the keyboard scan key, so
|
||||||
* TTY:D, i.e. it is a DECODED scanner that emits ASCII over the serial port -
|
* the system arms the scanner and delivers the decode via the scan-key path -
|
||||||
* no BAR: decoder LDD needed. The earlier TTY:D read returned nothing because
|
* not via an app-opened TTY:D or BAR: channel (both of which gave us nothing).
|
||||||
* the port's default handshake sets P_OBEY_DSR, and the I/O Devices Reference
|
* This build opens NOTHING and simply reads the keyboard, echoing every key
|
||||||
* states that if the remote device does not assert DSR, an outstanding P_FREAD
|
* code. If the decoded barcode is injected as keystrokes (a "wedge"), it will
|
||||||
* is suspended. The laser does not drive DSR, so the read blocked forever.
|
* appear here.
|
||||||
*
|
*
|
||||||
* This build opens TTY:D, applies a P_SRCHAR config at 9600/8/1 with P_OBEY_DSR
|
* Test order:
|
||||||
* cleared (P_IGN_CTS only, so reads are not gated on modem lines), forces DTR
|
* 1. Press normal keys ('1' = 49, '2' = 50, ...) to confirm the read works.
|
||||||
* active, then dumps every byte of each read so the decoded UPC format is seen.
|
* 2. Press the scan key and scan a barcode - watch for the digits.
|
||||||
*
|
* Esc (27) quits.
|
||||||
* Blocking I/O; exit via the System screen.
|
|
||||||
*/
|
*/
|
||||||
#include <plib.h>
|
#include <plib.h>
|
||||||
#include <p_serial.h>
|
|
||||||
|
|
||||||
GLDEF_C INT main(VOID)
|
GLDEF_C INT main(VOID)
|
||||||
{
|
{
|
||||||
VOID *chan;
|
INT c, cnt;
|
||||||
P_SRCHAR ser;
|
|
||||||
UBYTE buf[64];
|
|
||||||
UBYTE ctrl[2];
|
|
||||||
INT err, n, i;
|
|
||||||
|
|
||||||
err = p_open(&chan, "TTY:D", (UINT)-1);
|
p_printf("Keyboard/scan-key test.\n");
|
||||||
p_printf("open TTY:D: %d\n", err);
|
p_printf("Press keys; press the scan key and scan a barcode.\n");
|
||||||
if (err < 0) {
|
p_printf("Esc (27) quits.\n\n");
|
||||||
p_printf("Press a key to exit.\n");
|
|
||||||
p_getch();
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* 9600 baud, 8 data bits, 1 stop, no parity; do NOT obey DSR/DCD (only
|
cnt = 0;
|
||||||
ignore CTS) so a scanner that leaves the modem lines idle can be read. */
|
|
||||||
ser.tbaud = P_BAUD_9600;
|
|
||||||
ser.rbaud = P_BAUD_9600;
|
|
||||||
ser.frame = P_DATA_8;
|
|
||||||
ser.parity = 0;
|
|
||||||
ser.hand = P_IGN_CTS;
|
|
||||||
ser.xon = 0x11;
|
|
||||||
ser.xoff = 0x13;
|
|
||||||
ser.flags = 0;
|
|
||||||
ser.tmask = 0;
|
|
||||||
err = p_iow(chan, P_FSET, &ser);
|
|
||||||
p_printf("config 9600/8/1: %d\n", err);
|
|
||||||
|
|
||||||
/* Force DTR (the scanner enable line) active. Opening already drives it,
|
|
||||||
but make it explicit. ctrl[0] is the read-back of input lines. */
|
|
||||||
ctrl[0] = 0;
|
|
||||||
ctrl[1] = P_SRDTR_ON;
|
|
||||||
err = p_iow(chan, P_FCTRL, ctrl);
|
|
||||||
p_printf("assert DTR: %d\n", err);
|
|
||||||
|
|
||||||
p_printf("\nScan a barcode. System screen to exit.\n\n");
|
|
||||||
|
|
||||||
/* Read ONE byte per call: with tmask=0 a multi-byte P_FREAD waits for the
|
|
||||||
full requested count and would block on a short scan. Streaming single
|
|
||||||
bytes returns each character as it arrives, whatever the terminator. */
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
n = p_read(chan, buf, 1);
|
c = p_getch();
|
||||||
if (n < 0) {
|
cnt++;
|
||||||
p_printf("<err %d>", n);
|
p_printf(" %d", c);
|
||||||
continue;
|
if (c == 13 || c == 10)
|
||||||
}
|
|
||||||
if (n == 0)
|
|
||||||
continue;
|
|
||||||
i = buf[0];
|
|
||||||
p_printf(" %d", i);
|
|
||||||
if (i == 13 || i == 10)
|
|
||||||
p_printf(" <EOL>\n");
|
p_printf(" <EOL>\n");
|
||||||
|
if (c == 27)
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
p_printf("\n%d keys read.\n", cnt);
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user