private void addOverlayToOverlayList(string name, bool useV2DriverLoader = true) { OverlayControlClass newOverlay = new OverlayControlClass(name, useV2DriverLoader); this.ControlsAvailable.Add(newOverlay); this.OverlayNames.Add(newOverlay.FriendlyOverlayName); }
public void ScanSerialPortsForV2Overlay(OverlayControlClass v2OverlayControl) { if (v2OverlayControl == null || v2OverlayControl.UsesV2DriverLoader == false || File.Exists(@"C:\Program Files\InspectIT\Drivers\overlay.dll") == false) { return; } string[] validPorts = System.IO.Ports.SerialPort.GetPortNames(); if (validPorts.Length == 0) { return; } if (this.V2DriverLoader == null) { this.V2DriverLoader = new DriverLoader(); this.V2DriverLoader.DriverDirectory = @"C:\Program Files\InspectIT\Drivers"; this.V2DriverLoader.ScanDriverDirectory(); } try { this.V2DriverLoader.LoadDriver(v2OverlayControl.OverlayName); } catch (Exception ex) { MessageBox.Show("Error encountered loading driver: '" + v2OverlayControl.OverlayName + "'\n\nSpecific Error: " + ex.Message); } if (this.V2DriverLoader.DriverIsLoaded == true) { for (int i = 0; i < validPorts.Length; i++) { string curPort = validPorts[i]; //Handle if it's an LPT (or otherwise non-COM) port: if (curPort.Contains("COM") == false) { continue; } this.V2DriverLoader.PortId = int.Parse(curPort.Replace("COM", "")); try { if (this.V2DriverLoader.PortIsOpen) { this.V2DriverLoader.ClosePort(); } this.V2DriverLoader.OpenPort(); float tempTestFloat = this.V2DriverLoader.GetCounter(1); V2DriverLoader.ClosePort(); if (tempTestFloat.Equals(float.NaN) == false) { this.OverlayPort = V2DriverLoader.PortId; this.LateralPort = V2DriverLoader.PortId + 1; return; } } catch (Exception ex) { //This violates single-responsibility, but I'm allowing this to show a messagebox because the port may be locked by another process, or it may have a driver-level issue //I've seen ports which claim they don't exist when I scan them, even though Windows says they exist. I'd rather these ports don't prevent scanning the other ports. MessageBox.Show("Error encountered scanning port " + V2DriverLoader.PortId.ToString() + "\n\nSpecific Error: " + ex.Message); } finally { this.V2DriverLoader.ClosePort(); this.V2DriverLoader.UnloadDriver(); this.V2DriverLoader.PortId = -1; } } } }