public void TestSerialPortsSearch()
        {
            var serialPorts = new SerialPorts();
            var portsCount  = serialPorts.GetPortsCount();

            if (portsCount <= 0)
            {
                LogAssert.Expect(LogType.Error, "no ports");
            }

            for (uint i = 0; i < portsCount; i++)
            {
                var portInfo = serialPorts.GetPortAt(i);
                Assert.True(portInfo.IsValid);
                var portInfo2 = serialPorts.GetPortByName(portInfo.port);
                Assert.True(portInfo2.IsValid);
                Assert.True(portInfo == portInfo2);
            }

            // invalid port name
            {
                var portInfo2 = serialPorts.GetPortByName("<invalid port name>");
                Assert.True(!portInfo2.IsValid);
            }
        }
Пример #2
0
    void Start()
    {
        var ports = new SerialPorts();

        Label.text = "Start test:\n";

        var portsCount = ports.GetPortsCount();

        Label.text += "Ports count: " + portsCount + "\n";

        for (uint i = 0; i < portsCount + 1; i++)
        {
            Label.text += "Port #" + i + ": " + ports.GetPortAt(i) + "\n";
        }

        Label.text += "Port \"/dev/cu.usbmodem14C1\": " + ports.GetPortByName("/dev/cu.usbmodem14C1") + "\n";


        Label.text += "Done.\n";
    }