[sane-devel] Problem with setting Fujitsu fi-4120c to Grayscale

Henning Meier-Geinitz henning@meier-geinitz.de
Fri, 25 Apr 2003 10:40:11 +0200


Hi,

On Thu, Apr 24, 2003 at 03:43:38PM -0500, Peter Chen wrote:
> I tried to set fi-4120c to Grayscale. I used the following code flow:
> 
>         status = sane_init(version_code, NULL);
>         status = sane_get_devices(&device_list, true);
>         ...
>         sane_exit();

Some backends don't like it if you call sane_exit() and then
sane_init() again. But I guess fujitsu doesn't ahve this bug.

>         status = sane_init(version_code, NULL);
>         status = sane_open("dev/usb/scanner0", &device );
>         sane_control_option (device, 0, SANE_ACTION_GET_VALUE,
> &num_dev_options, 0);
>   for (i = 0; i < num_dev_options; ++i)
>     {
>       opt = sane_get_option_descriptor (device, i);

Better check if opt != 0. Shouldn't happen but you never know...

>       // Set the resolutions to 300 dpi
>       if ( strcmp(opt->name, SANE_NAME_SCAN_X_RESOLUTION) == 0)
>       {
>           value = 300;
>           sane_control_option (device, i, SANE_ACTION_SET_VALUE, &value,
> &info);
>       }
>       if ( strcmp(opt->name, SANE_NAME_SCAN_Y_RESOLUTION) == 0)
>       {
>           value = 300;
>           sane_control_option (device, i, SANE_ACTION_SET_VALUE, &value,
> &info);
>       }

These two options are of SANE_TYPE_INT. So if value is of this type,
it's ok.

>       // Set the scan mode to GrayScale
>       if ( strcmp(opt->name, SANE_NAME_SCAN_MODE) == 0)
>       {
>           value = 3;
>           sane_control_option (device, i, SANE_ACTION_SET_VALUE, &value,
> &info);
>       }
>     }

This option is of type SANE_TYPE_STRING with a string-list contsraint.
So you must use a string. E.g. SANE_String s = "ADF";
 sane_control_option (device, i, SANE_ACTION_SET_VALUE, (void *) s, &info);

And better check the returned status codes.

Bye,
  Henning