Learning the ScanJet protocol
Post date: Jan 25, 2013 7:38:54 AM
Almost all HP scanners - even the new OfficeJet 6500a that I'm testing this with - are controlled by the Scanner Control Language, which is a series of commands that one can send to or receive from a scanner.
I've found a documentation of the protocol at http://cubexyz.blogspot.ca/2008/09/programming-flatbed-scanner.html (thanks!) There's also some documentation from the hplip headers: http://stuff.mit.edu/afs/athena/astaff/project/opssrc/cups/hplip-3.9.12/scan/sane/scl.h
With these guides, let's decode this snippet of the ScanJet protocol, sent by xsane and captured by Wireshark.
00000000 30 30 00
From scanner: Scanner reports that it's free.
00000000 1b 45 .E
To scanner: ESC E is reset.
00000002 1b 2a 66 31 48 .*f1H
To scanner: ESC * f 1 H is SCL_CMD_SET_DEVICE_LOCK, so probably this locks the scanner's control panel.
00000007 1b 2a 66 30 49 1b 2a 73 35 30 35 45 .*f0I.*s 505E
To scanner: SCL_CMD_SET_DEVICE_LOCK_TIMEOUT - timeout to 0, then send binary data for dithering, I think.
00000002 1b 2a 73 35 30 35 64 35 57 .*s505d5 W
0000000B 30 30 30 30 37 00007
00000013 1b 2a 61 34 54 .*a4T
To scanner: data type set to 4 (grayscale)
00000018 1b 2a 61 38 47 1b 2a 6d 32 53 1b 2a 61 32 43 1b .*a8G.*m 2S.*a2C.
To scanner: data width is 8, ccd resolution is 2, MFPDTF to 2 (???), compression to 2.
00000028 2a 6d 31 30 51 1b 2a 61 33 30 30 52 1b 2a 61 33 *m10Q.*a 300R.*a3
To scanner: JPEG quality to 10, 300 DPI
00000038 30 30 53 1b 2a 66 30 58 1b 2a 66 30 59 1b 2a 66 00S.*f0X .*f0Y.*f
To scanner: 300 DPI, window x = 0 window y = 0
00000048 32 35 34 39 50 1b 2a 66 34 35 30 30 51 1b 2a 73 2549P.*f 4500Q.*s
To scanner; window end x =2549, window end y = 4500
00000058 31 30 32 36 45 1026E
To scanner: Query number of scanlines
00000010 1b 2a 73 31 30 32 36 64 34 35 30 30 56 .*s1026d 4500V
From scanner: response to the capability query.
0000005D 1b 2a 73 31 30 32 34 45 .*s1024E
To scanner: Query pixels per scan line.
0000001D 1b 2a 73 31 30 32 34 64 32 35 34 39 56 .*s1024d 2549V
From scanner: response to the capability query.
00000065 1b 2a 6f 45 .*oE
To scanner: clear errors
00000069 1b 2a 66 30 53 .*f0S
To scanner: and scan!
Caveats:
- Any invalid command (e.g. some zeros) causes the scanner to cancel the scan.
- A reset sent during a scan also causes the scanner to cancel the scan.