Home › Forums › TWAIN Classic › TWAIN for C# Question
- This topic has 4 replies, 3 voices, and was last updated 8 years ago by tickies.
- AuthorPosts
I am working with the code samples for the TWAIN for C# Project (https://sourceforge.net/projects/twainforcsharp/).
I am looking for sample code to change scanner settings programmatically. For example, I am looking for some code samples to not show the Twain Driver window and use scan type of ADF Duplex without any user input. How can this be accomplished?
Thanks in advance for your help.
The TWAIN C# project comes with two applications. One is a diagnostic application. The other is a regular scanning application, and is designed to show how one can write a C# application to interface to the TWAIN C# toolkit.
The built-in toolkit attempts to make coding easier by moving the image transfer code into a callback. The application starts scanning, and the callback processes images, metadata and status returns.
As for communication, the toolkit does this using CSV strings. This was done to take away the pain of having C# marshal to C/C++ data structures.
Here is how to turn on duplex scanning. You can find this code similar to this in: TWAIN CS 02.03.02.00twaincssourcetwaincsscansourceFormScan.cs
string szStatus = “”;
string szCapability = “CAP_DUPLEXENABLED,TWON_ONEVALUE,TWTY_BOOL,1”;
TWAINCSToolkit.STS sts = m_twaincstoolkit.Send(“DG_CONTROL”, “DAT_CAPABILITY”, “MSG_SET”, ref szCapability, ref szStatus);
Be sure to confirm that the status is success, in case the scanner doesn’t support duplex.This is the command sent to start scanning. You can find this code in: TWAIN CS 02.03.02.00twaincssourcetwaincsscansourceFormScan.cs
string szStatus = “”;
string szTwmemref = “0,0,” + this.Handle;
TWAINCSToolkit.STS sts = m_twaincstoolkit.Send(“DG_CONTROL”, “DAT_USERINTERFACE”, “MSG_ENABLEDS”, ref szTwmemref, ref szStatus);The contents of szTwmemref are a CSV encoded version of the TW_USERINTERFACE structure described in the TWAIN Specification and found in the C/C++ TWAIN.H file.
Note that this CSV scheme can be used with the diagnostic application, so that’s a good tool for experimenting with a driver to see how it all works.
Thanks @MarkM. Great answer. Is there a way to programmatically suppress the scanner device driver messagebox that pops up?
Sorry I replied too early. It seems like this code will suppress the message box.
This is the command sent to start scanning. You can find this code in: TWAIN CS 02.03.02.00twaincssourcetwaincsscansourceFormScan.cs
string szStatus = “”;
string szTwmemref = “0,0,” + this.Handle;
TWAINCSToolkit.STS sts = m_twaincstoolkit.Send(“DG_CONTROL”, “DAT_USERINTERFACE”, “MSG_ENABLEDS”, ref szTwmemref, ref szStatus);I will try this out.
Thanks for your help.
Hello,
I have the same problem as shekharsh described in the text above. I would like to suppress all message boxes.
Further information:
I am also working with the code samples for the TWAIN for C# Project (https://sourceforge.net/projects/twainforcsharp/).I start scanning with this:
TWAINCSToolkit.STS sts = m_twaincstoolkit.Send(“DG_CONTROL”, “DAT_USERINTERFACE”, “MSG_ENABLEDS”, ref szTwmemref, ref szStatus);but it still does not work. Could anybody help here?
- AuthorPosts