public void TestDataBits() { SerialPortDataHandler port = new SerialPortDataHandler(new CurrentPacketParser(new RawPacketParser())); port.DataBits = 8; Assert.Equal(port.DataBits, 8); port.DataBits = 7; Assert.Equal(port.DataBits, 7); }
public void TestDeviceStatus() { SerialPortDataHandler port = new SerialPortDataHandler(new CurrentPacketParser(new RawPacketParser())); port.DataBits = 8; port.Parity = Terminal.Interface.Enums.Parity.None; port.StopBits = StopBits.One; Assert.Equal(port.DeviceStatus, "8;N;1"); }
public void TestFlowControl() { SerialPortDataHandler port = new SerialPortDataHandler(new CurrentPacketParser(new RawPacketParser())); port.FlowControl = FlowControl.None; Assert.Equal(port.FlowControl, FlowControl.None); port.FlowControl = FlowControl.RequestToSend; Assert.Equal(port.FlowControl, FlowControl.RequestToSend); }
public void TestPortOpenClose() { SerialPortDataHandler port = new SerialPortDataHandler(new CurrentPacketParser(new RawPacketParser())); Assert.Equal(port.PortState, PortState.Closed); port.DeviceName = port.Devices[0]; port.PortState = PortState.Open; Assert.Equal(port.PortState, PortState.Open); port.PortState = PortState.Closed; Assert.Equal(port.PortState, PortState.Closed); }
public void TestPortEnumeration() { var availablePorts = SerialPort.GetPortNames(); SerialPortDataHandler port = new SerialPortDataHandler(new CurrentPacketParser(new RawPacketParser())); foreach (var device in port.Devices) { Assert.Contains(device, availablePorts); } Assert.Equal(availablePorts.Length, port.Devices.Length); }
public void TestPortWriteData() { SerialPortDataHandler port = new SerialPortDataHandler(new CurrentPacketParser(new RawPacketParser())); port.DeviceName = "COM1"; port.PortState = PortState.Open; Assert.Equal(port.PortState, PortState.Open); Assert.Equal(port.Write((byte)0), 1); Assert.Equal(port.Write('T'), 1); Assert.Equal(port.Write("est"), 3); Assert.Equal(port.Write(new byte[] { 0, 1, 2, 3 }), 4); port.PortState = PortState.Closed; }
public void TestParity() { SerialPortDataHandler port = new SerialPortDataHandler(new CurrentPacketParser(new RawPacketParser())); port.Parity = Terminal.Interface.Enums.Parity.None; Assert.Equal(port.Parity, Terminal.Interface.Enums.Parity.None); port.Parity = Terminal.Interface.Enums.Parity.Even; Assert.Equal(port.Parity, Terminal.Interface.Enums.Parity.Even); port.Parity = Terminal.Interface.Enums.Parity.Odd; Assert.Equal(port.Parity, Terminal.Interface.Enums.Parity.Odd); port.Parity = Terminal.Interface.Enums.Parity.Mark; Assert.Equal(port.Parity, Terminal.Interface.Enums.Parity.Mark); port.Parity = Terminal.Interface.Enums.Parity.Space; Assert.Equal(port.Parity, Terminal.Interface.Enums.Parity.Space); }
public void TestPortOpenException() { SerialPortDataHandler port = new SerialPortDataHandler(new CurrentPacketParser(new RawPacketParser())); Assert.Equal(port.PortState, PortState.Closed); port.DeviceName = port.Devices[0]; port.PortState = PortState.Open; Assert.Equal(port.PortState, PortState.Open); SerialPortDataHandler port2 = new SerialPortDataHandler(new CurrentPacketParser(new RawPacketParser())); port2.DeviceName = port.Devices[0]; Assert.Throws <UnauthorizedAccessException>(() => port2.PortState = PortState.Open); port.PortState = PortState.Closed; }
public void TestEnumeration() { SerialPortDataHandler port = new SerialPortDataHandler(new CurrentPacketParser(new RawPacketParser())); Assert.Equal(port.Devices, port.ListAvailableDevices().ToArray()); }
public void TestDeviceType() { SerialPortDataHandler port = new SerialPortDataHandler(new CurrentPacketParser(new RawPacketParser())); Assert.Equal(port.DeviceType, DeviceType.SerialPort); }