[sane-devel] problem setting custom resolution

Henning Meier-Geinitz henning@meier-geinitz.de
Fri, 22 Aug 2003 08:03:36 +0200


Hi,

On Tue, Sep 23, 2003 at 10:34:13AM +0530, aneesh m raj wrote:
> Im trying to read the scanned data using sane form UMAX 2000p but
> when i set a custom resolution the read is causing some problem. This
> is my code.

Which problem exactly? Does it work with other frontends?

The code looks mostly ok for me, only some error checking for NULL-pointers
is missing. And be careful not to create buffer overflows with strcpy.

You should put sane_start inside the outer "do" loop if this loop is
intended for multi-pass scanning.

>   do
>   {
>     
>     status = read_data(devHnd, buffer, MAX_LEN, &len);
>     if(status == SANE_STATUS_GOOD )
>      {
>     
>       fwrite(buffer,len,sizeof(SANE_Byte),fp);
>      }
>     else if(status != SANE_STATUS_EOF)
>     {
>   
>       set_error(act); 
>       printf("Reading scanned data failed...\n");
>     }
>     free(buffer);
>     buffer = (SANE_Byte*)malloc(sizeof(SANE_Byte) * MAX_LEN);

I don't understand why you free the buffer and malloc it right again.


>   }while( status == SANE_STATUS_GOOD && len != 0);

len can be 0 when you called sane_set_io_mode and set the io_mode to
non-blocking.

>   if( status == SANE_STATUS_EOF)
>   {
>     pthread_cond_signal(&pollevent);
>     printf("Reading complete...\n"); 
>   }
>   else 
>   {
>     pthread_cond_signal(&pollevent);
>     ret = 1;
>     set_error(act); 
>     printf("Reason: %s",(char*)sane_strstatus(status)); 
>   }

If you get an error here, I'd leave the "do" loop. It doesn't really
make sense to try to read the other frames if reading one of them
resulted in an error.

> any help is appreciated

How do you set the resolution? To which value? How does read_data()
look like?

Bye,
  Henning