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