{"id":2089,"date":"2015-06-14T12:11:01","date_gmt":"2015-06-14T12:11:01","guid":{"rendered":"http:\/\/www.gssezisoft.com\/main\/?p=2089"},"modified":"2015-06-14T12:19:10","modified_gmt":"2015-06-14T12:19:10","slug":"the-cmdtwain-initialization-process","status":"publish","type":"post","link":"http:\/\/www.gssezisoft.com\/main\/2015\/06\/the-cmdtwain-initialization-process\/","title":{"rendered":"The CmdTwain Initialization Process"},"content":{"rendered":"<p>This might help if you are seeing &#8220;TWAIN unavailable&#8221; or &#8220;&#8230; check cables&#8221; messages.<br \/>\n<!--more--><br \/>\nOne of the first things that CmdTwain does is initialize the scanner for the selected resolution (200 DPI by default). This triggers a lot of startup activity to get ready to be able to do that.<\/p>\n<p>Internally, CmdTwain runs ScanBmp.exe. That controls the document scanner and gets images as raw bitmaps.<\/p>\n<p>The action that kicks everything off in ScanBmp is a C function &#8220;CmdDPI()&#8221; which calls &#8220;CmdUnits()&#8221; and specifies &#8220;inches&#8221; (for the dots per inch that is about to happen).<\/p>\n<p>CmdUnits() calls &#8220;InitTwain()&#8221; to set up the scanner connection.<\/p>\n<p>If you see the &#8220;TWAIN is unavailable&#8221; message it means that the program failed to:<br \/>\n&#8211; Load the source manager<br \/>\n&#8211; &#8211; look in GetWindowsDirectory() for &#8220;TWAIN_32.DLL&#8221;<br \/>\n&#8211; &#8211; check that the file can be opened<br \/>\n&#8211; &#8211; LoadLibrary() to load the DLL into memory<br \/>\n&#8211; &#8211; GetProcAddress(&#8220;DSM_Entry&#8221;)<br \/>\n&#8211; Unload the source manager<br \/>\n&#8211; &#8211; This should be trivial after the above<\/p>\n<p>So long as you have a TWAIN_32.DLL in your Windows directory, you should pass this step.<\/p>\n<p>If you see the &#8220;&#8230; check cables&#8221; message then you passed the initial step and you do have the necessary DLL. It fails somewhere along this sequence:<br \/>\n&#8211; Open the default source<br \/>\n&#8211; &#8211; Load the source manager (it already did this so should be ok)<br \/>\n&#8211; &#8211; Send an OPEN DSM command to the source manager (should be fine)<br \/>\n&#8211; Open Data Source 0<br \/>\n&#8211; Set native transfer mode<\/p>\n<p>The usual problem here is that the TWAIN_32.DLL tries to talk to a scanner driver which tries to talk to the scanner via a cable from the computer. You could also have a problem if:<br \/>\n&#8211; there isn&#8217;t a scanner driver installed.<br \/>\n&#8211; none of the scanner drivers is selected as the default.<br \/>\n&#8211; the scanner doesn&#8217;t support native mode transfers.<\/p>\n<p>On my Win8.1 machine, there is a C:\\Windows\\twain_32 folder which contains at least one driver (wiatwain.ds). The &#8220;.ds&#8221; shows that this is a TWAIN Data Source (for Windows Imaging Architecture [wia] devices that have been set up to allow TWAIN). There is also a subdirectory (&#8220;escndv&#8221; in my case) which contains a file &#8220;nx120.ds&#8221;. I have an Epson NX120 printer\/scanner attached at the moment.<\/p>\n<p>I can&#8217;t get CmdTwain ver 2.01 to select a source with the scanner cable disconnected. It should be able to, so I&#8217;ll see if I can fix this in a later version (it works fine if the cables are connected). Using the IrfanView File \/ Select scan&#8221; option brings up the &#8220;Select Source&#8221; dialog box like this:<\/p>\n<p><a href=\"http:\/\/www.gssezisoft.com\/main\/wp-content\/uploads\/2015\/06\/Screenshot-2015-06-14-21.50.48.png\"><img loading=\"lazy\" src=\"http:\/\/www.gssezisoft.com\/main\/wp-content\/uploads\/2015\/06\/Screenshot-2015-06-14-21.50.48.png\" alt=\"Screenshot 2015-06-14 21.50.48\" width=\"312\" height=\"169\" class=\"alignnone size-full wp-image-2090\" srcset=\"http:\/\/www.gssezisoft.com\/main\/wp-content\/uploads\/2015\/06\/Screenshot-2015-06-14-21.50.48.png 312w, http:\/\/www.gssezisoft.com\/main\/wp-content\/uploads\/2015\/06\/Screenshot-2015-06-14-21.50.48-150x81.png 150w, http:\/\/www.gssezisoft.com\/main\/wp-content\/uploads\/2015\/06\/Screenshot-2015-06-14-21.50.48-300x163.png 300w\" sizes=\"(max-width: 312px) 100vw, 312px\" \/><\/a><\/p>\n<p>If you don&#8217;t see any to choose from, your scanner isn&#8217;t installed as a TWAIN device (and I&#8217;m guessing that there isn&#8217;t a driver for it in C:\\Windows\\twain_32 or a subdirectory).<\/p>\n<p>If you do have a selected TWAIN device and your cables are connected, perhaps your scanner doesn&#8217;t support &#8220;native transfer mode&#8221;. It is far-fetched because this is the simplest mode for scanners to provide; but it is possible.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This might help if you are seeing &#8220;TWAIN unavailable&#8221; or &#8220;&#8230; check cables&#8221; messages.<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[7,15],"tags":[],"_links":{"self":[{"href":"http:\/\/www.gssezisoft.com\/main\/wp-json\/wp\/v2\/posts\/2089"}],"collection":[{"href":"http:\/\/www.gssezisoft.com\/main\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.gssezisoft.com\/main\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.gssezisoft.com\/main\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"http:\/\/www.gssezisoft.com\/main\/wp-json\/wp\/v2\/comments?post=2089"}],"version-history":[{"count":0,"href":"http:\/\/www.gssezisoft.com\/main\/wp-json\/wp\/v2\/posts\/2089\/revisions"}],"wp:attachment":[{"href":"http:\/\/www.gssezisoft.com\/main\/wp-json\/wp\/v2\/media?parent=2089"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.gssezisoft.com\/main\/wp-json\/wp\/v2\/categories?post=2089"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.gssezisoft.com\/main\/wp-json\/wp\/v2\/tags?post=2089"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}