Wed, 01 Apr 2009 22:11:05 +0100
initial commit
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include "hexdump.h"
5 #define ESC 0x1b
7 int main(int argc, char **argv)
8 {
9 FILE *prn;
11 // check command line args
12 if (argc < 2) {
13 printf("ERROR: must specify device name\n");
14 return -1;
15 }
17 // open printer device
18 if ((prn = fopen(argv[1], "r+b")) == NULL) {
19 printf("ERROR: couldn't open printer device '%s'\n", argv[1]);
20 return -1;
21 }
23 // INITIALISE
24 fprintf(prn, "%c%c", ESC, '@');
26 // REQUEST STATUS
27 fprintf(prn, "%c%c%c", ESC, 'i', 'S');
29 // Read status buffer from printer
30 unsigned char buf[32];
31 int timeout = 128;
32 do {
33 fread(buf, 1, 32, prn);
34 } while ((buf[0] != 0x80) && (timeout-- > 0));
36 if (timeout > 0) {
37 printf("Printer status:\n");
38 hex_dump(buf, 32);
39 } else {
40 printf("TIMEOUT\n");
41 return -1;
42 }
44 // Close the printer stream
45 fclose(prn);
46 return 0;
47 }