public static extern ReturnCode DsmLinux32( [In, Out] TW_IDENTITY origin, [In, Out] TW_IDENTITY destination, DataGroups dg, DataArgumentType dat, Message msg, ref TW_SETUPMEMXFER data);
public static extern ReturnCode DsmLinux32( [In, Out] TW_IDENTITY origin, IntPtr zero, DataGroups dg, DataArgumentType dat, Message msg, [In, Out] TW_IDENTITY data);
public ReturnCode CloseDS(TW_IDENTITY source) { var rc = DoIt(Message.CloseDS, source); if (rc == ReturnCode.Success) { Session.State = TwainState.S3; Session.CurrentSource = null; } return(rc); }
public ReturnCode OpenDS(TW_IDENTITY source) { Session.StepDown(TwainState.DsmOpened); var rc = DoIt(Message.OpenDS, source); if (rc == ReturnCode.Success) { Session.CurrentSource = Session.GetSourceSingleton(source); Session.State = TwainState.S4; Session.RegisterCallback(); } return(rc); }
ReturnCode Handle32BitCallback(TW_IDENTITY origin, TW_IDENTITY destination, DataGroups dg, DataArgumentType dat, Message msg, IntPtr data) { // from the docs this needs to return Success // before handling the msg thus BeginInvoke is used. Debug.WriteLine($"Thread {Thread.CurrentThread.ManagedThreadId}: {nameof(Handle32BitCallback)}({dg}, {dat}, {msg}, {data})"); InternalBeginInvoke(() => { Debug.WriteLine($"Thread {Thread.CurrentThread.ManagedThreadId}: in BeginInvoke {nameof(Handle32BitCallback)}({dg}, {dat}, {msg}, {data})"); HandleSourceMsg(msg); }); Debug.WriteLine($"Thread {Thread.CurrentThread.ManagedThreadId}: after BeginInvoke {nameof(Handle32BitCallback)}({dg}, {dat}, {msg}, {data})"); return(ReturnCode.Success); }
internal DataSource GetSourceSingleton(TW_IDENTITY sourceId) { DataSource source = null; var key = $"{sourceId.Id}|{sourceId.Manufacturer}|{sourceId.ProductFamily}|{sourceId.ProductName}"; if (_ownedSources.ContainsKey(key)) { source = _ownedSources[key]; } else { _ownedSources[key] = source = new DataSource(this, sourceId); } return(source); }
ReturnCode DoIt(Message msg, TW_IDENTITY source) { if (Is32Bit) { if (IsWin) { return(NativeMethods.DsmWin32(Session.Config.App32, IntPtr.Zero, DataGroups.Control, DataArgumentType.Identity, msg, source)); } else if (IsLinux) { return(NativeMethods.DsmLinux32(Session.Config.App32, IntPtr.Zero, DataGroups.Control, DataArgumentType.Identity, msg, source)); } else if (IsMac) { return(NativeMethods.DsmMac32(Session.Config.App32, IntPtr.Zero, DataGroups.Control, DataArgumentType.Identity, msg, source)); } } else { if (IsWin) { return(NativeMethods.DsmWin64(Session.Config.App32, IntPtr.Zero, DataGroups.Control, DataArgumentType.Identity, msg, source)); } else if (IsLinux) { return(NativeMethods.DsmLinux64(Session.Config.App32, IntPtr.Zero, DataGroups.Control, DataArgumentType.Identity, msg, source)); } else if (IsMac) { return(NativeMethods.DsmMac64(Session.Config.App32, IntPtr.Zero, DataGroups.Control, DataArgumentType.Identity, msg, source)); } } return(ReturnCode.Failure); }
private static extern UInt16 Linux64DsmEntryPalette8 ( ref TW_IDENTITY origin, ref TW_IDENTITY dest, DG dg, DAT dat, MSG msg, ref TW_PALETTE8 twpalette8 );
private static extern UInt16 Linux64DsmEntryImagenativexfer ( ref TW_IDENTITY origin, ref TW_IDENTITY dest, DG dg, DAT dat, MSG msg, ref IntPtr intptrBitmap );
private static extern UInt16 Linux64DsmEntryImagelayout ( ref TW_IDENTITY origin, ref TW_IDENTITY dest, DG dg, DAT dat, MSG msg, ref TW_IMAGELAYOUT twimagelayout );
private static extern UInt16 Linux64DsmEntryImagefilexfer ( ref TW_IDENTITY origin, ref TW_IDENTITY dest, DG dg, DAT dat, MSG msg, IntPtr twmemref );
private static extern UInt16 Linux64DsmEntryGrayresponse ( ref TW_IDENTITY origin, ref TW_IDENTITY dest, DG dg, DAT dat, MSG msg, ref TW_GRAYRESPONSE twgrayresponse );
/// <summary> /// Convert a public identity to a legacy identity... /// </summary> /// <param name="a_twidentity">Identity to convert</param> /// <returns>Legacy form of identity</returns> private TW_IDENTITY_LEGACY TwidentityToTwidentitylegacy(TW_IDENTITY a_twidentity) { TW_IDENTITY_LEGACY twidentitylegacy = new TW_IDENTITY_LEGACY(); twidentitylegacy.Id = (uint)a_twidentity.Id; twidentitylegacy.Manufacturer = a_twidentity.Manufacturer; twidentitylegacy.ProductFamily = a_twidentity.ProductFamily; twidentitylegacy.ProductName = a_twidentity.ProductName; twidentitylegacy.ProtocolMajor = a_twidentity.ProtocolMajor; twidentitylegacy.ProtocolMinor = a_twidentity.ProtocolMinor; twidentitylegacy.SupportedGroups = a_twidentity.SupportedGroups; twidentitylegacy.Version.Country = a_twidentity.Version.Country; twidentitylegacy.Version.Info = a_twidentity.Version.Info; twidentitylegacy.Version.Language = a_twidentity.Version.Language; twidentitylegacy.Version.MajorNum = a_twidentity.Version.MajorNum; twidentitylegacy.Version.MinorNum = a_twidentity.Version.MinorNum; return (twidentitylegacy); }
private static extern UInt16 Linux64DsmEntryDeviceevent ( ref TW_IDENTITY origin, ref TW_IDENTITY dest, DG dg, DAT dat, MSG msg, ref TW_DEVICEEVENT twdeviceevent );
internal DataSource(TwainSession session, TW_IDENTITY src) { this.Session = session; this.Identity32 = src; ProtocolVersion = new Version(src.ProtocolMajor, src.ProtocolMinor); }
public ReturnCode GetNext(out TW_IDENTITY source) { source = new TW_IDENTITY(); return(DoIt(Message.GetNext, source)); }
/// <summary> /// Convert the contents of a string to an identity structure... /// </summary> /// <param name="a_twidentity">A TWAIN structure</param> /// <param name="a_szIdentity">A CSV string of the TWAIN structure</param> /// <returns>True if the conversion is successful</returns> public bool CsvToIdentity(ref TW_IDENTITY a_twidentity, string a_szIdentity) { // Init stuff... a_twidentity = default(TW_IDENTITY); // Build the string... try { string[] asz = CSV.Parse(a_szIdentity); // Grab the values... a_twidentity.Id = ulong.Parse(asz[0]); a_twidentity.Version.MajorNum = ushort.Parse(asz[1]); a_twidentity.Version.MinorNum = ushort.Parse(asz[2]); a_twidentity.Version.Language = (TWLG)Enum.Parse(typeof(TWLG), asz[3]); a_twidentity.Version.Country = (TWCY)Enum.Parse(typeof(TWCY), asz[4]); a_twidentity.Version.Info.Set(asz[5]); a_twidentity.ProtocolMajor = ushort.Parse(asz[6]); a_twidentity.ProtocolMinor = ushort.Parse(asz[7]); a_twidentity.SupportedGroups = asz[8].ToLower().StartsWith("0x") ? Convert.ToUInt32(asz[8].Remove(0, 2), 16) : Convert.ToUInt32(asz[8], 16); a_twidentity.Manufacturer.Set(asz[9]); a_twidentity.ProductFamily.Set(asz[10]); a_twidentity.ProductName.Set(asz[11]); } catch { return (false); } // All done... return (true); }
private static extern UInt16 Linux64DsmEntryEntrypoint ( ref TW_IDENTITY origin, ref TW_IDENTITY dest, DG dg, DAT dat, MSG msg, ref TW_ENTRYPOINT twentrypoint );
/// <summary> /// Convert a macosx identity to a public identity... /// </summary> /// <param name="a_twidentitymacosx">Mac OS X identity to convert</param> /// <returns>Regular identity</returns> private TW_IDENTITY TwidentitymacosxToTwidentity(TW_IDENTITY_MACOSX a_twidentitymacosx) { TW_IDENTITY twidentity = new TW_IDENTITY(); twidentity.Id = a_twidentitymacosx.Id; twidentity.Manufacturer = a_twidentitymacosx.Manufacturer; twidentity.ProductFamily = a_twidentitymacosx.ProductFamily; twidentity.ProductName = a_twidentitymacosx.ProductName; twidentity.ProtocolMajor = a_twidentitymacosx.ProtocolMajor; twidentity.ProtocolMinor = a_twidentitymacosx.ProtocolMinor; twidentity.SupportedGroups = a_twidentitymacosx.SupportedGroups; twidentity.Version.Country = a_twidentitymacosx.Version.Country; twidentity.Version.Info = a_twidentitymacosx.Version.Info; twidentity.Version.Language = a_twidentitymacosx.Version.Language; twidentity.Version.MajorNum = a_twidentitymacosx.Version.MajorNum; twidentity.Version.MinorNum = a_twidentitymacosx.Version.MinorNum; return (twidentity); }
private static extern UInt16 Linux64DsmEntryFilesystem ( ref TW_IDENTITY origin, ref TW_IDENTITY dest, DG dg, DAT dat, MSG msg, ref TW_FILESYSTEM twfilesystem );
private static extern UInt16 Linux64DsmEntryFilter ( ref TW_IDENTITY origin, ref TW_IDENTITY dest, DG dg, DAT dat, MSG msg, ref TW_FILTER twfilter );
private static extern UInt16 Linux64DsmEntryIdentity ( ref TW_IDENTITY origin, IntPtr dest, DG dg, DAT dat, MSG msg, ref TW_IDENTITY twidentity );
private static extern UInt16 Linux64DsmEntryIccprofile ( ref TW_IDENTITY origin, ref TW_IDENTITY dest, DG dg, DAT dat, MSG msg, ref TW_MEMORY twmemory );
private static extern UInt16 Linux64DsmEntryParent ( ref TW_IDENTITY origin, IntPtr dest, DG dg, DAT dat, MSG msg, ref IntPtr hwnd );
private static extern UInt16 Linux64DsmEntryImageinfo ( ref TW_IDENTITY origin, ref TW_IDENTITY dest, DG dg, DAT dat, MSG msg, ref TW_IMAGEINFO_LINUX64 twimageinfolinux64 );
private static extern UInt16 Linux64DsmEntryPassthru ( ref TW_IDENTITY origin, ref TW_IDENTITY dest, DG dg, DAT dat, MSG msg, ref TW_PASSTHRU twpassthru );
private static extern UInt16 Linux64DsmEntryImagememxfer ( ref TW_IDENTITY origin, ref TW_IDENTITY dest, DG dg, DAT dat, MSG msg, ref TW_IMAGEMEMXFER_LINUX64 twimagememxferlinux64 );
private static extern UInt16 Linux64DsmEntryPendingxfers ( ref TW_IDENTITY origin, ref TW_IDENTITY dest, DG dg, DAT dat, MSG msg, ref TW_PENDINGXFERS twpendingxfers );
private static extern UInt16 Linux64DsmEntryJpegcompression ( ref TW_IDENTITY origin, ref TW_IDENTITY dest, DG dg, DAT dat, MSG msg, ref TW_JPEGCOMPRESSION twjpegcompression );
private static extern UInt16 Linux64DsmEntrySetupmemxfer ( ref TW_IDENTITY origin, ref TW_IDENTITY dest, DG dg, DAT dat, MSG msg, ref TW_SETUPMEMXFER twsetupmemxfer );
private static extern UInt16 Linux64DsmEntryRgbresponse ( ref TW_IDENTITY origin, ref TW_IDENTITY dest, DG dg, DAT dat, MSG msg, ref TW_RGBRESPONSE twrgbresponse );
private static extern UInt16 Linux64DsmEntryStatusutf8 ( ref TW_IDENTITY origin, ref TW_IDENTITY dest, DG dg, DAT dat, MSG msg, ref TW_STATUSUTF8 twstatusutf8 );
/// <summary> /// Convert the contents of an identity to a string that we can show in /// our simple GUI... /// </summary> /// <param name="a_twidentity">A TWAIN structure</param> /// <returns>A CSV string of the TWAIN structure</returns> public string IdentityToCsv(TW_IDENTITY a_twidentity) { try { CSV csv = new CSV(); csv.Add(a_twidentity.Id.ToString()); csv.Add(a_twidentity.Version.MajorNum.ToString()); csv.Add(a_twidentity.Version.MinorNum.ToString()); csv.Add(a_twidentity.Version.Language.ToString()); csv.Add(a_twidentity.Version.Country.ToString()); csv.Add(a_twidentity.Version.Info.Get()); csv.Add(a_twidentity.ProtocolMajor.ToString()); csv.Add(a_twidentity.ProtocolMinor.ToString()); csv.Add("0x" + a_twidentity.SupportedGroups.ToString("X")); csv.Add(a_twidentity.Manufacturer.Get()); csv.Add(a_twidentity.ProductFamily.Get()); csv.Add(a_twidentity.ProductName.Get()); return (csv.Get()); } catch { return ("***error***"); } }
private static extern UInt16 Linux64DsmEntryUserinterface ( ref TW_IDENTITY origin, ref TW_IDENTITY dest, DG dg, DAT dat, MSG msg, ref TW_USERINTERFACE twuserinterface );
/// <summary> /// Issue identity commands... /// </summary> /// <param name="a_dg">Data group</param> /// <param name="a_msg">Operation</param> /// <param name="a_twidentity">IDENTITY structure</param> /// <returns>TWAIN status</returns> public STS DatIdentity(DG a_dg, MSG a_msg, ref TW_IDENTITY a_twidentity) { STS sts; // Submit the work to the TWAIN thread... if ((m_threadTwain != null) && (m_threadTwain.ManagedThreadId != Thread.CurrentThread.ManagedThreadId)) { lock (m_lockTwain) { // Set our command variables... ThreadData threaddata = default(ThreadData); threaddata.twidentity = a_twidentity; threaddata.dg = a_dg; threaddata.msg = a_msg; threaddata.dat = DAT.IDENTITY; long lIndex = m_twaincommand.Submit(threaddata); // Submit the command and wait for the reply... CallerToThreadSet(); ThreadToCallerWaitOne(); // Return the result... a_twidentity = m_twaincommand.Get(lIndex).twidentity; sts = m_twaincommand.Get(lIndex).sts; // Clear the command variables... m_twaincommand.Delete(lIndex); } return (sts); } // Log it... if (Log.GetLevel() > 0) { Log.LogSendBefore(a_dg.ToString(), DAT.IDENTITY.ToString(), a_msg.ToString(), ((a_msg == MSG.OPENDS) ? IdentityToCsv(a_twidentity) : "")); } // Windows... if (ms_platform == Platform.WINDOWS) { TW_IDENTITY_LEGACY twidentitylegacy = TwidentityToTwidentitylegacy(a_twidentity); // Issue the command... try { if (m_blUseLegacyDSM) { sts = (STS)WindowsTwain32DsmEntryIdentity(ref m_twidentitylegacyApp, IntPtr.Zero, a_dg, DAT.IDENTITY, a_msg, ref twidentitylegacy); } else { sts = (STS)WindowsTwaindsmDsmEntryIdentity(ref m_twidentitylegacyApp, IntPtr.Zero, a_dg, DAT.IDENTITY, a_msg, ref twidentitylegacy); } } catch { // The driver crashed... Log.LogSendAfter(STS.BUMMER.ToString(), ""); return (STS.BUMMER); } a_twidentity = TwidentitylegacyToTwidentity(twidentitylegacy); } // Linux... else if (ms_platform == Platform.LINUX) { // Issue the command... try { if (GetMachineWordBitSize() == 32) { TW_IDENTITY_LEGACY twidentitylegacy = TwidentityToTwidentitylegacy(a_twidentity); sts = (STS)LinuxDsmEntryIdentity(ref m_twidentitylegacyApp, IntPtr.Zero, a_dg, DAT.IDENTITY, a_msg, ref twidentitylegacy); a_twidentity = TwidentitylegacyToTwidentity(twidentitylegacy); } else { sts = (STS)Linux64DsmEntryIdentity(ref m_twidentityApp, IntPtr.Zero, a_dg, DAT.IDENTITY, a_msg, ref a_twidentity); } } catch { // The driver crashed... Log.LogSendAfter(STS.BUMMER.ToString(), ""); return (STS.BUMMER); } } // Mac OS X, which has to be different... else if (ms_platform == Platform.MACOSX) { TW_IDENTITY_MACOSX twidentitymacosx = TwidentityToTwidentitymacosx(a_twidentity); // Issue the command... try { sts = (STS)MacosxDsmEntryIdentity(ref m_twidentitymacosxApp, IntPtr.Zero, a_dg, DAT.IDENTITY, a_msg, ref twidentitymacosx); } catch { // The driver crashed... Log.LogSendAfter(STS.BUMMER.ToString(), ""); return (STS.BUMMER); } a_twidentity = TwidentitymacosxToTwidentity(twidentitymacosx); } // Uh-oh... else { Log.LogSendAfter(STS.BUMMER.ToString(), ""); return (STS.BUMMER); } // Log it... if (Log.GetLevel() > 0) { Log.LogSendAfter(sts.ToString(), IdentityToCsv(a_twidentity)); } // If we opened, go to state 4... if (a_msg == MSG.OPENDS) { if (sts == STS.SUCCESS) { // Change our state, and record the identity we picked... m_state = STATE.S4; m_twidentityDs = a_twidentity; m_twidentitylegacyDs = TwidentityToTwidentitylegacy(m_twidentityDs); m_twidentitymacosxDs = TwidentityToTwidentitymacosx(m_twidentityDs); // Register for callbacks... // Windows... if (ms_platform == Platform.WINDOWS) { if (m_blUseCallbacks) { TW_CALLBACK twcallback = new TW_CALLBACK(); twcallback.CallBackProc = Marshal.GetFunctionPointerForDelegate(m_windowsdsmentrycontrolcallbackdelegate); // Log it... if (Log.GetLevel() > 0) { Log.LogSendBefore(a_dg.ToString(), DAT.CALLBACK.ToString(), a_msg.ToString(), CallbackToCsv(twcallback)); } // Issue the command... try { if (m_blUseLegacyDSM) { sts = (STS)WindowsTwain32DsmEntryCallback(ref m_twidentitylegacyApp, ref m_twidentitylegacyDs, DG.CONTROL, DAT.CALLBACK, MSG.REGISTER_CALLBACK, ref twcallback); } else { sts = (STS)WindowsTwaindsmDsmEntryCallback(ref m_twidentitylegacyApp, ref m_twidentitylegacyDs, DG.CONTROL, DAT.CALLBACK, MSG.REGISTER_CALLBACK, ref twcallback); } } catch { // The driver crashed... Log.LogSendAfter(STS.BUMMER.ToString(), ""); return (STS.BUMMER); } // Log it... if (Log.GetLevel() > 0) { Log.LogSendAfter(sts.ToString(), ""); } } } // Linux... else if (ms_platform == Platform.LINUX) { TW_CALLBACK twcallback = new TW_CALLBACK(); twcallback.CallBackProc = Marshal.GetFunctionPointerForDelegate(m_linuxdsmentrycontrolcallbackdelegate); // Log it... if (Log.GetLevel() > 0) { Log.LogSendBefore(a_dg.ToString(), DAT.CALLBACK.ToString(), MSG.REGISTER_CALLBACK.ToString(), CallbackToCsv(twcallback)); } // Issue the command... try { if (TWAIN.GetMachineWordBitSize() == 32) { sts = (STS)LinuxDsmEntryCallback(ref m_twidentitylegacyApp, ref m_twidentitylegacyDs, DG.CONTROL, DAT.CALLBACK, MSG.REGISTER_CALLBACK, ref twcallback); } else { sts = (STS)Linux64DsmEntryCallback(ref m_twidentityApp, ref m_twidentityDs, DG.CONTROL, DAT.CALLBACK, MSG.REGISTER_CALLBACK, ref twcallback); } } catch { // The driver crashed... Log.LogSendAfter(STS.BUMMER.ToString(), ""); return (STS.BUMMER); } // Log it... if (Log.GetLevel() > 0) { Log.LogSendAfter(sts.ToString(), ""); } } // Mac OS X, which has to be different... else if (ms_platform == Platform.MACOSX) { IntPtr intptr = IntPtr.Zero; TW_CALLBACK twcallback = new TW_CALLBACK(); twcallback.CallBackProc = Marshal.GetFunctionPointerForDelegate(m_macosxdsmentrycontrolcallbackdelegate); // Log it... if (Log.GetLevel() > 0) { Log.LogSendBefore(a_dg.ToString(), DAT.CALLBACK.ToString(), a_msg.ToString(), CallbackToCsv(twcallback)); } // Issue the command... try { sts = (STS)MacosxDsmEntryCallback(ref m_twidentitymacosxApp, intptr, DG.CONTROL, DAT.CALLBACK, MSG.REGISTER_CALLBACK, ref twcallback); } catch { // The driver crashed... Log.LogSendAfter(STS.BUMMER.ToString(), ""); return (STS.BUMMER); } // Log it... if (Log.GetLevel() > 0) { Log.LogSendAfter(sts.ToString(), ""); } } } } // If we closed, go to state 3... else if (a_msg == MSG.CLOSEDS) { if (sts == STS.SUCCESS) { m_state = STATE.S3; } } // All done... return (AutoDatStatus(sts)); }
private static extern UInt16 Linux64DsmEntryXfergroup ( ref TW_IDENTITY origin, ref TW_IDENTITY dest, DG dg, DAT dat, MSG msg, ref UInt32 twuint32 );
/// <summary> /// Convert a public identity to a macosx identity... /// </summary> /// <param name="a_twidentity">Identity to convert</param> /// <returns>Mac OS X form of identity</returns> public static TW_IDENTITY_MACOSX TwidentityToTwidentitymacosx(TW_IDENTITY a_twidentity) { TW_IDENTITY_MACOSX twidentitymacosx = new TW_IDENTITY_MACOSX(); twidentitymacosx.Id = (uint)a_twidentity.Id; twidentitymacosx.Manufacturer = a_twidentity.Manufacturer; twidentitymacosx.ProductFamily = a_twidentity.ProductFamily; twidentitymacosx.ProductName = a_twidentity.ProductName; twidentitymacosx.ProtocolMajor = a_twidentity.ProtocolMajor; twidentitymacosx.ProtocolMinor = a_twidentity.ProtocolMinor; twidentitymacosx.SupportedGroups = a_twidentity.SupportedGroups; twidentitymacosx.Version.Country = a_twidentity.Version.Country; twidentitymacosx.Version.Info = a_twidentity.Version.Info; twidentitymacosx.Version.Language = a_twidentity.Version.Language; twidentitymacosx.Version.MajorNum = a_twidentity.Version.MajorNum; twidentitymacosx.Version.MinorNum = a_twidentity.Version.MinorNum; return (twidentitymacosx); }
private static extern UInt16 Linux64DsmEntryCiecolor ( ref TW_IDENTITY origin, ref TW_IDENTITY dest, DG dg, DAT dat, MSG msg, ref TW_CIECOLOR twciecolor );
private static extern UInt16 Linux64DsmEntryExtimageinfo ( ref TW_IDENTITY origin, ref TW_IDENTITY dest, DG dg, DAT dat, MSG msg, ref TW_EXTIMAGEINFO twextimageinfo );
public ReturnCode UserSelect(out TW_IDENTITY source) { source = new TW_IDENTITY(); return(DoIt(Message.UserSelect, source)); }