Previous Up Next Reference

Source Manager Object

The source manager provides the communications interface to the TWAIN subsystem. It also provides the factory for creating a Source Object.

Constructor

SourceManager(HWND)

This function is used to create a source manager object. It has a single mandatory parameter and eleven optional named parameters. The parameters are as follows:
Name Description Default Value
HWND A handle to the application window. mandatory
MajorNum Application Version Number. 1
MinorNum Application minor verson number (revision). 0
Language User language (TWLG_* constant) TWLG_USA
Country User Country (TWCY_* constant) TWCY_USA
Info Information (string). TWAIN Python Interface 1.0.0.0 10/02/2002
ProductName Client product name (string) TWAIN Python Interface
ProtocolMajor Protocol Major version (TWON_PROTOCOLMAJOR). TWON_PROTOCOLMAJOR
ProtocolMinor Protocol Minor version (TWON_PROTOCOLMINOR). TWON_PROTOCOLMINOR
SupportedGroups Data Groups supported, i.e. images/audio. DG_IMAGE | DG_CONTROL
Manufacturer Sofware producers. Kevin Gill
ProductFamily Sofware information. TWAIN Python Interface

This method returns a single parameter, which is a SourceManger object. On failure it raises the following exceptions:
ExceptionMeaning
excSMLoadFileFailedThe SourceManger DLL TWAIN_32.DLL could not be loaded. This dll should be in your windows directory if TWAIN is installed. Check your software installation for your device.
excSMGetProcAddressFailedCould not locate the entry point in the TWAIN_32.DLL. Check to see if you have the right DLL in your windows directory.
excSMOpenFailedCould not open the connection to the SourceManager. A return code should be returned in the exc_info. Check this against the TWRC_* constants for detailed information on the error.

Methods

SourceManager.DSM_Entry(datagroup, dataitem, messageid, message)

This method is used to make a call directly to the TWAIN manager DLL. You can use it to implement any calls which have not been implemented in the DLL. Note that there is a separate implementation of this call in the Source object, for messages to the Data Source.

Be aware that there is a risk associated with using this method. Passing incorrect data may result in memory corruption.

Name Description Default Value
datagroup Data Group identifier. One of the DG_* constants. mandatory
dataitemid Data Item Type identifier. One of the DAT_* constants. mandatory
messageid The command to be performed. One of the MSG_* constants. mandatory
message The data for the operation. This should be built up using the struct python module. In many of the operations, the result is returned in this buffer. mandatory

This method returns the TWAIN Source Manager return value as an integer. This value is one of the TWRC_* values.

SourceManager.GetSourceList()

This method is used to return the list of the names of sources which are available in the source manager. This method can be used to replace the standard OpenSource dialog with an application specific dialog.

The result is a list of strings.

SourceManager.SetCallback(pfnCallback)

This method is used to set the callback handler. The callback handler is invoked when the TWAIN source signals our application. It can signal our application to indicate that there is data ready for us or that it wants to shutdown.

The expected events are:
MSG_XFERREADY (0x101) - the data source has data ready
MSG_CLOSEDSREQ (0x0102) - Request for Application. to close DS
MSG_CLOSEDSOK (0x0103) - Tell the Application. to save the state.
MSG_DEVICEEVENT (0X0104) - Event specific to Source

Name Description Default Value
pfnCallback The function to be invoked. The function should expect a single parameter, which is the event which caused it to be called. mandatory

SourceManager.GetIdentity()

Returns a dictionary containing the configuration information for the SourceManager. This is our configuration in the twain sub-system.

SourceManager.destroy()

Disconnects from the TWAIN sub-system. This function is called automatically by the source manager destructor. It is provided as a separate function to give finer-grained control over the disconnection and dll unloading.


Previous Up Next Reference