sane-project-website/html/doc013.html

100 wiersze
4.9 KiB
HTML

<html><body>
<a href="doc014.html"><img src=../icons/next.gif alt="Next"></a>
<a href="doc000.html"><img src=../icons/up.gif alt="Up"></a>
<a href="doc012.html"><img src=../icons/previous.gif alt="Previous"></a>
<a href="doc000.html"><img src=../icons/contents.gif alt="Contents"></a>
<a href="doc019.html"><img src=../icons/index.gif alt="Index"></a>
<hr>
<title>Code Flow</title>
<h2><a name="s4.4">4.4 Code Flow</a></h2><a name="i106">
<p>The code flow for the SANE API is illustrated in
Figure <a href="doc013.html#f4">4</a>. Functions <tt>sane_init()</tt> and
<tt>sane_exit()</tt> initialize and exit the backend, respectively.
All other calls must be performed after initialization and before
exiting the backend.
<p><p><a name="f4"></a>
<center>
<img width=566 height=510 src="img003.gif">
<p><center>Figure 4: Code flow</center>
</center>
<p>
<p>Function <tt>sane_get_devices()</tt> can be called any time after
<tt>sane_init()</tt> has been called. It returns the list of the
devices that are known at the time of the call. This list may change
over time since some devices may be turned on or off or a remote host
may boot or shutdown between different calls. It should be noted that
this operation may be relatively slow since it requires contacting all
configured devices (some of which may be on remote hosts). A frontend
may therefore want to provide the ability for a user to directly
select a desired device without requiring a call to this function.
<p>Once a device has been chosen, it is opened using a call to
<tt>sane_open()</tt>. Multiple devices can be open at any given time.
A SANE backend must not impose artificial constraints on how many
devices can be open at any given time.
<p>An opened device can be setup through the corresponding device handle
using functions <tt>sane_get_option_descriptor()</tt> and
<tt>sane_control_option()</tt>. While setting up a device, obtaining
option descriptors and setting and reading of option values can be
mixed freely. It is typical for a frontend to read out all available
options at the beginning and then build a dialog (either graphical or
a command-line oriented option list) that allows to control the
available options. It should be noted that the number of options is
fixed for a given handle. However, as options are set, other options
may become active or inactive. Thus, after setting an option, it
maybe necessary to re-read some or all option descriptors. While
setting up the device, it is also admissible to call
<tt>sane_get_parameters()</tt> to get an estimate of what the image
parameters will look like once image acquisition begins.
<p>The device handle can be put in blocking or non-blocking mode by a
call to <tt>sane_set_io_mode()</tt>. Devices are required to support
blocking mode (which is the default mode), but support for
non-blocking I/O is strongly encouraged for operating systems such as
UNIX.
<p>After the device is setup properly, image acquisition can be started
by a call to <tt>sane_start()</tt>. The backend calculates the exact
image parameters at this point. So future calls to
<tt>sane_get_parameters()</tt> will return the exact values, rather
than estimates. Whether the physical image acquisition starts at this
point or during the first call to <tt>sane_read()</tt> is unspecified
by the SANE API. If non-blocking I/O and/or a select-style interface
is desired, the frontend may attempt to call
<tt>sane_set_io_mode()</tt> and/or <tt>sane_get_select_fd()</tt> at
this point. Either of these functions may fail if the backend does
not support the requested operation.
<p>Image data is collected by repeatedly calling <tt>sane_read()</tt>.
Eventually, this function will return an end-of-file status
(<tt>SANE_STATUS_EOF</tt>). This indicates the end of the current
frame. If the frontend expects additional frames (e.g., the
individual channels in of a red/green/blue image or multiple images),
it can call <tt>sane_start()</tt> again. Once all desired frames have
been acquired, function <tt>sane_cancel()</tt> must be called. This
operation can also be called at any other time to cancel a pending
operation. Note that <tt>sane_cancel()</tt> must be called even if the
last read operation returned <tt>SANE_STATUS_EOF</tt>.
<p>When done using the device, the handle should be closed by a call to
<tt>sane_close()</tt>. Finally, before exiting the application,
function <tt>sane_exit()</tt> must be called. It is important not to
forget to call this function since otherwise some resources (e.g.,
temporary files or locks) may remain unclaimed.
<p><p><hr>
<a href="doc014.html"><img src=../icons/next.gif alt="Next"></a>
<a href="doc000.html"><img src=../icons/up.gif alt="Up"></a>
<a href="doc012.html"><img src=../icons/previous.gif alt="Previous"></a>
<a href="doc000.html"><img src=../icons/contents.gif alt="Contents"></a>
<a href="doc019.html"><img src=../icons/index.gif alt="Index"></a>
<hr>
</body></html>