mirror of
https://github.com/soukoku/ntwain.git
synced 2026-01-26 21:48:36 +08:00
Add call to open DS in wrapper.
This commit is contained in:
11
NTwain.sln
11
NTwain.sln
@@ -14,6 +14,10 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "common", "common", "{4CE0B9
|
|||||||
EndProject
|
EndProject
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NTwain", "NTwain\NTwain.csproj", "{B391C1B7-5647-4B7A-9079-81E835E633DD}"
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NTwain", "NTwain\NTwain.csproj", "{B391C1B7-5647-4B7A-9079-81E835E633DD}"
|
||||||
EndProject
|
EndProject
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Net5Console", "samples\Net5Console\Net5Console.csproj", "{9F6C1B39-D0C9-4466-96A0-AB41C58762A9}"
|
||||||
|
EndProject
|
||||||
|
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Samples", "Samples", "{707B4313-8EF8-4D0F-A95E-590783422187}"
|
||||||
|
EndProject
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
Debug|Any CPU = Debug|Any CPU
|
Debug|Any CPU = Debug|Any CPU
|
||||||
@@ -24,10 +28,17 @@ Global
|
|||||||
{B391C1B7-5647-4B7A-9079-81E835E633DD}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
{B391C1B7-5647-4B7A-9079-81E835E633DD}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
{B391C1B7-5647-4B7A-9079-81E835E633DD}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
{B391C1B7-5647-4B7A-9079-81E835E633DD}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
{B391C1B7-5647-4B7A-9079-81E835E633DD}.Release|Any CPU.Build.0 = Release|Any CPU
|
{B391C1B7-5647-4B7A-9079-81E835E633DD}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{9F6C1B39-D0C9-4466-96A0-AB41C58762A9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{9F6C1B39-D0C9-4466-96A0-AB41C58762A9}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{9F6C1B39-D0C9-4466-96A0-AB41C58762A9}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{9F6C1B39-D0C9-4466-96A0-AB41C58762A9}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(SolutionProperties) = preSolution
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
HideSolutionNode = FALSE
|
HideSolutionNode = FALSE
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
|
GlobalSection(NestedProjects) = preSolution
|
||||||
|
{9F6C1B39-D0C9-4466-96A0-AB41C58762A9} = {707B4313-8EF8-4D0F-A95E-590783422187}
|
||||||
|
EndGlobalSection
|
||||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||||
SolutionGuid = {7459323B-44F6-4E07-8574-E1B4B525086B}
|
SolutionGuid = {7459323B-44F6-4E07-8574-E1B4B525086B}
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
|
|||||||
@@ -1,13 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace NTwain.Internal
|
|
||||||
{
|
|
||||||
static class TwainUtility
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -55,6 +55,11 @@ namespace NTwain
|
|||||||
GC.SuppressFinalize(this);
|
GC.SuppressFinalize(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the low-level twain object.
|
||||||
|
/// </summary>
|
||||||
|
public TWAIN TWAIN { get { return _twain; } }
|
||||||
|
|
||||||
#region event callbacks
|
#region event callbacks
|
||||||
|
|
||||||
private void HandleUIThreadAction(Action action)
|
private void HandleUIThreadAction(Action action)
|
||||||
@@ -85,7 +90,7 @@ namespace NTwain
|
|||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
// Try to get an event...
|
// Try to get an event...
|
||||||
twdeviceevent = default(TW_DEVICEEVENT);
|
twdeviceevent = default;
|
||||||
sts = _twain.DatDeviceevent(DG.CONTROL, MSG.GET, ref twdeviceevent);
|
sts = _twain.DatDeviceevent(DG.CONTROL, MSG.GET, ref twdeviceevent);
|
||||||
if (sts != STS.SUCCESS)
|
if (sts != STS.SUCCESS)
|
||||||
{
|
{
|
||||||
@@ -124,6 +129,17 @@ namespace NTwain
|
|||||||
get { return _twain.GetState(); }
|
get { return _twain.GetState(); }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the manager status. Useful after getting a non-success return code.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
public TW_STATUS GetStatus()
|
||||||
|
{
|
||||||
|
TW_STATUS stat = default;
|
||||||
|
var sts = _twain.DatStatus(DG.CONTROL, MSG.GET, ref stat);
|
||||||
|
return stat;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Opens the TWAIN data source manager.
|
/// Opens the TWAIN data source manager.
|
||||||
/// This needs to be done before anything else.
|
/// This needs to be done before anything else.
|
||||||
@@ -152,7 +168,7 @@ namespace NTwain
|
|||||||
var list = new List<TW_IDENTITY>();
|
var list = new List<TW_IDENTITY>();
|
||||||
if (State > STATE.S2)
|
if (State > STATE.S2)
|
||||||
{
|
{
|
||||||
var twidentity = default(TW_IDENTITY);
|
TW_IDENTITY twidentity = default;
|
||||||
STS sts;
|
STS sts;
|
||||||
|
|
||||||
for (sts = _twain.DatIdentity(DG.CONTROL, MSG.GETFIRST, ref twidentity);
|
for (sts = _twain.DatIdentity(DG.CONTROL, MSG.GETFIRST, ref twidentity);
|
||||||
@@ -172,7 +188,7 @@ namespace NTwain
|
|||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
var twidentity = default(TW_IDENTITY);
|
TW_IDENTITY twidentity = default;
|
||||||
var sts = _twain.DatIdentity(DG.CONTROL, MSG.GETDEFAULT, ref twidentity);
|
var sts = _twain.DatIdentity(DG.CONTROL, MSG.GETDEFAULT, ref twidentity);
|
||||||
if (sts == STS.SUCCESS) return twidentity;
|
if (sts == STS.SUCCESS) return twidentity;
|
||||||
return null;
|
return null;
|
||||||
@@ -189,7 +205,8 @@ namespace NTwain
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the currently open device.
|
/// Gets or sets the currently open device.
|
||||||
|
/// Setting it will try to open it.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public TW_IDENTITY? CurrentDevice
|
public TW_IDENTITY? CurrentDevice
|
||||||
{
|
{
|
||||||
@@ -197,7 +214,7 @@ namespace NTwain
|
|||||||
{
|
{
|
||||||
if (State > STATE.S3)
|
if (State > STATE.S3)
|
||||||
{
|
{
|
||||||
var twidentity = default(TW_IDENTITY);
|
TW_IDENTITY twidentity = default;
|
||||||
if (TWAIN.CsvToIdentity(ref twidentity, _twain.GetDsIdentity()))
|
if (TWAIN.CsvToIdentity(ref twidentity, _twain.GetDsIdentity()))
|
||||||
{
|
{
|
||||||
return twidentity;
|
return twidentity;
|
||||||
@@ -205,6 +222,15 @@ namespace NTwain
|
|||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
set
|
||||||
|
{
|
||||||
|
StepDown(STATE.S3);
|
||||||
|
if (value.HasValue)
|
||||||
|
{
|
||||||
|
var twidentity = value.Value;
|
||||||
|
_twain.DatIdentity(DG.CONTROL, MSG.OPENDS, ref twidentity);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -213,7 +239,7 @@ namespace NTwain
|
|||||||
/// <param name="state"></param>
|
/// <param name="state"></param>
|
||||||
public void StepDown(STATE state)
|
public void StepDown(STATE state)
|
||||||
{
|
{
|
||||||
var twpendingxfers = default(TW_PENDINGXFERS);
|
TW_PENDINGXFERS twpendingxfers = default;
|
||||||
|
|
||||||
// Make sure we have something to work with...
|
// Make sure we have something to work with...
|
||||||
if (_twain == null)
|
if (_twain == null)
|
||||||
@@ -239,14 +265,14 @@ namespace NTwain
|
|||||||
// 5 --> 4
|
// 5 --> 4
|
||||||
if ((_twain.GetState() == STATE.S5) && (state < STATE.S5))
|
if ((_twain.GetState() == STATE.S5) && (state < STATE.S5))
|
||||||
{
|
{
|
||||||
var twuserinterface = default(TW_USERINTERFACE);
|
TW_USERINTERFACE twuserinterface = default;
|
||||||
_twain.DatUserinterface(DG.CONTROL, MSG.DISABLEDS, ref twuserinterface);
|
_twain.DatUserinterface(DG.CONTROL, MSG.DISABLEDS, ref twuserinterface);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 4 --> 3
|
// 4 --> 3
|
||||||
if ((_twain.GetState() == STATE.S4) && (state < STATE.S4))
|
if ((_twain.GetState() == STATE.S4) && (state < STATE.S4))
|
||||||
{
|
{
|
||||||
var twidentity = default(TW_IDENTITY);
|
TW_IDENTITY twidentity = default;
|
||||||
TWAIN.CsvToIdentity(ref twidentity, _twain.GetDsIdentity());
|
TWAIN.CsvToIdentity(ref twidentity, _twain.GetDsIdentity());
|
||||||
_twain.DatIdentity(DG.CONTROL, MSG.CLOSEDS, ref twidentity);
|
_twain.DatIdentity(DG.CONTROL, MSG.CLOSEDS, ref twidentity);
|
||||||
}
|
}
|
||||||
|
|||||||
12
samples/Net5Console/Net5Console.csproj
Normal file
12
samples/Net5Console/Net5Console.csproj
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<OutputType>Exe</OutputType>
|
||||||
|
<TargetFramework>net5.0-windows</TargetFramework>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\..\NTwain\NTwain.csproj" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
||||||
38
samples/Net5Console/Program.cs
Normal file
38
samples/Net5Console/Program.cs
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
using NTwain;
|
||||||
|
using System;
|
||||||
|
using System.Reflection;
|
||||||
|
|
||||||
|
namespace Net5Console
|
||||||
|
{
|
||||||
|
class Program
|
||||||
|
{
|
||||||
|
static void Main(string[] args)
|
||||||
|
{
|
||||||
|
using (var twain = new TwainSession(Assembly.GetExecutingAssembly(), null, IntPtr.Zero))
|
||||||
|
{
|
||||||
|
if (twain.Open() == TWAINWorkingGroup.STS.SUCCESS)
|
||||||
|
{
|
||||||
|
Console.WriteLine("Opened DSM");
|
||||||
|
Console.WriteLine("Default device:");
|
||||||
|
Console.WriteLine($"\t{twain.DefaultDevice}");
|
||||||
|
Console.WriteLine("All devices:");
|
||||||
|
foreach (var dev in twain.GetDevices())
|
||||||
|
{
|
||||||
|
Console.WriteLine($"\t{dev}");
|
||||||
|
}
|
||||||
|
Console.WriteLine("Current device:");
|
||||||
|
Console.WriteLine($"\t{twain.CurrentDevice}");
|
||||||
|
twain.CurrentDevice = twain.DefaultDevice;
|
||||||
|
Console.WriteLine("Current device after setting:");
|
||||||
|
Console.WriteLine($"\t{twain.CurrentDevice}");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Console.Error.WriteLine("Failed to open DSM");
|
||||||
|
}
|
||||||
|
Console.WriteLine("Test Ended");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user