Made usb_low_read_rows more robust. Limited maximum block size and

added option for this. New version: 1.0-9.
Henning Meier-Geinitz <henning@meier-geinitz.de>
DEVEL_2_0_BRANCH-1
Henning Geinitz 2001-12-22 18:33:48 +00:00
rodzic b9c7f93d2b
commit fcb2863616
7 zmienionych plików z 90 dodań i 28 usunięć

Wyświetl plik

@ -46,7 +46,7 @@
This file implements a SANE backend for Mustek 1200UB and similar
flatbed scanners. */
#define BUILD 8
#define BUILD 9
#include "../include/sane/config.h"
@ -85,6 +85,9 @@ static SANE_Int num_devices;
static Mustek_Usb_Device *first_dev;
static Mustek_Usb_Scanner *first_handle;
/* Maximum amount of data read in one turn from USB */
static SANE_Word max_block_size = 8 * 1024;
/* Array of newly attached devices */
static Mustek_Usb_Device **new_dev;
@ -537,7 +540,8 @@ attach (SANE_String_Const devname, Mustek_Usb_Device ** devp,
return status;
}
dev->chip->scanner_type = scanner_type;
dev->chip->max_block_size = max_block_size;
DBG (2, "attach: found %s %s %s at %s\n", dev->sane.vendor, dev->sane.type,
dev->sane.model, dev->sane.name);
++num_devices;
@ -692,7 +696,7 @@ SANE_Status
sane_init (SANE_Int * version_code, SANE_Auth_Callback authorize)
{
SANE_Char line[PATH_MAX];
SANE_Char *word;
SANE_Char *word, *end;
SANE_String_Const cp;
SANE_Int linenumber;
FILE *fp;
@ -749,7 +753,36 @@ sane_init (SANE_Int * version_code, SANE_Auth_Callback authorize)
word = 0;
cp = sanei_config_get_string (cp, &word);
if (strcmp (word, "1200ub") == 0)
if (strcmp (word, "max_block_size") == 0)
{
free (word);
word = 0;
cp = sanei_config_get_string (cp, &word);
errno = 0;
max_block_size = strtol (word, &end, 0);
if (end == word)
{
DBG(3, "sane-init: config file line %d: max_block_size "
"must have a parameter; using 8192 bytes\n", linenumber);
max_block_size = 8192;
}
if (errno)
{
DBG(3, "sane-init: config file line %d: max_block_size `%s' "
"is invalid (%s); using 8192 bytes\n", linenumber,
word, strerror (errno));
max_block_size = 8192;
}
else
{
DBG(3, "sane_init: config file line %d: max_block_size set "
"to %d bytes\n", linenumber, max_block_size);
}
if (word)
free (word);
word = 0;
}
else if (strcmp (word, "1200ub") == 0)
{
if (new_dev_len > 0)
{

Wyświetl plik

@ -1,6 +1,9 @@
# mustek_usb.conf: Configuration file for Mustek USB scanner
# Read man sane-mustek_usb for documentation
# If USB errors occur, using this option may help
#option max_block_size 1024
# Autodetect 1200 UB and Trust Compact Scan USB 19200
usb 0x055f 0x0006

Wyświetl plik

@ -1,6 +1,6 @@
:backend "mustek_usb"
:status :new
:version "1.0-8"
:version "1.0-9"
:manpage "sane-mustek_usb"
:url "http://www.meier-geinitz.de/sane/"

Wyświetl plik

@ -2614,39 +2614,44 @@ usb_low_wait_rowing (ma1017 * chip)
SANE_Status
usb_low_read_rows (ma1017 * chip, SANE_Byte * data, SANE_Word byte_count)
{
size_t n;
size_t n, bytes_total;
SANE_Status status;
DBG (7, "usb_low_read_rows: start\n");
if (!chip->is_opened)
if (!(chip->is_opened))
{
DBG (3, "usb_low_read_rows: is_opened==SANE_FALSE\n");
return SANE_STATUS_INVAL;
}
if (!chip->is_rowing)
if (!(chip->is_rowing))
{
DBG (3, "usb_low_read_rows: is_rowing==SANE_FALSE\n");
return SANE_STATUS_INVAL;
}
n = byte_count;
status = sanei_usb_read_bulk (chip->fd, (SANE_Byte *) data, &n);
if (status != SANE_STATUS_GOOD)
n = MIN(byte_count, chip->max_block_size);
bytes_total = 0;
while ((SANE_Word) bytes_total < byte_count)
{
DBG (7, "usb_low_read_rows: problems during read: %s\n",
sane_strstatus (status));
return status;
status = sanei_usb_read_bulk (chip->fd, (SANE_Byte *) (data + bytes_total), &n);
if (status != SANE_STATUS_GOOD)
{
DBG (7, "usb_low_read_rows: problems during read: %s -- exiting\n",
sane_strstatus (status));
return status;
}
bytes_total += n;
if ((SANE_Word) bytes_total != byte_count)
{
DBG (7, "usb_low_read_rows: wanted %d, got %d "
"bytes (%d in total) -- retrying\n", byte_count, (SANE_Word) n,
(SANE_Word) bytes_total);
}
n = MIN((byte_count - (SANE_Word) bytes_total), chip->max_block_size);
}
if ((SANE_Word) n != byte_count)
{
DBG (7, "usb_low_read_rows: problems during read, wanted %ul, got %ul "
"bytes: %s\n", (unsigned long) byte_count, (unsigned long) n,
sane_strstatus (status));
return SANE_STATUS_IO_ERROR;
}
DBG (7, "usb_low_read_rows: exit, read %ul bytes\n", (unsigned long) n);
DBG (7, "usb_low_read_rows: exit, read %d bytes\n", (SANE_Word) bytes_total);
return SANE_STATUS_GOOD;
}

Wyświetl plik

@ -181,6 +181,7 @@ typedef struct ma1017
Sensor_Type sensor;
Motor_Type motor;
Mustek_Type scanner_type;
SANE_Word max_block_size;
}
ma1017;

Wyświetl plik

@ -1,5 +1,17 @@
CHANGES for the SANE Mustek USB backend
2001-12-08
* Release of version 1.0-9.
2001-12-08
* Added option max_block_size to limit amount of data acquired in one turn.
2001-12-07
* usb_low_read_rows: Retry until all the data is received. Set maximum
size of data acquired in one turn.
2001-11-15
* Release of version 1.0-8.

Wyświetl plik

@ -1,4 +1,4 @@
.TH sane-mustek 5 "15 Nov 2001"
.TH sane-mustek 5 "9 Dec 2001"
.IX sane-mustek_usb
.SH NAME
sane-mustek_usb - SANE backend for Mustek USB flatbed scanners
@ -91,11 +91,18 @@ work, a device name and the option specifying the scanner type must be placed
in
.IR mustek_usb.conf .
.PP
The global
.I option max_block_size
can be used to limit the amount of data acquired in one turn from the USB
system. It may be woth trying, if USB errors occur.
.PP
A sample configuration file is shown below:
.PP
.RS
# Comment
.br
option max_block_size 1024
.br
usb 0x055f 0x0001
.br
/dev/usb/scanner0
@ -103,10 +110,11 @@ usb 0x055f 0x0001
option 600cu
.RE
.PP
The first line is ignored. The second line tries to autodetect a scanner with
vendor id 0x055f and product id 0x0001 (Mustek 1200 CU). The third line tells
the backend to attach to /dev/usb/scanner0 and the fourth line specifies that
/dev/usb/scanner 0 is a Mustek 600 CU.
The first line is ignored. The second line sets the buffer size to a maximum of
1024 bytes. The third line tries to autodetect a scanner with vendor id 0x055f
and product id 0x0001 (Mustek 1200 CU). The fourth line tells the backend to
attach to /dev/usb/scanner0 and the fifth line specifies that
/dev/usb/scanner0 is a Mustek 600 CU.
.SH FILES
.TP
.I @CONFIGDIR@/mustek_usb.conf