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(); } }
public SetupWindow(ComSetup comSetup, EcuSetup ecuSetup) { ComSetup = comSetup; EcuSetup = ecuSetup; InitializeComponent(); InitializeComPort(); }
private void BtnEdit_Click(object sender, RoutedEventArgs e) { var setupWin = new SetupWindow(_comSetup, _ecuSetup); setupWin.ShowDialog(); _comSetup = setupWin.ComSetup; _ecuSetup = setupWin.EcuSetup; cbComPort.SelectedItem = _serialPort.Setup.PortName; }
//public delegate void InfoHandler(InfoEventArgs e); //public event InfoHandler = delegate { }; public Serial() { _comPort = new SerialPort(); _setup = new ComSetup(); _comPort.DataReceived += _comPort_DataReceived; _comPort.Disposed += _comPort_Disposed; _comPort.ErrorReceived += _comPort_ErrorReceived; _comPort.PinChanged += _comPort_PinChanged; }
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); }
public void CheckSetup(ref ComSetup setup) { if (!String.IsNullOrEmpty(setup.BaudRate) && !String.IsNullOrEmpty(setup.PortName)) return; setup.BaudRate = "10400"; setup.Parity = "None"; setup.TimeOutMs = 0; setup.StopBits = "One"; setup.DataBits = "8"; setup.Handshake = "None"; setup.Encoding = "ASCII"; setup.RtsEnable = true; setup.DtrEnable = false; setup.PortName = SerialComPort.Helper.SetupValues.GetPortNameValues()[0]; }
public void CheckSetup(ref ComSetup setup) { if (!String.IsNullOrEmpty(setup.BaudRate) && !String.IsNullOrEmpty(setup.PortName)) { return; } setup.BaudRate = "10400"; setup.Parity = "None"; setup.TimeOutMs = 0; setup.StopBits = "One"; setup.DataBits = "8"; setup.Handshake = "None"; setup.Encoding = "ASCII"; setup.RtsEnable = true; setup.DtrEnable = false; setup.PortName = SerialComPort.Helper.SetupValues.GetPortNameValues()[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"); }
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(); }
public bool Open(ComSetup setup) { _setup = setup; return Open(); }
public bool Open(ComSetup setup) { _setup = setup; return(Open()); }