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>
public ContainerType ContainerType { get { return (Values.ContainerType)_conType; } set { _conType = (ushort)value; } }
internal IntPtr Container { get { return _hContainer; } }
#endregion
#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)]
void SetOneValue(TWOneValue value)
{
@@ -698,7 +673,7 @@ namespace NTwain.Data
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
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));
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)]
void SetEnumValue(TWEnumeration value)
{
@@ -779,7 +689,7 @@ namespace NTwain.Data
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;
_hContainer = MemoryManager.Instance.Allocate((uint)valueSize);
@@ -794,40 +704,10 @@ namespace NTwain.Data
{
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)]
void SetRangeValue(TWRange value)
{
@@ -835,7 +715,7 @@ namespace NTwain.Data
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
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));
if (_hContainer != IntPtr.Zero)
@@ -845,46 +725,8 @@ namespace NTwain.Data
}
#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>
/// Entry call for writing values to a pointer.
/// </summary>
@@ -948,7 +790,7 @@ namespace NTwain.Data
// WriteUString(baseAddr, offset, value as string, 512);
// break;
}
offset += GetItemTypeSize(type);
offset += CapReadOut.GetItemTypeSize(type);
}
/// <summary>
/// Writes string value.
@@ -1020,112 +862,7 @@ namespace NTwain.Data
// 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
#region IDisposable Members

View File

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

View File

@@ -12,8 +12,8 @@ namespace NTwain
class _NTwainVersionInfo
{
// 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
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)
{
var mech = this.GetCurrentCap<XferMech>(CapabilityId.ICapXferMech);
var mech = this.GetCurrentCap(CapabilityId.ICapXferMech).ConvertToEnum<XferMech>();
switch (mech)
{
case XferMech.Native:
@@ -737,7 +737,7 @@ namespace NTwain
}
if ((xferGroup & DataGroups.Audio) == DataGroups.Audio)
{
var mech = this.GetCurrentCap<XferMech>(CapabilityId.ACapXferMech);
var mech = this.GetCurrentCap(CapabilityId.ACapXferMech).ConvertToEnum<XferMech>();
switch (mech)
{
case XferMech.Native:

View File

@@ -8,7 +8,7 @@ using System.Text;
namespace NTwain
{
/// <summary>
/// Defines common methods on <see cref="TwainSessionOld"/> using the raw
/// Defines common methods on <see cref="TwainSession"/> using the raw
/// TWAIN triplet api.
/// </summary>
public static class TwainSessionExtensions
@@ -87,142 +87,79 @@ namespace NTwain
#region common caps
/// <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>
/// <typeparam name="T"></typeparam>
/// <param name="session">The session.</param>
/// <param name="capId">The cap id.</param>
/// <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))
{
var rc = session.DGControl.Capability.GetCurrent(cap);
if (rc == ReturnCode.Success)
{
switch (cap.ContainerType)
var read = CapReadOut.ReadValue(cap);
switch (read.ContainerType)
{
case ContainerType.Enum:
var enu = cap.GetEnumValue();
if (enu.ItemType < ItemType.Frame)
if (read.CollectionValues != null)
{
// does this work?
return ConvertValueToType<T>(enu.ItemList[enu.CurrentIndex].ToString(), true);
return read.CollectionValues[read.EnumCurrentIndex];
}
break;
case ContainerType.OneValue:
var one = cap.GetOneValue();
if (one.ItemType < ItemType.Frame)
{
return ConvertValueToType<T>(one.Item, true);
}
break;
return read.OneValue;
case ContainerType.Range:
var range = cap.GetRangeValue();
if (range.ItemType < ItemType.Frame)
return read.RangeCurrentValue;
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;
}
}
}
return default(T);
}
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);
return null;
}
/// <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>
/// <typeparam name="TCapVal">The expected capability value type.</typeparam>
/// <param name="capability">The capability returned from the source.</param>
/// <param name="toPopulate">The list to populate if necessary.</param>
/// <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);
}
static IList<TCapVal> ReadMultiCapValues<TCapVal>(this TWCapability capability, IList<TCapVal> toPopulate, bool tryUpperWord) where TCapVal : struct,IConvertible
{
if (toPopulate == null) { toPopulate = new List<TCapVal>(); }
if (toPopulate == null) { toPopulate = new List<object>(); }
switch (capability.ContainerType)
var read = CapReadOut.ReadValue(capability);
switch (read.ContainerType)
{
case ContainerType.OneValue:
var value = capability.GetOneValue();
if (value != null)
if (read.OneValue != null)
{
var val = ConvertValueToType<TCapVal>(value.Item, tryUpperWord);// (T)Convert.ToUInt16(value.Item);
toPopulate.Add(val);
toPopulate.Add(read.OneValue);
}
break;
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:
var enumr = capability.GetEnumValue();
if (enumr != null && enumr.ItemList != null)
if (read.CollectionValues != 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(val);
toPopulate.Add(o);
}
}
break;
case ContainerType.Range:
var range = capability.GetRangeValue();
if (range != null)
for (var i = read.RangeMinValue; i <= read.RangeMaxValue; i += read.RangeStepSize)
{
for (uint i = range.MinValue; i < range.MaxValue; i += range.StepSize)
{
var val = ConvertValueToType<TCapVal>(i, tryUpperWord);
toPopulate.Add(val);
}
toPopulate.Add(i);
}
break;
}
@@ -230,22 +167,21 @@ namespace NTwain
}
/// <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>
/// <typeparam name="TCapVal">The expected capability value type.</typeparam>
/// <param name="session">The session.</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>
/// <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))
{
var rc = session.DGControl.Capability.Get(cap);
if (rc == ReturnCode.Success)
{
cap.ReadMultiCapValues<TCapVal>(list, tryUpperWord);
cap.ReadMultiCapValues(list);
}
}
return list;
@@ -259,7 +195,7 @@ namespace NTwain
/// <returns></returns>
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
@@ -272,7 +208,7 @@ namespace NTwain
/// <returns></returns>
public static IList<XferMech> CapGetImageXferMech(this TwainSession session)
{
return session.GetCapabilityValues<XferMech>(CapabilityId.ICapXferMech, true);
return session.GetCapabilityValues(CapabilityId.ICapXferMech).CastToEnum<XferMech>(true);
}
#endregion
@@ -287,7 +223,7 @@ namespace NTwain
/// <returns></returns>
public static IList<Compression> CapGetCompression(this TwainSession session)
{
return session.GetCapabilityValues<Compression>(CapabilityId.ICapCompression, true);
return session.GetCapabilityValues(CapabilityId.ICapCompression).CastToEnum<Compression>(true);
}
/// <summary>
@@ -316,7 +252,7 @@ namespace NTwain
/// <returns></returns>
public static IList<FileFormat> CapGetImageFileFormat(this TwainSession session)
{
return session.GetCapabilityValues<FileFormat>(CapabilityId.ICapImageFileFormat, true);
return session.GetCapabilityValues(CapabilityId.ICapImageFileFormat).CastToEnum<FileFormat>(true);
}
/// <summary>
@@ -345,7 +281,7 @@ namespace NTwain
/// <returns></returns>
public static IList<PixelType> CapGetPixelTypes(this TwainSession session)
{
return session.GetCapabilityValues<PixelType>(CapabilityId.ICapPixelType, true);
return session.GetCapabilityValues(CapabilityId.ICapPixelType).CastToEnum<PixelType>(true);
}
/// <summary>
@@ -377,7 +313,7 @@ namespace NTwain
/// <returns></returns>
public static IList<XferMech> CapGetImageXferMechs(this TwainSession session)
{
return session.GetCapabilityValues<XferMech>(CapabilityId.ICapXferMech, true);
return session.GetCapabilityValues(CapabilityId.ICapXferMech).CastToEnum<XferMech>(true);
}
/// <summary>
@@ -388,7 +324,7 @@ namespace NTwain
/// <returns></returns>
public static IList<XferMech> CapGetAudioXferMechs(this TwainSession session)
{
return session.GetCapabilityValues<XferMech>(CapabilityId.ACapXferMech, true);
return session.GetCapabilityValues(CapabilityId.ACapXferMech).CastToEnum<XferMech>(true);
}
/// <summary>
@@ -435,9 +371,9 @@ namespace NTwain
/// </summary>
/// <param name="session">The session.</param>
/// <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>
@@ -446,7 +382,7 @@ namespace NTwain
/// <param name="session">The session.</param>
/// <param name="dpi">The DPI.</param>
/// <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);
}
@@ -458,7 +394,7 @@ namespace NTwain
/// <param name="xDPI">The x DPI.</param>
/// <param name="yDPI">The y DPI.</param>
/// <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();
one.Item = (uint)xDPI;// ((uint)dpi) << 16;
@@ -491,7 +427,7 @@ namespace NTwain
/// <returns></returns>
public static IList<SupportedSize> CapGetSupportedSizes(this TwainSession session)
{
return session.GetCapabilityValues<SupportedSize>(CapabilityId.ICapSupportedSizes, true);
return session.GetCapabilityValues(CapabilityId.ICapSupportedSizes).CastToEnum<SupportedSize>(true);
}
/// <summary>

View File

@@ -68,7 +68,7 @@ namespace NTwain
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))
//{

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>
<ListBox x:Name="CapDetailList" Grid.Row="1" Grid.Column="2" MinWidth="100"
SelectionChanged="CapDetailList_SelectionChanged"
ScrollViewer.CanContentScroll="True"
Style="{StaticResource AppListBox}"></ListBox>
<StackPanel Orientation="Horizontal" Grid.Column="3" >

View File

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

View File

@@ -46,7 +46,7 @@ namespace Tester.WPF
{
// 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 wantFormat = formats.Contains(FileFormat.Tiff) ? FileFormat.Tiff : FileFormat.Bmp;