diff --git a/src/NTwain/Caps/CapReader.cs b/src/NTwain/Caps/CapReader.cs new file mode 100644 index 0000000..e22cbd5 --- /dev/null +++ b/src/NTwain/Caps/CapReader.cs @@ -0,0 +1,91 @@ +using NTwain.Data; +using System; +using System.Collections.Generic; + +namespace NTwain.Caps +{ + public class CapReader where TValue : struct + { + readonly TwainAppSession _twain; + + public CapReader(TwainAppSession twain, CAP cap) + { + _twain = twain; + Cap = cap; + } + + public CAP Cap { get; } + + public STS LastSTS { get; private set; } + + TWQC? _qc; + public TWQC Supports + { + get + { + if (!_qc.HasValue) _qc = _twain.QueryCapSupport(Cap); + return _qc.Value; + } + } + + public IList Get() + { + LastSTS = _twain.GetCapValues(Cap, out IList values); + if (LastSTS.IsSuccess) + { + return values; + }; + return Array.Empty(); + } + + public TValue GetCurrent() + { + LastSTS = _twain.GetCapCurrent(Cap, out TValue value); + if (LastSTS.IsSuccess) + { + return value; + }; + return default; + } + + public TValue GetDefault() + { + LastSTS = _twain.GetCapDefault(Cap, out TValue value); + if (LastSTS.IsSuccess) + { + return value; + }; + return default; + } + + public string? GetLabel() + { + LastSTS = _twain.GetCapLabel(Cap, out string? value); + if (LastSTS.IsSuccess) + { + return value; + }; + return default; + } + + public string? GetHelp() + { + LastSTS = _twain.GetCapHelp(Cap, out string? value); + if (LastSTS.IsSuccess) + { + return value; + }; + return default; + } + + public IList GetLabelEnum() + { + LastSTS = _twain.GetCapLabelEnum(Cap, out IList value); + if (LastSTS.IsSuccess) + { + return value; + }; + return Array.Empty(); + } + } +} diff --git a/src/NTwain/Caps/CapWriter.cs b/src/NTwain/Caps/CapWriter.cs new file mode 100644 index 0000000..03be15f --- /dev/null +++ b/src/NTwain/Caps/CapWriter.cs @@ -0,0 +1,16 @@ +using NTwain.Data; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace NTwain.Caps +{ + public class CapWriter : CapReader where TValue : struct + { + public CapWriter(TwainAppSession twain, CAP cap) : base(twain, cap) + { + } + } +} diff --git a/src/NTwain/Caps/KnownCaps.Audio.cs b/src/NTwain/Caps/KnownCaps.Audio.cs new file mode 100644 index 0000000..ba6fc11 --- /dev/null +++ b/src/NTwain/Caps/KnownCaps.Audio.cs @@ -0,0 +1,14 @@ +using NTwain.Data; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace NTwain.Caps +{ + partial class KnownCaps + { + + } +} diff --git a/src/NTwain/Caps/KnownCaps.General.cs b/src/NTwain/Caps/KnownCaps.General.cs new file mode 100644 index 0000000..ba6fc11 --- /dev/null +++ b/src/NTwain/Caps/KnownCaps.General.cs @@ -0,0 +1,14 @@ +using NTwain.Data; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace NTwain.Caps +{ + partial class KnownCaps + { + + } +} diff --git a/src/NTwain/Caps/KnownCaps.Image.cs b/src/NTwain/Caps/KnownCaps.Image.cs new file mode 100644 index 0000000..ba6fc11 --- /dev/null +++ b/src/NTwain/Caps/KnownCaps.Image.cs @@ -0,0 +1,14 @@ +using NTwain.Data; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace NTwain.Caps +{ + partial class KnownCaps + { + + } +} diff --git a/src/NTwain/Caps/KnownCaps.cs b/src/NTwain/Caps/KnownCaps.cs new file mode 100644 index 0000000..65f955a --- /dev/null +++ b/src/NTwain/Caps/KnownCaps.cs @@ -0,0 +1,23 @@ +using NTwain.Data; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace NTwain.Caps +{ + /// + /// Provides reader/writer wrapper of known s. + /// + public partial class KnownCaps + { + private readonly TwainAppSession _twain; + + public KnownCaps(TwainAppSession twain) + { + _twain = twain; + } + + } +} diff --git a/src/NTwain/TwainAppSession.Caps.cs b/src/NTwain/TwainAppSession.Caps.cs index 8a94c59..d0576ed 100644 --- a/src/NTwain/TwainAppSession.Caps.cs +++ b/src/NTwain/TwainAppSession.Caps.cs @@ -1,5 +1,7 @@ -using NTwain.Data; +using NTwain.Caps; +using NTwain.Data; using NTwain.Triplets; +using System; using System.Collections.Generic; using System.Linq; using System.Text; @@ -10,20 +12,16 @@ namespace NTwain partial class TwainAppSession { - ///// - ///// Gets all the supported caps for the current source. - ///// - ///// - //public IList GetAllCaps() - //{ - // // just as a sample of how to read cap values + private KnownCaps? _knownCaps; + + /// + /// Access the known and pre-defined caps as properties. + /// + public KnownCaps Caps + { + get { return _knownCaps ??= new KnownCaps(this); } + } - // if (GetCapValues(CAP.CAP_SUPPORTEDCAPS, out TW_CAPABILITY value).RC == TWRC.SUCCESS) - // { - // return value.ReadArray(this); - // } - // return Array.Empty(); - //} /// /// Gets a CAP's actual supported operations. @@ -251,9 +249,9 @@ namespace NTwain /// /// /// - public STS GetCapLabelEnum(CAP cap, out IList? labels) + public STS GetCapLabelEnum(CAP cap, out IList labels) { - labels = null; + labels = Array.Empty(); var value = new TW_CAPABILITY(cap); var rc = DGControl.Capability.GetLabelEnum(ref _appIdentity, ref _currentDS, ref value); if (rc == TWRC.SUCCESS)