private void Connect() { HIDInfoSet device; if (m_connList.Count == 0) { return; } device = m_connList[0]; if (HIDDevice.GetInfoSets(device.VendorID, device.ProductID, device.SerialNumberString).Count > 0) { if (m_usb.Connect(device.DevicePath, true)) { //lbConnectionText.Text = "Connected"; //pbLED.Image = Properties.Resources.ledgreen; IsMuted = false; /*m_ToolStripStatusIcon.ToolTipText = "Manufacturer: " + m_usb.ManufacturerString + "\n" + * "Product Name: " + m_usb.ProductString + "\n" + * "Serial Number: " + m_usb.SerialNumberString + "\n" + * "SW Version: " + m_usb.VersionInBCD; */ } } else { ScanConnection(); MessageBox.Show(String.Format("DEVICE: {0} is used in other program !", device.ProductString)); } }
private void ScanConnection() { int vid = int.Parse(MutePuckApp.Properties.Resources.VID, System.Globalization.NumberStyles.HexNumber); int pid = int.Parse(MutePuckApp.Properties.Resources.PID, System.Globalization.NumberStyles.HexNumber); m_connList = HIDDevice.GetInfoSets(vid, pid); /* cbConnectionChooser.Items.Clear(); * * foreach (var hidInfoSet in m_connList) * { * if (hidInfoSet.ProductString == "") * { * cbConnectionChooser.Items.Add("Unknown HID device"); * } * else * { * cbConnectionChooser.Items.Add(hidInfoSet.GetInfo()); * } * } * * if (cbConnectionChooser.Items.Count > 0) * { * cbConnectionChooser.SelectedIndex = 0; * * } */ }
private void Connect() { HIDInfoSet device; if (m_connList.Count == 0) { return; } device = m_connList[m_ToolStripComboBox.SelectedIndex]; if (HIDDevice.GetInfoSets(device.VendorID, device.ProductID, device.SerialNumberString).Count > 0) { if (m_usb.Connect(device.DevicePath, true)) { LogDataGridView.Enabled = true; ConnectToolStripButton.Text = "Disconnect"; ConnectToolStripButton.Image = Properties.Resources.Disconnect; m_ToolStripComboBox.Enabled = false; m_ToolStripStatusString.Text = "USB Device connected"; m_ToolStripStatusString.ForeColor = Color.DarkSlateGray; m_ToolStripStatusIcon.Image = Properties.Resources.USB_OK; m_ToolStripStatusIcon.ToolTipText = "Manufacturer: " + m_usb.ManufacturerString + "\n" + "Product Name: " + m_usb.ProductString + "\n" + "Serial Number: " + m_usb.SerialNumberString + "\n" + "SW Version: " + m_usb.VersionInBCD; } } else { ScanConnection(); MessageBox.Show(String.Format("DEVICE: {0} is used in other program !", device.ProductString), "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning); } }
private void ScanConnection() { m_connList = HIDDevice.GetInfoSets(m_settings.USB_VID, m_settings.USB_PID); m_ToolStripComboBox.Items.Clear(); foreach (var hidInfoSet in m_connList) { if (hidInfoSet.ProductString == "") { m_ToolStripComboBox.Items.Add("Unknovn HID device"); } else { m_ToolStripComboBox.Items.Add(hidInfoSet.GetInfo()); } } if (m_ToolStripComboBox.Items.Count > 0) { m_ToolStripComboBox.Enabled = true; ConnectToolStripButton.Text = "Connect"; ConnectToolStripButton.Image = Properties.Resources.Connect; ConnectToolStripButton.Enabled = true; m_ToolStripComboBox.SelectedIndex = 0; m_ToolStripStatusIcon.Enabled = true; m_ToolStripStatusIcon.Image = Properties.Resources.USB_Disable; m_ToolStripStatusIcon.ToolTipText = "USB Device Disconnected"; m_ToolStripStatusString.Text = "USB Device is ready for connecting"; m_ToolStripStatusString.ForeColor = Color.DarkSlateGray; } else { m_ToolStripComboBox.Enabled = false; ConnectToolStripButton.Text = "Connect"; ConnectToolStripButton.Image = Properties.Resources.Connect; ConnectToolStripButton.Enabled = false; m_ToolStripStatusIcon.Enabled = false; m_ToolStripStatusIcon.Image = Properties.Resources.USB; m_ToolStripStatusIcon.ToolTipText = string.Empty; m_ToolStripStatusString.Text = "USB Device not found, check the HW connection on PC side !"; m_ToolStripStatusString.ForeColor = Color.FromArgb(255, 204, 0, 0); } }
private void usb_OnDeviceRemoved(object sender, EventArgs e) { if (!Dispatcher.CheckAccess()) { Dispatcher.Invoke(new EventHandler(usb_OnDeviceRemoved), new object[] { sender, e }); } else { if (m_usb.IsConnected) { if (HIDDevice.GetInfoSets(m_usb.VendorID, m_usb.ProductID, m_usb.SerialNumberString).Count == 0) { Disconnect(); } } ScanConnection(); } }
public void RefreshAllDevice() { try { m_connList = HIDDevice.GetInfoSets(); this.m_listDeviceDescription.Clear(); foreach (var item in m_connList) { if (item.ProductString.ToUpper().Contains(ProductStr)) { m_listDeviceDescription.Add(item); } } } catch (Exception ex) { MessageBox.Show("获取USB设备报错:" + ex.Message); } }