Basic TWAIN Information

Top  Previous  Next

TWAIN is a protocol and Application Programming Interface (API) that standardizes communication between an application and image acquisition devices such as scanners and digital cameras.  This standard allows a developer to make standard calls to any image acquisition device that supports TWAIN.  Thus the application would not have to be rewritten to support every device.

 

There are three key elements in TWAIN

 

       The application software

       The Source Manager

       The Source Software (The Source)

 

The difficulties in making TWAIN work successfully with an application are the following:

 

TWAIN is a message driven Application Programmers Interface (API).  Unlike other API's that you may be familiar with such as the Windows API, ODBC, etc. TWAIN works by constantly sending messages to your application whenever an image is being acquired, your application must respond to these messages correctly.  To make a TWAIN application work, your application must adjust the application's main event loop and prepare to process TWAIN messages that are sent to the application whenever an image is being acquired. With DTWAIN, this is an optional step, since many languages do not have the ability to adjust the application's loop.

 

TWAIN must be controlled by means of state transitions.  This basically means that the application must call certain TWAIN functions in a specific order.  If the order is not followed, TWAIN most likely fails, either gracefully (the error is reported) or ungracefully (the application causes an exception error to occur).   When using DTWAIN, the application does not have to handle the state transition logic, however a knowledge of the state transitions is always a plus when implementing a TWAIN compatible application.

 

TWAIN may not be implemented correctly by some manufacturers.  For example, a series of TWAIN calls that are correct (according to the TWAIN specification) will work for most scanners, but for one or two models, may not work.  This is more of an anomaly than what is usually encountered, but it does happen.  Part of the reason for this is that there is no official TWAIN governing body that determines whether a TWAIN Source meets the TWAIN standard.  This gives way for some Source writers to "cut corners" and sometimes improvise their implementations.  Given this, there may be nothing that DTWAIN or any other library can do to make these Source's behave correctly with a normal set of TWAIN calls in the sequence specified by the TWAIN standard.  However DTWAIN makes it easy to the application logic if the programmer needs to structure their code for a particular Source.