summaryrefslogtreecommitdiffstats
path: root/Documentation/usb/scanner.txt
blob: 1dce956deed417f8f4370676f963a45cce7eaf74 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
Copyright (C) 1999, 2000 David E. Nelson

April 26, 2000

CHANGES

- Amended for linux-2.3.99-pre6-3
- Appended hp_scan.c to end of this README
- Removed most references to HP
- Updated uhci/ohci host controller info
- Updated support for multiple scanner support
- Updated supported scanners list
- Updated usbdevfs info
- Spellcheck

OVERVIEW

This README addresses issues regarding how to configure the kernel
to access a USB scanner.  Although the driver was originally conceived
for USB HP scanners, it's general enough so that it can be used with
other scanners.  Also, one can now pass the USB Vendor and Product
ID's using module parameters for unknown scanners.  Refer to the
document scanner-hp-sane.txt for guidance on how to configure SANE to
use a USB HP Scanner.


ADDITIONAL INFORMATION

http://www.linux-usb.org/


REQUIREMENTS

A host with a USB port.  Ideally, either a UHCI (Intel) or OHCI
(Compaq and others) hardware port should work.  At the time of this
writing, there are two UHCI drivers and one OHCI.

A Linux development kernel (2.3.x) with USB support enabled or a
backported version to linux-2.2.x.  See http://www.linux-usb.org for
more information on accomplishing this.

A Linux kernel with USB Scanner support enabled.

'lspci' which is only needed to determine the type of USB hardware
available/installed in your machine.

CONFIGURATION

Using `lspci -v`, determine the type of USB hardware available/installed.

  If you see something like:

    USB Controller: ......
    Flags: .....
    I/O ports at ....

  Then you have a UHCI based controller.

  If you see something like:

     USB Controller: .....
     Flags: ....
     Memory at .....

  Then you have a OHCI based controller.

Using `make menuconfig` or your preferred method for configuring the
kernel, select 'Support for USB', 'OHCI/UHCI' depending on your
hardware (determined from the steps above), 'USB Scanner support', and
'Preliminary USB device filesystem'.  Compile and install the modules
(you may need to execute `depmod -a` to update the module
dependencies). If any of the USB sections were compiled into the
kernel, a reboot is necessary. NOTE: Updating the boot disk with
'lilo' may also be required. Testing was performed only as modules,
YMMV.

Beginning with version 0.4 of the driver, up to 16 scanners can be
connected/used simultaneously.  If you intend to use more than
one scanner at a time:

   Add a device for the USB scanner:
	`mknod /dev/usbscanner0 c 180 48`
	`mknod /dev/usbscanner1 c 180 49`
                      . 
                      .
	`mknod /dev/usb/scanner15 180 63`


If you foresee using only one scanner it is best to:
	`mknod /dev/usbscanner0 c 180 48`
	`ln -s /dev/usbscanner0 /dev/usbscanner`


Set appropriate permissions for /dev/usbscanner[0-15] (don't forget
about group and world permissions).  Both read and write permissions
are required for proper operation. For example:
	`chmod 666 /dev/usbscanner0`

Load the appropriate modules (if compiled as modules):

  OHCI:
    modprobe usb-ohci
    modprobe scanner

  UHCI:
    modprobe usb-uhci
    modprobe scanner

That's it.  SANE should now be able to access the device.  

There is a small test program (hp_scan.c -- appended below) that can
be used to test the scanner device if it's an HP scanner that supports
SCL (Scanner Control Language).  Known HP scanner that support SCL are
the 4100, 5200, 6200, the 6300 -- note that the 4200 is *not*
supported since it does not understand SCL; it's also strongly
suspected that the 3300 and the PhotoSmart S20 are not SCL compliant.
Hp_scan.c's purpose is to test the driver without having to
retrieve/configure SANE.  Hp_scan.c will scan the entire bed and put
the output into a file called 'out.dat' in the current directory.  The
data in the file is raw data so it's not very useful for imaging.

MESSAGES

On occasions the message 'usb_control/bulk_msg: timeout' or something
similar will appear in '/var/adm/messages' or on the console or both,
depending on how your system is configured.  This is a side effect
that scanners are sometimes very slow at warming up and/or
initializing.  In most cases, however, only several of these messages
should appear and is generally considered to be normal.  If you see
a message of the type 'excessive NAK's received' then this should
be considered abnormal and generally indicates that the USB system is
unable to communicate with the scanner for some particular reason.

SUPPORTED SCANNERS

NOTE: Just because a product is listed here does not mean that
applications exist that support the product.  It's in the hopes that
this will allow developers a means to produce applications that will
support the listed USB products.

At the time of this writing, the following scanners were supported by
scanner.c:

 Acer
	 Prisa Acerscan 620U & 640U (!)
	 Prisa AcerScan 620U (!)
 Agfa
	 SnapScan 1212U
	 Another SnapScan 1212U (?)
	 SnapScan Touch
 Colorado -- See Primax/Colorado below
 Epson -- See Seiko/Epson below
 Genius
         ColorPage-Vivid Pro
 Hewlett Packard
	 3300C
	 4100C
	 4200C
	 PhotoSmart S20
	 5200C
	 6200C
	 6300C
 Microtek
	 ScanMaker X6 - X6U
	 Phantom 336CX - C3
	 Phantom 336CX - C3 #2
	 Phantom C6
	 ScanMaker V6USL
	 ScanMaker V6USL #2
	 ScanMaker V6UL - SpicyU
 Mustek
	 1200 CU
 Primax/Colorado
	 G2-300 #1
	 G2-600 #1
	 G2E-300 #1
	 ReadyScan 636i
	 G2-300 #2
	 G2-600 #2
	 G2E-300 #2
	 G2E-600
	 Colorado USB 9600
	 Colorado USB 19200
	 Colorado 600u
	 Colorado 1200u
 Seiko/Epson Corp.
	 Perfection 636U and 636Photo
	 Perfection 610
	 Perfection 1200U and 1200Photo
 Umax
	 Astra 1220U
	 Astra 1236U
	 Astra 2000U
	 Astra 2200U
 Visioneer
	 OneTouch 5300
	 OneTouch 7600 duplicate ID (!)
	 6100


MODULE PARAMETERS

If you have a device that you wish to experiment with or try using
this driver with, but the Vendor and Product ID's are not coded in,
don't despair.  If the driver was compiled as a module, you can pass
options to the driver.  Simply add 

  options scanner vendor=0x#### product=0x****

to the /etc/modules.conf file replacing the #'s and the *'s with the
correct ID's.  The ID's can be retrieved from the messages file or
using `cat /proc/bus/usb/devices`. Note that USB /proc support must be
enabled during kernel configuration.  If the 'scanner' module is
already loaded into memory, it must be reloaded for the module
parameters to take effect.  In essence, `rmmod scanner; modprobe
scanner` must be performed.

**NOTE**: In later kernels (2.3.38+), a new filesystem was introduced,
usbdevfs.  To mount the filesystem, issue the command (as root):

  mount -t usbdevfs /proc/bus/usb /proc/bus/usb

An alternative and more permanent method would be to add

  none  /proc/bus/usb  usbdevfs  defaults  0  0

to /etc/fstab.  This will mount usbdevfs at each reboot.  You can then
issue `cat /proc/bus/usb/devices` to extract USB device information.


BUGS

Just look at the list of fixes in the source files.  So, if you
encounter any problems feel free to drop me an email.

David /\/elson
dnelson@jump.net
http://www.jump.net/~dnelson

--------------- snip -- hp_scan.c -- snip ---------------
/*

This is a really crude attempt at writing a short test program.  It's
mostly only to be used to test connectivity with USB HP scanners that
understand SCL.  Currently, the supported models are 4100C, 5200C,
6200C, and the 6300C.  Note that the 4200C is *NOT* acceptable.

Copyright (C) David E. Nelson <dnelson@jump.net>, 1999

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or (at
your option) any later version.

*/

#include <stdio.h>
#include <stdlib.h>
#include <error.h>
#include <unistd.h>
#include <fcntl.h>

/*
   Gray Output produces about a 8945400 byte file.
   Color Output produces a 26836200 byte file. 
   
   To compile: gcc -o hp_scan hp_scan.c
*/

// #define COLOR /* Undef to scan GrayScale */

int send_cmd(int, const char *, int);
int read_cmd(int, char *, int);

int
main(void) {

	ssize_t cnt = 0, total_cnt = 0;

	FILE *fpout;

	int fp;
	int data_size = 32768;

	char *data;

	static char reset_cmd[] = {'\x1b','E'};

#ifdef COLOR
	static char data_type_cmd[] = {'\x1b','*','a','5','T'}; /* Color */
	static char data_width_cmd[] = {'\x1b','*','a','2','4','G'}; /* 24 Bit Color */
#else
	static char data_type_cmd[] = {'\x1b','*','a','4','T'}; /* Gray */
	static char data_width_cmd[] = {'\x1b','*','a','8','G'}; /* 8 Bit Gray */
#endif

	static char query_cmd[] = {'\x1b', '*', 's', '2', '5', '7', 'E'};
	static char start_scan_cmd[] = {'\x1b','*','f','0','S'};
	
	if(!(data=malloc(data_size))) {
		perror("malloc failed");
		exit (1);
	}
	
	if((fp=open("/dev/usbscanner", O_RDWR)) < 0) {
		perror("Unable to open scanner device");
		exit (1);
	}

	if((fpout=fopen("out.dat", "w+")) == NULL) {
		perror("Unable to open ouput file");
		exit(1);
	}

	send_cmd(fp, reset_cmd, sizeof(reset_cmd));
	send_cmd(fp, data_type_cmd, sizeof(data_type_cmd));
	send_cmd(fp, data_width_cmd, sizeof(data_width_cmd));
	send_cmd(fp, start_scan_cmd, sizeof(start_scan_cmd));

	while ((cnt = read(fp, data, data_size)) > 0) {
		printf("Read: %u\n", cnt); 
		if(fwrite(data, sizeof(char), cnt, fpout) < 0) {
			perror("Write to output file failed");
			exit (1);
		}
		total_cnt += cnt;
	}
	if (cnt < 0) {
		perror("Read from scanner failed");
		exit (1);
	}

	printf("\nRead %lu bytes.\n", total_cnt);

	send_cmd(fp, reset_cmd, sizeof(reset_cmd));

	close(fp);
	fclose(fpout);
	return (0);
}

int
send_cmd(int fp, const char * cmd, int length) {

	int result;
	int x;

	if((result = write(fp, cmd, length)) != length) {
		printf ("Write warning: %d bytes requested, %d written\n");
	} else if (result < 0) {
		perror ("send_cmd failure");
		exit (1);
	}
	return (result);
}
	
int
read_cmd(int fp, char * response, int length) {

	return read(fp, response, length);

}