Added reading of supported caps.

This commit is contained in:
Eugene Wang
2021-04-24 22:24:24 -04:00
parent 0416b281ba
commit e0f1f96947
5 changed files with 228 additions and 4 deletions

View File

@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.Linq;
using System.Reflection;
using System.Text;
@@ -285,6 +286,62 @@ namespace NTwain
}
}
/// <summary>
/// Queries current device for supported capabilities.
/// Not all devices supports this.
/// </summary>
/// <returns></returns>
public IEnumerable<CAP> SupportedCaps()
{
List<CAP> caps = null;
if (State >= STATE.S4)
{
TW_CAPABILITY cap = default;
// get list of supported caps
cap.Cap = CAP.CAP_SUPPORTEDCAPS;
var sts = _twain.DatCapability(DG.CONTROL, MSG.GET, ref cap);
if (sts == STS.SUCCESS)
{
var csv = TWAIN.CapabilityToCsv(cap, true);
caps = csv.Split(',').Skip(4).Select(val =>
{
if (Enum.TryParse(val, out CAP c))
{
return c;
}
else if (val.StartsWith("0x"))
{
return (CAP)Convert.ToUInt16(val, 16);
}
else if (ushort.TryParse(val, out ushort num))
{
return (CAP)num;
}
return (CAP)0;
}).ToList();
}
//foreach (CAP capId in Enum.GetValues(typeof(CAP)))
//{
// cap.ConType = TWON.ONEVALUE;
// cap.Cap = capId;
// var sts = _twain.DatCapability(DG.CONTROL, MSG.QUERYSUPPORT, ref cap);
// if (sts == STS.SUCCESS)
// {
// if (Enum.TryParse(_twain.CapabilityOneValueToString(cap), out TWQC qc))
// {
// }
// }
//}
}
return caps ?? Enumerable.Empty<CAP>();
}
/// <summary>
/// Attempts to show the current device's settings dialog if supported.
/// </summary>