2026-07-06 17:41:44 +01:00
|
|
|
/*
|
2026-07-06 21:56:22 +01:00
|
|
|
* scan.c - Phase 1: WL2:D scanner, asynchronous read (reverse-engineered).
|
2026-07-06 17:41:44 +01:00
|
|
|
*
|
2026-07-06 21:56:22 +01:00
|
|
|
* 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.
|
2026-07-06 17:41:44 +01:00
|
|
|
*/
|
|
|
|
|
#include <plib.h>
|
2026-07-06 18:28:22 +01:00
|
|
|
|
2026-07-06 21:52:26 +01:00
|
|
|
#define WL2_TRIG1 6
|
|
|
|
|
#define WL2_TRIG2 7
|
2026-07-06 21:23:19 +01:00
|
|
|
|
2026-07-06 17:41:44 +01:00
|
|
|
GLDEF_C INT main(VOID)
|
|
|
|
|
{
|
2026-07-06 19:04:43 +01:00
|
|
|
VOID *chan;
|
2026-07-06 20:39:17 +01:00
|
|
|
UBYTE buf[256];
|
2026-07-06 21:56:22 +01:00
|
|
|
WORD stat;
|
|
|
|
|
UWORD len;
|
|
|
|
|
INT err, i;
|
2026-07-06 18:28:22 +01:00
|
|
|
|
2026-07-06 21:44:10 +01:00
|
|
|
err = p_open(&chan, "WL2:D", (UINT)-1);
|
|
|
|
|
p_printf("open WL2:D: %d\n", err);
|
|
|
|
|
if (err < 0) {
|
|
|
|
|
p_printf("Press a key to exit.\n");
|
2026-07-06 19:04:43 +01:00
|
|
|
p_getch();
|
|
|
|
|
return 1;
|
2026-07-06 17:41:44 +01:00
|
|
|
}
|
2026-07-06 18:51:31 +01:00
|
|
|
|
2026-07-06 21:56:22 +01:00
|
|
|
p_printf("Present a barcode under the laser. Async reads:\n\n");
|
2026-07-06 20:14:54 +01:00
|
|
|
|
2026-07-06 19:04:43 +01:00
|
|
|
for (;;) {
|
2026-07-06 21:56:22 +01:00
|
|
|
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 */
|
2026-07-06 21:52:26 +01:00
|
|
|
p_iow(chan, WL2_TRIG2);
|
2026-07-06 21:56:22 +01:00
|
|
|
|
|
|
|
|
p_iowait(); /* wait for a completion */
|
|
|
|
|
|
|
|
|
|
if (stat == E_FILE_PENDING) { /* our read didn't finish */
|
|
|
|
|
p_iow(chan, P_FCANCEL);
|
|
|
|
|
p_waitstat(&stat);
|
2026-07-06 19:04:43 +01:00
|
|
|
continue;
|
|
|
|
|
}
|
2026-07-06 21:56:22 +01:00
|
|
|
if (stat < 0) {
|
|
|
|
|
p_printf("stat %d\n", stat);
|
2026-07-06 21:52:26 +01:00
|
|
|
continue;
|
2026-07-06 21:56:22 +01:00
|
|
|
}
|
|
|
|
|
p_printf("len=%d:", len);
|
|
|
|
|
for (i = 0; i < 40 && i < 256; i++)
|
2026-07-06 20:39:17 +01:00
|
|
|
p_printf(" %d", buf[i]);
|
|
|
|
|
p_printf(" \"");
|
2026-07-06 21:56:22 +01:00
|
|
|
for (i = 0; i < 40 && i < 256; i++)
|
2026-07-06 20:39:17 +01:00
|
|
|
p_putch(buf[i] >= ' ' ? buf[i] : '.');
|
|
|
|
|
p_printf("\"\n");
|
2026-07-06 19:04:43 +01:00
|
|
|
}
|
2026-07-06 17:41:44 +01:00
|
|
|
}
|