Added custom DAT with capability functions in ref to #9.

This commit is contained in:
soukoku 2014-05-15 07:29:03 -04:00
parent 1cd21f86cb
commit 6d8ef7bdd9
7 changed files with 187 additions and 16 deletions

View File

@ -151,6 +151,9 @@
<Compile Include="..\NTwain\Triplets\DGControl\DGControl.Capability.cs">
<Link>Triplets\DGControl\DGControl.Capability.cs</Link>
</Compile>
<Compile Include="..\NTwain\Triplets\DGControl\DGControl.CapabilityCustom.cs">
<Link>Triplets\DGControl\DGControl.CapabilityCustom.cs</Link>
</Compile>
<Compile Include="..\NTwain\Triplets\DGControl\DGControl.cs">
<Link>Triplets\DGControl\DGControl.cs</Link>
</Compile>

View File

@ -80,6 +80,7 @@
<Compile Include="TransferErrorEventArgs.cs" />
<Compile Include="TransferReadyEventArgs.cs" />
<Compile Include="Triplets\DGControl\DGControl.Callback2.cs" />
<Compile Include="Triplets\DGControl\DGControl.CapabilityCustom.cs" />
<Compile Include="Triplets\DGImage\DGImage.Filter.cs" />
<Compile Include="Triplets\OpBase.cs" />
<Compile Include="Triplets\Dsm.Linux.cs" />

View File

@ -14,6 +14,6 @@ namespace NTwain
// keep this same in majors releases
public const string Release = "1.0.0.0";
// change this for each nuget release
public const string Build = "1.0.1";
public const string Build = "1.0.2";
}
}

View File

@ -17,7 +17,7 @@ namespace NTwain.Triplets
public ReturnCode Get(TWCapability capability)
{
Session.VerifyState(4, 7, DataGroups.Control, DataArgumentType.Capability, Message.Get);
return Dsm.DsmEntry(Session.AppId, Session.SourceId, Message.Get, capability);
return Dsm.DsmEntry(Session.AppId, Session.SourceId, DataArgumentType.Capability, Message.Get, capability);
}
/// <summary>
@ -28,7 +28,7 @@ namespace NTwain.Triplets
public ReturnCode GetCurrent(TWCapability capability)
{
Session.VerifyState(4, 7, DataGroups.Control, DataArgumentType.Capability, Message.GetCurrent);
return Dsm.DsmEntry(Session.AppId, Session.SourceId, Message.GetCurrent, capability);
return Dsm.DsmEntry(Session.AppId, Session.SourceId, DataArgumentType.Capability, Message.GetCurrent, capability);
}
/// <summary>
@ -39,7 +39,7 @@ namespace NTwain.Triplets
public ReturnCode GetDefault(TWCapability capability)
{
Session.VerifyState(4, 7, DataGroups.Control, DataArgumentType.Capability, Message.GetDefault);
return Dsm.DsmEntry(Session.AppId, Session.SourceId, Message.GetDefault, capability);
return Dsm.DsmEntry(Session.AppId, Session.SourceId, DataArgumentType.Capability, Message.GetDefault, capability);
}
/// <summary>
@ -51,7 +51,7 @@ namespace NTwain.Triplets
public ReturnCode GetHelp(TWCapability capability)
{
Session.VerifyState(4, 4, DataGroups.Control, DataArgumentType.Capability, Message.GetHelp);
return Dsm.DsmEntry(Session.AppId, Session.SourceId, Message.GetHelp, capability);
return Dsm.DsmEntry(Session.AppId, Session.SourceId, DataArgumentType.Capability, Message.GetHelp, capability);
}
/// <summary>
@ -63,7 +63,7 @@ namespace NTwain.Triplets
public ReturnCode GetLabel(TWCapability capability)
{
Session.VerifyState(4, 4, DataGroups.Control, DataArgumentType.Capability, Message.GetLabel);
return Dsm.DsmEntry(Session.AppId, Session.SourceId, Message.GetLabel, capability);
return Dsm.DsmEntry(Session.AppId, Session.SourceId, DataArgumentType.Capability, Message.GetLabel, capability);
}
/// <summary>
@ -75,7 +75,7 @@ namespace NTwain.Triplets
public ReturnCode GetLabelEnum(TWCapability capability)
{
Session.VerifyState(4, 4, DataGroups.Control, DataArgumentType.Capability, Message.GetLabelEnum);
return Dsm.DsmEntry(Session.AppId, Session.SourceId, Message.GetLabelEnum, capability);
return Dsm.DsmEntry(Session.AppId, Session.SourceId, DataArgumentType.Capability, Message.GetLabelEnum, capability);
}
/// <summary>
@ -86,7 +86,7 @@ namespace NTwain.Triplets
public ReturnCode QuerySupport(TWCapability capability)
{
Session.VerifyState(4, 7, DataGroups.Control, DataArgumentType.Capability, Message.QuerySupport);
return Dsm.DsmEntry(Session.AppId, Session.SourceId, Message.QuerySupport, capability);
return Dsm.DsmEntry(Session.AppId, Session.SourceId, DataArgumentType.Capability, Message.QuerySupport, capability);
}
/// <summary>
@ -98,7 +98,7 @@ namespace NTwain.Triplets
public ReturnCode Reset(TWCapability capability)
{
Session.VerifyState(4, 4, DataGroups.Control, DataArgumentType.Capability, Message.Reset);
return Dsm.DsmEntry(Session.AppId, Session.SourceId, Message.Reset, capability);
return Dsm.DsmEntry(Session.AppId, Session.SourceId, DataArgumentType.Capability, Message.Reset, capability);
}
/// <summary>
@ -110,7 +110,7 @@ namespace NTwain.Triplets
public ReturnCode ResetAll(TWCapability capability)
{
Session.VerifyState(4, 4, DataGroups.Control, DataArgumentType.Capability, Message.ResetAll);
return Dsm.DsmEntry(Session.AppId, Session.SourceId, Message.ResetAll, capability);
return Dsm.DsmEntry(Session.AppId, Session.SourceId, DataArgumentType.Capability, Message.ResetAll, capability);
}
/// <summary>
@ -125,7 +125,7 @@ namespace NTwain.Triplets
public ReturnCode Set(TWCapability capability)
{
Session.VerifyState(4, 6, DataGroups.Control, DataArgumentType.Capability, Message.Set);
return Dsm.DsmEntry(Session.AppId, Session.SourceId, Message.Set, capability);
return Dsm.DsmEntry(Session.AppId, Session.SourceId, DataArgumentType.Capability, Message.Set, capability);
}
/// <summary>
@ -139,7 +139,7 @@ namespace NTwain.Triplets
public ReturnCode SetConstraint(TWCapability capability)
{
Session.VerifyState(4, 7, DataGroups.Control, DataArgumentType.Capability, Message.SetConstraint);
return Dsm.DsmEntry(Session.AppId, Session.SourceId, Message.SetConstraint, capability);
return Dsm.DsmEntry(Session.AppId, Session.SourceId, DataArgumentType.Capability, Message.SetConstraint, capability);
}
}
}

View File

@ -0,0 +1,157 @@
using NTwain.Data;
using NTwain.Internals;
namespace NTwain.Triplets
{
/// <summary>
/// This is to support custom DAT value for custom capability defined by some manufacturers.
/// </summary>
public sealed class CapabilityCustom : OpBase
{
internal CapabilityCustom(ITwainSessionInternal session) : base(session) { }
/// <summary>
/// Returns the Sources Current, Default and Available Values for a specified capability.
/// </summary>
/// <param name="customDAT">The custom DAT_* value from manufacturer.</param>
/// <param name="capability">The capability.</param>
/// <returns></returns>
public ReturnCode Get(ushort customDAT, TWCapability capability)
{
Session.VerifyState(4, 7, DataGroups.Control, (DataArgumentType)customDAT, Message.Get);
return Dsm.DsmEntry(Session.AppId, Session.SourceId, (DataArgumentType)customDAT, Message.Get, capability);
}
/// <summary>
/// Returns the Sources Current Value for the specified capability.
/// </summary>
/// <param name="customDAT">The custom DAT_* value from manufacturer.</param>
/// <param name="capability">The capability.</param>
/// <returns></returns>
public ReturnCode GetCurrent(ushort customDAT, TWCapability capability)
{
Session.VerifyState(4, 7, DataGroups.Control, (DataArgumentType)customDAT, Message.GetCurrent);
return Dsm.DsmEntry(Session.AppId, Session.SourceId, (DataArgumentType)customDAT, Message.GetCurrent, capability);
}
/// <summary>
/// Returns the Sources Default Value. This is the Sources preferred default value.
/// </summary>
/// <param name="customDAT">The custom DAT_* value from manufacturer.</param>
/// <param name="capability">The capability.</param>
/// <returns></returns>
public ReturnCode GetDefault(ushort customDAT, TWCapability capability)
{
Session.VerifyState(4, 7, DataGroups.Control, (DataArgumentType)customDAT, Message.GetDefault);
return Dsm.DsmEntry(Session.AppId, Session.SourceId, (DataArgumentType)customDAT, Message.GetDefault, capability);
}
/// <summary>
/// Returns help text suitable for use in a GUI; for instance: "Specify the amount of detail in an
/// image. Higher values result in more detail." for ICapXRESOLUTION.
/// </summary>
/// <param name="customDAT">The custom DAT_* value from manufacturer.</param>
/// <param name="capability">The capability.</param>
/// <returns></returns>
public ReturnCode GetHelp(ushort customDAT, TWCapability capability)
{
Session.VerifyState(4, 4, DataGroups.Control, (DataArgumentType)customDAT, Message.GetHelp);
return Dsm.DsmEntry(Session.AppId, Session.SourceId, (DataArgumentType)customDAT, Message.GetHelp, capability);
}
/// <summary>
/// Returns a label suitable for use in a GUI, for instance "Resolution:"
/// for ICapXRESOLUTION.
/// </summary>
/// <param name="customDAT">The custom DAT_* value from manufacturer.</param>
/// <param name="capability">The capability.</param>
/// <returns></returns>
public ReturnCode GetLabel(ushort customDAT, TWCapability capability)
{
Session.VerifyState(4, 4, DataGroups.Control, (DataArgumentType)customDAT, Message.GetLabel);
return Dsm.DsmEntry(Session.AppId, Session.SourceId, (DataArgumentType)customDAT, Message.GetLabel, capability);
}
/// <summary>
/// Return all of the labels for a capability of type <see cref="TWArray"/> or <see cref="TWEnumeration"/>, for example
/// "US Letter" for ICapSupportedSizes TWSS_USLETTER.
/// </summary>
/// <param name="customDAT">The custom DAT_* value from manufacturer.</param>
/// <param name="capability">The capability.</param>
/// <returns></returns>
public ReturnCode GetLabelEnum(ushort customDAT, TWCapability capability)
{
Session.VerifyState(4, 4, DataGroups.Control, (DataArgumentType)customDAT, Message.GetLabelEnum);
return Dsm.DsmEntry(Session.AppId, Session.SourceId, (DataArgumentType)customDAT, Message.GetLabelEnum, capability);
}
/// <summary>
/// Returns the Sources support status of this capability.
/// </summary>
/// <param name="customDAT">The custom DAT_* value from manufacturer.</param>
/// <param name="capability">The capability.</param>
/// <returns></returns>
public ReturnCode QuerySupport(ushort customDAT, TWCapability capability)
{
Session.VerifyState(4, 7, DataGroups.Control, (DataArgumentType)customDAT, Message.QuerySupport);
return Dsm.DsmEntry(Session.AppId, Session.SourceId, (DataArgumentType)customDAT, Message.QuerySupport, capability);
}
/// <summary>
/// Change the Current Value of the specified capability back to its power-on value and return the
/// new Current Value.
/// </summary>
/// <param name="customDAT">The custom DAT_* value from manufacturer.</param>
/// <param name="capability">The capability.</param>
/// <returns></returns>
public ReturnCode Reset(ushort customDAT, TWCapability capability)
{
Session.VerifyState(4, 4, DataGroups.Control, (DataArgumentType)customDAT, Message.Reset);
return Dsm.DsmEntry(Session.AppId, Session.SourceId, (DataArgumentType)customDAT, Message.Reset, capability);
}
/// <summary>
/// This command resets all of the current values and constraints to their defaults for all of the
/// negotiable capabilities supported by the driver.
/// </summary>
/// <param name="customDAT">The custom DAT_* value from manufacturer.</param>
/// <param name="capability">The capability.</param>
/// <returns></returns>
public ReturnCode ResetAll(ushort customDAT, TWCapability capability)
{
Session.VerifyState(4, 4, DataGroups.Control, (DataArgumentType)customDAT, Message.ResetAll);
return Dsm.DsmEntry(Session.AppId, Session.SourceId, (DataArgumentType)customDAT, Message.ResetAll, capability);
}
/// <summary>
/// Changes the Current Value(s) and Available Values of the specified capability to those specified
/// by the application. As of TWAIN 2.2 this only modifies the Current Value of the specified capability, constraints cannot be
/// changed with this.
/// Current Values are set when the container is a <see cref="TWOneValue"/> or <see cref="TWArray"/>. Available and
/// Current Values are set when the container is a <see cref="TWEnumeration"/> or <see cref="TWRange"/>.
/// </summary>
/// <param name="customDAT">The custom DAT_* value from manufacturer.</param>
/// <param name="capability">The capability.</param>
/// <returns></returns>
public ReturnCode Set(ushort customDAT, TWCapability capability)
{
Session.VerifyState(4, 6, DataGroups.Control, (DataArgumentType)customDAT, Message.Set);
return Dsm.DsmEntry(Session.AppId, Session.SourceId, (DataArgumentType)customDAT, Message.Set, capability);
}
/// <summary>
/// Changes the Current Value(s) and Available Value(s) of the specified capability to those specified
/// by the application.
/// </summary>
/// Current Values are set when the container is a <see cref="TWOneValue"/> or <see cref="TWArray"/>. Available and
/// Current Values are set when the container is a <see cref="TWEnumeration"/> or <see cref="TWRange"/>.
/// <param name="customDAT">The custom DAT_* value from manufacturer.</param>
/// <param name="capability">The capability.</param>
/// <returns></returns>
public ReturnCode SetConstraint(ushort customDAT, TWCapability capability)
{
Session.VerifyState(4, 7, DataGroups.Control, (DataArgumentType)customDAT, Message.SetConstraint);
return Dsm.DsmEntry(Session.AppId, Session.SourceId, (DataArgumentType)customDAT, Message.SetConstraint, capability);
}
}
}

View File

@ -42,7 +42,16 @@ namespace NTwain.Triplets
if (_capability == null) { _capability = new Capability(_session); }
return _capability;
}
}
}
CapabilityCustom _capabilityCust;
public CapabilityCustom CapabilityCustom
{
get
{
if (_capabilityCust == null) { _capabilityCust = new CapabilityCustom(_session); }
return _capabilityCust;
}
}
CustomDSData _customDSData;
public CustomDSData CustomDSData
{

View File

@ -74,17 +74,18 @@ namespace NTwain.Triplets
public static ReturnCode DsmEntry(
TWIdentity origin,
TWIdentity destination,
DataArgumentType dat,
Message msg,
TWCapability data)
{
if (Platform.IsWin)
{
if (Platform.UseNewDSM) { return NativeMethods.DsmWinNew(origin, destination, DataGroups.Control, DataArgumentType.Capability, msg, data); }
else { return NativeMethods.DsmWinOld(origin, destination, DataGroups.Control, DataArgumentType.Capability, msg, data); }
if (Platform.UseNewDSM) { return NativeMethods.DsmWinNew(origin, destination, DataGroups.Control, dat, msg, data); }
else { return NativeMethods.DsmWinOld(origin, destination, DataGroups.Control, dat, msg, data); }
}
else if (Platform.IsLinux)
{
return NativeMethods.DsmLinux(origin, destination, DataGroups.Control, DataArgumentType.Capability, msg, data);
return NativeMethods.DsmLinux(origin, destination, DataGroups.Control, dat, msg, data);
}
throw new PlatformNotSupportedException();
}