pytwain
pytwain copied to clipboard
Scanning issues with Avision 186+
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?
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.