Next Up Previous Contents
Programming With SANE

5 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:

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

sane_close (handle):
allows you to close a SANE device.

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).

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.

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

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.


Next Up Previous Contents