feat(inventory): WL2:D async read (p_ioc + trigger + p_iowait)
This commit is contained in:
+27
-17
@@ -1,12 +1,11 @@
|
|||||||
/*
|
/*
|
||||||
* scan.c - Phase 1: WL2:D scanner, trigger + read loop (reverse-engineered).
|
* scan.c - Phase 1: WL2:D scanner, asynchronous read (reverse-engineered).
|
||||||
*
|
*
|
||||||
* Confirmed from the previous build: opening WL2:D then issuing control ops 6
|
* Confirmed: opening WL2:D and issuing control ops 6/7 triggers a scan (laser
|
||||||
* and 7 triggers a scan (laser fires, green good-read LED). What was missing was
|
* fires, green LED). Neither synchronous read form returned data, and SCANAPP
|
||||||
* the read: a bare p_iow(chan, P_FREAD, buf) passes no length. This uses p_read
|
* in the ROM uses an async pattern (post read -> P_FREAD -> P_FCANCEL). So this
|
||||||
* (which passes &len) to collect the decoded result, and re-triggers (ops 6/7)
|
* posts an asynchronous read (p_ioc), triggers the scan (ops 6/7), then waits
|
||||||
* each iteration so successive scans work without relying on the scan key.
|
* for completion (p_iowait). Decoded output is CR/LF-terminated.
|
||||||
* Decoded output is CR/LF-terminated (default Symbol2 postamble).
|
|
||||||
*/
|
*/
|
||||||
#include <plib.h>
|
#include <plib.h>
|
||||||
|
|
||||||
@@ -17,7 +16,9 @@ GLDEF_C INT main(VOID)
|
|||||||
{
|
{
|
||||||
VOID *chan;
|
VOID *chan;
|
||||||
UBYTE buf[256];
|
UBYTE buf[256];
|
||||||
INT err, n, i;
|
WORD stat;
|
||||||
|
UWORD len;
|
||||||
|
INT err, i;
|
||||||
|
|
||||||
err = p_open(&chan, "WL2:D", (UINT)-1);
|
err = p_open(&chan, "WL2:D", (UINT)-1);
|
||||||
p_printf("open WL2:D: %d\n", err);
|
p_printf("open WL2:D: %d\n", err);
|
||||||
@@ -27,23 +28,32 @@ GLDEF_C INT main(VOID)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
p_printf("Present a barcode under the laser. Reads:\n\n");
|
p_printf("Present a barcode under the laser. Async reads:\n\n");
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
p_iow(chan, WL2_TRIG1); /* trigger a scan */
|
len = sizeof(buf);
|
||||||
|
stat = E_FILE_PENDING;
|
||||||
|
p_ioc(chan, P_FREAD, &stat, buf, &len); /* post async read */
|
||||||
|
|
||||||
|
p_iow(chan, WL2_TRIG1); /* trigger the scan */
|
||||||
p_iow(chan, WL2_TRIG2);
|
p_iow(chan, WL2_TRIG2);
|
||||||
n = p_read(chan, buf, sizeof(buf)); /* collect decoded result (with len) */
|
|
||||||
if (n < 0) {
|
p_iowait(); /* wait for a completion */
|
||||||
p_printf("read %d\n", n);
|
|
||||||
|
if (stat == E_FILE_PENDING) { /* our read didn't finish */
|
||||||
|
p_iow(chan, P_FCANCEL);
|
||||||
|
p_waitstat(&stat);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (n == 0)
|
if (stat < 0) {
|
||||||
|
p_printf("stat %d\n", stat);
|
||||||
continue;
|
continue;
|
||||||
p_printf("n=%d:", n);
|
}
|
||||||
for (i = 0; i < n && i < 40; i++)
|
p_printf("len=%d:", len);
|
||||||
|
for (i = 0; i < 40 && i < 256; i++)
|
||||||
p_printf(" %d", buf[i]);
|
p_printf(" %d", buf[i]);
|
||||||
p_printf(" \"");
|
p_printf(" \"");
|
||||||
for (i = 0; i < n && i < 40; i++)
|
for (i = 0; i < 40 && i < 256; i++)
|
||||||
p_putch(buf[i] >= ' ' ? buf[i] : '.');
|
p_putch(buf[i] >= ' ' ? buf[i] : '.');
|
||||||
p_printf("\"\n");
|
p_printf("\"\n");
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user