private void InitializeData()
        {
            _ecuSetup = EcuSetup.Load(FileType);
            _comSetup = ComSetup.Load(FileType);
            var lastPortName = string.Empty;
            var portFound    = false;

            foreach (var portName in SerialComPort.Helper.SetupValues.GetPortNameValues())
            {
                if (_comSetup.PortName.Equals(portName))
                {
                    portFound = true;
                    break;
                }
                lastPortName = portName;
            }
            if (!portFound)
            {
                _comSetup.PortName = lastPortName;
            }
            Emulator.Setup    = _ecuSetup;
            Emulator.Register = RegisterList.Load(FileType);
            if (Emulator.Register.Items.Count <= 0)
            {
                Emulator.Register = Emulator.InitRegister();
            }
        }
Esempio n. 2
0
        public void ComPortInitialization()
        {
            //XML
            var setup = ComSetup.Load();

            CheckSetup(ref setup);
            setup.Save();

            //JSon
            var setupJ = ComSetup.Load(Serializer.ConversionTypes.Json);

            CheckSetup(ref setupJ);
            setupJ.Save(Serializer.ConversionTypes.Json);
        }
Esempio n. 3
0
        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");
        }