diff --git a/code/inventory/scan.c b/code/inventory/scan.c index a7a3430..c7b6a92 100644 --- a/code/inventory/scan.c +++ b/code/inventory/scan.c @@ -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 - * and 7 triggers a scan (laser fires, green good-read LED). What was missing was - * the read: a bare p_iow(chan, P_FREAD, buf) passes no length. This uses p_read - * (which passes &len) to collect the decoded result, and re-triggers (ops 6/7) - * each iteration so successive scans work without relying on the scan key. - * Decoded output is CR/LF-terminated (default Symbol2 postamble). + * Confirmed: opening WL2:D and issuing control ops 6/7 triggers a scan (laser + * fires, green LED). Neither synchronous read form returned data, and SCANAPP + * in the ROM uses an async pattern (post read -> P_FREAD -> P_FCANCEL). So this + * posts an asynchronous read (p_ioc), triggers the scan (ops 6/7), then waits + * for completion (p_iowait). Decoded output is CR/LF-terminated. */ #include @@ -17,7 +16,9 @@ GLDEF_C INT main(VOID) { VOID *chan; UBYTE buf[256]; - INT err, n, i; + WORD stat; + UWORD len; + INT err, i; err = p_open(&chan, "WL2:D", (UINT)-1); p_printf("open WL2:D: %d\n", err); @@ -27,23 +28,32 @@ GLDEF_C INT main(VOID) 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 (;;) { - 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); - n = p_read(chan, buf, sizeof(buf)); /* collect decoded result (with len) */ - if (n < 0) { - p_printf("read %d\n", n); + + p_iowait(); /* wait for a completion */ + + if (stat == E_FILE_PENDING) { /* our read didn't finish */ + p_iow(chan, P_FCANCEL); + p_waitstat(&stat); continue; } - if (n == 0) + if (stat < 0) { + p_printf("stat %d\n", stat); 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(" \""); - for (i = 0; i < n && i < 40; i++) + for (i = 0; i < 40 && i < 256; i++) p_putch(buf[i] >= ' ' ? buf[i] : '.'); p_printf("\"\n"); }