Special Device Events

Top  Previous  Next

Some image devices such as digital cameras have the ability to send information in the form of an event if the device has been changed by external means.  For example, if the device is taken off-line or if the flash has been removed, it would be advantageous if the device immediately reports to the application that the device has been changed by someone (or something).  Device events are not sent if the application programmatically changes settings on the image device.

 

Introduced in TWAIN specification 1.8, DTWAIN has made it possible to capture these special device events easily.  To invoke special device event handling, the following must be true for the image device:

 

The device must support sending special device events.
The DTWAIN application must be set for DTWAIN Modeless operation if all of the device events are to be captured.
The DTWAIN application must let the device know which events are to be sent.

 

For the first item to be true, the device must have the DTWAIN_CV_CAPDEVICEEVENT capability supported.  You can test this support by either calling DTWAIN_IsCapSupported.  If this function return TRUE, the device can send events.

 

DTWAIN Modeless processing allows the application loop to continuously look for messages.  Since device events can occur outside of the normal acquisition process, the only way to capture all of the device messages is to let the application send all TWAIN messages to DTWAIN.  On the other hand, DTWAIN Modal processing can only handle special device events that occur during acquisition processing.

 

By default, no device events will be sent to the application.  To initialize setting up the device events to be captured, the application must inform DTWAIN of the device events that are to be captured.  This allows the application to filter out messages that are not important to the application.  Two functions are used to get or to set the current notifications to inform the application:

DTWAIN_SetDeviceNotifications

DTWAIN_GetDeviceNotifications

 

If an external event occurs, DTWAIN sends the DTWAIN_TN_DEVICEEVENT notification to the application window, as well as the DTWAIN_SOURCE as the lParam. When the event notification is sent, the application can call the following function to see which event has occurred:

DTWAIN_GetDeviceEvent

 

If more information is required as to the event that has occurred, the following is used:

DTWAIN_GetDeviceEventInfo

DTWAIN_GetDeviceEventEx