sjamesr / jfreesane

Java API to talk to the SANE scanning daemon
Apache License 2.0
60 stars 25 forks source link

Brother ADS-2800W STATUS_INVAL #106

Closed gh0ztbuster closed 1 year ago

gh0ztbuster commented 3 years ago

Ubuntu 18.04 (5.4.0-67-generic) Xsane and Simple Scan works I have tested various device options given the error but have been unsuccessful:

SANE_STATUS_INVAL: The scan cannot be started with the current set of options. The frontend should reload the option descriptors, as if SANE_INFO_RELOAD_OPTIONS had been returned from a call to sane_control_option(), since the device's capabilities may have changed.

The error:

au.com.southsky.jfreesane.SaneException: STATUS_INVAL at au.com.southsky.jfreesane.FrameReader.readRecord(FrameReader.java:108) at au.com.southsky.jfreesane.FrameReader.readFrame(FrameReader.java:53) at au.com.southsky.jfreesane.SaneSession.acquireImage(SaneSession.java:335) at au.com.southsky.jfreesane.SaneDevice.acquireImage(SaneDevice.java:105) at network.wisework.cite.scan.ScannerTest.getDocument(ScannerTest.java:220) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50) at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12) at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47) at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17) at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57) at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290) at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71) at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288) at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58) at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268) at org.junit.internal.runners.statements.FailOnTimeout$CallableStatement.call(FailOnTimeout.java:298) at org.junit.internal.runners.statements.FailOnTimeout$CallableStatement.call(FailOnTimeout.java:292) at java.util.concurrent.FutureTask.run(FutureTask.java:266) at java.lang.Thread.run(Thread.java:748)

Xsane works with these device settings (Brother:CustomScanner.drc):

"XSANE_DEVICE_RC" "Brother:CustomScanner" "xsane-version" "0.999" "mode" "24bit Color[Fast]" "resolution" 150 "source" "Automatic Document Feeder(center aligned,Duplex)" "MultifeedDetection" 0 "AutoDocumentSize" 0 "AutoDeskew" 0 "SkipBlankPage" 0 "SkipBlankPageSensitivity" 3276800 "tl-x" 0 "tl-y" 0 "br-x" 13315696 "br-y" 19305138 "xsane-main-window-x-position" 91 "xsane-main-window-y-position" 132 "xsane-main-window-width" 432 "xsane-main-window-height" 461 "xsane-project-window-x-position" 87 "xsane-project-window-y-position" 690 "xsane-standard-options-window-x-position" 88 "xsane-standard-options-window-y-position" 663 "xsane-advanced-options-window-x-position" 280 "xsane-advanced-options-window-y-position" 420 "xsane-histogram-window-x-position" 280 "xsane-histogram-window-y-position" 50 "xsane-gamma-window-x-position" 280 "xsane-gamma-window-y-position" 420 "xsane-batch-window-x-position" 480 "xsane-batch-window-y-position" 420 "xsane-preview-window-x-position" 0 "xsane-preview-window-y-position" 0 "xsane-preview-window-width" 490 "xsane-preview-window-height" 689 "xsane-gamma" 64135 "xsane-gamma-red" 65536 "xsane-gamma-green" 65536 "xsane-gamma-blue" 65536 "xsane-brightness" -1760668 "xsane-brightness-red" 0 "xsane-brightness-green" 0 "xsane-brightness-blue" 0 "xsane-contrast" 1760668 "xsane-contrast-red" 0 "xsane-contrast-green" 0 "xsane-contrast-blue" 0 "xsane-lineart-mode" 0 "xsane-threshold" 3276800 "xsane-threshold-min" 0 "xsane-threshold-max" 6553600 "xsane-threshold-multiplier" 65536 "xsane-threshold-offset" 0 "xsane-grayscale-scanmode" "" "xsane-enhancement-rgb-default" 1 "xsane-negative" 0 "xsane-show-preview" 0 "xsane-enable-color-management" 0 "xsane-scanner-default-color-icm-profile" "" "xsane-scanner-default-gray-icm-profile" ""

My code:

InetAddress address = InetAddress.getLocalHost(); SaneSession session = SaneSession.withRemoteSane(address); device = session.listDevices().get(0); // session.getDevice("brother5:net1;dev0"); device.open(); if (device != null) while (true) try { BufferedImage image = device.acquireImage(); process(image); } catch (IOException | SaneException e) { if (((SaneException) e).getStatus() == SaneStatus.STATUS_NO_DOCS) logger.info("getDocument end of document"); else logger.error(e, "getDocument device scan error"); break; }

I used brother sane drivers (https://download.brother.com/welcome/dlf104033/brscan5-1.2.6-0.amd64.deb):

sudo dpkg -i --force-all brscan5-1.2.6-0.amd64.deb sudo brsaneconfig5 -a name=CustomScanner model=ADS-2800W ip=xx.xx.xx.xx

Various options provided by printer: DEFAULTS:

mode: 24bit Color[Fast] resolution: 100 UNIT_DPI source: Automatic Document Feeder(left aligned) MultifeedDetection: false AutoDocumentSize: false AutoDeskew: false SkipBlankPage: false SkipBlankPageSensitivity: 50.0 UNIT_PERCENT tl-x: 0.0 UNIT_MM tl-y: 0.0 UNIT_MM br-x: 215.89999389648438 UNIT_MM br-y: 355.59999084472656 UNIT_MM

CONSTRAINTS:

mode: [24bit Color[Fast], Black & White, True Gray, Gray[Error Diffusion]] resolution (fixed): [0.00152587890625, 0.002288818359375, 0.0030517578125, 0.00457763671875, 0.006103515625, 0.0091552734375, 0.018310546875] resolution (int): [100, 150, 200, 300, 400, 600, 1200] source: [Automatic Document Feeder(left aligned), Automatic Document Feeder(center aligned), Automatic Document Feeder(left aligned,Duplex), Automatic Document Feeder(center aligned,Duplex)] brightness (not active): [MinFixed=-50.0, MaxFixed=50.0, QuanFixed=1.0, MinInt=-3276800, MaxInt=3276800, QuanInt=65536] contrast (not active): [MinFixed=-50.0, MaxFixed=50.0, QuanFixed=1.0, MinInt=-3276800, MaxInt=3276800, QuanInt=65536] SkipBlankPageSensitivity: [MinFixed=0.0, MaxFixed=100.0, QuanFixed=1.0, MinInt=0, MaxInt=6553600, QuanInt=65536] tl-x: [MinFixed=0.0, MaxFixed=215.89999389648438, QuanFixed=0.0999908447265625, MinInt=0, MaxInt=14149222, QuanInt=6553] tl-y: [MinFixed=0.0, MaxFixed=355.59999084472656, QuanFixed=0.0999908447265625, MinInt=0, MaxInt=23304601, QuanInt=6553] br-x: [MinFixed=0.0, MaxFixed=215.89999389648438, QuanFixed=0.0999908447265625, MinInt=0, MaxInt=14149222, QuanInt=6553] br-y: [MinFixed=0.0, MaxFixed=355.59999084472656, QuanFixed=0.0999908447265625, MinInt=0, MaxInt=23304601, QuanInt=6553]

scanimage -h:

Usage: scanimage [OPTION]...

Start image acquisition on a scanner device and write image data to standard output.

Parameters are separated by a blank from single-character options (e.g. -d epson) and by a "=" from multi-character options (e.g. --device-name=epson). -d, --device-name=DEVICE use a given scanner device (e.g. hp:/dev/scanner) --format=pnm|tiff|png|jpeg file format of output file -i, --icc-profile=PROFILE include this ICC profile into TIFF file -L, --list-devices show available scanner devices -f, --formatted-device-list=FORMAT similar to -L, but the FORMAT of the output can be specified: %d (device name), %v (vendor), %m (model), %t (type), %i (index number), and %n (newline) -b, --batch[=FORMAT] working in batch mode, FORMAT is 'out%d.pnm' out%d.tif' 'out%d.png' orout%d.jpg' by default depending on --format --batch-start=# page number to start naming files with --batch-count=# how many pages to scan in batch mode --batch-increment=# increase page number in filename by # --batch-double increment page number by two, same as --batch-increment=2 --batch-print print image filenames to stdout --batch-prompt ask for pressing a key before scanning a page --accept-md5-only only accept authorization requests using md5 -p, --progress print progress messages -n, --dont-scan only set options, don't actually scan -T, --test test backend thoroughly -A, --all-options list all available backend options -h, --help display this help message and exit -v, --verbose give even more status messages -B, --buffer-size=# change input buffer size (in kB, default 32) -V, --version print version information scanimage: rounded value of br-x from 215.9 to 215.88 scanimage: rounded value of br-y from 355.6 to 355.567

Options specific to device `brother5:net1;dev0': : --mode 24bit Color[Fast]|Black & White|True Gray|Gray[Error Diffusion] [24bit Color[Fast]] Select the scan mode --resolution 100|150|200|300|400|600|1200dpi [100] Sets the resolution of the scanned image. --source Automatic Document Feeder(left aligned)|Automatic Document Feeder(center aligned)|Automatic Document Feeder(left aligned,Duplex)|Automatic Document Feeder(center aligned,Duplex) [Automatic Document Feeder(left aligned)] Selects the scan source (such as a document-feeder). --brightness -50..50% (in steps of 1) [inactive] Controls the brightness of the acquired image. --contrast -50..50% (in steps of 1) [inactive] Controls the contrast of the acquired image. --MultifeedDetection[=(yes|no)] [no]

--AutoDocumentSize[=(yes|no)] [no]

--AutoDeskew[=(yes|no)] [no]

--SkipBlankPage[=(yes|no)] [no]

--SkipBlankPageSensitivity 0..100% (in steps of 1) [50]

Geometry: -l 0..215.9mm (in steps of 0.0999908) [0] Top-left x position of scan area. -t 0..355.6mm (in steps of 0.0999908) [0] Top-left y position of scan area. -x 0..215.9mm (in steps of 0.0999908) [215.88] Width of scan-area. -y 0..355.6mm (in steps of 0.0999908) [355.567] Height of scan-area.

Type "scanimage --help -d DEVICE'' to get list of all options for DEVICE.

List of available devices: brother5:net1;dev0`

sjamesr commented 3 years ago

Thank you for the detailed report. Does this exception happen on the very first call to acquireImage, or on the 2nd or subsequent?

gh0ztbuster commented 3 years ago

First call to acquireImage, I tried only doing one acquisition as well, didn't work.

gh0ztbuster commented 3 years ago

Upon further investigation, I discovered an additional option titled "Number of options":

option [name=, title=Number of options, type=BOOLEAN, units=UNIT_NONE]

I am unsure whether this is an intended feature, but thought I should mention it just in case.

This is the complete list of options (there were no null options in the list):

option [name=, title=Number of options, type=BOOLEAN, units=UNIT_NONE] option [name=mode, title=Scan mode, type=STRING, units=UNIT_NONE] option [name=resolution, title=Scan resolution, type=INT, units=UNIT_DPI] option [name=source, title=Scan source, type=STRING, units=UNIT_NONE] option [name=brightness, title=Brightness, type=FIXED, units=UNIT_PERCENT] option [name=contrast, title=Contrast, type=FIXED, units=UNIT_PERCENT] option [name=MultifeedDetection, title=Multifeed Detection, type=BOOLEAN, units=UNIT_NONE] option [name=AutoDocumentSize, title=Auto Document Size, type=BOOLEAN, units=UNIT_NONE] option [name=AutoDeskew, title=Auto Deskew, type=BOOLEAN, units=UNIT_NONE] option [name=SkipBlankPage, title=Skip Blank Page, type=BOOLEAN, units=UNIT_NONE] option [name=SkipBlankPageSensitivity, title=Skip Blank Page sensitivity, type=FIXED, units=UNIT_PERCENT] option [name=tl-x, title=Top-left x, type=FIXED, units=UNIT_MM] option [name=tl-y, title=Top-left y, type=FIXED, units=UNIT_MM] option [name=br-x, title=Bottom-right x, type=FIXED, units=UNIT_MM] option [name=br-y, title=Bottom-right y, type=FIXED, units=UNIT_MM]

gh0ztbuster commented 3 years ago

The scanner runs at over 40 pages per minute; I am unsure as to whether this could have an effect as well.

gh0ztbuster commented 3 years ago

I have found a quick fix by downgrading to brother config 4 instead of 5 (although I lose some options):

sudo brsaneconfig5 -r CustomScanner sudo brsaneconfig4 -a name=CustomScanner model=ADS-2800W ip=xx.xx.xx.xx

I lose the following options by doing so making this a less than idea fix:

option [name=MultifeedDetection, title=Multifeed Detection, type=BOOLEAN, units=UNIT_NONE] option [name=AutoDocumentSize, title=Auto Document Size, type=BOOLEAN, units=UNIT_NONE] option [name=AutoDeskew, title=Auto Deskew, type=BOOLEAN, units=UNIT_NONE] option [name=SkipBlankPage, title=Skip Blank Page, type=BOOLEAN, units=UNIT_NONE] option [name=SkipBlankPageSensitivity, title=Skip Blank Page sensitivity, type=FIXED, units=UNIT_PERCENT]

I will also attempt to reach out to Brother with respect to the sane driver.

The thing that bothers me is that Xsane and other front-end sane worked on brscan5, just not this implementation.

gh0ztbuster commented 3 years ago

I have found a quick fix by downgrading to brother config 4 instead of 5 (although I lose some options):

sudo brsaneconfig5 -r CustomScanner sudo brsaneconfig4 -a name=CustomScanner model=ADS-2800W ip=xx.xx.xx.xx

I lose the following options by doing so making this a less than idea fix:

option [name=MultifeedDetection, title=Multifeed Detection, type=BOOLEAN, units=UNIT_NONE] option [name=AutoDocumentSize, title=Auto Document Size, type=BOOLEAN, units=UNIT_NONE] option [name=AutoDeskew, title=Auto Deskew, type=BOOLEAN, units=UNIT_NONE] option [name=SkipBlankPage, title=Skip Blank Page, type=BOOLEAN, units=UNIT_NONE] option [name=SkipBlankPageSensitivity, title=Skip Blank Page sensitivity, type=FIXED, units=UNIT_PERCENT]

I will also attempt to reach out to Brother with respect to the sane driver.

The thing that bothers me is that Xsane and other front-end sane worked on brscan5, just not this implementation.

The device is unusable without these features. Xsane allows me to enable all of them perfectly fine in brsaneconfig5:

"XSANE_DEVICE_RC" "Brother:CustomScanner" "xsane-version" "0.999" "mode" "24bit Color[Fast]" "resolution" 100 "source" "Automatic Document Feeder(left aligned,Duplex)" "MultifeedDetection" 1 "AutoDocumentSize" 1 "AutoDeskew" 1 "SkipBlankPage" 1 "SkipBlankPageSensitivity" 3276800 "tl-x" 0 "tl-y" 0 "br-x" 13885807 "br-y" 23302468 ...

gh0ztbuster commented 3 years ago

Closing was an accident ^

Upon further investigation, I discovered an additional option titled "Number of options":

option [name=, title=Number of options, type=BOOLEAN, units=UNIT_NONE]

I am unsure whether this is an intended feature, but thought I should mention it just in case.

This is the complete list of options (there were no null options in the list):

option [name=, title=Number of options, type=BOOLEAN, units=UNIT_NONE] option [name=mode, title=Scan mode, type=STRING, units=UNIT_NONE] option [name=resolution, title=Scan resolution, type=INT, units=UNIT_DPI] option [name=source, title=Scan source, type=STRING, units=UNIT_NONE] option [name=brightness, title=Brightness, type=FIXED, units=UNIT_PERCENT] option [name=contrast, title=Contrast, type=FIXED, units=UNIT_PERCENT] option [name=MultifeedDetection, title=Multifeed Detection, type=BOOLEAN, units=UNIT_NONE] option [name=AutoDocumentSize, title=Auto Document Size, type=BOOLEAN, units=UNIT_NONE] option [name=AutoDeskew, title=Auto Deskew, type=BOOLEAN, units=UNIT_NONE] option [name=SkipBlankPage, title=Skip Blank Page, type=BOOLEAN, units=UNIT_NONE] option [name=SkipBlankPageSensitivity, title=Skip Blank Page sensitivity, type=FIXED, units=UNIT_PERCENT] option [name=tl-x, title=Top-left x, type=FIXED, units=UNIT_MM] option [name=tl-y, title=Top-left y, type=FIXED, units=UNIT_MM] option [name=br-x, title=Bottom-right x, type=FIXED, units=UNIT_MM] option [name=br-y, title=Bottom-right y, type=FIXED, units=UNIT_MM]

Confirmed that "Number of options" was present with the brsaneconfig4 which worked, is likely not related.

gh0ztbuster commented 3 years ago

I take notice that Xsane seems to save these as integers and not doubles:

"SkipBlankPageSensitivity" 3276800 "tl-x" 0 "tl-y" 0 "br-x" 13885807 "br-y" 23302468

I wonder if this could have something to do with it.

Also, I take notice that this is the first time (excluding "Number of options") that boolean is used:

"MultifeedDetection" 1 "AutoDocumentSize" 1 "AutoDeskew" 1 "SkipBlankPage" 1

gh0ztbuster commented 3 years ago

CONFIRMED: The firmware is up to date. [R1512]

scanadf for the device fails...

scanadf --verbose --device-name "brother5:net1;dev0" --resolution 150 --MultifeedDetection=yes --AutoDocumentSize=yes --AutoDeskew=yes --SkipBlankPage=yes -o "/tmp/testscan%04d.pnm" Segmentation fault (core dumped) scanadf --verbose --device-name "brother5:net1;dev0" -o "/tmp/testscan%04d.pnm" Segmentation fault (core dumped)

scanimage for the device succeeds...

scanimage --device-name "brother5:net1;dev0" --resolution 150 --MultifeedDetection=yes --AutoDocumentSize=yes --AutoDeskew=yes --SkipBlankPage=yes > "/tmp/testscan.pnm" scanimage: rounded value of br-x from 215.9 to 215.88 scanimage: rounded value of br-y from 355.6 to 355.567

amaan75 commented 3 years ago

can confirm the issue with brother ADS-3600W also

amaan75 commented 3 years ago

quick update on this, i debugged and figured out, that this is not an issue with jfreesane but an issue with saned instead, https://gitlab.com/sane-project/backends/-/issues/478 link for reference

sjamesr commented 3 years ago

Nicely done, thank you!