mylise Posted March 9, 2022 Share Posted March 9, 2022 I have not used Autoit for a while but a recent project required me to automate two scanners using 32 bits drivers. The C++ program could not access these directly as I am using a 64 bit compiler. So the simplest solution was to execute an external program that will interface with the scanners using Twain. The available programs did not give me the control I wanted so I searched for a library I could interface with in Autoit. The library is called EZTwain Classic Library, http://www.eztwain.com/eztwain1.htm but it seems that you can not download the zip? but I have found an earlier version online. I have converted about 80% of the available functions. The rest I did not see a need for. The Twain low level access "_EZTwain_CallMgr" and "_EZTwain_CallDS" functions are limited The Manufacturer's interface will show up when using function " _EZTwain_DeviceUserInterface($hWnd)" but it hangs when you ask to scan Here is the simplest way to scan and save as a BMP file. #include <twain_udf.au3> $ezDebug = 1 ;obtain console debug messages _EZTwain_Start() ;load Easy Twain Classic library _EZTwain_LoadSourceManager() ;load source ;_EZTwain_DeviceSelect() ; use to open GUI to select Twain device _EZTwain_DeviceOpen() ; open default Twain device ;_EZTwain_DeviceSetDPI(600) ;used to get image DPI _EZTwain_DeviceAcquire_File("d:\test.bmp") ; Scan image and save as a BMP file ;$hDIB = _EZTwain_DeviceAcquire_DIB() ; Used to scan file and save in memory as DIB image _EZTwain_Stop() ; Clean up and unload DLL It is not fully tested. EZTW32.dll eztwain_example.au3 twain_enum.au3 twain_struct.au3 twain_udf.au3 Gianni and dmob 2 Link to comment Share on other sites More sharing options...
dmob Posted March 17, 2022 Share Posted March 17, 2022 Your UDF is much much more complete than what I had been using. Thank you for sharing Link to comment Share on other sites More sharing options...
mylise Posted March 21, 2022 Author Share Posted March 21, 2022 Had to fix small issues to UDF files to get some of the low level functions to work correctly. I only show the get operations here but you can also set using _EZTwain_SetCapValue function and $MSG_SET operation. expandcollapse popup#include <twain_udf.au3> $ezDebug = 1 ;obtain console debug messages _EZTwain_Start() ;load Easy Twain Classic library _EZTwain_LoadSourceManager() ;load source _EZTwain_DeviceOpen() ; open default Twain device ;------------------------------------------------------------------- ; Using low level Capabilities get operation $tTemp = DllStructCreate("word;") $pTemp = DllStructGetPtr($tTemp) _EZTwain_GetCapValue($ICAP_BITDEPTH,$TWTY_UINT16,$pTemp) ConsoleWrite("Bit Depth returned value = " & DllStructGetData($tTemp,1) & @CRLF) _EZTwain_GetCapValue($ICAP_BITORDER,$TWTY_UINT16,$pTemp) ConsoleWrite("Bit Order returned value = " & DllStructGetData($tTemp,1) & @CRLF) _EZTwain_GetCapValue($ICAP_COMPRESSION,$TWTY_UINT16,$pTemp) ConsoleWrite("Image Compression returned value = " & DllStructGetData($tTemp,1) & @CRLF) _EZTwain_GetCapValue($ICAP_PIXELFLAVOR,$TWTY_UINT16,$pTemp) ConsoleWrite("Pixel Flavor returned value = " & DllStructGetData($tTemp,1) & @CRLF) _EZTwain_GetCapValue($ICAP_PIXELTYPE,$TWTY_UINT16,$pTemp) ConsoleWrite("Pixel Type returned value = " & DllStructGetData($tTemp,1) & @CRLF) _EZTwain_GetCapValue($ICAP_PLANARCHUNKY,$TWTY_UINT16,$pTemp) ConsoleWrite("Planar chunky returned value = " & DllStructGetData($tTemp,1) & @CRLF) _EZTwain_GetCapValue($ICAP_SUPPORTEDSIZES,$TWTY_UINT16,$pTemp) ConsoleWrite("Supported Sizes returned value = " & DllStructGetData($tTemp,1) & @CRLF) _EZTwain_GetCapValue($ICAP_UNITS,$TWTY_UINT16,$pTemp) ConsoleWrite("Units returned value = " & DllStructGetData($tTemp,1) & @CRLF) _EZTwain_GetCapValue($ICAP_XFERMECH,$TWTY_UINT16,$pTemp) ConsoleWrite("Transfer Mechanism returned value = " & DllStructGetData($tTemp,1) & @CRLF) _EZTwain_GetCapValue($CAP_DUPLEX,$TWTY_UINT16,$pTemp) ConsoleWrite("Device Duplex returned value = " & DllStructGetData($tTemp,1) & @CRLF) $tTemp = DllStructCreate("long;") $pTemp = DllStructGetPtr($tTemp) _EZTwain_GetCapValue($ICAP_PHYSICALHEIGHT,$TWTY_FIX32,$pTemp) ConsoleWrite("Physical Height returned value = " & _EZTwain_Fix32ToFloat(DllStructGetData($tTemp,1)) & @CRLF) _EZTwain_GetCapValue($ICAP_PHYSICALWIDTH,$TWTY_FIX32,$pTemp) ConsoleWrite("Physical Width returned value = " & _EZTwain_Fix32ToFloat(DllStructGetData($tTemp,1)) & @CRLF) _EZTwain_GetCapValue($ICAP_XRESOLUTION,$TWTY_FIX32,$pTemp) ConsoleWrite("X Resolution returned value = " & _EZTwain_Fix32ToFloat(DllStructGetData($tTemp,1)) & @CRLF) _EZTwain_GetCapValue($ICAP_YRESOLUTION,$TWTY_FIX32,$pTemp) ConsoleWrite("Y Resolution returned value = " & _EZTwain_Fix32ToFloat(DllStructGetData($tTemp,1)) & @CRLF) $tTemp = DllStructCreate("boolean;") $pTemp = DllStructGetPtr($tTemp) _EZTwain_GetCapValue($CAP_DEVICEONLINE,$TWTY_BOOL,$pTemp) ConsoleWrite("DEVICEONLINE returned value = " & DllStructGetData($tTemp,1) & @CRLF) _EZTwain_GetCapValue($CAP_DUPLEXENABLED,$TWTY_BOOL,$pTemp) ConsoleWrite("Duplex enabled returned value = " & DllStructGetData($tTemp,1) & @CRLF) ;------------------------------------------------------------------ ; Examples of Operation Triplets to obtain twain device identity $tTemp = DllStructCreate($tagTW_IDENTITY) $pTemp = DllStructGetPtr($tTemp) _EZTwain_CallDS($DG_CONTROL,$DAT_IDENTITY,$MSG_GET,$pTemp) For $i = 0 To 12 ConsoleWrite( $ezIdentity[$i] & " = " & DllStructGetData($tTemp, $i+1) & @CRLF) Next _EZTwain_CallMgr($DG_CONTROL,$DAT_IDENTITY,$MSG_GETDEFAULT,$pTemp) For $i = 0 To 12 ConsoleWrite( $ezIdentity[$i] & " = " & DllStructGetData($tTemp, $i+1) & @CRLF) Next _EZTwain_CallMgr($DG_CONTROL,$DAT_IDENTITY,$MSG_GETFIRST,$pTemp) For $i = 0 To 12 ConsoleWrite( $ezIdentity[$i] & " = " & DllStructGetData($tTemp, $i+1) & @CRLF) Next _EZTwain_CallMgr($DG_CONTROL,$DAT_IDENTITY,$MSG_GETNEXT,$pTemp) For $i = 0 To 12 ConsoleWrite( $ezIdentity[$i] & " = " & DllStructGetData($tTemp, $i+1) & @CRLF) Next _EZTwain_Stop() ; Clean up and unload DLL twain_enum.au3 twain_struct.au3 twain_udf.au3 Gianni 1 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now