Redone the cap value read code to support all twain types (#3).

This commit is contained in:
soukoku
2014-04-09 21:30:07 -04:00
parent ec19eb0151
commit 14bb274f0c
11 changed files with 663 additions and 573 deletions

347
NTwain/Data/CapReadOut.cs Normal file
View File

@@ -0,0 +1,347 @@
using NTwain.Values;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
namespace NTwain.Data
{
/// <summary>
/// The one-stop class for reading TWAIN cap values.
/// This contains all the properties for the 4 container types.
/// </summary>
public class CapReadOut
{
/// <summary>
/// Reads the value from a <see cref="TWCapability"/> that was returned
/// from a TWAIN source.
/// </summary>
/// <param name="capability">The capability.</param>
/// <returns></returns>
/// <exception cref="System.ArgumentNullException">capability</exception>
/// <exception cref="System.ArgumentException">
/// Capability contains no data.;capability
/// or
/// capability
/// </exception>
public static CapReadOut ReadValue(TWCapability capability)
{
if (capability == null) { throw new ArgumentNullException("capability"); }
if (capability.Container == IntPtr.Zero) { throw new ArgumentException("Capability contains no data.", "capability"); }
IntPtr baseAddr = IntPtr.Zero;
try
{
baseAddr = MemoryManager.Instance.Lock(capability.Container);
switch (capability.ContainerType)
{
case ContainerType.Array:
return new CapReadOut
{
ContainerType = capability.ContainerType,
}.ReadArrayValue(baseAddr);
case ContainerType.Enum:
return new CapReadOut
{
ContainerType = capability.ContainerType,
}.ReadEnumValue(baseAddr);
case ContainerType.OneValue:
return new CapReadOut
{
ContainerType = capability.ContainerType,
}.ReadOneValue(baseAddr);
case ContainerType.Range:
return new CapReadOut
{
ContainerType = capability.ContainerType,
}.ReadRangeValue(baseAddr);
default:
throw new ArgumentException(string.Format("Capability has invalid container type {0}.", capability.ContainerType), "capability");
}
}
finally
{
if (baseAddr != IntPtr.Zero)
{
MemoryManager.Instance.Unlock(baseAddr);
}
}
}
#region common prop
/// <summary>
/// Gets the underlying container type.
/// </summary>
/// <value>
/// The container.
/// </value>
public ContainerType ContainerType { get; private set; }
/// <summary>
/// Gets the type of the TWAIN value.
/// </summary>
/// <value>
/// The type of the value.
/// </value>
public ItemType ItemType { get; private set; }
/// <summary>
/// Gets the one value if container is <see cref="ContainerType.Array"/>.
/// </summary>
/// <value>
/// The one value.
/// </value>
public object OneValue { get; private set; }
/// <summary>
/// Gets the collection values if container is <see cref="ContainerType.Enum"/> or <see cref="ContainerType.Range"/> .
/// </summary>
/// <value>
/// The collection values.
/// </value>
public IList<object> CollectionValues { get; private set; }
#endregion
#region enum prop
/// <summary>
/// Gets the current value index if container is <see cref="ContainerType.Enum"/>.
/// </summary>
public int EnumCurrentIndex { get; private set; }
/// <summary>
/// Gets the default value index if container is <see cref="ContainerType.Enum" />.
/// </summary>
public int EnumDefaultIndex { get; private set; }
#endregion
#region range prop
/// <summary>
/// Gets the current value if container is <see cref="ContainerType.Range" />.
/// </summary>
/// <value>
/// The range current value.
/// </value>
public object RangeCurrentValue { get; private set; }
/// <summary>
/// Gets the default value if container is <see cref="ContainerType.Range" />.
/// </summary>
/// <value>
/// The range default value.
/// </value>
public object RangeDefaultValue { get; private set; }
/// <summary>
/// The least positive/most negative value of the range.
/// </summary>
/// <value>
/// The range minimum value.
/// </value>
public uint RangeMinValue { get; private set; }
/// <summary>
/// The most positive/least negative value of the range.
/// </summary>
/// <value>
/// The range maximum value.
/// </value>
public uint RangeMaxValue { get; private set; }
/// <summary>
/// The delta between two adjacent values of the range.
/// e.g. Item2 - Item1 = StepSize;
/// </summary>
/// <value>
/// The size of the range step.
/// </value>
public uint RangeStepSize { get; private set; }
#endregion
#region reader methods
CapReadOut ReadOneValue(IntPtr baseAddr)
{
int offset = 0;
ItemType = (ItemType)(ushort)Marshal.ReadInt16(baseAddr, offset);
offset += 2;
OneValue = ReadValue(baseAddr, ref offset, ItemType);
return this;
}
CapReadOut ReadArrayValue(IntPtr baseAddr)
{
int offset = 0;
ItemType = (ItemType)(ushort)Marshal.ReadInt16(baseAddr, offset);
offset += 2;
var count = Marshal.ReadInt32(baseAddr, offset);
offset += 4;
if (count > 0)
{
CollectionValues = new object[count];
for (int i = 0; i < count; i++)
{
CollectionValues[i] = ReadValue(baseAddr, ref offset, ItemType);
}
}
return this;
}
CapReadOut ReadEnumValue(IntPtr baseAddr)
{
int offset = 0;
ItemType = (ItemType)(ushort)Marshal.ReadInt16(baseAddr, offset);
offset += 2;
int count = Marshal.ReadInt32(baseAddr, offset);
offset += 4;
EnumCurrentIndex = Marshal.ReadInt32(baseAddr, offset);
offset += 4;
EnumDefaultIndex = Marshal.ReadInt32(baseAddr, offset);
offset += 4;
if (count > 0)
{
CollectionValues = new object[count];
for (int i = 0; i < count; i++)
{
CollectionValues[i] = ReadValue(baseAddr, ref offset, ItemType);
}
}
return this;
}
CapReadOut ReadRangeValue(IntPtr baseAddr)
{
int offset = 0;
ItemType = (ItemType)(ushort)Marshal.ReadInt16(baseAddr, offset);
offset += 2;
RangeMinValue = (uint)Marshal.ReadInt32(baseAddr, offset);
offset += 4;
RangeMaxValue = (uint)Marshal.ReadInt32(baseAddr, offset);
offset += 4;
RangeStepSize = (uint)Marshal.ReadInt32(baseAddr, offset);
offset += 4;
RangeDefaultValue = (uint)Marshal.ReadInt32(baseAddr, offset);
offset += 4;
RangeCurrentValue = (uint)Marshal.ReadInt32(baseAddr, offset);
return this;
}
static object ReadValue(IntPtr baseAddr, ref int offset, ItemType type)
{
object val = null;
switch (type)
{
case ItemType.Int8:
val = (sbyte)Marshal.ReadByte(baseAddr, offset);
break;
case ItemType.UInt8:
val = Marshal.ReadByte(baseAddr, offset);
break;
case ItemType.Bool:
case ItemType.UInt16:
val = (ushort)Marshal.ReadInt16(baseAddr, offset);
break;
case ItemType.Int16:
val = Marshal.ReadInt16(baseAddr, offset);
break;
case ItemType.UInt32:
val = (uint)Marshal.ReadInt32(baseAddr, offset);
break;
case ItemType.Int32:
val = Marshal.ReadInt32(baseAddr, offset);
break;
case ItemType.Fix32:
TWFix32 f32 = new TWFix32();
f32.Whole = Marshal.ReadInt16(baseAddr, offset);
f32.Fraction = (ushort)Marshal.ReadInt16(baseAddr, offset + 2);
val = f32;
break;
case ItemType.Frame:
TWFrame frame = new TWFrame();
frame.Left = (TWFix32)ReadValue(baseAddr, ref offset, ItemType.Fix32);
frame.Top = (TWFix32)ReadValue(baseAddr, ref offset, ItemType.Fix32);
frame.Right = (TWFix32)ReadValue(baseAddr, ref offset, ItemType.Fix32);
frame.Bottom = (TWFix32)ReadValue(baseAddr, ref offset, ItemType.Fix32);
return frame; // no need to update offset again after reading fix32
case ItemType.String128:
val = ReadString(baseAddr, offset, 128);
break;
case ItemType.String255:
val = ReadString(baseAddr, offset, 255);
break;
case ItemType.String32:
val = ReadString(baseAddr, offset, 32);
break;
case ItemType.String64:
val = ReadString(baseAddr, offset, 64);
break;
case ItemType.Handle:
val = new IntPtr(baseAddr.ToInt64() + offset);
break;
}
offset += GetItemTypeSize(type);
return val;
}
/// <summary>
/// Read string value.
/// </summary>
/// <param name="baseAddr"></param>
/// <param name="offset"></param>
/// <param name="maxLength"></param>
/// <returns></returns>
static string ReadString(IntPtr baseAddr, int offset, int maxLength)
{
// todo: add support for other platform
var sb = new StringBuilder(maxLength);
byte bt;
while (sb.Length < maxLength &&
(bt = Marshal.ReadByte(baseAddr, offset++)) != 0)
{
sb.Append((char)bt);
}
return sb.ToString();
}
/// <summary>
/// Gets the byte size of the item type.
/// </summary>
/// <param name="type"></param>
/// <returns></returns>
internal static int GetItemTypeSize(ItemType type)
{
switch (type)
{
case ItemType.Int8:
case ItemType.UInt8:
return 1;
case ItemType.UInt16:
case ItemType.Int16:
case ItemType.Bool:
return 2;
case ItemType.Int32:
case ItemType.UInt32:
case ItemType.Fix32:
return 4;
case ItemType.Frame:
return 16;
case ItemType.String32:
return TwainConst.String32;
case ItemType.String64:
return TwainConst.String64;
case ItemType.String128:
return TwainConst.String128;
case ItemType.String255:
return TwainConst.String255;
case ItemType.Handle:
return IntPtr.Size;
}
return 0;
}
#endregion
}
}

View File

@@ -660,37 +660,12 @@ namespace NTwain.Data
/// </summary> /// </summary>
public ContainerType ContainerType { get { return (Values.ContainerType)_conType; } set { _conType = (ushort)value; } } public ContainerType ContainerType { get { return (Values.ContainerType)_conType; } set { _conType = (ushort)value; } }
internal IntPtr Container { get { return _hContainer; } }
#endregion #endregion
#region value functions #region value functions
/// <summary>
/// Gets the <see cref="TWOneValue"/> stored in this capability.
/// </summary>
/// <returns></returns>
/// <exception cref="System.ArgumentException"></exception>
public TWOneValue GetOneValue()
{
if (ContainerType != Values.ContainerType.OneValue) { throw new ArgumentException(Resources.BadContainerType, "value"); }
var value = new TWOneValue();
if (_hContainer != IntPtr.Zero)
{
IntPtr baseAddr = MemoryManager.Instance.Lock(_hContainer);
try
{
int offset = 0;
value.ItemType = (ItemType)(ushort)Marshal.ReadInt16(baseAddr, offset);
offset += 2;
value.Item = (uint)ReadValue(baseAddr, ref offset, ItemType.UInt32);
}
catch { }
MemoryManager.Instance.Unlock(_hContainer);
}
return value;
}
[EnvironmentPermissionAttribute(SecurityAction.LinkDemand)] [EnvironmentPermissionAttribute(SecurityAction.LinkDemand)]
void SetOneValue(TWOneValue value) void SetOneValue(TWOneValue value)
{ {
@@ -698,7 +673,7 @@ namespace NTwain.Data
if (ContainerType != Values.ContainerType.OneValue) { throw new ArgumentException(Resources.BadContainerType, "value"); } if (ContainerType != Values.ContainerType.OneValue) { throw new ArgumentException(Resources.BadContainerType, "value"); }
// since one value can only house UInt32 we will not allow type size > 4 // since one value can only house UInt32 we will not allow type size > 4
if (GetItemTypeSize(value.ItemType) > 4) { throw new ArgumentException("Invalid one value type"); } if (CapReadOut.GetItemTypeSize(value.ItemType) > 4) { throw new ArgumentException("Invalid one value type"); }
_hContainer = MemoryManager.Instance.Allocate((uint)Marshal.SizeOf(value)); _hContainer = MemoryManager.Instance.Allocate((uint)Marshal.SizeOf(value));
if (_hContainer != IntPtr.Zero) if (_hContainer != IntPtr.Zero)
@@ -707,71 +682,6 @@ namespace NTwain.Data
} }
} }
/// <summary>
/// Gets the <see cref="TWArray"/> stored in this capability.
/// </summary>
/// <returns></returns>
/// <exception cref="System.ArgumentException"></exception>
public TWArray GetArrayValue()
{
if (ContainerType != Values.ContainerType.Array) { throw new ArgumentException(Resources.BadContainerType, "value"); }
var value = new TWArray();
if (_hContainer != IntPtr.Zero)
{
IntPtr baseAddr = MemoryManager.Instance.Lock(_hContainer);
int offset = 0;
value.ItemType = (ItemType)(ushort)Marshal.ReadInt16(baseAddr, offset);
offset += 2;
var count = Marshal.ReadInt32(baseAddr, offset);
offset += 4;
if (count > 0)
{
value.ItemList = new object[count];
for (int i = 0; i < count; i++)
{
value.ItemList[i] = ReadValue(baseAddr, ref offset, value.ItemType);
}
}
MemoryManager.Instance.Unlock(_hContainer);
}
return value;
}
/// <summary>
/// Gets the <see cref="TWEnumeration"/> stored in this capability.
/// </summary>
/// <returns></returns>
/// <exception cref="System.ArgumentException"></exception>
public TWEnumeration GetEnumValue()
{
if (ContainerType != Values.ContainerType.Enum) { throw new ArgumentException(Resources.BadContainerType, "value"); }
var value = new TWEnumeration();
if (_hContainer != IntPtr.Zero)
{
IntPtr baseAddr = MemoryManager.Instance.Lock(_hContainer);
int offset = 0;
value.ItemType = (ItemType)(ushort)Marshal.ReadInt16(baseAddr, offset);
offset += 2;
int count = Marshal.ReadInt32(baseAddr, offset);
offset += 4;
value.CurrentIndex = Marshal.ReadInt32(baseAddr, offset);
offset += 4;
value.DefaultIndex = Marshal.ReadInt32(baseAddr, offset);
offset += 4;
if (count > 0)
{
value.ItemList = new object[count];
for (int i = 0; i < count; i++)
{
value.ItemList[i] = ReadValue(baseAddr, ref offset, value.ItemType);
}
}
MemoryManager.Instance.Unlock(_hContainer);
}
return value;
}
[EnvironmentPermissionAttribute(SecurityAction.LinkDemand)] [EnvironmentPermissionAttribute(SecurityAction.LinkDemand)]
void SetEnumValue(TWEnumeration value) void SetEnumValue(TWEnumeration value)
{ {
@@ -779,7 +689,7 @@ namespace NTwain.Data
if (ContainerType != Values.ContainerType.Enum) { throw new ArgumentException(Resources.BadContainerType, "value"); } if (ContainerType != Values.ContainerType.Enum) { throw new ArgumentException(Resources.BadContainerType, "value"); }
Int32 valueSize = value.ItemOffset + value.ItemList.Length * GetItemTypeSize(value.ItemType); Int32 valueSize = value.ItemOffset + value.ItemList.Length * CapReadOut.GetItemTypeSize(value.ItemType);
int offset = 0; int offset = 0;
_hContainer = MemoryManager.Instance.Allocate((uint)valueSize); _hContainer = MemoryManager.Instance.Allocate((uint)valueSize);
@@ -794,40 +704,10 @@ namespace NTwain.Data
{ {
WriteValue(baseAddr, ref offset, value.ItemType, item); WriteValue(baseAddr, ref offset, value.ItemType, item);
} }
MemoryManager.Instance.Unlock(_hContainer); MemoryManager.Instance.Unlock(baseAddr);
} }
/// <summary>
/// Gets the <see cref="TWRange"/> stored in this capability.
/// </summary>
/// <returns></returns>
/// <exception cref="System.ArgumentException"></exception>
public TWRange GetRangeValue()
{
if (ContainerType != Values.ContainerType.Range) { throw new ArgumentException(Resources.BadContainerType, "value"); }
var value = new TWRange();
if (_hContainer != IntPtr.Zero)
{
IntPtr baseAddr = MemoryManager.Instance.Lock(_hContainer);
int offset = 0;
value.ItemType = (ItemType)(ushort)Marshal.ReadInt16(baseAddr, offset);
offset += 2;
value.MinValue = (uint)Marshal.ReadInt32(baseAddr, offset);
offset += 4;
value.MaxValue = (uint)Marshal.ReadInt32(baseAddr, offset);
offset += 4;
value.StepSize = (uint)Marshal.ReadInt32(baseAddr, offset);
offset += 4;
value.DefaultValue = (uint)Marshal.ReadInt32(baseAddr, offset);
offset += 4;
value.CurrentValue = (uint)Marshal.ReadInt32(baseAddr, offset);
MemoryManager.Instance.Unlock(_hContainer);
}
return value;
}
[EnvironmentPermissionAttribute(SecurityAction.LinkDemand)] [EnvironmentPermissionAttribute(SecurityAction.LinkDemand)]
void SetRangeValue(TWRange value) void SetRangeValue(TWRange value)
{ {
@@ -835,7 +715,7 @@ namespace NTwain.Data
if (ContainerType != Values.ContainerType.Range) { throw new ArgumentException(Resources.BadContainerType, "value"); } if (ContainerType != Values.ContainerType.Range) { throw new ArgumentException(Resources.BadContainerType, "value"); }
// since range value can only house UInt32 we will not allow type size > 4 // since range value can only house UInt32 we will not allow type size > 4
if (GetItemTypeSize(value.ItemType) > 4) { throw new ArgumentException("Invalid range value type"); } if (CapReadOut.GetItemTypeSize(value.ItemType) > 4) { throw new ArgumentException("Invalid range value type"); }
_hContainer = MemoryManager.Instance.Allocate((uint)Marshal.SizeOf(value)); _hContainer = MemoryManager.Instance.Allocate((uint)Marshal.SizeOf(value));
if (_hContainer != IntPtr.Zero) if (_hContainer != IntPtr.Zero)
@@ -845,46 +725,8 @@ namespace NTwain.Data
} }
#endregion #endregion
#region readwrites #region writes
/// <summary>
/// Gets the byte size of the item type.
/// </summary>
/// <param name="type"></param>
/// <returns></returns>
private int GetItemTypeSize(ItemType type)
{
switch (type)
{
case ItemType.Int8:
case ItemType.UInt8:
return 1;
case ItemType.UInt16:
case ItemType.Int16:
case ItemType.Bool:
return 2;
case ItemType.Int32:
case ItemType.UInt32:
case ItemType.Fix32:
return 4;
case ItemType.Frame:
return 16;
case ItemType.String32:
return TwainConst.String32;
case ItemType.String64:
return TwainConst.String64;
case ItemType.String128:
return TwainConst.String128;
case ItemType.String255:
return TwainConst.String255;
// deprecated
//case ItemType.String1024:
// return TwainConst.String1024;
//case ItemType.Unicode512:
// return TwainConst.String1024;
}
return 0;
}
/// <summary> /// <summary>
/// Entry call for writing values to a pointer. /// Entry call for writing values to a pointer.
/// </summary> /// </summary>
@@ -948,7 +790,7 @@ namespace NTwain.Data
// WriteUString(baseAddr, offset, value as string, 512); // WriteUString(baseAddr, offset, value as string, 512);
// break; // break;
} }
offset += GetItemTypeSize(type); offset += CapReadOut.GetItemTypeSize(type);
} }
/// <summary> /// <summary>
/// Writes string value. /// Writes string value.
@@ -1020,112 +862,7 @@ namespace NTwain.Data
// Marshal.WriteByte(baseAddr, offset, 0); // Marshal.WriteByte(baseAddr, offset, 0);
// } // }
//} //}
/// <summary>
/// Entry call for reading values.
/// </summary>
/// <param name="baseAddr"></param>
/// <param name="offset"></param>
/// <param name="type"></param>
/// <returns></returns>
private object ReadValue(IntPtr baseAddr, ref int offset, ItemType type)
{
object val = null;
switch (type)
{
case ItemType.Int8:
case ItemType.UInt8:
val = Marshal.ReadByte(baseAddr, offset);
break;
case ItemType.Bool:
case ItemType.UInt16:
val = (ushort)Marshal.ReadInt16(baseAddr, offset);
break;
case ItemType.Int16:
val = Marshal.ReadInt16(baseAddr, offset);
break;
case ItemType.UInt32:
val = (uint)Marshal.ReadInt32(baseAddr, offset);
break;
case ItemType.Int32:
val = Marshal.ReadInt32(baseAddr, offset);
break;
case ItemType.Fix32:
TWFix32 f32 = new TWFix32();
f32.Whole = Marshal.ReadInt16(baseAddr, offset);
f32.Fraction = (ushort)Marshal.ReadInt16(baseAddr, offset + 2);
val = f32;
break;
case ItemType.Frame:
TWFrame frame = new TWFrame();
frame.Left = (TWFix32)ReadValue(baseAddr, ref offset, ItemType.Fix32);
frame.Top = (TWFix32)ReadValue(baseAddr, ref offset, ItemType.Fix32);
frame.Right = (TWFix32)ReadValue(baseAddr, ref offset, ItemType.Fix32);
frame.Bottom = (TWFix32)ReadValue(baseAddr, ref offset, ItemType.Fix32);
return frame; // no need to update offset for this
//case ItemType.String1024:
// val = ReadString(baseAddr, offset, 1024);
// break;
case ItemType.String128:
val = ReadString(baseAddr, offset, 128);
break;
case ItemType.String255:
val = ReadString(baseAddr, offset, 255);
break;
case ItemType.String32:
val = ReadString(baseAddr, offset, 32);
break;
case ItemType.String64:
val = ReadString(baseAddr, offset, 64);
break;
//case ItemType.Unicode512:
// val = ReadUString(baseAddr, offset, 512);
// break;
}
offset += GetItemTypeSize(type);
return val;
}
/// <summary>
/// Read string value.
/// </summary>
/// <param name="baseAddr"></param>
/// <param name="offset"></param>
/// <param name="maxLength"></param>
/// <returns></returns>
private object ReadString(IntPtr baseAddr, int offset, int maxLength)
{
StringBuilder sb = new StringBuilder(maxLength);
for (int i = 0; i < maxLength; i++)
{
byte b;
while ((b = Marshal.ReadByte(baseAddr, offset)) != 0)
{
sb.Append((char)b);
offset++;
}
}
return sb.ToString();
}
/// <summary>
/// Read unicode string value.
/// </summary>
/// <param name="baseAddr"></param>
/// <param name="offset"></param>
/// <param name="maxLength"></param>
/// <returns></returns>
private object ReadUString(IntPtr baseAddr, int offset, int maxLength)
{
StringBuilder sb = new StringBuilder(maxLength);
for (int i = 0; i < maxLength; i++)
{
char c;
while ((c = (char)Marshal.ReadInt16(baseAddr, offset)) != 0)
{
sb.Append(c);
offset += 2;
}
}
return sb.ToString();
}
#endregion #endregion
#region IDisposable Members #region IDisposable Members

View File

@@ -52,6 +52,7 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Include="AsyncPump.cs" /> <Compile Include="AsyncPump.cs" />
<Compile Include="Data\CapReadOut.cs" />
<Compile Include="Data\TypesExtended.cs" /> <Compile Include="Data\TypesExtended.cs" />
<Compile Include="DeviceEventArgs.cs" /> <Compile Include="DeviceEventArgs.cs" />
<Compile Include="Extensions.cs" /> <Compile Include="Extensions.cs" />
@@ -124,6 +125,7 @@
<Compile Include="Values\DataValues.cs" /> <Compile Include="Values\DataValues.cs" />
<Compile Include="Values\SourceEnableMode.cs" /> <Compile Include="Values\SourceEnableMode.cs" />
<Compile Include="Values\TwainConst.cs" /> <Compile Include="Values\TwainConst.cs" />
<Compile Include="Values\ValueConverter.cs" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<None Include="NTwain.nuspec" /> <None Include="NTwain.nuspec" />

View File

@@ -12,8 +12,8 @@ namespace NTwain
class _NTwainVersionInfo class _NTwainVersionInfo
{ {
// keep this same in majors releases // keep this same in majors releases
public const string Release = "0.9.0.0"; public const string Release = "0.10.0.0";
// change this for each nuget release // change this for each nuget release
public const string Build = "0.9.2"; public const string Build = "0.10.0";
} }
} }

View File

@@ -718,7 +718,7 @@ namespace NTwain
if ((xferGroup & DataGroups.Image) == DataGroups.Image) if ((xferGroup & DataGroups.Image) == DataGroups.Image)
{ {
var mech = this.GetCurrentCap<XferMech>(CapabilityId.ICapXferMech); var mech = this.GetCurrentCap(CapabilityId.ICapXferMech).ConvertToEnum<XferMech>();
switch (mech) switch (mech)
{ {
case XferMech.Native: case XferMech.Native:
@@ -737,7 +737,7 @@ namespace NTwain
} }
if ((xferGroup & DataGroups.Audio) == DataGroups.Audio) if ((xferGroup & DataGroups.Audio) == DataGroups.Audio)
{ {
var mech = this.GetCurrentCap<XferMech>(CapabilityId.ACapXferMech); var mech = this.GetCurrentCap(CapabilityId.ACapXferMech).ConvertToEnum<XferMech>();
switch (mech) switch (mech)
{ {
case XferMech.Native: case XferMech.Native:

View File

@@ -8,7 +8,7 @@ using System.Text;
namespace NTwain namespace NTwain
{ {
/// <summary> /// <summary>
/// Defines common methods on <see cref="TwainSessionOld"/> using the raw /// Defines common methods on <see cref="TwainSession"/> using the raw
/// TWAIN triplet api. /// TWAIN triplet api.
/// </summary> /// </summary>
public static class TwainSessionExtensions public static class TwainSessionExtensions
@@ -87,142 +87,79 @@ namespace NTwain
#region common caps #region common caps
/// <summary> /// <summary>
/// Gets the current value for a general capability. This only works for types that are under 32bit. /// Gets the current value for a capability.
/// </summary> /// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="session">The session.</param> /// <param name="session">The session.</param>
/// <param name="capId">The cap id.</param> /// <param name="capId">The cap id.</param>
/// <returns></returns> /// <returns></returns>
public static T GetCurrentCap<T>(this TwainSession session, CapabilityId capId) where T : struct,IConvertible public static object GetCurrentCap(this TwainSession session, CapabilityId capId)
{ {
using (TWCapability cap = new TWCapability(capId)) using (TWCapability cap = new TWCapability(capId))
{ {
var rc = session.DGControl.Capability.GetCurrent(cap); var rc = session.DGControl.Capability.GetCurrent(cap);
if (rc == ReturnCode.Success) if (rc == ReturnCode.Success)
{ {
switch (cap.ContainerType) var read = CapReadOut.ReadValue(cap);
switch (read.ContainerType)
{ {
case ContainerType.Enum: case ContainerType.Enum:
var enu = cap.GetEnumValue(); if (read.CollectionValues != null)
if (enu.ItemType < ItemType.Frame)
{ {
// does this work? return read.CollectionValues[read.EnumCurrentIndex];
return ConvertValueToType<T>(enu.ItemList[enu.CurrentIndex].ToString(), true);
} }
break; break;
case ContainerType.OneValue: case ContainerType.OneValue:
var one = cap.GetOneValue(); return read.OneValue;
if (one.ItemType < ItemType.Frame)
{
return ConvertValueToType<T>(one.Item, true);
}
break;
case ContainerType.Range: case ContainerType.Range:
var range = cap.GetRangeValue(); return read.RangeCurrentValue;
if (range.ItemType < ItemType.Frame) case ContainerType.Array:
// no source should ever return an array but anyway
if (read.CollectionValues != null)
{ {
return ConvertValueToType<T>(range.CurrentValue, true); return read.CollectionValues.FirstOrDefault();
} }
break; break;
} }
} }
} }
return default(T); return null;
}
static ushort GetLowerWord(uint value)
{
return (ushort)(value & 0xffff);
}
static uint GetUpperWord(uint value)
{
return (ushort)(value >> 16);
}
static T ConvertValueToType<T>(object value, bool tryUpperWord) where T : struct,IConvertible
{
var returnType = typeof(T);
if (returnType.IsEnum)
{
if (tryUpperWord)
{
// small routine to work with bad sources that put
// 16bit value in the upper word instead of lower word as per the twain spec.
var rawType = Enum.GetUnderlyingType(returnType);
if (typeof(ushort).IsAssignableFrom(rawType))
{
var intVal = Convert.ToUInt32(value);
var enumVal = GetLowerWord(intVal);
if (!Enum.IsDefined(returnType, enumVal))
{
return (T)Enum.ToObject(returnType, GetUpperWord(intVal));
}
}
}
// this may work better?
return (T)Enum.ToObject(returnType, value);
//// cast to underlying type first then to the enum
//return (T)Convert.ChangeType(value, rawType);
}
return (T)Convert.ChangeType(value, returnType);
} }
/// <summary> /// <summary>
/// A generic method that returns the data in a <see cref="TWCapability" />. /// A general method that returns the data in a <see cref="TWCapability" />.
/// </summary> /// </summary>
/// <typeparam name="TCapVal">The expected capability value type.</typeparam>
/// <param name="capability">The capability returned from the source.</param> /// <param name="capability">The capability returned from the source.</param>
/// <param name="toPopulate">The list to populate if necessary.</param> /// <param name="toPopulate">The list to populate if necessary.</param>
/// <returns></returns> /// <returns></returns>
public static IList<TCapVal> ReadMultiCapValues<TCapVal>(this TWCapability capability, IList<TCapVal> toPopulate) where TCapVal : struct,IConvertible public static IList<object> ReadMultiCapValues(this TWCapability capability, IList<object> toPopulate)
{ {
return ReadMultiCapValues<TCapVal>(capability, toPopulate, true); if (toPopulate == null) { toPopulate = new List<object>(); }
}
static IList<TCapVal> ReadMultiCapValues<TCapVal>(this TWCapability capability, IList<TCapVal> toPopulate, bool tryUpperWord) where TCapVal : struct,IConvertible
{
if (toPopulate == null) { toPopulate = new List<TCapVal>(); }
switch (capability.ContainerType) var read = CapReadOut.ReadValue(capability);
switch (read.ContainerType)
{ {
case ContainerType.OneValue: case ContainerType.OneValue:
var value = capability.GetOneValue(); if (read.OneValue != null)
if (value != null)
{ {
var val = ConvertValueToType<TCapVal>(value.Item, tryUpperWord);// (T)Convert.ToUInt16(value.Item); toPopulate.Add(read.OneValue);
toPopulate.Add(val);
} }
break; break;
case ContainerType.Array: case ContainerType.Array:
var arr = capability.GetArrayValue();
if (arr != null && arr.ItemList != null)
{
for (int i = 0; i < arr.ItemList.Length; i++)
{
var val = ConvertValueToType<TCapVal>(arr.ItemList[i], tryUpperWord);// (T)Convert.ToUInt16(enumr.ItemList[i]);
toPopulate.Add(val);
}
}
break;
case ContainerType.Enum: case ContainerType.Enum:
var enumr = capability.GetEnumValue(); if (read.CollectionValues != null)
if (enumr != null && enumr.ItemList != null)
{ {
for (int i = 0; i < enumr.ItemList.Length; i++) foreach (var o in read.CollectionValues)
{ {
var val = ConvertValueToType<TCapVal>(enumr.ItemList[i], tryUpperWord);// (T)Convert.ToUInt16(enumr.ItemList[i]); toPopulate.Add(o);
toPopulate.Add(val);
} }
} }
break; break;
case ContainerType.Range: case ContainerType.Range:
var range = capability.GetRangeValue(); for (var i = read.RangeMinValue; i <= read.RangeMaxValue; i += read.RangeStepSize)
if (range != null)
{ {
for (uint i = range.MinValue; i < range.MaxValue; i += range.StepSize) toPopulate.Add(i);
{
var val = ConvertValueToType<TCapVal>(i, tryUpperWord);
toPopulate.Add(val);
}
} }
break; break;
} }
@@ -230,22 +167,21 @@ namespace NTwain
} }
/// <summary> /// <summary>
/// A generic method that tries to get capability values from current <see cref="TwainSessionOld" />. /// A general method that tries to get capability values from current <see cref="TwainSession" />.
/// </summary> /// </summary>
/// <typeparam name="TCapVal">The expected capability value type.</typeparam>
/// <param name="session">The session.</param> /// <param name="session">The session.</param>
/// <param name="capabilityId">The capability unique identifier.</param> /// <param name="capabilityId">The capability unique identifier.</param>
/// <param name="tryUpperWord">if set to <c>true</c> then apply to workaround for certain bad sources.</param> /// <param name="tryUpperWord">if set to <c>true</c> then apply to workaround for certain bad sources.</param>
/// <returns></returns> /// <returns></returns>
public static IList<TCapVal> GetCapabilityValues<TCapVal>(this TwainSession session, CapabilityId capabilityId, bool tryUpperWord) where TCapVal : struct,IConvertible public static IList<object> GetCapabilityValues(this TwainSession session, CapabilityId capabilityId)
{ {
var list = new List<TCapVal>(); var list = new List<object>();
using (TWCapability cap = new TWCapability(capabilityId)) using (TWCapability cap = new TWCapability(capabilityId))
{ {
var rc = session.DGControl.Capability.Get(cap); var rc = session.DGControl.Capability.Get(cap);
if (rc == ReturnCode.Success) if (rc == ReturnCode.Success)
{ {
cap.ReadMultiCapValues<TCapVal>(list, tryUpperWord); cap.ReadMultiCapValues(list);
} }
} }
return list; return list;
@@ -259,7 +195,7 @@ namespace NTwain
/// <returns></returns> /// <returns></returns>
internal static IList<CapabilityId> GetCapabilities(this TwainSession session) internal static IList<CapabilityId> GetCapabilities(this TwainSession session)
{ {
return session.GetCapabilityValues<CapabilityId>(CapabilityId.CapSupportedCaps, false); return session.GetCapabilityValues(CapabilityId.CapSupportedCaps).CastToEnum<CapabilityId>(false);
} }
#region xfer mech #region xfer mech
@@ -272,7 +208,7 @@ namespace NTwain
/// <returns></returns> /// <returns></returns>
public static IList<XferMech> CapGetImageXferMech(this TwainSession session) public static IList<XferMech> CapGetImageXferMech(this TwainSession session)
{ {
return session.GetCapabilityValues<XferMech>(CapabilityId.ICapXferMech, true); return session.GetCapabilityValues(CapabilityId.ICapXferMech).CastToEnum<XferMech>(true);
} }
#endregion #endregion
@@ -287,7 +223,7 @@ namespace NTwain
/// <returns></returns> /// <returns></returns>
public static IList<Compression> CapGetCompression(this TwainSession session) public static IList<Compression> CapGetCompression(this TwainSession session)
{ {
return session.GetCapabilityValues<Compression>(CapabilityId.ICapCompression, true); return session.GetCapabilityValues(CapabilityId.ICapCompression).CastToEnum<Compression>(true);
} }
/// <summary> /// <summary>
@@ -316,7 +252,7 @@ namespace NTwain
/// <returns></returns> /// <returns></returns>
public static IList<FileFormat> CapGetImageFileFormat(this TwainSession session) public static IList<FileFormat> CapGetImageFileFormat(this TwainSession session)
{ {
return session.GetCapabilityValues<FileFormat>(CapabilityId.ICapImageFileFormat, true); return session.GetCapabilityValues(CapabilityId.ICapImageFileFormat).CastToEnum<FileFormat>(true);
} }
/// <summary> /// <summary>
@@ -345,7 +281,7 @@ namespace NTwain
/// <returns></returns> /// <returns></returns>
public static IList<PixelType> CapGetPixelTypes(this TwainSession session) public static IList<PixelType> CapGetPixelTypes(this TwainSession session)
{ {
return session.GetCapabilityValues<PixelType>(CapabilityId.ICapPixelType, true); return session.GetCapabilityValues(CapabilityId.ICapPixelType).CastToEnum<PixelType>(true);
} }
/// <summary> /// <summary>
@@ -377,7 +313,7 @@ namespace NTwain
/// <returns></returns> /// <returns></returns>
public static IList<XferMech> CapGetImageXferMechs(this TwainSession session) public static IList<XferMech> CapGetImageXferMechs(this TwainSession session)
{ {
return session.GetCapabilityValues<XferMech>(CapabilityId.ICapXferMech, true); return session.GetCapabilityValues(CapabilityId.ICapXferMech).CastToEnum<XferMech>(true);
} }
/// <summary> /// <summary>
@@ -388,7 +324,7 @@ namespace NTwain
/// <returns></returns> /// <returns></returns>
public static IList<XferMech> CapGetAudioXferMechs(this TwainSession session) public static IList<XferMech> CapGetAudioXferMechs(this TwainSession session)
{ {
return session.GetCapabilityValues<XferMech>(CapabilityId.ACapXferMech, true); return session.GetCapabilityValues(CapabilityId.ACapXferMech).CastToEnum<XferMech>(true);
} }
/// <summary> /// <summary>
@@ -435,9 +371,9 @@ namespace NTwain
/// </summary> /// </summary>
/// <param name="session">The session.</param> /// <param name="session">The session.</param>
/// <returns></returns> /// <returns></returns>
public static IList<int> CapGetDPIs(this TwainSession session) public static IList<TWFix32> CapGetDPIs(this TwainSession session)
{ {
return session.GetCapabilityValues<int>(CapabilityId.ICapXResolution, true); return session.GetCapabilityValues(CapabilityId.ICapXResolution).Cast<TWFix32>().ToList();
} }
/// <summary> /// <summary>
@@ -446,7 +382,7 @@ namespace NTwain
/// <param name="session">The session.</param> /// <param name="session">The session.</param>
/// <param name="dpi">The DPI.</param> /// <param name="dpi">The DPI.</param>
/// <returns></returns> /// <returns></returns>
public static ReturnCode CapSetDPI(this TwainSession session, int dpi) public static ReturnCode CapSetDPI(this TwainSession session, TWFix32 dpi)
{ {
return CapSetDPI(session, dpi, dpi); return CapSetDPI(session, dpi, dpi);
} }
@@ -458,7 +394,7 @@ namespace NTwain
/// <param name="xDPI">The x DPI.</param> /// <param name="xDPI">The x DPI.</param>
/// <param name="yDPI">The y DPI.</param> /// <param name="yDPI">The y DPI.</param>
/// <returns></returns> /// <returns></returns>
public static ReturnCode CapSetDPI(this TwainSession session, int xDPI, int yDPI) public static ReturnCode CapSetDPI(this TwainSession session, TWFix32 xDPI, TWFix32 yDPI)
{ {
TWOneValue one = new TWOneValue(); TWOneValue one = new TWOneValue();
one.Item = (uint)xDPI;// ((uint)dpi) << 16; one.Item = (uint)xDPI;// ((uint)dpi) << 16;
@@ -491,7 +427,7 @@ namespace NTwain
/// <returns></returns> /// <returns></returns>
public static IList<SupportedSize> CapGetSupportedSizes(this TwainSession session) public static IList<SupportedSize> CapGetSupportedSizes(this TwainSession session)
{ {
return session.GetCapabilityValues<SupportedSize>(CapabilityId.ICapSupportedSizes, true); return session.GetCapabilityValues(CapabilityId.ICapSupportedSizes).CastToEnum<SupportedSize>(true);
} }
/// <summary> /// <summary>

View File

@@ -68,7 +68,7 @@ namespace NTwain
if (!args.CancelAll && !args.CancelCurrent) if (!args.CancelAll && !args.CancelCurrent)
{ {
Values.XferMech mech = this.GetCurrentCap<XferMech>(CapabilityId.ICapXferMech); Values.XferMech mech = this.GetCurrentCap(CapabilityId.ICapXferMech).ConvertToEnum<XferMech>();
//if (args.CanDoFileXfer && !string.IsNullOrEmpty(args.OutputFile)) //if (args.CanDoFileXfer && !string.IsNullOrEmpty(args.OutputFile))
//{ //{

View File

@@ -0,0 +1,71 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace NTwain.Values
{
/// <summary>
/// Utility on converting (possibly bad) integer values to enum values.
/// </summary>
public static class ValueConverter
{
public static IList<T> CastToEnum<T>(this IList<object> list) where T : struct,IConvertible
{
return list.CastToEnum<T>(true);
}
public static IList<T> CastToEnum<T>(this IList<object> list, bool tryUpperWord) where T : struct,IConvertible
{
return list.Select(o => o.ConvertToEnum<T>(tryUpperWord)).ToList();
}
public static T ConvertToEnum<T>(this object value) where T : struct,IConvertible
{
return ConvertToEnum<T>(value, true);
}
public static T ConvertToEnum<T>(this object value, bool tryUpperWord) where T : struct,IConvertible
{
var returnType = typeof(T);
// standard int values
if (returnType.IsEnum)
{
if (tryUpperWord)
{
// small routine to work with bad sources that may put
// 16bit value in the upper word instead of lower word (as per the twain spec).
var rawType = Enum.GetUnderlyingType(returnType);
if (typeof(ushort).IsAssignableFrom(rawType))
{
var intVal = Convert.ToUInt32(value);
var enumVal = GetLowerWord(intVal);
if (!Enum.IsDefined(returnType, enumVal))
{
return (T)Enum.ToObject(returnType, GetUpperWord(intVal));
}
}
}
// this may work better?
return (T)Enum.ToObject(returnType, value);
//// cast to underlying type first then to the enum
//return (T)Convert.ChangeType(value, rawType);
}
else if (typeof(IConvertible).IsAssignableFrom(returnType))
{
// for regular integers and whatnot
return (T)Convert.ChangeType(value, returnType);
}
// return as-is from cap. if caller made a mistake then there should be exceptions
return (T)value;
}
static ushort GetLowerWord(uint value)
{
return (ushort)(value & 0xffff);
}
static uint GetUpperWord(uint value)
{
return (ushort)(value >> 16);
}
}
}

View File

@@ -40,6 +40,7 @@
<Label Content="Cap values" Grid.Column="2"></Label> <Label Content="Cap values" Grid.Column="2"></Label>
<ListBox x:Name="CapDetailList" Grid.Row="1" Grid.Column="2" MinWidth="100" <ListBox x:Name="CapDetailList" Grid.Row="1" Grid.Column="2" MinWidth="100"
SelectionChanged="CapDetailList_SelectionChanged" SelectionChanged="CapDetailList_SelectionChanged"
ScrollViewer.CanContentScroll="True"
Style="{StaticResource AppListBox}"></ListBox> Style="{StaticResource AppListBox}"></ListBox>
<StackPanel Orientation="Horizontal" Grid.Column="3" > <StackPanel Orientation="Horizontal" Grid.Column="3" >

View File

@@ -43,10 +43,6 @@ namespace Tester.WPF
} }
_twainVM = new TwainVM(); _twainVM = new TwainVM();
_twainVM.SourceDisabled += delegate
{
ModernMessageBox.Show(this, "Success!");
};
this.DataContext = _twainVM; this.DataContext = _twainVM;
} }
@@ -116,505 +112,505 @@ namespace Tester.WPF
switch (cap) switch (cap)
{ {
case CapabilityId.ACapXferMech: case CapabilityId.ACapXferMech:
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<XferMech>(cap, true); CapDetailList.ItemsSource = _twainVM.GetCapabilityValues(cap).CastToEnum<XferMech>();
break; break;
case CapabilityId.CapAlarms: case CapabilityId.CapAlarms:
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<AlarmType>(cap, true); CapDetailList.ItemsSource = _twainVM.GetCapabilityValues(cap).CastToEnum<AlarmType>();
break; break;
case CapabilityId.CapAlarmVolume: case CapabilityId.CapAlarmVolume:
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<ushort>(cap, true); CapDetailList.ItemsSource = _twainVM.GetCapabilityValues(cap);
break;
case CapabilityId.CapAuthor:
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues(cap);
break; break;
//case CapabilityId.CapAuthor:
// CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<AlarmType>(cap, true);
// break;
case CapabilityId.CapAutoFeed: case CapabilityId.CapAutoFeed:
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<ushort>(cap, true); CapDetailList.ItemsSource = _twainVM.GetCapabilityValues(cap);
break; break;
case CapabilityId.CapAutomaticCapture: case CapabilityId.CapAutomaticCapture:
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<ushort>(cap, true); CapDetailList.ItemsSource = _twainVM.GetCapabilityValues(cap);
break; break;
case CapabilityId.CapAutomaticSenseMedium: case CapabilityId.CapAutomaticSenseMedium:
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<ushort>(cap, true); CapDetailList.ItemsSource = _twainVM.GetCapabilityValues(cap);
break; break;
case CapabilityId.CapAutoScan: case CapabilityId.CapAutoScan:
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<ushort>(cap, true); CapDetailList.ItemsSource = _twainVM.GetCapabilityValues(cap);
break; break;
case CapabilityId.CapBatteryMinutes: case CapabilityId.CapBatteryMinutes:
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<ushort>(cap, true); CapDetailList.ItemsSource = _twainVM.GetCapabilityValues(cap);
break; break;
case CapabilityId.CapBatteryPercentage: case CapabilityId.CapBatteryPercentage:
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<ushort>(cap, true); CapDetailList.ItemsSource = _twainVM.GetCapabilityValues(cap);
break; break;
case CapabilityId.CapCameraEnabled: case CapabilityId.CapCameraEnabled:
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<ushort>(cap, true); CapDetailList.ItemsSource = _twainVM.GetCapabilityValues(cap);
break; break;
case CapabilityId.CapCameraOrder: case CapabilityId.CapCameraOrder:
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<ushort>(cap, true); CapDetailList.ItemsSource = _twainVM.GetCapabilityValues(cap);
break; break;
case CapabilityId.CapCameraPreviewUI: case CapabilityId.CapCameraPreviewUI:
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<ushort>(cap, true); CapDetailList.ItemsSource = _twainVM.GetCapabilityValues(cap);
break; break;
case CapabilityId.CapCameraSide: case CapabilityId.CapCameraSide:
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<CameraSide>(cap, true); CapDetailList.ItemsSource = _twainVM.GetCapabilityValues(cap).CastToEnum<CameraSide>();
break;
case CapabilityId.CapCaption:
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues(cap);
break; break;
//case CapabilityId.CapCaption:
// CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<ushort>(cap, true);
// break;
case CapabilityId.CapClearBuffers: case CapabilityId.CapClearBuffers:
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<ClearBuffer>(cap, true); CapDetailList.ItemsSource = _twainVM.GetCapabilityValues(cap).CastToEnum<ClearBuffer>();
break; break;
case CapabilityId.CapClearPage: case CapabilityId.CapClearPage:
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<ushort>(cap, true); CapDetailList.ItemsSource = _twainVM.GetCapabilityValues(cap);
break; break;
case CapabilityId.CapCustomDSData: case CapabilityId.CapCustomDSData:
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<ushort>(cap, true); CapDetailList.ItemsSource = _twainVM.GetCapabilityValues(cap);
break;
case CapabilityId.CapCustomInterfaceGuid:
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues(cap);
break; break;
//case CapabilityId.CapCustomInterfaceGuid:
// CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<ushort>(cap, true);
// break;
case CapabilityId.CapDeviceEvent: case CapabilityId.CapDeviceEvent:
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<DeviceEvent>(cap, true); CapDetailList.ItemsSource = _twainVM.GetCapabilityValues(cap).CastToEnum<DeviceEvent>();
break; break;
case CapabilityId.CapDeviceOnline: case CapabilityId.CapDeviceOnline:
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<ushort>(cap, true); CapDetailList.ItemsSource = _twainVM.GetCapabilityValues(cap);
break; break;
case CapabilityId.CapDeviceTimeDate: case CapabilityId.CapDeviceTimeDate:
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<ushort>(cap, true); CapDetailList.ItemsSource = _twainVM.GetCapabilityValues(cap);
break; break;
case CapabilityId.CapDoubleFeedDetection: case CapabilityId.CapDoubleFeedDetection:
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<DoubleFeedDetection>(cap, true); CapDetailList.ItemsSource = _twainVM.GetCapabilityValues(cap).CastToEnum<DoubleFeedDetection>();
break; break;
case CapabilityId.CapDoubleFeedDetectionLength: case CapabilityId.CapDoubleFeedDetectionLength:
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<ushort>(cap, true); CapDetailList.ItemsSource = _twainVM.GetCapabilityValues(cap);
break; break;
case CapabilityId.CapDoubleFeedDetectionResponse: case CapabilityId.CapDoubleFeedDetectionResponse:
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<DoubleFeedDetectionResponse>(cap, true); CapDetailList.ItemsSource = _twainVM.GetCapabilityValues(cap).CastToEnum<DoubleFeedDetectionResponse>();
break; break;
case CapabilityId.CapDoubleFeedDetectionSensitivity: case CapabilityId.CapDoubleFeedDetectionSensitivity:
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<DoubleFeedDetectionSensitivity>(cap, true); CapDetailList.ItemsSource = _twainVM.GetCapabilityValues(cap).CastToEnum<DoubleFeedDetectionSensitivity>();
break; break;
case CapabilityId.CapDuplex: case CapabilityId.CapDuplex:
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<Duplex>(cap, true); CapDetailList.ItemsSource = _twainVM.GetCapabilityValues(cap).CastToEnum<Duplex>();
break; break;
case CapabilityId.CapDuplexEnabled: case CapabilityId.CapDuplexEnabled:
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<ushort>(cap, true); CapDetailList.ItemsSource = _twainVM.GetCapabilityValues(cap);
break; break;
case CapabilityId.CapEnableDSUIOnly: case CapabilityId.CapEnableDSUIOnly:
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<ushort>(cap, true); CapDetailList.ItemsSource = _twainVM.GetCapabilityValues(cap);
break; break;
//case CapabilityId.CapEndorser: //case CapabilityId.CapEndorser:
// CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<ushort>(cap, true); // CapDetailList.ItemsSource = _twainVM.GetCapabilityValues(cap);
// break; // break;
case CapabilityId.CapExtendedCaps: case CapabilityId.CapExtendedCaps:
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<ushort>(cap, true); CapDetailList.ItemsSource = _twainVM.GetCapabilityValues(cap);
break; break;
case CapabilityId.CapFeederAlignment: case CapabilityId.CapFeederAlignment:
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<FeederAlignment>(cap, true); CapDetailList.ItemsSource = _twainVM.GetCapabilityValues(cap).CastToEnum<FeederAlignment>();
break; break;
case CapabilityId.CapFeederEnabled: case CapabilityId.CapFeederEnabled:
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<ushort>(cap, true); CapDetailList.ItemsSource = _twainVM.GetCapabilityValues(cap);
break; break;
case CapabilityId.CapFeederLoaded: case CapabilityId.CapFeederLoaded:
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<ushort>(cap, true); CapDetailList.ItemsSource = _twainVM.GetCapabilityValues(cap);
break; break;
case CapabilityId.CapFeederOrder: case CapabilityId.CapFeederOrder:
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<FeederOrder>(cap, true); CapDetailList.ItemsSource = _twainVM.GetCapabilityValues(cap).CastToEnum<FeederOrder>();
break; break;
case CapabilityId.CapFeederPocket: case CapabilityId.CapFeederPocket:
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<FeederPocket>(cap, true); CapDetailList.ItemsSource = _twainVM.GetCapabilityValues(cap).CastToEnum<FeederPocket>();
break; break;
case CapabilityId.CapFeederPrep: case CapabilityId.CapFeederPrep:
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<ushort>(cap, true); CapDetailList.ItemsSource = _twainVM.GetCapabilityValues(cap);
break; break;
case CapabilityId.CapFeedPage: case CapabilityId.CapFeedPage:
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<ushort>(cap, true); CapDetailList.ItemsSource = _twainVM.GetCapabilityValues(cap);
break; break;
case CapabilityId.CapIndicators: case CapabilityId.CapIndicators:
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<ushort>(cap, true); CapDetailList.ItemsSource = _twainVM.GetCapabilityValues(cap);
break; break;
case CapabilityId.CapIndicatorsMode: case CapabilityId.CapIndicatorsMode:
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<IndicatorsMode>(cap, true); CapDetailList.ItemsSource = _twainVM.GetCapabilityValues(cap).CastToEnum<IndicatorsMode>();
break; break;
case CapabilityId.CapJobControl: case CapabilityId.CapJobControl:
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<JobControl>(cap, true); CapDetailList.ItemsSource = _twainVM.GetCapabilityValues(cap).CastToEnum<JobControl>();
break; break;
case CapabilityId.CapLanguage: case CapabilityId.CapLanguage:
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<Language>(cap, true); CapDetailList.ItemsSource = _twainVM.GetCapabilityValues(cap).CastToEnum<Language>();
break; break;
case CapabilityId.CapMaxBatchBuffers: case CapabilityId.CapMaxBatchBuffers:
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<ushort>(cap, true); CapDetailList.ItemsSource = _twainVM.GetCapabilityValues(cap);
break; break;
case CapabilityId.CapMicrEnabled: case CapabilityId.CapMicrEnabled:
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<ushort>(cap, true); CapDetailList.ItemsSource = _twainVM.GetCapabilityValues(cap);
break; break;
case CapabilityId.CapPaperDetectable: case CapabilityId.CapPaperDetectable:
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<ushort>(cap, true); CapDetailList.ItemsSource = _twainVM.GetCapabilityValues(cap);
break; break;
case CapabilityId.CapPaperHandling: case CapabilityId.CapPaperHandling:
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<PaperHandling>(cap, true); CapDetailList.ItemsSource = _twainVM.GetCapabilityValues(cap).CastToEnum<PaperHandling>();
break; break;
case CapabilityId.CapPowerSaveTime: case CapabilityId.CapPowerSaveTime:
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<ushort>(cap, true); CapDetailList.ItemsSource = _twainVM.GetCapabilityValues(cap);
break; break;
case CapabilityId.CapPowerSupply: case CapabilityId.CapPowerSupply:
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<PowerSupply>(cap, true); CapDetailList.ItemsSource = _twainVM.GetCapabilityValues(cap).CastToEnum<PowerSupply>();
break; break;
case CapabilityId.CapPrinter: case CapabilityId.CapPrinter:
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<Printer>(cap, true); CapDetailList.ItemsSource = _twainVM.GetCapabilityValues(cap).CastToEnum<Printer>();
break; break;
case CapabilityId.CapPrinterCharRotation: case CapabilityId.CapPrinterCharRotation:
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<ushort>(cap, true); CapDetailList.ItemsSource = _twainVM.GetCapabilityValues(cap);
break; break;
case CapabilityId.CapPrinterEnabled: case CapabilityId.CapPrinterEnabled:
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<ushort>(cap, true); CapDetailList.ItemsSource = _twainVM.GetCapabilityValues(cap);
break; break;
case CapabilityId.CapPrinterFontStyle: case CapabilityId.CapPrinterFontStyle:
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<PrinterFontStyle>(cap, true); CapDetailList.ItemsSource = _twainVM.GetCapabilityValues(cap).CastToEnum<PrinterFontStyle>();
break; break;
case CapabilityId.CapPrinterIndex: case CapabilityId.CapPrinterIndex:
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<ushort>(cap, true); CapDetailList.ItemsSource = _twainVM.GetCapabilityValues(cap);
break; break;
case CapabilityId.CapPrinterIndexLeadChar: case CapabilityId.CapPrinterIndexLeadChar:
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<ushort>(cap, true); CapDetailList.ItemsSource = _twainVM.GetCapabilityValues(cap);
break; break;
case CapabilityId.CapPrinterIndexMaxValue: case CapabilityId.CapPrinterIndexMaxValue:
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<ushort>(cap, true); CapDetailList.ItemsSource = _twainVM.GetCapabilityValues(cap);
break; break;
case CapabilityId.CapPrinterIndexNumDigits: case CapabilityId.CapPrinterIndexNumDigits:
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<ushort>(cap, true); CapDetailList.ItemsSource = _twainVM.GetCapabilityValues(cap);
break; break;
case CapabilityId.CapPrinterIndexStep: case CapabilityId.CapPrinterIndexStep:
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<ushort>(cap, true); CapDetailList.ItemsSource = _twainVM.GetCapabilityValues(cap);
break; break;
case CapabilityId.CapPrinterIndexTrigger: case CapabilityId.CapPrinterIndexTrigger:
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<PrinterIndexTrigger>(cap, true); CapDetailList.ItemsSource = _twainVM.GetCapabilityValues(cap).CastToEnum<PrinterIndexTrigger>();
break; break;
case CapabilityId.CapPrinterMode: case CapabilityId.CapPrinterMode:
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<PrinterMode>(cap, true); CapDetailList.ItemsSource = _twainVM.GetCapabilityValues(cap).CastToEnum<PrinterMode>();
break;
case CapabilityId.CapPrinterString:
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues(cap);
break;
case CapabilityId.CapPrinterStringPreview:
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues(cap);
break;
case CapabilityId.CapPrinterSuffix:
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues(cap);
break; break;
//case CapabilityId.CapPrinterString:
// CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<ushort>(cap, true);
// break;
//case CapabilityId.CapPrinterStringPreview:
// CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<ushort>(cap, true);
// break;
//case CapabilityId.CapPrinterSuffix:
// CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<ushort>(cap, true);
// break;
case CapabilityId.CapPrinterVerticalOffset: case CapabilityId.CapPrinterVerticalOffset:
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<ushort>(cap, true); CapDetailList.ItemsSource = _twainVM.GetCapabilityValues(cap);
break; break;
case CapabilityId.CapReacquireAllowed: case CapabilityId.CapReacquireAllowed:
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<ushort>(cap, true); CapDetailList.ItemsSource = _twainVM.GetCapabilityValues(cap);
break; break;
case CapabilityId.CapRewindPage: case CapabilityId.CapRewindPage:
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<ushort>(cap, true); CapDetailList.ItemsSource = _twainVM.GetCapabilityValues(cap);
break; break;
case CapabilityId.CapSegmented: case CapabilityId.CapSegmented:
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<Segmented>(cap, true); CapDetailList.ItemsSource = _twainVM.GetCapabilityValues(cap).CastToEnum<Segmented>();
break;
case CapabilityId.CapSerialNumber:
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues(cap);
break;
case CapabilityId.CapSupportedCaps:
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues(cap).CastToEnum<CapabilityId>();
break; break;
//case CapabilityId.CapSerialNumber:
// CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<ushort>(cap, true);
// break;
//case CapabilityId.CapSupportedCaps:
// CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<ushort>(cap, true);
// break;
case CapabilityId.CapSupportedCapsSegmentUnique: case CapabilityId.CapSupportedCapsSegmentUnique:
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<ushort>(cap, true); CapDetailList.ItemsSource = _twainVM.GetCapabilityValues(cap);
break; break;
case CapabilityId.CapSupportedDATs: case CapabilityId.CapSupportedDATs:
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<ushort>(cap, true); CapDetailList.ItemsSource = _twainVM.GetCapabilityValues(cap);
break; break;
case CapabilityId.CapThumbnailsEnabled: case CapabilityId.CapThumbnailsEnabled:
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<ushort>(cap, true); CapDetailList.ItemsSource = _twainVM.GetCapabilityValues(cap);
break; break;
case CapabilityId.CapTimeBeforeFirstCapture: case CapabilityId.CapTimeBeforeFirstCapture:
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<ushort>(cap, true); CapDetailList.ItemsSource = _twainVM.GetCapabilityValues(cap);
break; break;
case CapabilityId.CapTimeBetweenCaptures: case CapabilityId.CapTimeBetweenCaptures:
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<ushort>(cap, true); CapDetailList.ItemsSource = _twainVM.GetCapabilityValues(cap);
break; break;
case CapabilityId.CapTimeDate: case CapabilityId.CapTimeDate:
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<ushort>(cap, true); CapDetailList.ItemsSource = _twainVM.GetCapabilityValues(cap);
break; break;
case CapabilityId.CapUIControllable: case CapabilityId.CapUIControllable:
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<ushort>(cap, true); CapDetailList.ItemsSource = _twainVM.GetCapabilityValues(cap);
break; break;
case CapabilityId.CapXferCount: case CapabilityId.CapXferCount:
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<uint>(cap, true); // spec says ushort but who knows CapDetailList.ItemsSource = _twainVM.GetCapabilityValues(cap);
break; break;
case CapabilityId.CustomBase: case CapabilityId.CustomBase:
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<ushort>(cap, true); CapDetailList.ItemsSource = _twainVM.GetCapabilityValues(cap);
break; break;
case CapabilityId.ICapAutoBright: case CapabilityId.ICapAutoBright:
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<ushort>(cap, true); CapDetailList.ItemsSource = _twainVM.GetCapabilityValues(cap);
break; break;
case CapabilityId.ICapAutoDiscardBlankPages: case CapabilityId.ICapAutoDiscardBlankPages:
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<ushort>(cap, true); CapDetailList.ItemsSource = _twainVM.GetCapabilityValues(cap);
break; break;
case CapabilityId.ICapAutomaticBorderDetection: case CapabilityId.ICapAutomaticBorderDetection:
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<ushort>(cap, true); CapDetailList.ItemsSource = _twainVM.GetCapabilityValues(cap);
break; break;
case CapabilityId.ICapAutomaticColorEnabled: case CapabilityId.ICapAutomaticColorEnabled:
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<ushort>(cap, true); CapDetailList.ItemsSource = _twainVM.GetCapabilityValues(cap);
break; break;
case CapabilityId.ICapAutomaticColorNonColorPixelType: case CapabilityId.ICapAutomaticColorNonColorPixelType:
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<PixelType>(cap, true); CapDetailList.ItemsSource = _twainVM.GetCapabilityValues(cap).CastToEnum<PixelType>();
break; break;
case CapabilityId.ICapAutomaticCropUsesFrame: case CapabilityId.ICapAutomaticCropUsesFrame:
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<ushort>(cap, true); CapDetailList.ItemsSource = _twainVM.GetCapabilityValues(cap);
break; break;
case CapabilityId.ICapAutomaticDeskew: case CapabilityId.ICapAutomaticDeskew:
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<ushort>(cap, true); CapDetailList.ItemsSource = _twainVM.GetCapabilityValues(cap);
break; break;
case CapabilityId.ICapAutomaticLengthDetection: case CapabilityId.ICapAutomaticLengthDetection:
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<ushort>(cap, true); CapDetailList.ItemsSource = _twainVM.GetCapabilityValues(cap);
break; break;
case CapabilityId.ICapAutomaticRotate: case CapabilityId.ICapAutomaticRotate:
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<ushort>(cap, true); CapDetailList.ItemsSource = _twainVM.GetCapabilityValues(cap);
break; break;
case CapabilityId.ICapAutoSize: case CapabilityId.ICapAutoSize:
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<ushort>(cap, true); CapDetailList.ItemsSource = _twainVM.GetCapabilityValues(cap);
break; break;
case CapabilityId.ICapBarcodeDetectionEnabled: case CapabilityId.ICapBarcodeDetectionEnabled:
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<ushort>(cap, true); CapDetailList.ItemsSource = _twainVM.GetCapabilityValues(cap);
break; break;
case CapabilityId.ICapBarcodeMaxRetries: case CapabilityId.ICapBarcodeMaxRetries:
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<ushort>(cap, true); CapDetailList.ItemsSource = _twainVM.GetCapabilityValues(cap);
break; break;
case CapabilityId.ICapBarcodeMaxSearchPriorities: case CapabilityId.ICapBarcodeMaxSearchPriorities:
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<ushort>(cap, true); CapDetailList.ItemsSource = _twainVM.GetCapabilityValues(cap);
break; break;
case CapabilityId.ICapBarcodeSearchMode: case CapabilityId.ICapBarcodeSearchMode:
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<ushort>(cap, true); CapDetailList.ItemsSource = _twainVM.GetCapabilityValues(cap);
break; break;
case CapabilityId.ICapBarcodeSearchPriorities: case CapabilityId.ICapBarcodeSearchPriorities:
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<ushort>(cap, true); CapDetailList.ItemsSource = _twainVM.GetCapabilityValues(cap);
break; break;
case CapabilityId.ICapBarcodeTimeout: case CapabilityId.ICapBarcodeTimeout:
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<ushort>(cap, true); CapDetailList.ItemsSource = _twainVM.GetCapabilityValues(cap);
break; break;
case CapabilityId.ICapBitDepth: case CapabilityId.ICapBitDepth:
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<ushort>(cap, true); CapDetailList.ItemsSource = _twainVM.GetCapabilityValues(cap);
break; break;
case CapabilityId.ICapBitDepthReduction: case CapabilityId.ICapBitDepthReduction:
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<BitDepthReduction>(cap, true); CapDetailList.ItemsSource = _twainVM.GetCapabilityValues(cap).CastToEnum<BitDepthReduction>();
break; break;
case CapabilityId.ICapBitOrder: case CapabilityId.ICapBitOrder:
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<BitOrder>(cap, true); CapDetailList.ItemsSource = _twainVM.GetCapabilityValues(cap).CastToEnum<BitOrder>();
break; break;
case CapabilityId.ICapBitOrderCodes: case CapabilityId.ICapBitOrderCodes:
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<ushort>(cap, true); CapDetailList.ItemsSource = _twainVM.GetCapabilityValues(cap);
break; break;
case CapabilityId.ICapBrightness: case CapabilityId.ICapBrightness:
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<ushort>(cap, true); CapDetailList.ItemsSource = _twainVM.GetCapabilityValues(cap);
break; break;
case CapabilityId.ICapCCITTKFactor: case CapabilityId.ICapCCITTKFactor:
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<ushort>(cap, true); CapDetailList.ItemsSource = _twainVM.GetCapabilityValues(cap);
break; break;
case CapabilityId.ICapColorManagementEnabled: case CapabilityId.ICapColorManagementEnabled:
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<ushort>(cap, true); CapDetailList.ItemsSource = _twainVM.GetCapabilityValues(cap);
break; break;
case CapabilityId.ICapCompression: case CapabilityId.ICapCompression:
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<Compression>(cap, true); CapDetailList.ItemsSource = _twainVM.GetCapabilityValues(cap).CastToEnum<Compression>();
break; break;
case CapabilityId.ICapContrast: case CapabilityId.ICapContrast:
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<ushort>(cap, true); CapDetailList.ItemsSource = _twainVM.GetCapabilityValues(cap);
break; break;
case CapabilityId.ICapCustHalftone: case CapabilityId.ICapCustHalftone:
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<ushort>(cap, true); CapDetailList.ItemsSource = _twainVM.GetCapabilityValues(cap);
break; break;
case CapabilityId.ICapExposureTime: case CapabilityId.ICapExposureTime:
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<ushort>(cap, true); CapDetailList.ItemsSource = _twainVM.GetCapabilityValues(cap);
break; break;
case CapabilityId.ICapExtImageInfo: case CapabilityId.ICapExtImageInfo:
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<ushort>(cap, true); CapDetailList.ItemsSource = _twainVM.GetCapabilityValues(cap);
break; break;
case CapabilityId.ICapFeederType: case CapabilityId.ICapFeederType:
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<FeederType>(cap, true); CapDetailList.ItemsSource = _twainVM.GetCapabilityValues(cap).CastToEnum<FeederType>();
break; break;
case CapabilityId.ICapFilmType: case CapabilityId.ICapFilmType:
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<FilmType>(cap, true); CapDetailList.ItemsSource = _twainVM.GetCapabilityValues(cap).CastToEnum<FilmType>();
break; break;
case CapabilityId.ICapFilter: case CapabilityId.ICapFilter:
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<FilterType>(cap, true); CapDetailList.ItemsSource = _twainVM.GetCapabilityValues(cap).CastToEnum<FilterType>();
break; break;
case CapabilityId.ICapFlashUsed: case CapabilityId.ICapFlashUsed:
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<ushort>(cap, true); CapDetailList.ItemsSource = _twainVM.GetCapabilityValues(cap);
break; break;
case CapabilityId.ICapFlashUsed2: case CapabilityId.ICapFlashUsed2:
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<ushort>(cap, true); CapDetailList.ItemsSource = _twainVM.GetCapabilityValues(cap);
break; break;
case CapabilityId.ICapFlipRotation: case CapabilityId.ICapFlipRotation:
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<FlipRotation>(cap, true); CapDetailList.ItemsSource = _twainVM.GetCapabilityValues(cap).CastToEnum<FlipRotation>();
break;
case CapabilityId.ICapFrames:
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues(cap);
break; break;
//case CapabilityId.ICapFrames:
// CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<TWFrame>(cap, true);
// break;
case CapabilityId.ICapGamma: case CapabilityId.ICapGamma:
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<ushort>(cap, true); CapDetailList.ItemsSource = _twainVM.GetCapabilityValues(cap);
break; break;
case CapabilityId.ICapHalftones: case CapabilityId.ICapHalftones:
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<ushort>(cap, true); CapDetailList.ItemsSource = _twainVM.GetCapabilityValues(cap);
break; break;
case CapabilityId.ICapHighlight: case CapabilityId.ICapHighlight:
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<ushort>(cap, true); CapDetailList.ItemsSource = _twainVM.GetCapabilityValues(cap);
break; break;
case CapabilityId.ICapICCProfile: case CapabilityId.ICapICCProfile:
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<IccProfile>(cap, true); CapDetailList.ItemsSource = _twainVM.GetCapabilityValues(cap).CastToEnum<IccProfile>();
break; break;
case CapabilityId.ICapImageDataset: case CapabilityId.ICapImageDataset:
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<ushort>(cap, true); CapDetailList.ItemsSource = _twainVM.GetCapabilityValues(cap);
break; break;
case CapabilityId.ICapImageFileFormat: case CapabilityId.ICapImageFileFormat:
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<FileFormat>(cap, true); CapDetailList.ItemsSource = _twainVM.GetCapabilityValues(cap).CastToEnum<FileFormat>();
break; break;
case CapabilityId.ICapImageFilter: case CapabilityId.ICapImageFilter:
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<ImageFilter>(cap, true); CapDetailList.ItemsSource = _twainVM.GetCapabilityValues(cap).CastToEnum<ImageFilter>();
break; break;
case CapabilityId.ICapImageMerge: case CapabilityId.ICapImageMerge:
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<ImageMerge>(cap, true); CapDetailList.ItemsSource = _twainVM.GetCapabilityValues(cap).CastToEnum<ImageMerge>();
break; break;
case CapabilityId.ICapImageMergeHeightThreshold: case CapabilityId.ICapImageMergeHeightThreshold:
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<ushort>(cap, true); CapDetailList.ItemsSource = _twainVM.GetCapabilityValues(cap);
break; break;
case CapabilityId.ICapJpegPixelType: case CapabilityId.ICapJpegPixelType:
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<PixelType>(cap, true); CapDetailList.ItemsSource = _twainVM.GetCapabilityValues(cap).CastToEnum<PixelType>();
break; break;
case CapabilityId.ICapJpegQuality: case CapabilityId.ICapJpegQuality:
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<JpegQuality>(cap, true); CapDetailList.ItemsSource = _twainVM.GetCapabilityValues(cap).CastToEnum<JpegQuality>();
break; break;
case CapabilityId.ICapJpegSubSampling: case CapabilityId.ICapJpegSubSampling:
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<JpegSubSampling>(cap, true); CapDetailList.ItemsSource = _twainVM.GetCapabilityValues(cap).CastToEnum<JpegSubSampling>();
break; break;
case CapabilityId.ICapLampState: case CapabilityId.ICapLampState:
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<ushort>(cap, true); CapDetailList.ItemsSource = _twainVM.GetCapabilityValues(cap);
break; break;
case CapabilityId.ICapLightPath: case CapabilityId.ICapLightPath:
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<LightPath>(cap, true); CapDetailList.ItemsSource = _twainVM.GetCapabilityValues(cap).CastToEnum<LightPath>();
break; break;
case CapabilityId.ICapLightSource: case CapabilityId.ICapLightSource:
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<LightSource>(cap, true); CapDetailList.ItemsSource = _twainVM.GetCapabilityValues(cap).CastToEnum<LightSource>();
break; break;
case CapabilityId.ICapMaxFrames: case CapabilityId.ICapMaxFrames:
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<ushort>(cap, true); CapDetailList.ItemsSource = _twainVM.GetCapabilityValues(cap);
break; break;
case CapabilityId.ICapMinimumHeight: case CapabilityId.ICapMinimumHeight:
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<uint>(cap, true); CapDetailList.ItemsSource = _twainVM.GetCapabilityValues(cap);
break; break;
case CapabilityId.ICapMinimumWidth: case CapabilityId.ICapMinimumWidth:
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<uint>(cap, true); CapDetailList.ItemsSource = _twainVM.GetCapabilityValues(cap);
break; break;
case CapabilityId.ICapMirror: case CapabilityId.ICapMirror:
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<Mirror>(cap, true); CapDetailList.ItemsSource = _twainVM.GetCapabilityValues(cap).CastToEnum<Mirror>();
break; break;
case CapabilityId.ICapNoiseFilter: case CapabilityId.ICapNoiseFilter:
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<NoiseFilter>(cap, true); CapDetailList.ItemsSource = _twainVM.GetCapabilityValues(cap).CastToEnum<NoiseFilter>();
break; break;
case CapabilityId.ICapOrientation: case CapabilityId.ICapOrientation:
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<NTwain.Values.Orientation>(cap, true); CapDetailList.ItemsSource = _twainVM.GetCapabilityValues(cap).CastToEnum<NTwain.Values.Orientation>();
break; break;
case CapabilityId.ICapOverScan: case CapabilityId.ICapOverScan:
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<OverScan>(cap, true); CapDetailList.ItemsSource = _twainVM.GetCapabilityValues(cap).CastToEnum<OverScan>();
break; break;
case CapabilityId.ICapPatchCodeDetectionEnabled: case CapabilityId.ICapPatchCodeDetectionEnabled:
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<ushort>(cap, true); CapDetailList.ItemsSource = _twainVM.GetCapabilityValues(cap);
break; break;
case CapabilityId.ICapPatchCodeMaxRetries: case CapabilityId.ICapPatchCodeMaxRetries:
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<ushort>(cap, true); CapDetailList.ItemsSource = _twainVM.GetCapabilityValues(cap);
break; break;
case CapabilityId.ICapPatchCodeMaxSearchPriorities: case CapabilityId.ICapPatchCodeMaxSearchPriorities:
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<PatchCode>(cap, true); CapDetailList.ItemsSource = _twainVM.GetCapabilityValues(cap).CastToEnum<PatchCode>();
break; break;
case CapabilityId.ICapPatchCodeSearchMode: case CapabilityId.ICapPatchCodeSearchMode:
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<ushort>(cap, true); CapDetailList.ItemsSource = _twainVM.GetCapabilityValues(cap);
break; break;
case CapabilityId.ICapPatchCodeSearchPriorities: case CapabilityId.ICapPatchCodeSearchPriorities:
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<ushort>(cap, true); CapDetailList.ItemsSource = _twainVM.GetCapabilityValues(cap);
break; break;
case CapabilityId.ICapPatchCodeTimeout: case CapabilityId.ICapPatchCodeTimeout:
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<ushort>(cap, true); CapDetailList.ItemsSource = _twainVM.GetCapabilityValues(cap);
break; break;
// TODO phys size are twfix32 // TODO phys size are twfix32
case CapabilityId.ICapPhysicalHeight: case CapabilityId.ICapPhysicalHeight:
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<uint>(cap, true); CapDetailList.ItemsSource = _twainVM.GetCapabilityValues(cap);
break; break;
case CapabilityId.ICapPhysicalWidth: case CapabilityId.ICapPhysicalWidth:
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<uint>(cap, true); CapDetailList.ItemsSource = _twainVM.GetCapabilityValues(cap);
break; break;
case CapabilityId.ICapPixelFlavor: case CapabilityId.ICapPixelFlavor:
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<PixelFlavor>(cap, true); CapDetailList.ItemsSource = _twainVM.GetCapabilityValues(cap).CastToEnum<PixelFlavor>();
break; break;
case CapabilityId.ICapPixelFlavorCodes: case CapabilityId.ICapPixelFlavorCodes:
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<ushort>(cap, true); CapDetailList.ItemsSource = _twainVM.GetCapabilityValues(cap);
break; break;
case CapabilityId.ICapPixelType: case CapabilityId.ICapPixelType:
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<PixelType>(cap, true); CapDetailList.ItemsSource = _twainVM.GetCapabilityValues(cap).CastToEnum<PixelType>();
break; break;
case CapabilityId.ICapPlanarChunky: case CapabilityId.ICapPlanarChunky:
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<PlanarChunky>(cap, true); CapDetailList.ItemsSource = _twainVM.GetCapabilityValues(cap).CastToEnum<PlanarChunky>();
break; break;
case CapabilityId.ICapRotation: case CapabilityId.ICapRotation:
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<Rotation>(cap, true); CapDetailList.ItemsSource = _twainVM.GetCapabilityValues(cap).CastToEnum<Rotation>();
break; break;
case CapabilityId.ICapShadow: case CapabilityId.ICapShadow:
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<ushort>(cap, true); CapDetailList.ItemsSource = _twainVM.GetCapabilityValues(cap);
break; break;
case CapabilityId.ICapSupportedBarcodeTypes: case CapabilityId.ICapSupportedBarcodeTypes:
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<BarcodeType>(cap, true); CapDetailList.ItemsSource = _twainVM.GetCapabilityValues(cap).CastToEnum<BarcodeType>();
break; break;
case CapabilityId.ICapSupportedExtImageInfo: case CapabilityId.ICapSupportedExtImageInfo:
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<ExtendedImageInfo>(cap, true); CapDetailList.ItemsSource = _twainVM.GetCapabilityValues(cap).CastToEnum<ExtendedImageInfo>();
break; break;
case CapabilityId.ICapSupportedPatchCodeTypes: case CapabilityId.ICapSupportedPatchCodeTypes:
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<PatchCode>(cap, true); CapDetailList.ItemsSource = _twainVM.GetCapabilityValues(cap).CastToEnum<PatchCode>();
break; break;
case CapabilityId.ICapSupportedSizes: case CapabilityId.ICapSupportedSizes:
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<SupportedSize>(cap, true); CapDetailList.ItemsSource = _twainVM.GetCapabilityValues(cap).CastToEnum<SupportedSize>();
break; break;
case CapabilityId.ICapThreshold: case CapabilityId.ICapThreshold:
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<ushort>(cap, true); CapDetailList.ItemsSource = _twainVM.GetCapabilityValues(cap);
break; break;
case CapabilityId.ICapTiles: case CapabilityId.ICapTiles:
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<ushort>(cap, true); CapDetailList.ItemsSource = _twainVM.GetCapabilityValues(cap);
break; break;
case CapabilityId.ICapTimeFill: case CapabilityId.ICapTimeFill:
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<ushort>(cap, true); CapDetailList.ItemsSource = _twainVM.GetCapabilityValues(cap);
break; break;
case CapabilityId.ICapUndefinedImageSize: case CapabilityId.ICapUndefinedImageSize:
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<ushort>(cap, true); CapDetailList.ItemsSource = _twainVM.GetCapabilityValues(cap);
break; break;
case CapabilityId.ICapUnits: case CapabilityId.ICapUnits:
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<Unit>(cap, true); CapDetailList.ItemsSource = _twainVM.GetCapabilityValues(cap).CastToEnum<Unit>();
break; break;
case CapabilityId.ICapXferMech: case CapabilityId.ICapXferMech:
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<XferMech>(cap, true); CapDetailList.ItemsSource = _twainVM.GetCapabilityValues(cap).CastToEnum<XferMech>();
break; break;
case CapabilityId.ICapXNativeResolution: case CapabilityId.ICapXNativeResolution:
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<ushort>(cap, true); CapDetailList.ItemsSource = _twainVM.GetCapabilityValues(cap);
break; break;
case CapabilityId.ICapXResolution: case CapabilityId.ICapXResolution:
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<ushort>(cap, true); CapDetailList.ItemsSource = _twainVM.GetCapabilityValues(cap);
break; break;
case CapabilityId.ICapXScaling: case CapabilityId.ICapXScaling:
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<ushort>(cap, true); CapDetailList.ItemsSource = _twainVM.GetCapabilityValues(cap);
break; break;
case CapabilityId.ICapYNativeResolution: case CapabilityId.ICapYNativeResolution:
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<ushort>(cap, true); CapDetailList.ItemsSource = _twainVM.GetCapabilityValues(cap);
break; break;
case CapabilityId.ICapYResolution: case CapabilityId.ICapYResolution:
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<ushort>(cap, true); CapDetailList.ItemsSource = _twainVM.GetCapabilityValues(cap);
break; break;
case CapabilityId.ICapYScaling: case CapabilityId.ICapYScaling:
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<ushort>(cap, true); CapDetailList.ItemsSource = _twainVM.GetCapabilityValues(cap);
break; break;
case CapabilityId.ICapZoomFactor: case CapabilityId.ICapZoomFactor:
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<ushort>(cap, true); CapDetailList.ItemsSource = _twainVM.GetCapabilityValues(cap);
break; break;
default: default:
if (cap > CapabilityId.CustomBase) if (cap > CapabilityId.CustomBase)
{ {
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<ushort>(cap, true); CapDetailList.ItemsSource = _twainVM.GetCapabilityValues(cap);
} }
else else
{ {

View File

@@ -46,7 +46,7 @@ namespace Tester.WPF
{ {
// set it up to use file xfer // set it up to use file xfer
if (this.GetCurrentCap<XferMech>(CapabilityId.ICapXferMech) == XferMech.File) if (this.GetCurrentCap(CapabilityId.ICapXferMech).ConvertToEnum<XferMech>() == XferMech.File)
{ {
var formats = this.CapGetImageFileFormat(); var formats = this.CapGetImageFileFormat();
var wantFormat = formats.Contains(FileFormat.Tiff) ? FileFormat.Tiff : FileFormat.Bmp; var wantFormat = formats.Contains(FileFormat.Tiff) ? FileFormat.Tiff : FileFormat.Bmp;