private void OpenEveryPortName() { string[] portNames = SerialPort.GetPortNames(); for (int i = 0; i < portNames.Length; ++i) { Debug.WriteLine("Opening port " + portNames[i]); bool portExists = false; foreach (string str in PortHelper.GetPorts()) { if (str == portNames[i]) { portExists = true; break; } } if (!portExists) { Debug.WriteLine("Real Port does not exist. Ignore the output from SerialPort.GetPortNames()"); continue; } using (SerialPort serialPort = new SerialPort(portNames[i])) { try { serialPort.Open(); } catch (UnauthorizedAccessException) { } } } }
private static int Main() { try { String[] portNames = PortHelper.GetPorts(); if (portNames.Length == 0) { Debug.WriteLine("No serial ports available. Not running test."); } else { s_done = false; Thread food = null; food = new Thread(new ThreadStart(gc_food)); food.Start(); foreach (String portName in portNames) { Debug.WriteLine(portName); OpenClose(portName); LeaveOpen(portName); } } // if neither of these crashed, then pass. s_done = true; // stop the gc thread return(100); } catch (Exception ex) { Debug.WriteLine("Unexpected exception! " + ex.ToString()); return(99); } }
private void AllGetPortNamesAreInHelperPorts() { string[] helperPortNames = PortHelper.GetPorts(); foreach (string serialPortName in SerialPort.GetPortNames()) { Assert.True(helperPortNames.Contains(serialPortName), $"{serialPortName} is not present in PortHelper.GetPorts result\r\n{PortInformationString}"); } }
public void AllHelperPortsAreInGetPortNames() { if (PlatformDetection.IsWindows && PlatformDetection.IsArmOrArm64Process) { // [ActiveIssue("https://github.com/dotnet/runtime/issues/28851")] throw new SkipTestException("Port detection broken on Windows IoT"); } string[] serialPortNames = SerialPort.GetPortNames(); foreach (string helperPortName in PortHelper.GetPorts()) { Assert.True(serialPortNames.Contains(helperPortName), $"{helperPortName} is not present in SerialPort.GetPortNames result\r\n{PortInformationString}"); } }
private void AllHelperPortsAreInGetPortNames() { if (PlatformDetection.IsWindows && PlatformDetection.IsArmOrArm64Process) { // ActiveIssue: 35722 throw new SkipTestException("Port detection broken on Windows IoT"); } string[] serialPortNames = SerialPort.GetPortNames(); foreach (string helperPortName in PortHelper.GetPorts()) { Assert.True(serialPortNames.Contains(helperPortName), $"{helperPortName} is not present in SerialPort.GetPortNames result\r\n{PortInformationString}"); } }
private bool OpenEveryPortName() { bool retValue = true; String[] portNames = SerialPort.GetPortNames(); SerialPort serialPort; for (int i = 0; i < portNames.Length; ++i) { Console.WriteLine("Opening port " + portNames[i]); bool portExists = false; foreach (string str in PortHelper.GetPorts()) { if (str == portNames[i]) { portExists = true; break; } } if (!portExists) { Console.WriteLine("Real Port does not exist. Ignore the output from SerialPort.GetPortNames()"); continue; } serialPort = new SerialPort(portNames[i]); try { serialPort.Open(); } catch (UnauthorizedAccessException) { } } return(retValue); }