/// <summary> /// 设置当前传输模式 /// </summary> /// <param name="transferMode"></param> /// <returns></returns> private bool SetTwainTransferMode(string transferMode) { string szTwmemref = "ICAP_XFERMECH"; string szStatus = ""; TWAIN.STS sts; sts = m_twaincstoolkit.Send("DG_CONTROL", "DAT_CAPABILITY", "MSG_GETCURRENT", ref szTwmemref, ref szStatus); string[] pros = (szTwmemref + "").Split(','); pros[3] = transferMode; szTwmemref = String.Join(",", pros); sts = m_twaincstoolkit.Send("DG_CONTROL", "DAT_CAPABILITY", "MSG_SET", ref szTwmemref, ref szStatus); return((sts == TWAIN.STS.SUCCESS) ? true : false); }
private void SetSelectedSource(int idx) { btnAddScan.Enabled = false; if (Sources.Any() && Sources[idx] != null) { var identity = Sources[idx].Identity; var status = ""; TwainToolkit.Send("DG_CONTROL", "DAT_IDENTITY", "MSG_SET", ref identity, ref status); if (TwainToolkit.Send("DG_CONTROL", "DAT_IDENTITY", "MSG_OPENDS", ref identity, ref status) != TWAINCSToolkit.STS.SUCCESS) { HandleError(Resources.ErrorCannotConnectToSource); return; } var capabilities = "ICAP_XFERMECH,TWON_ONEVALUE,TWTY_UINT16,2"; if (TwainToolkit.Send("DG_CONTROL", "DAT_CAPABILITY", "MSG_SET", ref capabilities, ref status) != TWAINCSToolkit.STS.SUCCESS) { HandleError(Resources.ErrorCannotSetSourceCapabilities); return; } capabilities = "CAP_INDICATORS,TWON_ONEVALUE,TWTY_UINT16," + (Settings.Default.ShowDriverMessages ? "1" : "0"); if (TwainToolkit.Send("DG_CONTROL", "DAT_CAPABILITY", "MSG_SET", ref capabilities, ref status) != TWAINCSToolkit.STS.SUCCESS) { HandleError(Resources.ErrorCannotSetSourceCapabilities); return; } btnAddScan.Enabled = true; } }
public FormSetup(ref TWAINCSToolkit a_twaincstoolkit, string a_szProductDirectory) { TWAIN.STS sts; string szStatus; string szCapability; string szUsrUiSettings; // Init stuff... InitializeComponent(); // More init stuff... this.FormClosing += new FormClosingEventHandler(FormSetup_FormClosing); // Init more stuff (the order matters). ApplicationData means the following: // Windows: C:\Users\USERNAME\AppData\Roaming (or C:\Documents and Settings\USERNAME\Application Data on XP) // Linux: /home/USERNAME/.config (or /root/.config for superuser) // Mac OS X: /Users/USERNAME/.config (or /var/root/.config for superuser) m_twaincstoolkit = a_twaincstoolkit; m_szTwainscanFolder = Path.Combine(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Personal), "twain"), "twaincsscan"); m_szSettingsFolder = Path.Combine(m_szTwainscanFolder, "settings"); m_szSettingsFolder = Path.Combine(m_szSettingsFolder, a_szProductDirectory); if (!Directory.Exists(m_szTwainscanFolder)) { try { Directory.CreateDirectory(m_szTwainscanFolder); } catch (Exception exception) { TWAINWorkingGroup.Log.Error("exception - " + exception.Message); m_szTwainscanFolder = Directory.GetCurrentDirectory(); } } // Restore values... m_textboxFolder.Text = RestoreFolder(); m_textboxUseUiSettings.Text = ""; // Make sure we prime the value... m_twaincstoolkit.SetImagePath(m_textboxFolder.Text, 0); // Check for support of Custom DS Data... szStatus = ""; szCapability = "CAP_CUSTOMDSDATA"; sts = m_twaincstoolkit.Send("DG_CONTROL", "DAT_CAPABILITY", "MSG_GETCURRENT", ref szCapability, ref szStatus); if ((sts != TWAIN.STS.SUCCESS) || !szCapability.EndsWith(",1")) { m_labelUseUiSettings.Enabled = false; m_textboxUseUiSettings.Enabled = false; m_buttonSaveUiSettings.Enabled = false; m_buttonUseUiSettings.Enabled = false; } // Restore the last saved snapshot... else { m_textboxUseUiSettings.Text = RestoreSetting(); if (m_textboxUseUiSettings.Text != "") { szUsrUiSettings = Path.Combine(m_szSettingsFolder, m_textboxUseUiSettings.Text); if (File.Exists(szUsrUiSettings)) { m_twaincstoolkit.RestoreSnapshot(szUsrUiSettings); } else { m_textboxUseUiSettings.Text = ""; } } } }
/// <summary> /// 初始化设备 /// </summary> /// <param name="devName"></param> public bool InitDevice(string devName) { _scanDevName = devName; string szStatus = ""; if (_scanCore == null) { InitCore(); } _scanCore.Send("DG_CONTROL", "DAT_IDENTITY", "MSG_SET", ref _scanDevName, ref szStatus); // Open it... TWAIN.STS sts = _scanCore.Send("DG_CONTROL", "DAT_IDENTITY", "MSG_OPENDS", ref _scanDevName, ref szStatus); if (sts != TWAIN.STS.SUCCESS) { //MessageBox.Show("Unable to open scanner (it is turned on and plugged in?)"); return(false); } // Strip off unsafe chars. Sadly, mono let's us down here... m_szProductDirectory = TWAINCSToolkit.CsvParse(_scanDevName)[11]; foreach (char c in new char[41] { '\x00', '\x01', '\x02', '\x03', '\x04', '\x05', '\x06', '\x07', '\x08', '\x09', '\x0A', '\x0B', '\x0C', '\x0D', '\x0E', '\x0F', '\x10', '\x11', '\x12', '\x13', '\x14', '\x15', '\x16', '\x17', '\x18', '\x19', '\x1A', '\x1B', '\x1C', '\x1D', '\x1E', '\x1F', '\x22', '\x3C', '\x3E', '\x7C', ':', '*', '?', '\\', '/' } ) { m_szProductDirectory = m_szProductDirectory.Replace(c, '_'); } szStatus = ""; string szCapability = "ICAP_XFERMECH,TWON_ONEVALUE,TWTY_UINT16,2"; sts = _scanCore.Send("DG_CONTROL", "DAT_CAPABILITY", "MSG_SET", ref szCapability, ref szStatus); if (sts != TWAIN.STS.SUCCESS) { return(false); } // Decide whether or not to show the driver's window messages... szStatus = ""; szCapability = "CAP_INDICATORS,TWON_ONEVALUE,TWTY_BOOL," + (m_blIndicators ? "1" : "0"); sts = _scanCore.Send("DG_CONTROL", "DAT_CAPABILITY", "MSG_SET", ref szCapability, ref szStatus); if (sts != TWAIN.STS.SUCCESS) { return(false); } if (m_formsetup == null) { m_formsetup = new FormSetup(ref _scanCore, m_szProductDirectory); } return(true); }