/// <summary> /// Find all available instruments. /// </summary> private void Find() { // Find all available VISA-over-USB devices. IEnumerable <string> devices = VisaDevice.Find(VisaPattern.USB); // Remove all items. comboBoxResources.Items.Clear(); // Add found items. foreach (string d in devices) { comboBoxResources.Items.Add(d); } // Select the first item. comboBoxResources.SelectedIndex = 0; }
public void Open() { // The device uses a USB VISA interface, so look for devices with that pattern. string[] resourceStrings = VisaDevice.Find(VisaPattern.USB).ToArray(); string errorMessage = string.Empty; bool success = false; // Try each resource, and use the first one that opens successfully. foreach (string resouceName in resourceStrings) { bool status = true; try { // Open a connection to the desired instrument. Open(resouceName); } catch (DeviceCommunicationException ex) { // Save the error message to display to the user later. errorMessage = ex.Message; // Note that the instrument didn't open. status = false; } // Stop when one of the resource strings connects successfully. if (status == true) { success = true; break; } } // If none of the resource strings yielded an instrument connection, throw // an exception. if (success == false) { throw new DeviceCommunicationException("Device was not found." + Environment.NewLine + "Details:" + Environment.NewLine + errorMessage); } }