paperwork icon indicating copy to clipboard operation
paperwork copied to clipboard

Lexmark Pro205 - WIA: Failed to get scanner properties

Open rob3r7 opened this issue 7 years ago • 9 comments

  • Windows 10 x64
  • Lexmark Pro205
  • scan via Windows tools without problems
INFO   paperwork.frontend.diag        ====== START OF SCANNER INFO ======
WARNING pyinsane2.wia.abstract         Failed to access scanner ('{6BDD1FC6-810F-11D0-BEC7-08002BE2092F}\\0000', 'Lexmark Pro200-S500 Series') : WIA: Failed to get scanner properties
ERROR  pyinsane2.wia.abstract         WIA: Failed to get scanner properties
Traceback (most recent call last):
  File "site-packages\pyinsane2-2.0.10-py3.4-win-amd64.egg\pyinsane2\wia\abstract.py", line 567, in get_devices
  File "site-packages\pyinsane2-2.0.10-py3.4-win-amd64.egg\pyinsane2\wia\abstract.py", line 420, in __init__
  File "site-packages\pyinsane2-2.0.10-py3.4-win-amd64.egg\pyinsane2\wia\abstract.py", line 470, in reload_options
  File "site-packages\pyinsane2-2.0.10-py3.4-win-amd64.egg\pyinsane2\wia\rawapi.py", line 112, in get_properties
  File "site-packages\pyinsane2-2.0.10-py3.4-win-amd64.egg\pyinsane2\wia\rawapi.py", line 34, in wait
  File "site-packages\pyinsane2-2.0.10-py3.4-win-amd64.egg\pyinsane2\wia\rawapi.py", line 39, in do
  File "site-packages\pyinsane2-2.0.10-py3.4-win-amd64.egg\pyinsane2\wia\rawapi.py", line 107, in _get_properties
pyinsane2.wia.rawapi.WIAException: WIA: Failed to get scanner properties
INFO   paperwork.frontend.diag        0 scanners found
INFO   paperwork.frontend.diag        ====== END OF SCANNER INFORMATIONS ======

rob3r7 avatar Sep 23 '17 20:09 rob3r7

Probably a duplicate of #661 and #590 :/

jflesch avatar Sep 23 '17 21:09 jflesch

  • the following code works quite well with standard python
# conda install pywin32
import os
from win32com.client import Dispatch

# List all available devices 
wia_dev_manager = Dispatch("WIA.DeviceManager")
for ix, device in enumerate(wia_dev_manager.DeviceInfos):
    print(ix,"|",device.Properties("Name").Value,"|",device.DeviceID)
#
# 0 | Lexmark Pro200-S500 Series | {6BDD1FC6-810F-11D0-BEC7-08002BE2092F}\0000
#

# Select a device per gui if there are more than one device
wia = Dispatch("WIA.CommonDialog")
dev = wia.ShowSelectDevice()
dev.Properties("Name").Value
# 'Lexmark Pro200-S500 Series'

# List Items of device
for ix, item in enumerate(dev.Items):
    print(ix,item.ItemID)

# 0 0000\Root\Flatbed
# 1 0000\Root\Feeder

# Select per number 
scanner = dev.Items[1]
scanner.ItemID
# '0000\\Root\\Flatbed'

# Show all properties
for ix,p in enumerate (scanner.Properties):
    print(f"{ix:3} {p.PropertyID:5} {p.Name:30} {p.Value}")

#  0  4098 Item Name                      Feeder
#  1  4099 Full Item Name                 0000\Root\Feeder
#  2  4101 Item Flags                     67
#  3  4120 Color Profile Name             sRGB Color Space Profile.icm
#  4  3076 Horizontal Sheet Feed Size     8500
#  5  3077 Vertical Sheet Feed Size       14000
#  6  3078 Sheet Feeder Registration      0
#  7  3096 Pages                          1
#  8  3088 Document Handling Select       2
#  9  3090 Horizontal Optical Resolution  600
# 10  3091 Vertical Optical Resolution    600
# 11  3103 Show preview control           0
# 12  3100 Preview                        0
# 13  4102 Access Rights                  2
# 14  4116 Item Size                      0
# 15  4106 Format                         {B96B3CAA-0728-11D3-9D7B-0000F81EF32E}
# 16  4105 Preferred Format               {B96B3CAA-0728-11D3-9D7B-0000F81EF32E}
# 17  4108 Media Type                     128
# 18  4118 Buffer Size                    65536
# 19  4103 Data Type                      2
# 20  4104 Bits Per Pixel                 8
# 21  4110 Bits Per Channel               8
# 22  4109 Channels Per Pixel             1
# 23  4107 Compression                    0
# 24  6147 Horizontal Resolution          75
# 25  6148 Vertical Resolution            75
# 26  6151 Horizontal Extent              637
# 27  6152 Vertical Extent                1050
# 28  6149 Horizontal Start Position      0
# 29  6150 Vertical Start Position        0
# 30  4112 Pixels Per Line                637
# 31  4113 Bytes Per Line                 640
# 32  4114 Number of Lines                1050
# 33  6154 Brightness                     0
# 34  6155 Contrast                       0
# 35  6146 Current Intent                 0
# 36  6159 Threshold                      128
# 37  6153 Photometric Interpretation     0
# 38  4111 Planar                         0
# 39  6161 Lamp Warm up Time              1000
# 40  4123 Filename extension             BMP

# Set resolution
scanner.Properties("Vertical Resolution").Value   = 300
scanner.Properties("Horizontal Resolution").Value = 300

WIA_IMG_FORMAT_PNG       = "{B96B3CAF-0728-11D3-9D7B-0000F81EF32E}"
image=scanner.Transfer(WIA_IMG_FORMAT_PNG)
image.SaveFile("c:/temp/scan.png")

  • Documentation: https://msdn.microsoft.com/en-us/library/windows/desktop/ms630490(v=vs.85).aspx

Does this help?

rob3r7 avatar Sep 25 '17 20:09 rob3r7

Actually it does. Because it proves your scanner is supported by WIA and therefore there is a bug in Pyinsane (or a lack of workaround, depending on your scanner drivers ;-). I'm working on a diagnostic program (IronScanner). It's close to be ready. It should help figuring out what is failing here and test possible fixes.

jflesch avatar Feb 27 '18 10:02 jflesch

The test program is ready: https://openpaper.work/en/scanner_db/#contribute . Can you give it a try please ? It will do a test scan, generate a report, and automatically upload it to https://openpaper.work/ .

jflesch avatar Mar 05 '18 21:03 jflesch

INFO   2018-03-06 20:35:10,691 ironscanner.main Looking for scanners ...
INFO   2018-03-06 20:35:10,693 pyinsane2.wia.rawapi pyinsane2/wia/rawapi.cpp(L132): WIA->get_devices()
INFO   2018-03-06 20:35:10,699 pyinsane2.wia.rawapi pyinsane2/wia/rawapi.cpp(L209): Opening device({6BDD1FC6-810F-11D0-BEC7-08002BE2092F}\0000)
INFO   2018-03-06 20:35:10,788 pyinsane2.wia.rawapi pyinsane2/wia/rawapi.cpp(L230): Device({6BDD1FC6-810F-11D0-BEC7-08002BE2092F}\0000) opened
INFO   2018-03-06 20:35:10,789 pyinsane2.wia.rawapi pyinsane2/wia/rawapi.cpp(L264): Getting sources
INFO   2018-03-06 20:35:10,791 pyinsane2.wia.rawapi pyinsane2/wia/rawapi.cpp(L326): Got source [0000\Root\Flatbed] (assuming flatbed)
INFO   2018-03-06 20:35:10,792 pyinsane2.wia.rawapi pyinsane2/wia/rawapi.cpp(L323): Got source [0000\Root\Feeder] (feeder)
WARNING 2018-03-06 20:35:10,792 pyinsane2.wia.rawapi pyinsane2/wia/rawapi.cpp(L286): get_sources(): enum_item->next() failed
WARNING 2018-03-06 20:35:10,792 pyinsane2.wia.rawapi NULL NULL NULL !!
INFO   2018-03-06 20:35:10,792 pyinsane2.wia.rawapi pyinsane2/wia/rawapi.cpp(L339): 2 sources found
INFO   2018-03-06 20:35:10,793 pyinsane2.wia.rawapi pyinsane2/wia/rawapi.cpp(L395): Getting Properties
WARNING 2018-03-06 20:35:10,797 pyinsane2.wia.rawapi pyinsane2/wia/rawapi.cpp(L416): WiaPropertyStorage->ReadMultiple() failed
WARNING 2018-03-06 20:35:10,797 pyinsane2.wia.rawapi pyinsane2/wia/rawapi.cpp(L417): HResult error code 0x80004001: Nicht implementiert
ERROR  2018-03-06 20:35:10,798 pyinsane2.wia.rawapi Unexpected exception
Traceback (most recent call last):
  File "site-packages\pyinsane2-2.0.12-py3.4-win-amd64.egg\pyinsane2\wia\rawapi.py", line 58, in do
  File "site-packages\pyinsane2-2.0.12-py3.4-win-amd64.egg\pyinsane2\wia\rawapi.py", line 130, in _get_properties
pyinsane2.wia.rawapi.WIAException: WIA: Failed to get scanner properties
WARNING 2018-03-06 20:35:10,799 pyinsane2.wia.abstract Failed to access scanner ('{6BDD1FC6-810F-11D0-BEC7-08002BE2092F}\\0000', 'Lexmark Pro200-S500 Series') : WIA: Failed to get scanner properties
ERROR  2018-03-06 20:35:10,801 pyinsane2.wia.abstract WIA: Failed to get scanner properties
Traceback (most recent call last):
  File "site-packages\pyinsane2-2.0.12-py3.4-win-amd64.egg\pyinsane2\wia\abstract.py", line 626, in get_devices
  File "site-packages\pyinsane2-2.0.12-py3.4-win-amd64.egg\pyinsane2\wia\abstract.py", line 458, in __init__
  File "site-packages\pyinsane2-2.0.12-py3.4-win-amd64.egg\pyinsane2\wia\abstract.py", line 515, in reload_options
  File "site-packages\pyinsane2-2.0.12-py3.4-win-amd64.egg\pyinsane2\wia\rawapi.py", line 135, in get_properties
  File "site-packages\pyinsane2-2.0.12-py3.4-win-amd64.egg\pyinsane2\wia\rawapi.py", line 50, in wait
  File "site-packages\pyinsane2-2.0.12-py3.4-win-amd64.egg\pyinsane2\wia\rawapi.py", line 58, in do
  File "site-packages\pyinsane2-2.0.12-py3.4-win-amd64.egg\pyinsane2\wia\rawapi.py", line 130, in _get_properties
pyinsane2.wia.rawapi.WIAException: WIA: Failed to get scanner properties
INFO   2018-03-06 20:35:10,803 ironscanner.main 0 scanners found

Does it really require lowlevel pyinsane2/wia/rawapi.cpp? What are the reasons not using win32com.client and Dispatch?

rob3r7 avatar Mar 06 '18 19:03 rob3r7

Because I didn't see any point in adding another dependency.

jflesch avatar Mar 06 '18 20:03 jflesch

Hm, ok, this is a tricky one.

Obviously, you can access WIA properties using the WIA automation layer. Which I'm not using ... because it has a nasty limitation: I haven't found a way to get the image on-the-fly during the scan with it. This is why I'm using the low-level WIA API: I can pass it a IStream object and get the stream as it goes (if the driver supports it .. some just write in the stream once the scan has been done). However, in your case, using the low-level WIA API to access properties returns HResult error code 0x80004001: Nicht implementiert ... which is obviously a problem.

jflesch avatar Mar 07 '18 10:03 jflesch

I think this is going to wait.

I'm going to rewrite Pyinsane anyway (in pure C this time --> libinsane). One the goal will be to handle multiple APIs (WIA, TWAIN, etc). This way, I will be able to use the low-level API to get the stream, and if it does not work, fall-back on the WIA automation layer (which will mean not getting the scan on-the-fly, but as I said, this is already a limitation of a bunch of drivers anyway).

Anyway, I must thank you. I'm glad you provided me with this information before I start designing the new library, because this will clearly impact its design.

jflesch avatar Mar 07 '18 10:03 jflesch

Thank you for the detailed explanation. I was almost expecting something like this. I am happy to help with further tests.

rob3r7 avatar Mar 07 '18 19:03 rob3r7