/* * scan.c - Phase 1 barcode diagnostic: software-triggered scan over TTY:D. * * TTY:D is the top-slot bar code interface. It did not auto-transmit on a scan, * so this build uses the documented escape-sequence trigger (I/O Devices * Reference, HC Intelligent Bar Code Reader chapter): * -y1J enable single-read mode * -y1K "read next scan" - arms the reader for one label * After each decoded label (terminated by CR) it re-arms with another K. * Every received byte is streamed as a decimal value. * * =0x1b, '-'=0x2d, 'y'=0x79. Escape sequences carry no embedded spaces. */ #include GLDEF_C INT main(VOID) { VOID *chan; UBYTE b; INT err, n, c; static TEXT cmdJ[5] = { 0x1b, '-', 'y', '1', 'J' }; /* single-read mode on */ static TEXT cmdK[5] = { 0x1b, '-', 'y', '1', 'K' }; /* trigger one scan */ 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"); p_getch(); return 1; } err = p_write(chan, cmdJ, 5); p_printf("single-read mode (Esc-y1J): %d\n", err); err = p_write(chan, cmdK, 5); p_printf("trigger (Esc-y1K): %d\n", err); p_printf("\nPoint at a barcode. Streaming bytes:\n\n"); for (;;) { n = p_read(chan, &b, 1); if (n < 0) { p_printf("", n); continue; } if (n == 0) continue; c = b; p_printf(" %d", c); if (c == 13 || c == 10) { p_printf(" \n"); p_write(chan, cmdK, 5); /* re-arm for the next scan */ } } }