Scanner utility and SANE backend for Canon PIXMA MP series

Copyright © 2006-2007 Wittawat Yamwong <wittawat@web.de>
Please put "pixma" somewhere in the subject line.
Homepage: http://home.arcor.de/wittawat/pixma/

Contents

About

Canon PIXMA MP is a series of multi-function devices (All-in-one printer). This software supports only the scanning function of the device. MP150, MP170, MP450 and MP500 are currently supported. I'm working on support for MP750 and other devices in the series. (See status) I've contacted Martin Schewe (the author of the driver for MP750/MP780) and started some experiments to integrate the both drivers in one binary. Because I only have MP150, I need your help for testing the software with other models. Currently, the software compiles and runs on Linux. Porting to other OSes that support USB is also possible.

The core driver, on which the SANE backend and stand-alone utility are based, is in an ALPHA stage and will stay in this stage because I've no programming manual or protocol specification for the devices at all. By analyzing USB traffics I could get enough information to write a driver that seems to work. Although many testers and I do our best to test the software, it will not work in every situation.

If you are looking for a Linux printer driver for these devices, have a look at turboprint (commercial software) or printer drivers by Canon in Japan (partially open-source software).

License

  Scanner utility and SANE backend for Canon PIXMA MP series
  Copyright (C) 2006-2007 Wittawat Yamwong

  1. Redistributions of source code must retain the above copyright
     notice, this list of conditions and the following disclaimer.
  2. Redistributions in binary form must reproduce the above copyright
     notice, this list of conditions and the following disclaimer in the
     documentation and/or other materials provided with the distribution.

  THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
  IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Status

See also detailed status(online).

Model USB ID Hardware features Status and comments
DPI GR GT AD BT
Protocol 1a: The backend is ready for day-to-day use although some features are missing.
MP150 4A9:1709 1200(1) Y Y - 1x1 working
MP170 4A9:170A 1200(1) Y Y - 2x1 working
MP450 4A9:170B 1200(1) Y Y - 2x4 working but making loud noise at 600 DPI
MP500 4A9:170C 1200(1) Y Y - 2x4 working
MP530 4A9:1712 1200(1) Y Y Y 2x1 working
MP800 4A9:170D 2400(2) Y Y - 2x5 working but no support for film scan
MP800R 4A9:170E 2400(2) Y Y - 2(?) working but no support for film scan
MP830 4A9:1713 2400(2) Y Y Y 2x1 working but no duplex ADF yet
Protocol 1b
MP160 4A9:1714 600 ? Y - ? Full scan @ 75DPI color works. TBD
MP180 4A9:1715(?) 1200 ? ? - ? untested
MP460 4A9:1716 1200 ? Y - ? Full scan @ 75DPI color works. TBD
MP510 4A9:1717(?) 1200 ? ? - ? untested
MP600 4A9:1718 2400 ? Y - ? Full scan @ 75DPI color works. TBD
MP600R 4A9:? 2400 ? Y - ? untested
MP810 4A9:? ? ? ? - ? untested
Protocol 2
MP360 4A9:263C 1200 Y - - ? The scanner locks up sometimes.
MP370 4A9:? 1200 ? - - ? Please send me output of lsusb.
MP390 4A9:? 1200 ? - - ? Please send me output of lsusb.
MP700 4A9:2630 1200 Y - - 1x1 working except grayscale @ 1200DPI
MP730 4A9:262F 1200 Y(?) - ? 1x1(?) ADF and grayscale are untested.
Protocol 3
MP750 4A9:1706 2400(2) - - Y 2x1 Canceling scan in ADF mode doesn't eject the paper!
MP760 4A9:1708 2400(2) - - - 2(?) The scanner hangs!
MP780 4A9:1707 2400(2) - - Y 2(?) Both flatbed and ADF work but scanner hangs when cancel during a scan.
Unknown protocol: These devices don't work with this backend and there is no easy way to add supports because they use a different command set which has to be analyzed first. Co-programmers are welcome! :-) I personally cannot do this because I don't have the devices.
MP110 4A9:1700 1200 N N - N unsupported
MP130 4A9:1701 1200 N N - N unsupported
  • DPI - maximum resolution
  • GR - grayscale
  • GT - gamma table
  • AD - automatic document feeder
  • BT - number of buttons x number of events per button
  • Y - supported by the subdriver
  • N - not supported by the subdriver
  • - - not applicable, no such feature in hardware
  • ? - unknown, please correct me!

Notes

  1. Maximum hardware resolution is 1200x2400 DPI but limited by the user interface to 1200x1200 DPI.
  2. Maximum hardware resolution is 2400x4800 DPI but limited by the user interface to 2400x2400 DPI.

Download and ChangeLog

You will find an up-to-date version here.

The SANE backend is now included in the sane-backends CVS. It can be downloaded from the SANE project homepage. Please follow the download instruction.

Version Comment
0.13.0
  • Added MP170, MP180, MP460, MP510 and MP600. Thanks to David Nicklay for the patch.
  • Fixed a buffer-overflow bug in sane_read().
0.12.2
  • Added SmartBase MP360 and PIXMA MP800R
  • MP760: Fixed color alignment (line correction) for 300DPI and 600DPI.
0.12.1
  • MP830: Fixed ADF. Single-side ADF should work now. Duplex mode is still a work in progress.
  • MP760: Fixed "fuzzy" scanned images. Line correction should be correct now.
  • MP760,MP780: Added work-around for the problem: device doesn't response to the first command. (Was the "hang" problem.) There are still cases that the second command is also timed out.
0.12.0
  • Now use own error codes. This increases portability a bit.
  • Added MP530 product ID.
  • MP700,MP730: Added experimental grayscale mode. Please test!
0.11.3
  • Fixed installation script, again. Look for libsane-dll.so.1 not libsane-dll.so.
  • MP750: Fixed lockups problems. Do MP750,MP760 and MP780 still hang with this version?
  • MP750: Added support for button events.
  • Fixed buffer underrun problem. If the scanner sends less data than expected, the driver will fill the rest with 0xff.
  • sane-pixma.html: Added description of the button-controlled option. It's experimental.
0.11.2
  • Fixed installation script. It should also find SANE installation in /usr/local.
  • Added sane-pixma.html - the backend man page in html format.
  • MP730: Added experimental code for ADF. Test with
    ./scan -d 10 -a -F experiment output.pnm
  • MP730,MP750: Added experimental code for buttons. Test with
    ./scan -d 10 -B
    and try pressing scanner buttons. Please report the result!
0.11.1
  • Added product ID for MP700 and MP800.
  • Fixed paper detection for ADF.
  • libsane-pixma.so: Fixed sane_get_devices(), now compatible with the SANE standard.
  • libsane-pixma.so: Removed emulate-adf option, use button-controlled instead.
  • libsane-pixma.so: Added button-controlled option, should work with both scanadf and xsane.
  • libsane-pixma.so: Improved button handling.
  • scan: Added compression option for tiff output format.
0.11.0
  • Removed scan's option: -P
  • Added product ID for MP830
  • Added sane.h and saneopts.h, so that libsane-pixma.so can be compiled without installing additional header files.
  • Implemented a reader task in the SANE backend. It makes the backend compatible with the SANE standard. Please test!
  • Added a simple installation and test script. Just type "sudo make install"

Contents of the package

Features

Installation

Warning - If you grant a group a full permission to access the scanner (by using udev, hotplug, resmgr etc.), every members in the group will have full access rights not only for the scanner part but also for the other parts of the device i.e. printer, memory-card reader and fax. These users can bypass your system's security policy and do everything with the device intentionally and unintentionally. If this is not what you want especially for a workgroup computer, you should consider using saned as a proxy. Then all other user frontends should be able to access the scanner only through saned. (saned is included in the sane-backends package.)

The software has been successfully tested on SUSE Linux 10.0 and 10.1 OSS (i386 and x86_64), kernel 2.6.13 and 2.6.16. It should compile on other Linux distributions as well. You need an ANSI C-Compiler and make, such as GNU gcc and make, and glibc. resmgr and libtiff (3.7.3 or later) are optional. SANE's header files sane.h and saneopts.h are also optional. If they are installed, Makefile will use them. If not, the files that come with the driver are used instead.

Note: For Linux kernel 2.4.x and other OS please download the driver (backend) from the SANE project homepage.

Unpack the package into a directory and compile with

make

The Makefile will automatically detect resmgr and libtiff. If it doesn't compile for some reasons or you don't want to link with them, run

make WITH_RESMGR=no WITH_TIFF=no

resmgr allows normal users to access USB devices through usbfs (if configured properly). Otherwise you have to run the program as root or set the usbfs permission accordingly e.g. by using a hotplug script or udev rules. By default the driver looks for USB devices in /dev/bus/usb then in /proc/bus/usb. Please consult the administration handbook of your OS (keywords: udev hotplug scanner sane) for how to grant a user an access to the scanner. (You need read and write permission.)

To install, type
sudo make install

If the automatic installation doesn't work, you can manually install the SANE backend:

  1. Copy libsane-pixma.so to your SANE's backend directory (normally /usr/lib/sane or /usr/lib64/sane),
  2. rename it to libsane-pixma.so.1 and
  3. add a line with the backend name pixma in dll.conf (normally in /etc/sane.d).

The device name is in the form "pixma:xxxxyyyy_zzzzzz" where x, y and z are vendor ID, product ID and serial number respectively. Example: pixma:04A91709_123456 is a MP150. Admitted, the device naming is not human-friendly but you can define an aliase with a human-friendly name (e.g. "MP150") in the config file dll.aliases. See also man sane-dll.

Because the SANE backend doesn't use any header files from sane-backends package (sanei_backend.h and friends), there could be compatibility and portability problems. Anyway, as far as I can test, there is no problem on SUSE Linux yet.

Usage

scan - the stand-alone program

You must have read and write permissions for the USB device node of your scanner. Otherwise, you have to run scan and SANE frontends as root.

./scan output.pnm

will scan the whole area at 75 DPI in color mode and save the output to output.pnm. Press the "scan" button on the device to begin. Running scan without parameters will show all available options.

./scan -LL
prints all supported models. Experimental subdrivers are disabled by default. scan will tell you how to enable them.

pixma - the SANE backend (libsane-pixma.so)

See sane-pixma man page and your frontend user manual.

Examples

  1. Archive color documents in a PDF file.

    Requirement: libtiff and tiff2pdf distributed in TIFF package.

    Turn to your computer's keyboard and type

    ./scan -r 150 -f tiff -m color /tmp/scan.tif

    Now you can go to your MP. Lay the first page in the scanner and press a scan button. (For MP150, there is only one "scan" button. For other models, there are 2 buttons, "Color" and "Gray". It makes no difference which button you press.) Then the next page and so on. Repeat this step until you've scanned all documents.

    Go back to your computer. Press Ctrl-C and run

    tiff2pdf -f -o YourDocumentName.pdf /tmp/scan.tif

    You may want to check the PDF file with your favorite PDF viewer.

  2. Scan a photo and correct color to sRGB.

    Requirement: libtiff, tifficc in lcms package and ICC profile of your scanner. You may find the ICC profile in Windows XP under %WINDIR%\system32\spool\drivers\color. For MP150, its name is CNFMP15R.ICC.

    I assume that the size of your photo is 15cm x 10cm. Lay a photo in the scanner and run

    ./scan -r 600 -w 150 -h 100 -m color -1 -f tiff /tmp/scan.tif
    tifficc -i YourScanner.ICC /tmp/scan.tif newphoto-sRGB.tif
    
  3. Launch a program when you press a scanner button.

    BUTTON=`./scan -B`
    case "$BUTTON" in
        1??)  Button1_pressed ;;
        2??)  Button2_pressed ;;
        *) echo "No button pressed" ;;
    esac
    

    The tables below show the button codes.

    Action (for MP450, MP500 and MP800) Button
    ColorGray
    Save at PC 101 201
    Save as PDF 102 202
    Attach to e-mail 103 203
    Open with application 104 204
    Scan and save film 105 205
    Model Button
    ColorGray
    MP150 (has only one "SCAN" button) 100 -
    MP170, MP530, MP750, MP760, MP780 100 200
    MP830 101 201

    Your exercise: write a script that monitors the button state. When a user presses a scanner button, launch a program that automatically scans a document, converts to PDF and then saves it in $HOME/Documents. ;-)

For testers and developers

For testers

  1. Scan just a small area at 75 DPI in color mode first! e.g 3cm x 2cm
    ./scan -1 -d 10 -w 30 -h 20 test.pnm 2> test.log
  2. Does it work at all?
  3. Check the output image.
  4. Does the driver recover from error conditions correctly? The scanner should return to the standby state after a few seconds and you should be able to start a new scan again.
  5. Do resolution settings work as expected?
  6. When a model passes all above tests, its status will be changed from "experimental" to "working". Please write me an email.
  7. For models with ADF, does it work?
  8. ...

If there are errors, set the debug level to 10.

./scan -d 10 [your-options] output.pnm 2> test.log

or if you are using a SANE frontend

export SANE_DEBUG_PIXMA=10
export PIXMA_EXPERIMENT=1 
xsane 2> test.log

Replace xsane with your frontend.

This will dump a short version of USB traffics to test.log but it still can be very long. The most relevant part is normally the first 100 lines and a few lines at the end. Compare the output with your log generated on Windows.

Any comments, feedbacks, questions etc. are welcome. Don't hesitate to contact me. :-) For bug reports, you should also attach (gzipped) debugging output. (But please don't send me any attachments bigger than 50kB. Upload logs or anything ≥ 50kB somewhere in the Internet and send me just the link.)

For developers

Install doxygen, if not yet installed, and run

make doc

You will find the API reference in doc/html/index.html.

To compile scan_sim:

make scan_sim

scan_sim checks IO traffics against a log file produced by usbsnoop. The tool helps developers who don't own the hardware for which they want to write a subdriver. I could rapidly prototype subdrivers for MP730 and MP750 because of this tool. More information on request.

Acknowledgment

I would like to thank:

Links

Contact

For the SANE backend: sane-devel mailing list and bug tracking system.

Or mail to Wittawat Yamwong <wittawat@web.de>. The subject line should contain the word "pixma". (for example "PIXMA MP830: ADF doesn't work!") If the size of log files are more than 50kB, put them on the web and send me just the link. (Prefered languages: Thai, German and English)


Wittawat Yamwong