/* Simple scanner test utility Redirect stdout to file Do a colour scan e.g. scantest > data.pbm */ #include main() { int rc; int a,b; int dpi; FILE *fopen(), *fp_out, *fp_in; a = 0; fp_out = fopen ("/dev/usb/scanner0", "wb"); if (fp_out == NULL) { printf ("\nError"); goto exit; } /* Do a reset */ rc = fprintf(fp_out, "\033zE"); fprintf (stderr, "\nfprintf returns %d", rc); fprintf (stderr, "\nEnter DPI: "); scanf ("%d", &dpi); /* set resolution, in DPI */ fprintf(fp_out, "\033*a%dR", dpi); fprintf(fp_out, "\033*a%dS", dpi); /* set scan extents, in 1/720'ths of an inch fprintf(fp_out, "\033*f%dX", 0); fprintf(fp_out, "\033*f%dY", 0); fprintf(fp_out, "\033*f%dP", 1440); /* x */ fprintf(fp_out, "\033*f%dQ", 1440); /* y */ /* set output data type to colour */ fprintf(fp_out, "\033*a%dT", 5); /* set inverse image */ fprintf(fp_out, "\033*a%dI", 1); /* Do a scan */ rc = fprintf(fp_out, "\033*f0S"); fprintf (stderr, "\nfprintf returns %d", rc); fclose (fp_out); /* Open scanner for reading input */ fp_in = fopen ("/dev/usb/scanner0","rb"); if (fp_in == NULL) { printf ("\nRead Error\n"); goto exit; } /* Header for PPM file */ printf("P6\n1440 1440 255\n"); while (a != EOF) { a = fgetc(fp_in); putchar (a); } fclose (fp_in); fprintf (stderr, "\nScan complete\n", rc); exit:; }