Inheritance: IDisposable
 private void InitializeComPort()
 {
     _dataReceived = String.Empty;
     _serialPort = new Serial {Setup = _comSetup};
     _serialPort.DataReceived += _serialPort_DataReceived;
     //_serialPort.InfoReceived += _serialPort_InfoReceived;
     cbComPort.ItemsSource = SerialComPort.Helper.SetupValues.GetPortNameValues();
     cbComPort.SelectedItem = _serialPort.Setup.PortName;
 }
        public void TestComPort()
        {
            var setupJ = ComSetup.Load(Serializer.ConversionTypes.Json);
            CheckSetup(ref setupJ);
            setupJ.Save(Serializer.ConversionTypes.Json);

            var serial = new Serial();
            serial.DataReceived += serial_DataReceived;
            Assert.IsTrue(serial.Open(setupJ), "Open Com Port " + setupJ.PortName);

            var i = 0;
            while (i++ <= 200)
            {
                Thread.Sleep(10);
                if (!String.IsNullOrEmpty(_response))
                    if(_response.Length >= 14)
                    {
                        Assert.AreEqual("81 11 F1 81 04", _response, "Init Request");
                        _response = string.Empty;
                        break;
                    }
            }

            //Send Init Response
            Assert.IsTrue(serial.Send("80 F1 11 03 C1 EA 8F BF"), "Send Init");

            i = 0;
            while (i++ <= 200)
            {
                Thread.Sleep(10);
                if (!String.IsNullOrEmpty(_response))
                    if (_response.Length >= 20)
                    {
                        Assert.AreEqual("80 11 F1 02 10 80 14", _response, "Enable Diagnostic Request");
                        _response = string.Empty;
                        break;
                    }
            }

            //Send Enable Diagnostic Response
            Assert.IsTrue(serial.Send("80 F1 11 02 50 80 54"), "Enable Diagnostic Response");

            //Wait for Gear request...
            i = 0;
            while (i++ <= 200)
            {
                Thread.Sleep(10);
                if (!String.IsNullOrEmpty(_response))
                    if (_response.Length >= 20)
                    {
                        Assert.AreEqual("80 11 F1 02 21 0B B0", _response, "Gear Request");
                        _response = string.Empty;
                        break;
                    }
            }
            //Send Gear Response
            Assert.IsTrue(serial.SendLine("80 F1 11 03 61 0B 00 F1"), "Send Neutral Gear Response");

            //Wait a bit..
            while (i++ <= 200)
                Thread.Sleep(10);

            Assert.IsTrue(serial.Close(), "Closing Com Port");
        }