Version 3 of Operating TWAIN Scanners through TCL and EZTWAIN.

Updated 2006-09-10 08:41:24

WJG (10/Sep/06) A quick search for Tcl/Tk resources to access TWAIN devices doesn't reveal much. There's Xbit but this is not-opensource. A quick Google Search only provides details of a small handful of development resources which are quite pricy for simple one-off projects. One these firms is DOSDADI, supplier an excellent commercial package which does everything but who have also released the first version, EZTwain Classic, into the public domain. Problem solved! EZTWAIN classic is a Windos DLL which adds a higher level of abstraction over TWAIN_32.dll shipped with Windows. Getting access to these functions was unbelievably easy using ffidl.dll. The code sample below shows how, in three lines, a TCL script can automate the scannig process. As EZTWAIN is a freebie it is limited to BMP file support only. However, this has not been to much of a hassle as I, like others that would find this useful, have probably already installed GraphicsMagick for conversions etc. I do have a fuller version that covers all the remaining functions of the EZTWAIN.DLL which I can send to anyone that asks. Happy scanning!

 #---------------
 # Tcl_EZTWAIN.tcl
 #---------------
 # Convert required functions in EZTW32.dll into Tcl proceedures using Ffidl
 #
 # EZTW32.DLL  http://www.dosadi.com/eztwain1.htm
 # ffidl.dll   http://rutherglen.ics.mq.edu.au/~steffen/tcltk/ffidl/doc/

 load ffidl05.dll

 #---------------
 # Basic Calls
 #---------------
 ffidl::callout EZ_TWAIN_AcquireToFilename {long pointer-utf8 } int [ffidl::symbol EZTW32.dll   TWAIN_AcquireToFilename]

 #---------------
 # select source and pre-scan and acquire to file
 #---------------
 proc demo {} {
  EZ_TWAIN_AcquireToFilename 0 Demo.bmp
  exit
 }

 demo