protected AgilentBase(String settings) : base() { var serialPortSettings = DmmSerialPortSettings.Parse(settings); if (serialPortSettings.BaudRate != 9600) { throw new ArgumentOutOfRangeException("settings", "Device only supports baud rate of 9600."); } if (serialPortSettings.Parity != Parity.None) { throw new ArgumentOutOfRangeException("settings", "Device only supports no parity."); } if (serialPortSettings.DataBits != 8) { throw new ArgumentOutOfRangeException("settings", "Device only supports 8 data bits."); } if (serialPortSettings.StopBits != StopBits.One) { throw new ArgumentOutOfRangeException("settings", "Device only supports 1 stop bit."); } this.SerialPort = new Medo.IO.UartPort(serialPortSettings.PortName, serialPortSettings.BaudRate, serialPortSettings.Parity, serialPortSettings.DataBits, serialPortSettings.StopBits); this.SerialPort.ReadTimeout = 250; this.SerialPort.WriteTimeout = 250; this.SerialPort.NewLine = "\n"; }
public void DmmSerialPortSettings_ParseNoStopBits() { var x = DmmSerialPortSettings.Parse("COM5:1200,e,5,0"); Assert.AreEqual("COM5", x.PortName); Assert.AreEqual(1200, x.BaudRate); Assert.AreEqual(Parity.Even, x.Parity); Assert.AreEqual(5, x.DataBits); Assert.AreEqual(StopBits.None, x.StopBits); Assert.AreEqual("COM5:1200,E,5,0", x.ToString()); }
public void DmmSerialPortSettings_Parse() { var x = DmmSerialPortSettings.Parse("COM 3:4800,o,7,2"); Assert.AreEqual("COM3", x.PortName); Assert.AreEqual(4800, x.BaudRate); Assert.AreEqual(Parity.Odd, x.Parity); Assert.AreEqual(7, x.DataBits); Assert.AreEqual(StopBits.Two, x.StopBits); Assert.AreEqual("COM3:4800,O,7,2", x.ToString()); }
public NewDeviceSerialInterfaceForm(Device device) //edit device : this() { this.Text = "Settings for " + device.DisplayName; txtDisplayName.Text = device.DisplayName; var settings = DmmSerialPortSettings.Parse(device.Settings); foreach (TagItem <string, string> item in cmbPortName.Items) { if (item.Key.Equals(settings.PortName)) { cmbPortName.SelectedItem = item; break; } } if (cmbPortName.SelectedIndex == -1) { cmbPortName.SelectedIndex = cmbPortName.Items.Add(new TagItem <string, string>(settings.PortName, "(" + settings.PortName + ")")); } foreach (TagItem <int, string> item in cmbBaudRate.Items) { if (item.Key.Equals(settings.BaudRate)) { cmbBaudRate.SelectedItem = item; break; } } if (cmbBaudRate.SelectedIndex == -1) { cmbBaudRate.SelectedIndex = cmbBaudRate.Items.Add(new TagItem <int, string>(settings.BaudRate, "(" + settings.BaudRate.ToString(CultureInfo.CurrentCulture) + ")")); } foreach (TagItem <Parity, string> item in cmbParity.Items) { if (item.Key.Equals(settings.Parity)) { cmbParity.SelectedItem = item; break; } } foreach (TagItem <int, string> item in cmbDataBits.Items) { if (item.Key.Equals(settings.DataBits)) { cmbDataBits.SelectedItem = item; break; } } foreach (TagItem <StopBits, string> item in cmbStopBits.Items) { if (item.Key.Equals(settings.StopBits)) { cmbStopBits.SelectedItem = item; break; } } }
public void DmmSerialPortSettings_ParseNonEmpty() { var x = DmmSerialPortSettings.Parse(" "); }
public void DmmSerialPortSettings_ParseEmpty() { var x = DmmSerialPortSettings.Parse(""); Assert.AreEqual("COM1:9600,N,8,1", x.ToString()); }
public void DmmSerialPortSettings_ParseNegativePort() { var x = DmmSerialPortSettings.Parse("COM-1:"); }
public void DmmSerialPortSettings_ParseZeroPort() { var x = DmmSerialPortSettings.Parse("COM0"); }
public void DmmSerialPortSettings_ParsePartialWithoutColon() { var x = DmmSerialPortSettings.Parse("COM4"); Assert.AreEqual("COM4:9600,N,8,1", x.ToString()); }