2026-07-06 17:41:44 +01:00
|
|
|
/*
|
2026-07-06 18:41:30 +01:00
|
|
|
* scan.c - Phase 1 barcode diagnostic: decoded laser over the serial port.
|
2026-07-06 17:41:44 +01:00
|
|
|
*
|
2026-07-06 18:41:30 +01:00
|
|
|
* The Workabout MX integral laser powered up and gave a good-read LED on
|
|
|
|
|
* TTY:D, i.e. it is a DECODED scanner that emits ASCII over the serial port -
|
|
|
|
|
* no BAR: decoder LDD needed. The earlier TTY:D read returned nothing because
|
|
|
|
|
* the port's default handshake sets P_OBEY_DSR, and the I/O Devices Reference
|
|
|
|
|
* states that if the remote device does not assert DSR, an outstanding P_FREAD
|
|
|
|
|
* is suspended. The laser does not drive DSR, so the read blocked forever.
|
2026-07-06 18:33:34 +01:00
|
|
|
*
|
2026-07-06 18:41:30 +01:00
|
|
|
* This build opens TTY:D, applies a P_SRCHAR config at 9600/8/1 with P_OBEY_DSR
|
|
|
|
|
* cleared (P_IGN_CTS only, so reads are not gated on modem lines), forces DTR
|
|
|
|
|
* active, then dumps every byte of each read so the decoded UPC format is seen.
|
2026-07-06 17:41:44 +01:00
|
|
|
*
|
2026-07-06 18:28:22 +01:00
|
|
|
* Blocking I/O; exit via the System screen.
|
2026-07-06 17:41:44 +01:00
|
|
|
*/
|
|
|
|
|
#include <plib.h>
|
2026-07-06 18:41:30 +01:00
|
|
|
#include <p_serial.h>
|
2026-07-06 18:28:22 +01:00
|
|
|
|
2026-07-06 17:41:44 +01:00
|
|
|
GLDEF_C INT main(VOID)
|
|
|
|
|
{
|
2026-07-06 18:41:30 +01:00
|
|
|
VOID *chan;
|
|
|
|
|
P_SRCHAR ser;
|
|
|
|
|
UBYTE buf[64];
|
|
|
|
|
UBYTE ctrl[2];
|
|
|
|
|
INT err, n, i;
|
2026-07-06 18:28:22 +01:00
|
|
|
|
2026-07-06 18:41:30 +01:00
|
|
|
err = p_open(&chan, "TTY:D", (UINT)-1);
|
|
|
|
|
p_printf("open TTY:D: %d\n", err);
|
|
|
|
|
if (err < 0) {
|
|
|
|
|
p_printf("Press a key to exit.\n");
|
2026-07-06 18:28:22 +01:00
|
|
|
p_getch();
|
2026-07-06 17:41:44 +01:00
|
|
|
return 1;
|
2026-07-06 18:28:22 +01:00
|
|
|
}
|
2026-07-06 18:19:53 +01:00
|
|
|
|
2026-07-06 18:41:30 +01:00
|
|
|
/* 9600 baud, 8 data bits, 1 stop, no parity; do NOT obey DSR/DCD (only
|
|
|
|
|
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");
|
2026-07-06 17:41:44 +01:00
|
|
|
|
2026-07-06 17:51:17 +01:00
|
|
|
for (;;) {
|
2026-07-06 18:41:30 +01:00
|
|
|
n = p_read(chan, buf, sizeof(buf));
|
|
|
|
|
if (n < 0) {
|
|
|
|
|
p_printf("read err %d\n", n);
|
2026-07-06 17:41:44 +01:00
|
|
|
continue;
|
|
|
|
|
}
|
2026-07-06 18:41:30 +01:00
|
|
|
if (n == 0)
|
2026-07-06 18:13:56 +01:00
|
|
|
continue;
|
2026-07-06 18:41:30 +01:00
|
|
|
p_printf("n=%d:", n);
|
|
|
|
|
for (i = 0; i < n; i++)
|
2026-07-06 18:13:56 +01:00
|
|
|
p_printf(" %d", buf[i]);
|
|
|
|
|
p_printf(" \"");
|
2026-07-06 18:41:30 +01:00
|
|
|
for (i = 0; i < n; i++)
|
2026-07-06 18:13:56 +01:00
|
|
|
p_putch(buf[i] >= ' ' ? buf[i] : '.');
|
|
|
|
|
p_printf("\"\n");
|
2026-07-06 17:41:44 +01:00
|
|
|
}
|
|
|
|
|
}
|