The SANE Scanner Interface

SANE makes it easy to support a wide variety of devices and of applications with a minimum amount of programming effort.
Programming With SANE

By definition, SANE is only as good as the programs that use it. This means the more applications and the more devices that use SANE, the merrier. The SANE distribution comes with a detailed document that explains the SANE API; however, the interface is quite simple. The six main functions are listed below:

  1. handle <- sane_open(device-name) allows you to open a SANE device by name (e.g., pnm:0).

  2. sane_close(handle) allows you to close a SANE device by name.

  3. sane_get_option_descriptor(handle, option-number) is used to query the controls available to the device (such as the brightness control in the PNM pseudo-device driver).

  4. sane_control_option(handle, option-number, action, value) is used to get or set the value of an option. For example, it can be used to set the value of the brightness option to 50 percent. In addition, some options support an auto-mode where the driver picks a reasonable value. For such options, sane_control_option() can also be used to turn auto-mode on or off.

  5. sane_start(handle) is used to start the acquisition of an image.

  6. bytes-read <- sane_read(handle, buffer, buffer-size) is used to read the actual image data until the entire image has been acquired.

The SANE API is simple by design. The goal was to make it possible to accomplish a simple task in a small amount of time while still providing enough functionality to enable sophisticated drivers and applications. The simplicity is best evidenced by the fact that it took just two evening sessions to convert the hpscanpbm program into a SANE driver for HP scanners. On the other end of the spectrum, the Mustek driver and xscanimage are fairly complicated programs and SANE had no problems accommodating them.

SANE and Commercial Applications/Drivers

What's our position with respect to commercial SANE drivers or applications? In the spirit of the GNU Public License, it is preferrable to have the source for SANE programs available. However, it is permissible to write a dynamically loaded, commercial SANE driver on Linux and other platforms that support dynamic loading. (Drivers are always dynamically loaded, so this doesn't cause any extra work.) By the same token, it is also proper to write a commercial application that links with the shared library. The basic ideas supporting this position are:

  1. Healthy competition between commercial and free programs is an asset, not a liability.

  2. The more wide-spread use SANE finds, the better for the Linux/Unix community.

Future Plans

In the immediate future, the plan is to add support for many more devices. For example, Agfa and Plustek scanner and Nikon filmscanner drivers are planned, and there is hope that drivers for some of the more popular digital cameras will materialize soon as well. To get the ultimate in network connectivity, there are also plans to implement a scanner application in Java, making it possible to control your scanner from your favorite Java-enabled web browser.

In the long term, it would be interesting to generalize SANE to embrace other multimedia devices including audio sources or video tape recorders.

In other words, SANE has just started, and there are many exciting projects to come. If you're interested in pursuing some of these by all means get in touch with other developers through the SANE mailing list (see Resources).



David recently graduated with a Ph.D. in Computer Science from the University of Arizona and is now a Member of the Technical Staff at HP Research Laboratories in Palo Alto. David first got involved with Linux when writing the Reed-Solomon error-correction code for the floppy tape driver. Then he pretty much forgot about it until he needed an affordable Alpha workstation. That's when he got involved with the Linux port to the Alpha. Ever since that time, he has been hanging around in the free software community. When not playing with computers, he enjoys spending time with his lovely wife. He can be reached via e-mail at



Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

sane recognizing multiple device on one machine

Anonymous's picture


how does sane recognize different devices on one machine?

the heirarchy u presented is using a network with a client having multiple devices.

Thanks for all the

Gimmy's picture

Thanks for all the information, I am definitely a SANE fan now and it's actually the first time I hear about it but I always needed it. I just hope this would spare me with any troubles with any Epson scanners.