Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scanning issues with Avision 186+ #21

Open
yoavmmn opened this issue Feb 24, 2019 · 1 comment
Open

Scanning issues with Avision 186+ #21

yoavmmn opened this issue Feb 24, 2019 · 1 comment

Comments

@yoavmmn
Copy link

yoavmmn commented Feb 24, 2019

I'm trying to scan documents using the following code:

import twain
from tkinter import *
from tkinter import messagebox
import traceback

root = Tk()
root.title('scan.py')

def scan():
    try:
        def counter():
            for i in range(1000):
                yield i

        count = counter()

        before = lambda file: 'C:/%s.png' % (next(count))

        srcManager = twain.SourceManager(parent_window=root)

        first_available = None

        for src in srcManager.source_list:
            print(src)
            try:
                first_available = srcManager.open_source(product_name=src)
            except:
                continue

        result = first_available.acquire_file(before=before,
                                    after=lambda file: print(file),
                                    show_ui=True,
                                    )
    except:
        messagebox.showerror("Error", traceback.format_exc())
        sys.exit(1)
    else:
        sys.exit(0 if result else 1)

root.after(1, scan)
root.mainloop()

This code produce the following error using Avision 186+, but works fine on HP LaserJet M426FDN and I need to support both scanners.

Traceback (most recent call last):
  File "C:/Users/Web/Desktop/pytwain-master/demo/scan.py", line 45, in scan
    show_ui=True,
  File "C:\Users\Web\AppData\Local\Programs\Python\Python37-32\lib\site-packages\twain.py", line 2054, in acquire_file
    self._acquire(callback, show_ui, modal)
  File "C:\Users\Web\AppData\Local\Programs\Python\Python37-32\lib\site-packages\twain.py", line 1856, in _acquire
    self._modal_loop(callback_lolevel)
  File "C:\Users\Web\AppData\Local\Programs\Python\Python37-32\lib\site-packages\twain.py", line 1837, in _modal_loop
    callback(event)
  File "C:\Users\Web\AppData\Local\Programs\Python\Python37-32\lib\site-packages\twain.py", line 1852, in callback_lolevel
    more = callback()
  File "C:\Users\Web\AppData\Local\Programs\Python\Python37-32\lib\site-packages\twain.py", line 2042, in callback
    raise excDSTransferCancelled
twain.excDSTransferCancelled

Any ideas?

@denisenkom
Copy link
Owner

This library is just a wrapper around TWAIN library. Take a look at TWAIN specification for more troubleshooting ideas: http://www.twain.org/wp-content/uploads/2017/03/TWAIN-2.4-Specification.pdf

Let me know if the problem is with the wrapper.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants