/* * scan.c - Phase 1 inventory demo: scan UPC barcodes and display them. * * Blocking design: the app opens the barcode serial channel (TTY:D) and reads * it with a blocking p_read, assembling bytes until the scanner's terminator, * then validates and prints each barcode. Exit via the System screen. * * (An earlier version waited on the keyboard asynchronously via CON: so Esc * could quit; that panicked the Window Server - on SIBO the keyboard is * event-driven through the window server, not a raw CON: byte read. A proper * scan-or-key loop needs the Window Server event API, whose reference manual * is not among the SDK docs in this repo. Blocking output via p_printf is * fine, so this version sticks to that.) * * This also serves as the format diagnostic: it prints the byte length of each * decoded barcode alongside the text, so we can see exactly what the scanner * emits for a UPC (12 vs 13 digits, any prefix/suffix) before Phase 2 uses it * as a database key. */ #include #include "bcode.h" #include "upc.h" GLDEF_C INT main(VOID) { VOID *bchan; UBYTE raw[BCODE_MAXLEN]; TEXT line[BCODE_MAXLEN]; INT lineLen = 0; INT err, n, textLen; if ((err = bcodeOpen(&bchan)) < 0) { p_printf("Cannot open barcode port TTY:D (err %d)\n", err); return 1; } p_printf("Inventory scan demo\n"); p_printf("Scan UPC barcodes. Exit via the System screen.\n\n"); for (;;) { n = p_read(bchan, raw, sizeof(raw)); /* blocks until bytes arrive */ if (n < 0) { p_printf("read error %d\n", n); continue; } if (bcodeAssemble(raw, n, line, &lineLen, BCODE_MAXLEN)) { textLen = 0; while (line[textLen] != '\0') textLen++; /* Diagnostic: length + text + validity. */ if (upcIsValid(line)) p_printf("len=%d [%s] OK\n", textLen, line); else p_printf("len=%d [%s] BAD\n", textLen, line); } } /* not reached in this diagnostic build */ }