mirror of
https://github.com/soukoku/ntwain.git
synced 2025-09-19 01:57:56 +08:00
Updated sample console to end xfer correctly.
This commit is contained in:
@@ -12,19 +12,23 @@ namespace Net5Console
|
|||||||
{
|
{
|
||||||
Console.WriteLine("Starting twain test in console...");
|
Console.WriteLine("Starting twain test in console...");
|
||||||
|
|
||||||
using (var twain = new TwainSession(Assembly.GetExecutingAssembly(), null, IntPtr.Zero))
|
using (var session = new TwainSession(Assembly.GetExecutingAssembly(), null, IntPtr.Zero))
|
||||||
using (var hold = new ManualResetEventSlim())
|
using (var hold = new ManualResetEventSlim())
|
||||||
{
|
{
|
||||||
twain.DeviceEvent += (sender, e) =>
|
session.DeviceEvent += (sender, e) =>
|
||||||
{
|
{
|
||||||
Console.WriteLine($"Got device event " + (TWDE)e.Event);
|
Console.WriteLine($"Got device event " + (TWDE)e.Event);
|
||||||
};
|
};
|
||||||
twain.ScanEvent += (sender, closing) =>
|
session.ScanEvent += (sender, closing) =>
|
||||||
{
|
{
|
||||||
Console.WriteLine($"Got scan event " + closing);
|
Console.WriteLine($"Got scan event " + closing);
|
||||||
|
|
||||||
|
// don't care, just end it
|
||||||
|
TW_PENDINGXFERS pending = default;
|
||||||
|
var sts = session.TWAIN.DatPendingxfers(DG.CONTROL, MSG.RESET, ref pending);
|
||||||
|
|
||||||
TW_USERINTERFACE twuserinterface = default;
|
TW_USERINTERFACE twuserinterface = default;
|
||||||
if (twain.TWAIN.DatUserinterface(DG.CONTROL, MSG.DISABLEDS, ref twuserinterface) == STS.SUCCESS)
|
if (session.TWAIN.DatUserinterface(DG.CONTROL, MSG.DISABLEDS, ref twuserinterface) == STS.SUCCESS)
|
||||||
{
|
{
|
||||||
Console.WriteLine("Disabled device.");
|
Console.WriteLine("Disabled device.");
|
||||||
}
|
}
|
||||||
@@ -35,16 +39,16 @@ namespace Net5Console
|
|||||||
hold.Set();
|
hold.Set();
|
||||||
};
|
};
|
||||||
|
|
||||||
if (twain.Open() == TWAINWorkingGroup.STS.SUCCESS)
|
if (session.Open() == TWAINWorkingGroup.STS.SUCCESS)
|
||||||
{
|
{
|
||||||
Console.WriteLine("Opened DSM");
|
Console.WriteLine("Opened DSM");
|
||||||
|
|
||||||
Console.WriteLine("Default device:");
|
Console.WriteLine("Default device:");
|
||||||
Console.WriteLine($"\t{twain.DefaultDevice}");
|
Console.WriteLine($"\t{session.DefaultDevice}");
|
||||||
|
|
||||||
Console.WriteLine("All devices:");
|
Console.WriteLine("All devices:");
|
||||||
TW_IDENTITY dsToUse = default;
|
TW_IDENTITY dsToUse = default;
|
||||||
foreach (var dev in twain.GetDevices())
|
foreach (var dev in session.GetDevices())
|
||||||
{
|
{
|
||||||
Console.WriteLine($"\t{dev}");
|
Console.WriteLine($"\t{dev}");
|
||||||
if (dev.ProductName == "TWAIN2 FreeImage Software Scanner")
|
if (dev.ProductName == "TWAIN2 FreeImage Software Scanner")
|
||||||
@@ -53,13 +57,13 @@ namespace Net5Console
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
twain.CurrentDevice = dsToUse;
|
session.CurrentDevice = dsToUse;
|
||||||
if (twain.CurrentDevice.HasValue)
|
if (session.CurrentDevice.HasValue)
|
||||||
{
|
{
|
||||||
Console.WriteLine("Current device after opening attempt:");
|
Console.WriteLine("Current device after opening attempt:");
|
||||||
Console.WriteLine($"\t{twain.CurrentDevice}");
|
Console.WriteLine($"\t{session.CurrentDevice}");
|
||||||
|
|
||||||
var sts = twain.StartCapture(false);
|
var sts = session.StartCapture(false);
|
||||||
if (sts == STS.SUCCESS)
|
if (sts == STS.SUCCESS)
|
||||||
{
|
{
|
||||||
Console.Error.WriteLine("Waiting for capture to complete.");
|
Console.Error.WriteLine("Waiting for capture to complete.");
|
||||||
|
Reference in New Issue
Block a user