mirror of
https://github.com/soukoku/ntwain.git
synced 2025-07-15 16:28:53 +08:00
Renamed TwainSession to TwainAppSession. I love renaming things.
This commit is contained in:
parent
946238c308
commit
5678fd3e77
13
README.md
13
README.md
@ -1,22 +1,23 @@
|
|||||||
# TWAIN dotnet library
|
# TWAIN dotnet library
|
||||||
|
|
||||||
NOTE: This is a rewrite test that internally uses parts of
|
NOTE: This is a rewrite test that doesn't fully work yet.
|
||||||
[twaincs](https://github.com/twain/twain-cs) from
|
|
||||||
the TWAIN Working Group. It doesn't fully work yet.
|
|
||||||
Use V3 branch for the current version.
|
Use V3 branch for the current version.
|
||||||
|
|
||||||
## Info
|
## Info
|
||||||
|
|
||||||
This is a dotnet library created to make working with
|
This is a dotnet library created to make working with
|
||||||
[TWAIN](http://twain.org/) devices easier in dotnet.
|
[TWAIN](http://twain.org/) devices easier in dotnet.
|
||||||
V4 of this lib has these goals:
|
It internally uses some parts of the
|
||||||
|
[twaincs](https://github.com/twain/twain-cs) code from
|
||||||
|
the TWAIN Working Group.
|
||||||
|
V4 of this lib has these features:
|
||||||
|
|
||||||
* Targets latest TWAIN version (2.5).
|
* Targets latest TWAIN version (2.5).
|
||||||
* Supports full framework and netcore apps (if the framework is still supported).
|
* Runs under full framework (4.6.2+) and netcore variants (6.0+).
|
||||||
|
|
||||||
## Using the lib
|
## Using the lib
|
||||||
|
|
||||||
Before using this lib, you are recommended to become reasonably
|
Before using this lib, you are required to be reasonably
|
||||||
familiar with the TWAIN spec and understand how it works in general.
|
familiar with the TWAIN spec and understand how it works in general.
|
||||||
The TWAIN spec can be downloaded from [twain.org](http://twain.org/).
|
The TWAIN spec can be downloaded from [twain.org](http://twain.org/).
|
||||||
|
|
||||||
|
@ -10,7 +10,7 @@ namespace WinForm32
|
|||||||
{
|
{
|
||||||
public partial class Form1 : Form
|
public partial class Form1 : Form
|
||||||
{
|
{
|
||||||
private TwainSession twain;
|
private TwainAppSession twain;
|
||||||
|
|
||||||
public Form1()
|
public Form1()
|
||||||
{
|
{
|
||||||
@ -18,7 +18,7 @@ namespace WinForm32
|
|||||||
Text += TwainPlatform.Is32bit ? " 32bit" : " 64bit";
|
Text += TwainPlatform.Is32bit ? " 32bit" : " 64bit";
|
||||||
TwainPlatform.PreferLegacyDSM = false;
|
TwainPlatform.PreferLegacyDSM = false;
|
||||||
|
|
||||||
twain = new TwainSession(new WinformMarshaller(this), Assembly.GetExecutingAssembly().Location);
|
twain = new TwainAppSession(new WinformMarshaller(this), Assembly.GetExecutingAssembly().Location);
|
||||||
twain.StateChanged += Twain_StateChanged;
|
twain.StateChanged += Twain_StateChanged;
|
||||||
twain.DefaultSourceChanged += Twain_DefaultSourceChanged;
|
twain.DefaultSourceChanged += Twain_DefaultSourceChanged;
|
||||||
twain.CurrentSourceChanged += Twain_CurrentSourceChanged;
|
twain.CurrentSourceChanged += Twain_CurrentSourceChanged;
|
||||||
@ -31,17 +31,17 @@ namespace WinForm32
|
|||||||
twain.Dispose();
|
twain.Dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Twain_CurrentSourceChanged(TwainSession arg1, TW_IDENTITY_LEGACY ds)
|
private void Twain_CurrentSourceChanged(TwainAppSession arg1, TW_IDENTITY_LEGACY ds)
|
||||||
{
|
{
|
||||||
lblCurrent.Text = ds.ProductName;
|
lblCurrent.Text = ds.ProductName;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Twain_DefaultSourceChanged(TwainSession arg1, TW_IDENTITY_LEGACY ds)
|
private void Twain_DefaultSourceChanged(TwainAppSession arg1, TW_IDENTITY_LEGACY ds)
|
||||||
{
|
{
|
||||||
lblDefault.Text = ds.ProductName;
|
lblDefault.Text = ds.ProductName;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Twain_StateChanged(TwainSession session, STATE state)
|
private void Twain_StateChanged(TwainAppSession session, STATE state)
|
||||||
{
|
{
|
||||||
lblState.Text = state.ToString();
|
lblState.Text = state.ToString();
|
||||||
}
|
}
|
||||||
|
@ -6,14 +6,14 @@
|
|||||||
<#@ import namespace="System.Collections.Generic" #>
|
<#@ import namespace="System.Collections.Generic" #>
|
||||||
<#@ output extension="dummy" #>
|
<#@ output extension="dummy" #>
|
||||||
<#
|
<#
|
||||||
List<(string className, string dllPath, string identityClass)> outputs = new() {
|
List<(string className, string dllPath, string identityClass, string addlInfo)> outputs = new() {
|
||||||
("OSXLegacyDSM", "/System/Library/Frameworks/framework/TWAIN", "TW_IDENTITY_MACOSX"),
|
("OSXLegacyDSM", "/System/Library/Frameworks/framework/TWAIN", "TW_IDENTITY_MACOSX", ""),
|
||||||
("OSXNewDSM", "/Library/Frameworks/TWAINDSM.framework/TWAINDSM", "TW_IDENTITY_MACOSX"),
|
("OSXNewDSM", "/Library/Frameworks/TWAINDSM.framework/TWAINDSM", "TW_IDENTITY_MACOSX", ""),
|
||||||
("LinuxDSM", "/usr/local/lib/libtwaindsm.so", "TW_IDENTITY_LEGACY"),
|
("LinuxDSM", "/usr/local/lib/libtwaindsm.so", "TW_IDENTITY_LEGACY", ""),
|
||||||
("Linux64DSM", "/usr/local/lib64/libtwaindsm.so", "TW_IDENTITY_LEGACY"),
|
("Linux64DSM", "/usr/local/lib64/libtwaindsm.so", "TW_IDENTITY_LEGACY", "For versions since 2.4."),
|
||||||
("LinuxBotched64DSM", "/usr/local/lib/libtwaindsm.so.2.3.2", "TW_IDENTITY"),
|
("LinuxBotched64DSM", "/usr/local/lib/libtwaindsm.so.2.3.2", "TW_IDENTITY", "For versions before 2.4."),
|
||||||
("WinLegacyDSM", "twain_32.dll", "TW_IDENTITY_LEGACY"),
|
("WinLegacyDSM", "twain_32.dll", "TW_IDENTITY_LEGACY", "For 32bit only."),
|
||||||
("WinNewDSM", "twaindsm.dll", "TW_IDENTITY_LEGACY")
|
("WinNewDSM", "twaindsm.dll", "TW_IDENTITY_LEGACY", "")
|
||||||
};
|
};
|
||||||
|
|
||||||
foreach(var file in outputs) {
|
foreach(var file in outputs) {
|
||||||
@ -25,7 +25,7 @@ using System.Runtime.InteropServices;
|
|||||||
namespace NTwain.DSM
|
namespace NTwain.DSM
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Low-level pinvoke methods using <#= file.dllPath #>.
|
/// Low-level pinvoke methods using <#= file.dllPath #>. <#= file.addlInfo #>
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static class <#= file.className #>
|
public static class <#= file.className #>
|
||||||
{
|
{
|
||||||
|
@ -5,7 +5,7 @@ using System.Runtime.InteropServices;
|
|||||||
namespace NTwain.DSM
|
namespace NTwain.DSM
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Low-level pinvoke methods using /usr/local/lib64/libtwaindsm.so.
|
/// Low-level pinvoke methods using /usr/local/lib64/libtwaindsm.so. For versions since 2.4.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static class Linux64DSM
|
public static class Linux64DSM
|
||||||
{
|
{
|
||||||
|
@ -5,7 +5,7 @@ using System.Runtime.InteropServices;
|
|||||||
namespace NTwain.DSM
|
namespace NTwain.DSM
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Low-level pinvoke methods using /usr/local/lib/libtwaindsm.so.2.3.2.
|
/// Low-level pinvoke methods using /usr/local/lib/libtwaindsm.so.2.3.2. For versions before 2.4.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static class LinuxBotched64DSM
|
public static class LinuxBotched64DSM
|
||||||
{
|
{
|
||||||
|
@ -5,7 +5,7 @@ using System.Runtime.InteropServices;
|
|||||||
namespace NTwain.DSM
|
namespace NTwain.DSM
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Low-level pinvoke methods using /usr/local/lib/libtwaindsm.so.
|
/// Low-level pinvoke methods using /usr/local/lib/libtwaindsm.so.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static class LinuxDSM
|
public static class LinuxDSM
|
||||||
{
|
{
|
||||||
|
@ -5,7 +5,7 @@ using System.Runtime.InteropServices;
|
|||||||
namespace NTwain.DSM
|
namespace NTwain.DSM
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Low-level pinvoke methods using /System/Library/Frameworks/framework/TWAIN.
|
/// Low-level pinvoke methods using /System/Library/Frameworks/framework/TWAIN.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static class OSXLegacyDSM
|
public static class OSXLegacyDSM
|
||||||
{
|
{
|
||||||
|
@ -5,7 +5,7 @@ using System.Runtime.InteropServices;
|
|||||||
namespace NTwain.DSM
|
namespace NTwain.DSM
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Low-level pinvoke methods using /Library/Frameworks/TWAINDSM.framework/TWAINDSM.
|
/// Low-level pinvoke methods using /Library/Frameworks/TWAINDSM.framework/TWAINDSM.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static class OSXNewDSM
|
public static class OSXNewDSM
|
||||||
{
|
{
|
||||||
|
@ -5,7 +5,7 @@ using System.Runtime.InteropServices;
|
|||||||
namespace NTwain.DSM
|
namespace NTwain.DSM
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Low-level pinvoke methods using twain_32.dll.
|
/// Low-level pinvoke methods using twain_32.dll. For 32bit only.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static class WinLegacyDSM
|
public static class WinLegacyDSM
|
||||||
{
|
{
|
||||||
|
@ -5,7 +5,7 @@ using System.Runtime.InteropServices;
|
|||||||
namespace NTwain.DSM
|
namespace NTwain.DSM
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Low-level pinvoke methods using twaindsm.dll.
|
/// Low-level pinvoke methods using twaindsm.dll.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static class WinNewDSM
|
public static class WinNewDSM
|
||||||
{
|
{
|
||||||
|
@ -724,8 +724,7 @@ namespace NTwain.Data
|
|||||||
|
|
||||||
//// unsafe method with 1 copy (does it work?)
|
//// unsafe method with 1 copy (does it work?)
|
||||||
//sbyte* bytes = (sbyte*)locked;
|
//sbyte* bytes = (sbyte*)locked;
|
||||||
//var str = new string(bytes, 0, length, Encoding.UTF8);
|
//val = new string(bytes, 0, length, Encoding.UTF8);
|
||||||
//return str;
|
|
||||||
#else
|
#else
|
||||||
val = Marshal.PtrToStringUTF8(locked, (int)Size);
|
val = Marshal.PtrToStringUTF8(locked, (int)Size);
|
||||||
#endif
|
#endif
|
||||||
|
@ -7,7 +7,7 @@ namespace NTwain
|
|||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// An <see cref="IThreadMarshaller"/> that can be used
|
/// An <see cref="IThreadMarshaller"/> that can be used
|
||||||
/// to integrate <see cref="TwainSession"/> with
|
/// to integrate <see cref="TwainAppSession"/> with
|
||||||
/// an existing Winforms app.
|
/// an existing Winforms app.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class WinformMarshaller : IThreadMarshaller
|
public class WinformMarshaller : IThreadMarshaller
|
||||||
@ -32,7 +32,7 @@ namespace NTwain
|
|||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// An <see cref="IThreadMarshaller"/> that can be used
|
/// An <see cref="IThreadMarshaller"/> that can be used
|
||||||
/// to integrate <see cref="TwainSession"/> with
|
/// to integrate <see cref="TwainAppSession"/> with
|
||||||
/// an existing WPF app.
|
/// an existing WPF app.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class WpfMarshaller : IThreadMarshaller
|
public class WpfMarshaller : IThreadMarshaller
|
||||||
|
@ -1,21 +1,20 @@
|
|||||||
All TWAIN operations are done through the a combination of
|
All TWAIN operations are done through the a combination of
|
||||||
Data Group (DG), Data Argument Type (DAT), and Message (MSG)
|
Data Group (DG), Data Argument Type (DAT), and Message (MSG)
|
||||||
triplets. Rather than dealing with all the combinations
|
triplets. Rather than dealing with all the combinations
|
||||||
directly and risk passing the wrong thing, all valid triplet
|
directly in the DSM pinvokes and risk passing the wrong thing,
|
||||||
combinations are simply made available under this namespace.
|
all valid triplet combinations are made available under this namespace.
|
||||||
|
|
||||||
Example:
|
Example:
|
||||||
To get the status of the DS, just use the
|
To get the status of the DS, the triplet is
|
||||||
"Get" method (represents MSG), in the
|
`DG_Control / DAT_STATUS / MSG_GET` in the documentation.
|
||||||
"Status" property (represnts DAT), in the
|
With this wrapper you can use a similar call path:
|
||||||
"DGControl" class (represents DG).
|
|
||||||
|
|
||||||
or better explained in code:
|
```cs
|
||||||
|
DGControl.Status.Get(...);
|
||||||
|
```
|
||||||
|
|
||||||
DGControl.Status.Get(...)
|
Only triplets usable by the application-side are defined here.
|
||||||
|
|
||||||
Only triplets usable by the
|
These are still relatively low-level calls and `TwainAppSession` is the next higher
|
||||||
application-side are defined here.
|
level abstraction with some state keeping and other dotnet-friendly methods
|
||||||
|
and events for regular use.
|
||||||
These are still low-level calls and TwainSession is the higher
|
|
||||||
level abstraction with some state keeping and other checks for ease of use.
|
|
||||||
|
@ -8,7 +8,7 @@ namespace NTwain
|
|||||||
{
|
{
|
||||||
// this file contains callback methods
|
// this file contains callback methods
|
||||||
|
|
||||||
partial class TwainSession
|
partial class TwainAppSession
|
||||||
{
|
{
|
||||||
|
|
||||||
delegate ushort LegacyIDCallbackDelegate(
|
delegate ushort LegacyIDCallbackDelegate(
|
@ -7,7 +7,7 @@ namespace NTwain
|
|||||||
{
|
{
|
||||||
// this file contains capability mgmt methods
|
// this file contains capability mgmt methods
|
||||||
|
|
||||||
partial class TwainSession
|
partial class TwainAppSession
|
||||||
{
|
{
|
||||||
///// <summary>
|
///// <summary>
|
||||||
///// Gets all the supported caps for the current source.
|
///// Gets all the supported caps for the current source.
|
@ -7,7 +7,7 @@ namespace NTwain
|
|||||||
{
|
{
|
||||||
// this file contains memory methods
|
// this file contains memory methods
|
||||||
|
|
||||||
partial class TwainSession : IMemoryManager
|
partial class TwainAppSession : IMemoryManager
|
||||||
{
|
{
|
||||||
internal TW_ENTRYPOINT_DELEGATES _entryPoint;
|
internal TW_ENTRYPOINT_DELEGATES _entryPoint;
|
||||||
|
|
@ -7,7 +7,7 @@ namespace NTwain
|
|||||||
{
|
{
|
||||||
// this file contains property and event definitions
|
// this file contains property and event definitions
|
||||||
|
|
||||||
partial class TwainSession
|
partial class TwainAppSession
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the app identity.
|
/// Gets the app identity.
|
||||||
@ -119,22 +119,22 @@ namespace NTwain
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Fires when <see cref="State"/> changes.
|
/// Fires when <see cref="State"/> changes.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public event Action<TwainSession, STATE>? StateChanged;
|
public event Action<TwainAppSession, STATE>? StateChanged;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Fires when <see cref="DefaultSource"/> changes.
|
/// Fires when <see cref="DefaultSource"/> changes.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public event Action<TwainSession, TW_IDENTITY_LEGACY>? DefaultSourceChanged;
|
public event Action<TwainAppSession, TW_IDENTITY_LEGACY>? DefaultSourceChanged;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Fires when <see cref="CurrentSource"/> changes.
|
/// Fires when <see cref="CurrentSource"/> changes.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public event Action<TwainSession, TW_IDENTITY_LEGACY>? CurrentSourceChanged;
|
public event Action<TwainAppSession, TW_IDENTITY_LEGACY>? CurrentSourceChanged;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Fires when the source has some device event happening.
|
/// Fires when the source has some device event happening.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public event Action<TwainSession, TW_DEVICEEVENT>? DeviceEvent;
|
public event Action<TwainAppSession, TW_DEVICEEVENT>? DeviceEvent;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Fires when there's an error during transfer.
|
/// Fires when there's an error during transfer.
|
@ -6,7 +6,7 @@ namespace NTwain
|
|||||||
{
|
{
|
||||||
// this file contains data source utilities
|
// this file contains data source utilities
|
||||||
|
|
||||||
partial class TwainSession
|
partial class TwainAppSession
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets all available sources.
|
/// Gets all available sources.
|
@ -15,7 +15,7 @@ namespace NTwain
|
|||||||
|
|
||||||
// contains parts for winform/wpf message loop integration
|
// contains parts for winform/wpf message loop integration
|
||||||
|
|
||||||
partial class TwainSession : IMessageFilter
|
partial class TwainAppSession : IMessageFilter
|
||||||
{
|
{
|
||||||
HwndSource? _wpfhook;
|
HwndSource? _wpfhook;
|
||||||
|
|
@ -10,7 +10,7 @@ namespace NTwain
|
|||||||
{
|
{
|
||||||
// this file contains various xfer methods
|
// this file contains various xfer methods
|
||||||
|
|
||||||
partial class TwainSession
|
partial class TwainAppSession
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Start the transfer loop.
|
/// Start the transfer loop.
|
@ -11,7 +11,7 @@ namespace NTwain
|
|||||||
{
|
{
|
||||||
// this file contains initialization/cleanup things.
|
// this file contains initialization/cleanup things.
|
||||||
|
|
||||||
public partial class TwainSession : IDisposable
|
public partial class TwainAppSession : IDisposable
|
||||||
{
|
{
|
||||||
static bool __encodingRegistered;
|
static bool __encodingRegistered;
|
||||||
|
|
||||||
@ -22,7 +22,7 @@ namespace NTwain
|
|||||||
/// <param name="exeFilePath"></param>
|
/// <param name="exeFilePath"></param>
|
||||||
/// <param name="appLanguage"></param>
|
/// <param name="appLanguage"></param>
|
||||||
/// <param name="appCountry"></param>
|
/// <param name="appCountry"></param>
|
||||||
public TwainSession(IThreadMarshaller uiThreadMarshaller,
|
public TwainAppSession(IThreadMarshaller uiThreadMarshaller,
|
||||||
string exeFilePath,
|
string exeFilePath,
|
||||||
TWLG appLanguage = TWLG.ENGLISH_USA, TWCY appCountry = TWCY.USA) :
|
TWLG appLanguage = TWLG.ENGLISH_USA, TWCY appCountry = TWCY.USA) :
|
||||||
this(uiThreadMarshaller, FileVersionInfo.GetVersionInfo(exeFilePath), appLanguage, appCountry)
|
this(uiThreadMarshaller, FileVersionInfo.GetVersionInfo(exeFilePath), appLanguage, appCountry)
|
||||||
@ -34,7 +34,7 @@ namespace NTwain
|
|||||||
/// <param name="appInfo"></param>
|
/// <param name="appInfo"></param>
|
||||||
/// <param name="appLanguage"></param>
|
/// <param name="appLanguage"></param>
|
||||||
/// <param name="appCountry"></param>
|
/// <param name="appCountry"></param>
|
||||||
public TwainSession(IThreadMarshaller uiThreadMarshaller,
|
public TwainAppSession(IThreadMarshaller uiThreadMarshaller,
|
||||||
FileVersionInfo appInfo,
|
FileVersionInfo appInfo,
|
||||||
TWLG appLanguage = TWLG.ENGLISH_USA, TWCY appCountry = TWCY.USA) :
|
TWLG appLanguage = TWLG.ENGLISH_USA, TWCY appCountry = TWCY.USA) :
|
||||||
this(uiThreadMarshaller,
|
this(uiThreadMarshaller,
|
||||||
@ -56,7 +56,7 @@ namespace NTwain
|
|||||||
/// <param name="appLanguage"></param>
|
/// <param name="appLanguage"></param>
|
||||||
/// <param name="appCountry"></param>
|
/// <param name="appCountry"></param>
|
||||||
/// <param name="supportedTypes"></param>
|
/// <param name="supportedTypes"></param>
|
||||||
public TwainSession(IThreadMarshaller uiThreadMarshaller,
|
public TwainAppSession(IThreadMarshaller uiThreadMarshaller,
|
||||||
string companyName, string productFamily, string productName,
|
string companyName, string productFamily, string productName,
|
||||||
Version productVersion, string productDescription = "",
|
Version productVersion, string productDescription = "",
|
||||||
TWLG appLanguage = TWLG.ENGLISH_USA, TWCY appCountry = TWCY.USA,
|
TWLG appLanguage = TWLG.ENGLISH_USA, TWCY appCountry = TWCY.USA,
|
Loading…
Reference in New Issue
Block a user