diff --git a/samples/Net5Console/Program.cs b/samples/Net5Console/Program.cs
index 7453dc2..7a46668 100644
--- a/samples/Net5Console/Program.cs
+++ b/samples/Net5Console/Program.cs
@@ -53,12 +53,12 @@ namespace Net5Console
Console.WriteLine();
Console.WriteLine("Default device:");
- Console.WriteLine($"\t{session.DefaultDevice}");
+ Console.WriteLine($"\t{session.DefaultDataSource}");
Console.WriteLine();
Console.WriteLine("All devices:");
TW_IDENTITY dsToUse = default;
- foreach (var dev in session.GetDevices())
+ foreach (var dev in session.GetDataSources())
{
Console.WriteLine($"\t{dev}");
if (dev.ProductName == "TWAIN2 FreeImage Software Scanner")
@@ -68,11 +68,11 @@ namespace Net5Console
}
Console.WriteLine();
- session.CurrentDevice = dsToUse;
- if (session.CurrentDevice.HasValue)
+ session.CurrentDataSource = dsToUse;
+ if (session.CurrentDataSource.HasValue)
{
Console.WriteLine("Current device after opening attempt:");
- Console.WriteLine($"\t{session.CurrentDevice}");
+ Console.WriteLine($"\t{session.CurrentDataSource}");
Console.WriteLine();
var caps = session.Capabilities;
diff --git a/src/NTwain/TwainSession.cs b/src/NTwain/TwainSession.cs
index 4b556be..4df1818 100644
--- a/src/NTwain/TwainSession.cs
+++ b/src/NTwain/TwainSession.cs
@@ -131,17 +131,6 @@ namespace NTwain
get { return _twain.GetState(); }
}
- /////
- ///// Gets the manager status. Useful after getting a non-success return code.
- /////
- /////
- //public TW_STATUS GetStatus()
- //{
- // TW_STATUS stat = default;
- // _ = _twain.DatStatus(DG.CONTROL, MSG.GET, ref stat);
- // return stat;
- //}
-
///
/// Opens the TWAIN data source manager.
/// This needs to be done before anything else.
@@ -163,10 +152,10 @@ namespace NTwain
}
///
- /// Gets list of TWAIN devices.
+ /// Gets list of TWAIN data sources.
///
///
- public IList GetDevices()
+ public IList GetDataSources()
{
var list = new List();
if (State > STATE.S2)
@@ -185,9 +174,9 @@ namespace NTwain
}
///
- /// Gets or sets the default device.
+ /// Gets or sets the default data source.
///
- public TW_IDENTITY? DefaultDevice
+ public TW_IDENTITY? DefaultDataSource
{
get
{
@@ -208,10 +197,10 @@ namespace NTwain
}
///
- /// Gets or sets the currently open device.
+ /// Gets or sets the currently open data source.
/// Setting it will try to open it.
///
- public TW_IDENTITY? CurrentDevice
+ public TW_IDENTITY? CurrentDataSource
{
get
{
@@ -285,7 +274,7 @@ namespace NTwain
private Capabilities _caps;
///
- /// Get current device's capabilities. Will be null if no device is open.
+ /// Get current data source's capabilities. Will be null if no data source is open.
///
///
public Capabilities Capabilities
@@ -301,7 +290,60 @@ namespace NTwain
}
///
- /// Attempts to show the current device's settings dialog if supported.
+ /// Gets/sets the current source's settings as opaque data.
+ /// Returns null if not supported.
+ ///
+ public byte[] CustomDsData
+ {
+ get
+ {
+ TW_CUSTOMDSDATA data = default;
+ var sts = _twain.DatCustomdsdata(DG.CONTROL, MSG.GET, ref data);
+ if (sts == STS.SUCCESS)
+ {
+ if (data.hData != IntPtr.Zero && data.InfoLength > 0)
+ {
+ try
+ {
+ var lockedPtr = _twain.DsmMemLock(data.hData);
+ var bytes = new byte[data.InfoLength];
+ Marshal.Copy(lockedPtr, bytes, 0, bytes.Length);
+ }
+ finally
+ {
+ _twain.DsmMemUnlock(data.hData);
+ _twain.DsmMemFree(ref data.hData);
+ }
+ }
+ return EmptyArray.Value;
+ }
+ return null;
+ }
+ set
+ {
+ if (value == null || value.Length == 0) return;
+
+ TW_CUSTOMDSDATA data = default;
+ data.InfoLength = (uint)value.Length;
+ data.hData = _twain.DsmMemAlloc(data.InfoLength);
+ try
+ {
+ var lockedPtr = _twain.DsmMemLock(data.hData);
+ Marshal.Copy(value, 0, lockedPtr, value.Length);
+ _twain.DsmMemUnlock(data.hData);
+ var sts = _twain.DatCustomdsdata(DG.CONTROL, MSG.SET, ref data);
+ }
+ finally
+ {
+ // should be freed already if no error but just in case
+ if (data.hData != IntPtr.Zero) _twain.DsmMemFree(ref data.hData);
+ }
+ }
+ }
+
+
+ ///
+ /// Attempts to show the current data source's settings dialog if supported.
///
///
public STS ShowSettings()
@@ -313,9 +355,9 @@ namespace NTwain
}
///
- /// Begins the capture process on the current device.
+ /// Begins the capture process on the current data source.
///
- /// Whether to display settings UI. Not all devices support this.
+ /// Whether to display settings UI. Not all data sources support this.
///
public STS StartCapture(bool showUI)
{