/////////////////////////////////////////////////////////////////////////////// // Public Methods... /////////////////////////////////////////////////////////////////////////////// #region Public Methods... /// <summary> /// Our constructor... /// </summary> /// <param name="a_aszIdentity">list of scanners to show</param> /// <param name="a_szDefault">the default selection</param> public FormSelect(string[] a_aszIdentity, string a_szDefault) { string[] aszIdentity; string[] aszDefault; // Init stuff... InitializeComponent(); // Explode the default... aszDefault = TWAINCSToolkit.CsvParse(a_szDefault); // Suspend updating... m_listboxSelect.BeginUpdate(); // Populate our driver list... foreach (string sz in a_aszIdentity) { aszIdentity = TWAINCSToolkit.CsvParse(sz); m_listboxSelect.Items.Add(aszIdentity[11].ToString()); } // Select the default... m_listboxSelect.SelectedIndex = m_listboxSelect.FindStringExact(aszDefault[11]); // Resume updating... m_listboxSelect.EndUpdate(); }
private void ParseSources(string[] sources) { Sources = new List <Source>(); cmbSources.Items.Clear(); foreach (var source in sources) { var info = TWAINCSToolkit.CsvParse(source); Sources.Add(new Source() { Identity = source, Manufacturer = info[9], ProductFamily = info[10], ProductName = info[11] }); } cmbSources.Items.Add(Sources[0].ProductName); cmbSources.SelectedIndex = 0; }
/// <summary> /// Select and open a TWAIN driver... /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void m_buttonOpen_Click(object sender, EventArgs e) { string szIdentity; string szCapability; string szDefault; string szStatus; string[] aszIdentity; FormSelect formselect; DialogResult dialogresult; TWAIN.STS sts; // Find out which driver we're using... szDefault = ""; aszIdentity = m_twaincstoolkit.GetDrivers(ref szDefault); if (aszIdentity == null) { MessageBox.Show("There are no TWAIN drivers installed on this system..."); return; } // Instantiate our form... formselect = new FormSelect(aszIdentity, szDefault); formselect.StartPosition = FormStartPosition.CenterParent; dialogresult = formselect.ShowDialog(this); if (dialogresult != System.Windows.Forms.DialogResult.OK) { m_blExit = true; return; } // Get all the identities... szIdentity = formselect.GetSelectedDriver(); if (szIdentity == null) { m_blExit = true; return; } // Get the selected identity... m_blExit = true; foreach (string sz in aszIdentity) { if (sz.Contains(szIdentity)) { m_blExit = false; szIdentity = sz; break; } } if (m_blExit) { return; } // Make it the default, we don't care if this succeeds... szStatus = ""; m_twaincstoolkit.Send("DG_CONTROL", "DAT_IDENTITY", "MSG_SET", ref szIdentity, ref szStatus); // Open it... szStatus = ""; sts = m_twaincstoolkit.Send("DG_CONTROL", "DAT_IDENTITY", "MSG_OPENDS", ref szIdentity, ref szStatus); if (sts != TWAIN.STS.SUCCESS) { MessageBox.Show("Unable to open scanner (it is turned on and plugged in?)"); m_blExit = true; return; } // Strip off unsafe chars. Sadly, mono let's us down here... m_szProductDirectory = TWAINCSToolkit.CsvParse(szIdentity)[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, '_'); } // We're doing memory transfers (TWSX_MEMORY == 2)... szStatus = ""; szCapability = "ICAP_XFERMECH,TWON_ONEVALUE,TWTY_UINT16,2"; sts = m_twaincstoolkit.Send("DG_CONTROL", "DAT_CAPABILITY", "MSG_SET", ref szCapability, ref szStatus); if (sts != TWAIN.STS.SUCCESS) { m_blExit = true; return; } // Decide whether or not to show the driver's window messages... szStatus = ""; szCapability = "CAP_INDICATORS,TWON_ONEVALUE,TWTY_BOOL," + (m_blIndicators?"1":"0"); sts = m_twaincstoolkit.Send("DG_CONTROL", "DAT_CAPABILITY", "MSG_SET", ref szCapability, ref szStatus); if (sts != TWAIN.STS.SUCCESS) { m_blExit = true; return; } // New state... SetButtons(EBUTTONSTATE.OPEN); // Create the setup form... m_formsetup = new FormSetup(ref m_twaincstoolkit, m_szProductDirectory); }
/// <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); }