[sane-devel] SANE_Handle question

abel deuring adeuring@gmx.net
Sun, 19 Sep 2004 13:33:16 +0200


Paul wrote:
> Hi,
> 
> I'm trying to implement using SANE within Scribus and I'm hitting a
> small snag. While the majority of the API is really simple to use, I'm
> having a problem with what SANE_Handle is.

Its great to hear that Scribus will support Sane.

> 
> The sane.h header has it defined as 
> 
> typedef void *SANE_Handle;
> 
> There are plenty of functions which require SANE_Handle, but nothing
> which actually sets it!

Well, there is a function which sets a SANE_Handle variable:

SANE_Status sane_open (SANE_String_Const name, SANE_Handle * h);

But it's easy to miss (or forget) this function while reading the docs 
-- that could have had easily happened for me too ;)

> According to the sane website, SANE does not require that a value of
> this type be a legal pointer value and an application shouldn't attempt
> to interpret the value of SANE_Handle.

I think all currently existing backends interpret SANE_Handle as a 
pointer, but this is not required. A frontend should interpret 
SANE_Handle to be simply an identifier; any assumption that it might be 
possible to access some backend-internal stuff may fail.

> How should I set the handle? For instance, when I obtain the device
> list, I have two show for my USB webcam and one for my scanner. I have
> to be able to set the handle to the scanner. Is it enough to set the
> handle to the device name or should it be set to the physical /dev/sg0
> value (which is not a good idea!)

call sane_get_devices, and use the field SANE_Device.name from the 
elements of device_list as the first parameter in the of call sane_open. 
  Using something like '/dev/sg0' will not work, because Sane does not 
know in this case, which backend should be used; 'mustek:/dev/sg0' might 
work. But I am not sure, if this is reasonable for a graphical 
frontend, where users are not supposed to have read the Sane 
documentation ;) The assignment of device names to real devices can 
offer some suprises. For example, /dev/sg0 means for Linux usually the 
device with the lowest SCSI ID on the first bus of the first adapter. 
But if this device was not powered when the SCSI adapter driver was 
loaded, it can later be made known to the SCSI system by a command like 
'echo "scsi add-single-device 0 0 4 0" > /proc/scsi/scsi' , and if the 
system has already found three other SCSI devices, the new device will 
be assigned to the device file /dev/sg3.

Abel