More source updates.

This commit is contained in:
soukoku
2014-09-17 20:15:05 -04:00
parent 450f8aa5b0
commit 11b6cb1040
13 changed files with 227 additions and 77 deletions

View File

@@ -78,6 +78,9 @@
<Compile Include="..\NTwain\DeviceEventArgs.cs">
<Link>DeviceEventArgs.cs</Link>
</Compile>
<Compile Include="..\NTwain\ICapController.cs">
<Link>ICapController.cs</Link>
</Compile>
<Compile Include="..\NTwain\IDataSource.cs">
<Link>IDataSource.cs</Link>
</Compile>

View File

@@ -311,7 +311,7 @@ namespace NTwain
/// <returns></returns>
public ReturnCode ResetAll()
{
return _source.ResetAll(Capability);
return _source.CapResetAll(Capability);
}
/// <summary>
@@ -320,7 +320,7 @@ namespace NTwain
/// <returns></returns>
public ReturnCode Reset()
{
return _source.Reset(Capability);
return _source.CapReset(Capability);
}
/// <summary>

View File

@@ -9,7 +9,7 @@ namespace NTwain
// this contains all cap-related methods prefixed with Cap
partial class DataSource
partial class DataSource : ICapController
{
#region low-level cap stuff
@@ -139,7 +139,7 @@ namespace NTwain
/// </summary>
/// <param name="capabilityId">The capability identifier.</param>
/// <returns></returns>
public ReturnCode ResetAll(CapabilityId capabilityId)
public ReturnCode CapResetAll(CapabilityId capabilityId)
{
using (TWCapability cap = new TWCapability(capabilityId)
{
@@ -156,7 +156,7 @@ namespace NTwain
/// </summary>
/// <param name="capabilityId">The capability identifier.</param>
/// <returns></returns>
public ReturnCode Reset(CapabilityId capabilityId)
public ReturnCode CapReset(CapabilityId capabilityId)
{
using (TWCapability cap = new TWCapability(capabilityId)
{

View File

@@ -23,6 +23,7 @@ namespace NTwain
{
_session = session;
Identity = sourceId;
ProtocolVersion = new Version(sourceId.ProtocolMajor, sourceId.ProtocolMinor);
}
/// <summary>
@@ -61,20 +62,6 @@ namespace NTwain
return rc;
}
/// <summary>
/// Enables the source to start transferring.
/// </summary>
/// <param name="mode">The mode.</param>
/// <param name="modal">if set to <c>true</c> any driver UI will display as modal.</param>
/// <param name="windowHandle">The window handle if modal.</param>
/// <returns></returns>
[Obsolete("Use Enable() instead.")]
public ReturnCode StartTransfer(SourceEnableMode mode, bool modal, IntPtr windowHandle)
{
return Enable(mode, modal, windowHandle);
}
/// <summary>
/// Enables the source to start transferring.
/// </summary>
@@ -138,7 +125,7 @@ namespace NTwain
public string ProductFamily { get { return Identity.ProductFamily; } }
/// <summary>
/// Gets the version information.
/// Gets the source's version information.
/// </summary>
/// <value>
/// The version.
@@ -154,21 +141,12 @@ namespace NTwain
public DataGroups DataGroup { get { return Identity.DataGroup; } }
/// <summary>
/// Gets the supported TWAIN protocol major number.
/// Gets the supported TWAIN protocol version.
/// </summary>
/// <value>
/// The protocol major number.
/// The protocol version.
/// </value>
public int ProtocolMajor { get { return Identity.ProtocolMajor; } }
/// <summary>
/// Gets the supported TWAIN protocol minor number.
/// </summary>
/// <value>
/// The protocol minor number.
/// </value>
public int ProtocolMinor { get { return Identity.ProtocolMinor; } }
public Version ProtocolVersion { get; private set; }
static readonly CapabilityId[] _emptyCapList = new CapabilityId[0];

70
NTwain/ICapController.cs Normal file
View File

@@ -0,0 +1,70 @@
using NTwain.Data;
using System;
using System.Collections.Generic;
namespace NTwain
{
/// <summary>
/// Interface for controlling caps.
/// </summary>
public interface ICapController
{
/// <summary>
/// A general method that tries to get capability values from current <see cref="DataSource" />.
/// </summary>
/// <param name="capabilityId">The capability unique identifier.</param>
/// <returns></returns>
IList<object> CapGet(CapabilityId capabilityId);
/// <summary>
/// Gets the current value for a capability.
/// </summary>
/// <param name="capId">The cap id.</param>
/// <returns></returns>
object CapGetCurrent(CapabilityId capId);
/// <summary>
/// Gets the default value for a capability.
/// </summary>
/// <param name="capId">The cap id.</param>
/// <returns></returns>
object CapGetDefault(CapabilityId capId);
/// <summary>
/// Gets the actual supported operations for a capability.
/// </summary>
/// <param name="capId">The cap identifier.</param>
/// <returns></returns>
QuerySupports CapQuerySupport(CapabilityId capId);
/// <summary>
/// Resets the current value to power-on default.
/// </summary>
/// <param name="capabilityId">The capability identifier.</param>
/// <returns></returns>
ReturnCode CapReset(CapabilityId capabilityId);
/// <summary>
/// Resets all values and constraint to power-on defaults.
/// </summary>
/// <param name="capabilityId">The capability identifier.</param>
/// <returns></returns>
ReturnCode CapResetAll(CapabilityId capabilityId);
//CapabilityControl<XferMech> CapAudioXferMech { get; }
//CapabilityControl<BoolType> CapDuplexEnabled { get; }
//CapabilityControl<BoolType> CapFeederEnabled { get; }
//CapabilityControl<BoolType> CapImageAutoDeskew { get; }
//CapabilityControl<BoolType> CapImageAutomaticBorderDetection { get; }
//CapabilityControl<BoolType> CapImageAutoRotate { get; }
//CapabilityControl<CompressionType> CapImageCompression { get; }
//CapabilityControl<FileFormat> CapImageFileFormat { get; }
//CapabilityControl<PixelType> CapImagePixelType { get; }
//CapabilityControl<SupportedSize> CapImageSupportedSize { get; }
//CapabilityControl<XferMech> CapImageXferMech { get; }
//CapabilityControl<TWFix32> CapImageXResolution { get; }
//CapabilityControl<TWFix32> CapImageYResolution { get; }
//CapabilityControl<int> CapXferCount { get; }
}
}

View File

@@ -1,4 +1,6 @@
using System;
using NTwain.Data;
using System;
using System.Collections.Generic;
namespace NTwain
{
/// <summary>
@@ -13,5 +15,86 @@ namespace NTwain
/// The name.
/// </value>
string Name { get; }
/// <summary>
/// Gets the supported data group.
/// </summary>
/// <value>
/// The data group.
/// </value>
DataGroups DataGroup { get; }
/// <summary>
/// Gets the source's manufacturer name.
/// </summary>
/// <value>
/// The manufacturer.
/// </value>
string Manufacturer { get; }
/// <summary>
/// Gets the source's product family.
/// </summary>
/// <value>
/// The product family.
/// </value>
string ProductFamily { get; }
/// <summary>
/// Gets the supported TWAIN protocol version.
/// </summary>
/// <value>
/// The protocol version.
/// </value>
Version ProtocolVersion { get; }
/// <summary>
/// Gets the supported caps for this source.
/// </summary>
/// <value>
/// The supported caps.
/// </value>
IList<CapabilityId> SupportedCaps { get; }
/// <summary>
/// Gets the source's version information.
/// </summary>
/// <value>
/// The version.
/// </value>
TWVersion Version { get; }
/// <summary>
/// Opens the source for capability negotiation.
/// </summary>
/// <returns></returns>
ReturnCode Open();
/// <summary>
/// Closes the source.
/// </summary>
/// <returns></returns>
ReturnCode Close();
/// <summary>
/// Enables the source to start transferring.
/// </summary>
/// <param name="mode">The mode.</param>
/// <param name="modal">if set to <c>true</c> any driver UI will display as modal.</param>
/// <param name="windowHandle">The window handle if modal.</param>
/// <returns></returns>
ReturnCode Enable(SourceEnableMode mode, bool modal, IntPtr windowHandle);
/// <summary>
/// Gets the source status. Only call this at state 4 or higher.
/// </summary>
/// <returns></returns>
TWStatus GetStatus();
/// <summary>
/// Gets the source status. Only call this at state 4 or higher.
/// </summary>
/// <returns></returns>
TWStatusUtf8 GetStatusUtf8();
}
}

View File

@@ -1,9 +1,8 @@
using NTwain.Data;
using NTwain.Internals;
using System;
using System.ComponentModel;
namespace NTwain
namespace NTwain.Internals
{
/// <summary>
/// Provides methods for managing memory on data exchanged with twain sources using old win32 methods.

View File

@@ -61,6 +61,7 @@
<Compile Include="Data\TwainTypesExtended.cs" />
<Compile Include="DeviceEventArgs.cs" />
<Compile Include="IDataSource.cs" />
<Compile Include="ICapController.cs" />
<Compile Include="Internals\Extensions.cs" />
<Compile Include="DataTransferredEventArgs.cs" />
<Compile Include="IMemoryManager.cs" />

View File

@@ -1,4 +1,5 @@
using NTwain.Triplets;
using NTwain.Internals;
using NTwain.Triplets;
using System;
using System.Collections.Generic;
using System.IO;

View File

@@ -3,17 +3,28 @@
[assembly: AssemblyCopyright("Copyright \x00a9 Yin-Chun Wang 2012-2014")]
[assembly: AssemblyCompany("Yin-Chun Wang")]
[assembly: AssemblyVersion(NTwain._NTwainVersionInfo.Release)]
[assembly: AssemblyFileVersion(NTwain._NTwainVersionInfo.Build)]
[assembly: AssemblyInformationalVersion(NTwain._NTwainVersionInfo.Build)]
[assembly: AssemblyVersion(NTwain.NTwainVersionInfo.Release)]
[assembly: AssemblyFileVersion(NTwain.NTwainVersionInfo.Build)]
[assembly: AssemblyInformationalVersion(NTwain.NTwainVersionInfo.Build)]
namespace NTwain
{
class _NTwainVersionInfo
/// <summary>
/// Contains version info of this assembly.
/// </summary>
public class NTwainVersionInfo
{
// keep this same in major (breaking) releases
public const string Release = "3.0.0.0";
// change this for each nuget release
public const string Build = "3.0.0";
/// <summary>
/// The major release version number.
/// </summary>
public const string Release = "3.0.0.0"; // keep this same in major (breaking) releases
/// <summary>
/// The build release version number.
/// </summary>
public const string Build = "3.0.0"; // change this for each nuget release
}
}

View File

@@ -11,6 +11,14 @@ namespace Tester
{
static void Main(string[] args)
{
if (PlatformInfo.Current.IsApp64bit)
{
Console.WriteLine("[64bit]");
}
else
{
Console.WriteLine("[32bit]");
}
// just an amusing example to do twain in console without UI
ThreadPool.QueueUserWorkItem(o =>
{
@@ -26,26 +34,45 @@ namespace Tester
private static TwainSession InitTwain()
{
var twain = new TwainSession(TWIdentity.CreateFromAssembly(DataGroups.Image, Assembly.GetExecutingAssembly()));
twain.DataTransferred += twain_DataTransferred;
twain.TransferReady += twain_TransferReady;
twain.SourceDisabled += twain_SourceDisabled;
twain.TransferReady += (s, e) =>
{
Console.WriteLine("Got xfer ready on thread {0}.", Thread.CurrentThread.ManagedThreadId);
};
twain.DataTransferred += (s, e) =>
{
if (e.NativeData != IntPtr.Zero)
{
Console.WriteLine("SUCCESS! Got twain data on thread {0}.", Thread.CurrentThread.ManagedThreadId);
}
else
{
Console.WriteLine("BUMMER! No twain data on thread {0}.", Thread.CurrentThread.ManagedThreadId);
}
};
twain.SourceDisabled += (s, e) =>
{
Console.WriteLine("Source disabled on thread {0}.", Thread.CurrentThread.ManagedThreadId);
var rc = twain.CurrentSource.Close();
rc = twain.Close();
};
return twain;
}
const string SAMPLE_SOURCE = "TWAIN2 FreeImage Software Scanner";
static void DoTwainWork()
{
Console.WriteLine("Getting ready to do twain stuff on thread {0}.", Thread.CurrentThread.ManagedThreadId);
Console.WriteLine("Getting ready to do twain stuff on thread {0}...", Thread.CurrentThread.ManagedThreadId);
Thread.Sleep(1000);
var rc = twain.Open();
if (rc == ReturnCode.Success)
{
var hit = twain.Where(s => string.Equals(s.Name, "TWAIN2 FreeImage Software Scanner")).FirstOrDefault();
var hit = twain.FirstOrDefault(s => string.Equals(s.Name, SAMPLE_SOURCE));
if (hit == null)
{
Console.WriteLine("The sample source \"TWAIN2 FreeImage Software Scanner\" is not installed.");
Console.WriteLine("The sample source \"" + SAMPLE_SOURCE + "\" is not installed.");
twain.Close();
}
else
@@ -54,7 +81,7 @@ namespace Tester
if (rc == ReturnCode.Success)
{
Console.WriteLine("Start capture from the sample source.");
Console.WriteLine("Starting capture from the sample source...");
rc = hit.Enable(SourceEnableMode.NoUI, false, IntPtr.Zero);
}
else
@@ -69,28 +96,5 @@ namespace Tester
}
}
static void twain_SourceDisabled(object sender, EventArgs e)
{
Console.WriteLine("Source disabled on thread {0}.", Thread.CurrentThread.ManagedThreadId);
var rc = twain.CurrentSource.Close();
rc = twain.Close();
}
static void twain_TransferReady(object sender, TransferReadyEventArgs e)
{
Console.WriteLine("Got xfer ready on thread {0}.", Thread.CurrentThread.ManagedThreadId);
}
static void twain_DataTransferred(object sender, DataTransferredEventArgs e)
{
if (e.NativeData != IntPtr.Zero)
{
Console.WriteLine("Got twain data on thread {0}.", Thread.CurrentThread.ManagedThreadId);
}
else
{
Console.WriteLine("No twain data on thread {0}.", Thread.CurrentThread.ManagedThreadId);
}
}
}
}

View File

@@ -23,7 +23,7 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>x86</PlatformTarget>
<PlatformTarget>x64</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>

View File

@@ -12,6 +12,6 @@ namespace Tester.WPF
public string Name { get { return DS.Name; } }
public string Version { get { return DS.Version.Info; } }
public string Protocol { get { return string.Format("{0}.{1}", DS.ProtocolMajor, DS.ProtocolMinor); } }
public string Protocol { get { return DS.ProtocolVersion.ToString(); } }
}
}