1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/main.c Wed Apr 01 22:11:05 2009 +0100 1.3 @@ -0,0 +1,47 @@ 1.4 +#include <stdio.h> 1.5 +#include <stdlib.h> 1.6 +#include "hexdump.h" 1.7 + 1.8 +#define ESC 0x1b 1.9 + 1.10 +int main(int argc, char **argv) 1.11 +{ 1.12 + FILE *prn; 1.13 + 1.14 + // check command line args 1.15 + if (argc < 2) { 1.16 + printf("ERROR: must specify device name\n"); 1.17 + return -1; 1.18 + } 1.19 + 1.20 + // open printer device 1.21 + if ((prn = fopen(argv[1], "r+b")) == NULL) { 1.22 + printf("ERROR: couldn't open printer device '%s'\n", argv[1]); 1.23 + return -1; 1.24 + } 1.25 + 1.26 + // INITIALISE 1.27 + fprintf(prn, "%c%c", ESC, '@'); 1.28 + 1.29 + // REQUEST STATUS 1.30 + fprintf(prn, "%c%c%c", ESC, 'i', 'S'); 1.31 + 1.32 + // Read status buffer from printer 1.33 + unsigned char buf[32]; 1.34 + int timeout = 128; 1.35 + do { 1.36 + fread(buf, 1, 32, prn); 1.37 + } while ((buf[0] != 0x80) && (timeout-- > 0)); 1.38 + 1.39 + if (timeout > 0) { 1.40 + printf("Printer status:\n"); 1.41 + hex_dump(buf, 32); 1.42 + } else { 1.43 + printf("TIMEOUT\n"); 1.44 + return -1; 1.45 + } 1.46 + 1.47 + // Close the printer stream 1.48 + fclose(prn); 1.49 + return 0; 1.50 +}