|
Hello,
when I execute this code, in the SET it returns FAILURE. Why?. I have to add some Capability.
Thank you for your help
|
|
|
|
|
Public Sub Acquire()
Dim rc As TwRC
CloseSrc()
If Equals(appid.Id, IntPtr.Zero) = True Then
Init(hwnd)
If Equals(appid.Id, IntPtr.Zero) = True Then
Return
End If
End If
rc = DSMident(appid, IntPtr.Zero, TwDG.Control, TwDAT.Identity, TwMSG.OpenDS, srcds)
If (rc <> TwRC.Success) Then
Return
End If
'Set Unit to Pixels
Dim Pixels As TwUnit = TwUnit.twPIXELS
Dim capUnit As TwCapability = New TwCapability(TwCap.IUnits, Pixels, TwType.Int16)
rc = DScap(appid, srcds, TwDG.Control, TwDAT.Capability, TwMSG.Set, capUnit)
If rc <> TwRC.Success Then
CloseSrc()
Return
End If
Dim xcap As TwCapability = New TwCapability(TwCap.XScaling, XScale, TwType.Fix32)
rc = DScap(appid, srcds, TwDG.Control, TwDAT.Capability, TwMSG.Set, xcap)
If rc <> TwRC.Success Then
CloseSrc()
Return
End If
xcap = New TwCapability(TwCap.YScaling, YScale, TwType.Fix32)
rc = DScap(appid, srcds, TwDG.Control, TwDAT.Capability, TwMSG.Set, xcap)
If rc <> TwRC.Success Then
CloseSrc()
Return
End If
Dim ps As TwCapability = New TwCapability(TwCap.SupportedSizes, PaperSize, TwType.Int16)
rc = DScap(appid, srcds, TwDG.Control, TwDAT.Capability, TwMSG.Set, ps)
If rc <> TwRC.Success Then
CloseSrc()
Return
End If
'Set Layout
Dim Layout As TwImageLayout = New TwImageLayout
rc = DSilayout(appid, srcds, TwDG.Image, TwDAT.ImageLayout, TwMSG.Get, Layout)
If rc <> TwRC.Success Then
CloseSrc()
Return
End If
If TopMargin > 0 Then
Layout.Frame.Top.FromFloat(CSng(TopMargin))
End If
If LeftMargin > 0 Then
Layout.Frame.Left.FromFloat(CSng(LeftMargin))
End If
If RightMargin > 0 Then
Layout.Frame.Right.FromFloat(CSng(RightMargin))
End If
If BottomMargin > 0 Then
Layout.Frame.Bottom.FromFloat(CSng(BottomMargin))
End If
Layout.FrameNumber = 1
Layout.PageNumber = 1
Layout.DocumentNumber = 1
rc = Me.DSilayout(appid, srcds, TwDG.Image, TwDAT.ImageLayout, TwMSG.Set, Layout)
If rc <> TwRC.Success Then
CloseSrc()
Return
End If
'Scan Colour
Dim Ccap As TwCapability = New TwCapability(TwCap.IPixelType, SColor, TwType.UInt16)
rc = DScap(appid, srcds, TwDG.Control, TwDAT.Capability, TwMSG.Set, Ccap)
If (rc <> TwRC.Success) Then
CloseSrc()
Return
End If
Dim cap As TwCapability = New TwCapability(TwCap.XferCount, 1, TwType.Int16)
rc = DScap(appid, srcds, TwDG.Control, TwDAT.Capability, TwMSG.Set, cap)
If (rc <> TwRC.Success) Then
CloseSrc()
Return
End If
Dim guif As TwUserInterface = New TwUserInterface
guif.ShowUI = 1
guif.ModalUI = 1
guif.ParentHand = hwnd
rc = DSuserif(appid, srcds, TwDG.Control, TwDAT.UserInterface, TwMSG.EnableDS, guif)
If (rc <> TwRC.Success) Then
CloseSrc()
Return
End If
End Sub
'Full code here. Just replace the original Acquire in TwainLib.vb from NETMaster. It should be work.
'Remember to change this also in the TwainDefs.vb.
<StructLayout(LayoutKind.Sequential, Pack:=2, CharSet:=CharSet.Ansi)> Friend Class TwIdentity
Public Id As IntPtr
Public Version As TwVersion
Public ProtocolMajor As Short
Public ProtocolMinor As Short
Public SupportedGroups As Integer
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=34)> Public Manufacturer As String
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=34)> Public ProductFamily As String
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=34)> Public ProductName As String
End Class
<StructLayout(LayoutKind.Sequential, Pack:=2, CharSet:=CharSet.Ansi)> Friend Structure TwVersion
Public MajorNum As Short
Public MinorNum As Short
Public Language As Short
Public Country As Short
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=34)> Public Info As String
End Structure
<StructLayout(LayoutKind.Sequential, Pack:=2)> Friend Class TwUserInterface
Public ShowUI As Short
Public ModalUI As Short
Public ParentHand As IntPtr
End Class
<StructLayout(LayoutKind.Sequential, Pack:=2)> Friend Class TwStatus
Public ConditionCode As Short
Public Reserved As Short
End Class
<StructLayout(LayoutKind.Sequential, Pack:=2)> Friend Structure TwEvent
Public EventPtr As IntPtr
Public Message As Short
End Structure
<StructLayout(LayoutKind.Sequential, Pack:=2)> Friend Class TwImageInfo
Public XResolution As Int32
Public YResolution As Int32
Public ImageWidth As Int32
Public ImageLength As Int32
Public SamplesPerPixel As Int16
<MarshalAs(UnmanagedType.ByValArray, SizeConst:=8)> Public BitsPerSample() As Short
Public BitsPerPixel As Int16
Public Planar As Boolean
Public PixelType As Int16
Public Compression As Short
End Class
<StructLayout(LayoutKind.Sequential, Pack:=2)> Friend Class TwPendingXfers
Public Count As Short
Public EOJ As Integer
End Class
<StructLayout(LayoutKind.Sequential, Pack:=2)> Friend Structure TwFix32
Public Whole As System.Int16
Public Frac As System.UInt32
Public Function ToFloat() As Single
Dim frac_sng As Single
frac_sng = System.Convert.ToSingle(Frac)
Return CType(Whole + (CType(frac_sng, Single) / 65536.0F), Single)
End Function
Public Sub FromFloat(ByVal f As Single)
Dim i As Int32 = CType(((f * 65536.0F) + 0.5F), Int32)
Whole = System.Convert.ToInt16(i / 2 ^ 16)
Frac = System.Convert.ToUInt32((i Or &HFFFF))
End Sub
End Structure
<StructLayout(LayoutKind.Sequential, Pack:=2)> Friend Structure TwFrame
Public Left As TwFix32
Public Top As TwFix32
Public Right As TwFix32
Public Bottom As TwFix32
End Structure
<StructLayout(LayoutKind.Sequential, Pack:=2)> Friend Class TwImageLayout
Public Frame As TwFrame
Public DocumentNumber As Integer
Public PageNumber As Integer
Public FrameNumber As Integer
End Class
<StructLayout(LayoutKind.Sequential, Pack:=2)> Friend Class TwCapability
Public Cap As Short
Public ConType As Short
Public Handle As IntPtr
Public Sub TwCapability(ByVal capIn As TwCap)
Cap = CType(capIn, Short)
ConType = -1
End Sub
Public Sub New(ByVal capIn As TwCap, ByVal sval As Short, ByVal TWType As TwType)
Cap = CType(capIn, Short)
ConType = CType(TwOn.One, Short)
Handle = Twain.GlobalAlloc(&H42, 6)
Dim pv As IntPtr = Twain.GlobalLock(Handle)
Marshal.WriteInt16(pv, 0, CType(TWType, Short))
Marshal.WriteInt32(pv, 2, CType(sval, Short))
Twain.GlobalUnlock(Handle)
End Sub
Public Sub Dispose()
If Not Equals(Handle, IntPtr.Zero) Then
Twain.GlobalFree(Handle)
End If
End Sub
Protected Overrides Sub Finalize()
If Not Equals(Handle, IntPtr.Zero) Then
Twain.GlobalFree(Handle)
End If
End Sub
End Class
|
|
|
|
|
I have solution in .Net with 2 projects . each projects contains one class and one interface each.. The interface contains name of function in class.
I have 3rd project with one interface . i want call all the 2 other interface in those 2 project in this interface and call that interface in client..
Please help me to solve this issue..
Joe
|
|
|
|
|
when I used it in the mainform, i mean in the parent windows,
it work great.
but i need to used it in the child window,
when it run the "select" or "acquire" nothing happen
it seem the child window can't catch the message.
very urgent.
please help.
|
|
|
|
|
set IsMdiContainer to true if you are using dotnet in properties window
|
|
|
|
|
Hi man, this is not working on VS 2005.
when i run it, nothing happens... any comments ??
thanks
ziad
|
|
|
|
|
OK , i found it, it is because of the "LoaderLock managed Debuging Assistent". MDAs only exsist in VS2005.
if anyone had this proplem, just go to Debug/Exceptions then + Managed Debuging Assistants then find and uncheck LoaderLock checkbox.
ziad
ziad
|
|
|
|
|
Hi,
I am new on twain. I have download the demo and also source files of this application. After I run this application, I have selected "Select Source". But nothing is happened. I have debugged the code. And in this part :
public void Init( IntPtr hwndp )<br />
{<br />
Finish();<br />
TwRC rc = DSMparent( appid, IntPtr.Zero, TwDG.Control, TwDAT.Parent, TwMSG.OpenDSM, ref hwndp );<br />
...<br />
}
rc returned as Failure. Where is the wrong? I have checked that in C:/WINDOWS directory, there are;
twunk_16.exe
twunk_32.exe
twain_32.dll
twain.dll
files. Is there any other needs such as registry any dll?
Thanks.
|
|
|
|
|
I've tried setting:
In the "Acquire" method in TwainLib.cs change:
TwCapability cap = new TwCapability( TwCap.XferCount, 1 );
to
TwCapability cap = new TwCapability( TwCap.XferCount, -1 );
However, it stops after scanning one image and I have to go through clicking acquire scan for the next image.
Can someone please send me a zip file of their project with scanning multi pages?
Thanks.
|
|
|
|
|
Hi asp-123,
Have anyone send you their zip file ?
Cause I have the same issue here, I also try below code in "Acquire" method
TwCapability cap = new TwCapability( TwCap.XferCount, 2 );
but it still did not work.
If you guys have sample application that you can send me, please send it to
tjendarta@gmail.com
I spent too much time and I really need this
Thank you
|
|
|
|
|
To scan multiple page you must execute the complete twain cycle many times over.
I believe that CAP_XFERCOUNT capability work on ADF scanner.
|
|
|
|
|
You set the Xfercount to -1 for multiple scans and 1 for a single scan.
Alan MacFadyen
|
|
|
|
|
the same problem with me, but with fujitsu scanner only and with others its working fine.
what could be the perfect solution?
thanks,
Jwalant Soneji (BE IT)
Mobile: +91 9969059127
http://jnsoneji.spaces.live.com
http://jnsoneji.blogspot.com
|
|
|
|
|
I too am having issues with multipage scanning w/TWAIN. Has anyone sent a solution via email?
|
|
|
|
|
hi , how do you convert the value to -1 . i mean i can see that the values is &H1
|
|
|
|
|
If overflow checking is switched on in the project settings,
it is useful to chage line 177,178 in TwainLib.cs to following:
winmsg.x = unchecked((short) (pos));
winmsg.y = unchecked((short) (pos >> 16));
Otherwise (no really) overflows causes to throw an exeption on certain mouse positions.
|
|
|
|
|
How Custominze Scan Area..
Muhammad Syed
|
|
|
|
|
check ICAP_FRAMES & ICAP_SUPPORTEDSIZES
|
|
|
|
|
I didnt find, ICAP_FRAMES & ICAP_SUPPORTEDSIZES in TWAIN.NET image scanner code.
Muhammad Syed
|
|
|
|
|
no, but you'll find it in the twain spec and following the brilliant examples here in c# or by looking at my vs2005 project in vb.net @ http://workspaces.gotdotnet.com/opentwain it can be figured out.
|
|
|
|
|
I tried this code with two different cameras (RICOH and HP) and when I click "Select Source" there isn't anything in the box. However, if I run this on WinXP, it works. Am I missing something?
I love to program!
|
|
|
|
|
How to set the page size dynamically with out using the UI from acquare() method?
Sugesh
|
|
|
|
|
dim PaperSize As TwSS = TwSS.TwSS_A4
Dim ps As TwCapability = New TwCapability(TwCap.SupportedSizes, PaperSize, TwType.Int16)
rc = DScap(appid, srcds, TwDG.Control, TwDAT.Capability, TwMSG.Set, ps)
If rc <> TwRC.Success Then
CloseSrc()
Return
End If
'Put this in TwainDefs.vb
Public Enum TwSS As Short
TwSS_None = &H0
TwSS_A4 = &H1
TwSS_B5Letter = &H2
TwSS_USLetter = &H3
End Enum
|
|
|
|
|
I tried the following steps in Visual Studio 2005 debugger (after a clean conversion):
*Started the app
*Acquired an image which brought up a preview screen
*Closed the preview form with the X button
*Closed the application with the X button
The debugger trapped the following exception:
LoaderLock was detected
Message: Attempting managed execution inside OS Loader lock. Do not attempt to run managed code inside a DllMain or image initialization function since doing so can cause the application to hang.
After doing a little research and trying a few things, I came up with the following:
Before:
namespace TwainLib
{
public class Twain
{
public void Finish()
{
TwRC rc;
CloseSrc();
if (appid.Id != IntPtr.Zero)
rc = DSMparent(appid, IntPtr.Zero, TwDG.Control, TwDAT.Parent, TwMSG.CloseDSM, ref hwnd);
appid.Id = IntPtr.Zero;
}
}
}
After:
namespace TwainLib
{
public class Twain
{
public void Finish()
{
TwRC rc;
Thread closeThread = new Thread(new ThreadStart(CloseSrc));
closeThread.Start();
closeThread.Join(5000); // Wait for the thread to finish
if (appid.Id != IntPtr.Zero)
rc = DSMparent(appid, IntPtr.Zero, TwDG.Control, TwDAT.Parent, TwMSG.CloseDSM, ref hwnd);
appid.Id = IntPtr.Zero;
}
}
}
This seems to do the trick. Feedback welcome
doug.spammenot
|
|
|
|
|
I am trying to rotate the image to a certain degree. Using the below written code :
public bool SetDegree(short val)
{
TwCapability cap = new TwCapability(TwCap.IRotation, val);
TwRC rc = DScap(appid, srcds, TwDG.Control, TwDAT.Capability, TwMSG.Set, cap);
if (rc == TwRC.Success)
return true;
else
return false;
}
But, its not workin. May be i am calling this function from a wrong place. But I am fed up of searching and modifiing the code for last three days.
Please help me out.
Syed Adil Umair
|
|
|
|
|