From 11b6cb1040f9273f58a7652088b24b0e5ec977cd Mon Sep 17 00:00:00 2001 From: soukoku Date: Wed, 17 Sep 2014 20:15:05 -0400 Subject: [PATCH] More source updates. --- NTwain.Net35/NTwain.Net35.csproj | 3 + NTwain/CapabilityControl.cs | 4 +- NTwain/DataSource.Caps.cs | 6 +- NTwain/DataSource.cs | 32 ++------ NTwain/ICapController.cs | 70 ++++++++++++++++++ NTwain/IDataSource.cs | 85 +++++++++++++++++++++- NTwain/Internals/WinMemoryManager.cs | 3 +- NTwain/NTwain.csproj | 1 + NTwain/PlatformInfo.cs | 3 +- NTwain/Properties/VersionInfo.cs | 27 +++++-- Tests/Tester.Console/Program.cs | 66 +++++++++-------- Tests/Tester.Console/Tester.Console.csproj | 2 +- Tests/Tester.WPF/ViewModels/DSVM.cs | 2 +- 13 files changed, 227 insertions(+), 77 deletions(-) create mode 100644 NTwain/ICapController.cs diff --git a/NTwain.Net35/NTwain.Net35.csproj b/NTwain.Net35/NTwain.Net35.csproj index fbd6602..7f5f752 100644 --- a/NTwain.Net35/NTwain.Net35.csproj +++ b/NTwain.Net35/NTwain.Net35.csproj @@ -78,6 +78,9 @@ DeviceEventArgs.cs + + ICapController.cs + IDataSource.cs diff --git a/NTwain/CapabilityControl.cs b/NTwain/CapabilityControl.cs index 59f5943..3cd5887 100644 --- a/NTwain/CapabilityControl.cs +++ b/NTwain/CapabilityControl.cs @@ -311,7 +311,7 @@ namespace NTwain /// public ReturnCode ResetAll() { - return _source.ResetAll(Capability); + return _source.CapResetAll(Capability); } /// @@ -320,7 +320,7 @@ namespace NTwain /// public ReturnCode Reset() { - return _source.Reset(Capability); + return _source.CapReset(Capability); } /// diff --git a/NTwain/DataSource.Caps.cs b/NTwain/DataSource.Caps.cs index 31971f6..bef41d0 100644 --- a/NTwain/DataSource.Caps.cs +++ b/NTwain/DataSource.Caps.cs @@ -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 /// /// The capability identifier. /// - public ReturnCode ResetAll(CapabilityId capabilityId) + public ReturnCode CapResetAll(CapabilityId capabilityId) { using (TWCapability cap = new TWCapability(capabilityId) { @@ -156,7 +156,7 @@ namespace NTwain /// /// The capability identifier. /// - public ReturnCode Reset(CapabilityId capabilityId) + public ReturnCode CapReset(CapabilityId capabilityId) { using (TWCapability cap = new TWCapability(capabilityId) { diff --git a/NTwain/DataSource.cs b/NTwain/DataSource.cs index a3b3afe..2267d21 100644 --- a/NTwain/DataSource.cs +++ b/NTwain/DataSource.cs @@ -23,6 +23,7 @@ namespace NTwain { _session = session; Identity = sourceId; + ProtocolVersion = new Version(sourceId.ProtocolMajor, sourceId.ProtocolMinor); } /// @@ -61,20 +62,6 @@ namespace NTwain return rc; } - - /// - /// Enables the source to start transferring. - /// - /// The mode. - /// if set to true any driver UI will display as modal. - /// The window handle if modal. - /// - [Obsolete("Use Enable() instead.")] - public ReturnCode StartTransfer(SourceEnableMode mode, bool modal, IntPtr windowHandle) - { - return Enable(mode, modal, windowHandle); - } - /// /// Enables the source to start transferring. /// @@ -138,7 +125,7 @@ namespace NTwain public string ProductFamily { get { return Identity.ProductFamily; } } /// - /// Gets the version information. + /// Gets the source's version information. /// /// /// The version. @@ -154,21 +141,12 @@ namespace NTwain public DataGroups DataGroup { get { return Identity.DataGroup; } } /// - /// Gets the supported TWAIN protocol major number. + /// Gets the supported TWAIN protocol version. /// /// - /// The protocol major number. + /// The protocol version. /// - public int ProtocolMajor { get { return Identity.ProtocolMajor; } } - - /// - /// Gets the supported TWAIN protocol minor number. - /// - /// - /// The protocol minor number. - /// - public int ProtocolMinor { get { return Identity.ProtocolMinor; } } - + public Version ProtocolVersion { get; private set; } static readonly CapabilityId[] _emptyCapList = new CapabilityId[0]; diff --git a/NTwain/ICapController.cs b/NTwain/ICapController.cs new file mode 100644 index 0000000..f7593ad --- /dev/null +++ b/NTwain/ICapController.cs @@ -0,0 +1,70 @@ +using NTwain.Data; +using System; +using System.Collections.Generic; +namespace NTwain +{ + /// + /// Interface for controlling caps. + /// + public interface ICapController + { + + /// + /// A general method that tries to get capability values from current . + /// + /// The capability unique identifier. + /// + IList CapGet(CapabilityId capabilityId); + + /// + /// Gets the current value for a capability. + /// + /// The cap id. + /// + object CapGetCurrent(CapabilityId capId); + + /// + /// Gets the default value for a capability. + /// + /// The cap id. + /// + object CapGetDefault(CapabilityId capId); + + /// + /// Gets the actual supported operations for a capability. + /// + /// The cap identifier. + /// + QuerySupports CapQuerySupport(CapabilityId capId); + + /// + /// Resets the current value to power-on default. + /// + /// The capability identifier. + /// + ReturnCode CapReset(CapabilityId capabilityId); + + /// + /// Resets all values and constraint to power-on defaults. + /// + /// The capability identifier. + /// + ReturnCode CapResetAll(CapabilityId capabilityId); + + + //CapabilityControl CapAudioXferMech { get; } + //CapabilityControl CapDuplexEnabled { get; } + //CapabilityControl CapFeederEnabled { get; } + //CapabilityControl CapImageAutoDeskew { get; } + //CapabilityControl CapImageAutomaticBorderDetection { get; } + //CapabilityControl CapImageAutoRotate { get; } + //CapabilityControl CapImageCompression { get; } + //CapabilityControl CapImageFileFormat { get; } + //CapabilityControl CapImagePixelType { get; } + //CapabilityControl CapImageSupportedSize { get; } + //CapabilityControl CapImageXferMech { get; } + //CapabilityControl CapImageXResolution { get; } + //CapabilityControl CapImageYResolution { get; } + //CapabilityControl CapXferCount { get; } + } +} diff --git a/NTwain/IDataSource.cs b/NTwain/IDataSource.cs index 880a906..a3f9875 100644 --- a/NTwain/IDataSource.cs +++ b/NTwain/IDataSource.cs @@ -1,4 +1,6 @@ -using System; +using NTwain.Data; +using System; +using System.Collections.Generic; namespace NTwain { /// @@ -13,5 +15,86 @@ namespace NTwain /// The name. /// string Name { get; } + + /// + /// Gets the supported data group. + /// + /// + /// The data group. + /// + DataGroups DataGroup { get; } + + /// + /// Gets the source's manufacturer name. + /// + /// + /// The manufacturer. + /// + string Manufacturer { get; } + + /// + /// Gets the source's product family. + /// + /// + /// The product family. + /// + string ProductFamily { get; } + + /// + /// Gets the supported TWAIN protocol version. + /// + /// + /// The protocol version. + /// + Version ProtocolVersion { get; } + + /// + /// Gets the supported caps for this source. + /// + /// + /// The supported caps. + /// + IList SupportedCaps { get; } + + /// + /// Gets the source's version information. + /// + /// + /// The version. + /// + TWVersion Version { get; } + + /// + /// Opens the source for capability negotiation. + /// + /// + ReturnCode Open(); + + /// + /// Closes the source. + /// + /// + ReturnCode Close(); + + /// + /// Enables the source to start transferring. + /// + /// The mode. + /// if set to true any driver UI will display as modal. + /// The window handle if modal. + /// + ReturnCode Enable(SourceEnableMode mode, bool modal, IntPtr windowHandle); + + /// + /// Gets the source status. Only call this at state 4 or higher. + /// + /// + TWStatus GetStatus(); + + /// + /// Gets the source status. Only call this at state 4 or higher. + /// + /// + TWStatusUtf8 GetStatusUtf8(); } } diff --git a/NTwain/Internals/WinMemoryManager.cs b/NTwain/Internals/WinMemoryManager.cs index 3253b02..8f0df2e 100644 --- a/NTwain/Internals/WinMemoryManager.cs +++ b/NTwain/Internals/WinMemoryManager.cs @@ -1,9 +1,8 @@ using NTwain.Data; -using NTwain.Internals; using System; using System.ComponentModel; -namespace NTwain +namespace NTwain.Internals { /// /// Provides methods for managing memory on data exchanged with twain sources using old win32 methods. diff --git a/NTwain/NTwain.csproj b/NTwain/NTwain.csproj index 4efe0ae..e9caf4e 100644 --- a/NTwain/NTwain.csproj +++ b/NTwain/NTwain.csproj @@ -61,6 +61,7 @@ + diff --git a/NTwain/PlatformInfo.cs b/NTwain/PlatformInfo.cs index 9fb4bd6..6423713 100644 --- a/NTwain/PlatformInfo.cs +++ b/NTwain/PlatformInfo.cs @@ -1,4 +1,5 @@ -using NTwain.Triplets; +using NTwain.Internals; +using NTwain.Triplets; using System; using System.Collections.Generic; using System.IO; diff --git a/NTwain/Properties/VersionInfo.cs b/NTwain/Properties/VersionInfo.cs index 67de7f4..1aef18c 100644 --- a/NTwain/Properties/VersionInfo.cs +++ b/NTwain/Properties/VersionInfo.cs @@ -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 + /// + /// Contains version info of this assembly. + /// + 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"; + /// + /// The major release version number. + /// + public const string Release = "3.0.0.0"; // keep this same in major (breaking) releases + + + /// + /// The build release version number. + /// + public const string Build = "3.0.0"; // change this for each nuget release + + } } \ No newline at end of file diff --git a/Tests/Tester.Console/Program.cs b/Tests/Tester.Console/Program.cs index 1f18196..15622ab 100644 --- a/Tests/Tester.Console/Program.cs +++ b/Tests/Tester.Console/Program.cs @@ -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); - } - } } } diff --git a/Tests/Tester.Console/Tester.Console.csproj b/Tests/Tester.Console/Tester.Console.csproj index 6ba359f..8c184ad 100644 --- a/Tests/Tester.Console/Tester.Console.csproj +++ b/Tests/Tester.Console/Tester.Console.csproj @@ -23,7 +23,7 @@ 4 - x86 + x64 pdbonly true bin\Release\ diff --git a/Tests/Tester.WPF/ViewModels/DSVM.cs b/Tests/Tester.WPF/ViewModels/DSVM.cs index 65d4b65..0d20246 100644 --- a/Tests/Tester.WPF/ViewModels/DSVM.cs +++ b/Tests/Tester.WPF/ViewModels/DSVM.cs @@ -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(); } } } }