openpaperwork / pyinsane

Python library to access and use image scanners (Linux/Windows/etc) (Sane/WIA) -- Moved to Gnome's Gitlab
https://gitlab.gnome.org/World/OpenPaperwork/pyinsane
63 stars 24 forks source link

WIADevMgr -> CreateDevice() failed #42

Closed Maier123 closed 6 years ago

Maier123 commented 6 years ago

Hello everyone, so I successfully installed pyinsane2 and started to run scan.py in my console (the comand was ..\examples>pyhton scan.py [-h](is '-h' the right thing to do for the first time running?)). The ouput of that was Output file: [Looking for scanners... pyinsane2\wia\rawapi.py: 72: RuntimeWarning: Pyinsane: Warning: WIADevMgr -> CreateDevice() failed Failed to access scanner (' {6BDD1FC6-810F-11D0-BEC7-08002BE2092F}\000', 'MX410 series _6277DE000000') : WIA: Failes to open (6BDD1FC6-810F-11D0-BEC7-08002BE2092F). Whats the problem here? I don't know if the number helps, but I'm hoping that someone might recognizes the order of the numbers and letters and can tell me what kind of number this is, so I could figure out what scanner it is referring and unable to access to. I get the same error when running [python list_all.py] I'm running python 3.6 on a windows 8 Computer and don't have WIA2 installed manually, but apprentley that comes with installing pyinsane2...?!

jflesch commented 6 years ago

Some people reported a similar issue when using Paperwork. At the moment I'm unclear what causes it. If I should take a bet, I would guess it's a permission issue. Have you tried running your script from a CMD terminal started as Administrator ?

Maier123 commented 6 years ago

How do I run it as an administrator? I am the only user on this computer so I should be the Admin anyway right ? And does the number above make any sense to you? maybe its the scanners fault...

jflesch commented 6 years ago

No you're usually not. https://www.computerhope.com/issues/ch001197.htm

Maier123 commented 6 years ago

I actually wasn't admin, but opening a CMD Terminal as an Administrator showed me C:\WINDOWS\system32> When I directed to the scan.py file then, (cd C:\Users....\pyinsane2\examples) and ran my script, the same error message as in the title appeared. Running python scan.py in the Admin CMD prompt (C:\WINDOWS\system32> python scan.py) tells me can't open file 'scan.py' no such file
How am I supposed to run my script from the admin cmd ?

jflesch commented 6 years ago

https://www.cs.princeton.edu/courses/archive/spr05/cos126/cmd-prompt.html

Maier123 commented 6 years ago

Sorry, but I can't get any info out of this. I don't understand how to run scripts as an admin without switching back to c:\users\MyName....\scan.py which is not the admin anymore, but the path where the scan.py file is stored in. Should I move the file to the location named when opening an Admin cmd, so e. g. C:\WINDWOS\system32\pyinsane2\scan.py p. s. Running "runas /user:administrator C:\users....\scan.py asks me for the password of the admin, but all of my suggestions were (I tried my own password and hitting enter, both didn't work) wrong.

jflesch commented 6 years ago

Sorry, nevermind, I misread your previous message. Basically, just cd \users\...\pyinsane2\examples + python scan.py should have done the trick to run the script as admin

jflesch commented 6 years ago

Can you post the complete output of the script please ?

Maier123 commented 6 years ago

So running just cd \users\...\pyinsane2\examples + python scan.py shows:

Syntax: 
    scan.py[ -s] <output file (JPG)>
Options:
   -s : Generate intermediate images (may generate a lot of images!)

so I run python scan.py again but add [ -s] to it. This prints out:

Output file: [-s]
Looking for scanners ...
C:\Users\MyName\AppData\Local\Programs\Python\Pyhton36-32\lib\site-packages\pyinsane2\wia\rawapi.py: 72: RuntimeWarning : Pyinsane: Warning: WiaDevMgr -> CreateDevice() failed
  out = _rawapi.open(devid)
Pyinsane: Warning: WiaDevMgr -> CreateDevice() failed
Failed to access Scanner (' {6BDD1FC6-810F-11D0-BEC7-08002BE2092F}\000', 'MX410 series _6277DE000000') : WIA: Failed to open (6BDD1FC6-810F-11D0-BEC7-08002BE2092F}\0000
WIA: Failed to open {6BDD1FC6-810F-11D0-BEC7-08002BE2092F}\0000 
Traceback (most recent call last):
File "C:\Users\MyName\AppData\Local\Programs\Python\Pyhton36-32\lib\site-packages\pyinsane2\wia\abstract.py", line 581, in get_device
   scanner = Scanner(dev[0]) 
File "C:\Users\MyName\AppData\Local\Programs\Python\Pyhton36-32\lib\site-packages\pyinsane2\wia\abstract.py", line 471, in __init__
   self._dev = rawapi.open(name)
File "C:\Users\MyName\AppData\Local\Programs\Python\Pyhton36-32\lib\site-packages\pyinsane2\wia\rawapi.py", line 79, in open
   return WIA  action(_open, devid+devid).wait()
File "C:\Users\MyName\AppData\Local\Programs\Python\Pyhton36-32\lib\site-packages\pyinsane2\wia\rawapi.py", line 34, in wait
   raise self.exception
File "C:\Users\MyName\AppData\Local\Programs\Python\Pyhton36-32\lib\site-packages\pyinsane2\wia\abstract.py", line 39, in do
   self.result = self.func (**self.kwargs)
File "C:\Users\MyName\AppData\Local\Programs\Python\Pyhton36-32\lib\site-packages\pyinsane2\wia\rawapi.py", line 74, in _open
   raise WIAexception ("Failed to open {}".format(devid))
pyinsane2.iwe.rawapi.WIAexception: Failed to open {6BDD1FC6-810F-11D0-BEC7-08002BE2092F}\0000 
Maier123 commented 6 years ago

Okay, I got a different output now. The scanner is all setup and recognized by the "Windows-Fax & -Scan " application, which I'm just saying because that wasn't the case before and seems like there's a wireless connection between my computer and the printer. But when I run python scan.py [-s] now, I get endless Warnings and Failed messages, where the most common error I can find in is raise WIAException("Failed to set scanner properties") and the last line is:

Pyinsane: Stream: :QueryInterface(): Unknown Interface requested

Writing output file...
Done

I can't tell whether this is good or not, but it seems to find my scanner now, but has some other issues. And what output file could have been created and where could I find it ?

jflesch commented 6 years ago
    scan.py[ -s] <output file (JPG)>

That's a weird typo in the output. The output should be scan.py [-s] <output file (JPG)>. The [ ] indicate optional arguments. In other words, you are supposed to type scan.py test.jpeg (I advise you to simply not use -s).

Here it seems you typed exactly scan.py [-s] (...) and so it assumed [-s] was the name of the output file it was supposed to write (see the message Output file: [-s]). Therefore you probably ended up with a file called [-s] in the directory where you were.

My 2 cents: If you seriously want to learn programming, I suggest you get used to terminals and shells (CMD.EXE, bash, etc) and all their idioms. I guess a possible way for that would be to use Linux (Windows terminals and shells are pure crap compared to those available on Linux).

Maier123 commented 6 years ago

Awesome, thanks for the comment. It does create a file in the directory where I'm in at the moment, which is perfect. Is there a) an option to choose between two or more devices? For example, it chooses the default printer?And b) is there a way to change the saving location?

jflesch commented 6 years ago

scan.py is simply an example script. It's just here to show how to use the Pyinsane API. For this demonstration, it just always picks the first scanner it finds (cf device = devices[0]).

pyinsane2.get_devices() returns an array of detected scanners. Then it's up to your program to select the scanner it wants. If you want to find back a specific scanner, you can identify them with their attribute name (it's actually an identifier that may not be really human friendly ; see example below).

Regarding the saving location, same thing. It's up to your program to device where to save the file (see img.save(...)).

By the way, other people reported problems similar to yours (WiaDevMgr -> CreateDevice() failed, etc) but I've never been able to reproduce it. How did you solve it ?


Random example:

import pyinsane2

devs = pyinsane2.get_devices()
target_dev = None

for dev in devs:
    if dev.name == "hplip://32.13241":
        target_dev = dev
        break

if target_dev is None:
    print("Not found")
else:
    print("Will use {} {}".format(target_dev.vendor, target_dev.model)    
Maier123 commented 6 years ago

Thanks for the example! Quick question, what does hplip://32.13241 stand for ? Obviously the printer but what exaclty? The IP address?

To your question, they have be sure, that, when opening the "Windows -Fax and-Scan" Application, the program/ computer itself recognizes a device. They might be recognized in the devices list in control panel, but that doesn't mean they are accessible to print/scan. I had to download the correct driver for my specific device. The link for that is usually found by double clicking the device in Control Panel\Hardware and Sound\Devices and Printers and then online documents.

jflesch commented 6 years ago

It's just an example. It's the kind of device name you can find on Linux for instance. On Windows, the device names are even less human-friendly. You will have to see by yourself what device names you get.

Thank you for your solution :)

Anyway, since you don't seem to have any issues with Pyinsane itself anymore, I'm closing this issue.

Maier123 commented 6 years ago

when trying to insert your example to the code of scan.py I get an invalid syntax error: device =device[0]

print("Looking for scanners ...")
    devices = pyinsane2.get_devices()
    target_dev = None
    if (len(devices) <= 0):
        print("No scanner detected !")
        sys.exit(1)

    for dev in devices:
       if dev.name == "Brother MFC-J6710DW LAN' (Brother, Brother MFC-J6710DW LAN, scanner,streaming_video)":
            target_dev = dev
            break

    if target_dev is None:
        print("Not found")
    else:
        print("Will use {} {}".format(target_dev.vendor, target_dev.model)

    device = devices[0]

changing devices [0] to target_dev doesn't help, same with device = dev

Maier123 commented 6 years ago

Can I even comment on a closed issue?

jflesch commented 6 years ago

Obviously you can. I'm going to reply on #43