public void SaveDllSettings(DllSettings settings) { DllSettings = settings; XmlSerializer xmlSerializer = new XmlSerializer(typeof(DllSettings)); using (TextWriter writer = new StreamWriter(_dllSettings_xml)) { xmlSerializer.Serialize(writer, DllSettings); writer.Close(); } }
public override bool InitializeAuto(DllSettings settings) { try { if (_CommELM.Online) { return(true); } _iStandard = settings.StandardIndex; if (settings.ComPort > 0) { // 使用串口连接ELM327 if (CommBase.GetPortAvailable(settings.ComPort) == CommBase.PortStatus.Available && Initialize(settings.ComPort, settings.BaudRate)) { settings.FirstRun = false; return(true); } if (settings.FirstRun) { string[] serials = SerialPort.GetPortNames(); for (int i = 0; i < serials.Length; i++) { if (int.TryParse(serials[i].Substring(3), out int iPort)) { if (iPort != settings.ComPort) { if (CommBase.GetPortAvailable(iPort) == CommBase.PortStatus.Available && Initialize(iPort, 38400)) { return(true); } } } } } } else { // 使用TCP连接ELM327 if (Initialize(settings.RemoteIP, settings.RemotePort)) { return(true); } } } catch (Exception ex) { if (_CommELM.Online) { _CommELM.Close(); } _log.TraceError("Initialize occur error: " + ex.Message); } return(false); }
public DllSettings LoadDllSettings() { try { XmlSerializer serializer = new XmlSerializer(typeof(DllSettings)); using (FileStream reader = new FileStream(_dllSettings_xml, FileMode.Open)) { DllSettings = (DllSettings)serializer.Deserialize(reader); reader.Close(); } } catch (Exception ex) { _log.TraceError("Using default dll settings because of failed to load them, reason: " + ex.Message); DllSettings = new DllSettings(); DllSettingsResult = false; } return(DllSettings); }
public override bool Initialize(DllSettings settings) { SetProtocol(settings.ProtocolIndex); _iStandard = settings.StandardIndex; if (settings.ComPort > 0) { // 使用串口连接ELM327 _log.TraceInfo(string.Format("Attempting initialization on port {0}", settings.HardwareIndex.ToString())); return(Initialize(settings.ComPort, settings.BaudRate)); } else { // 使用TCP连接ELM327 _log.TraceInfo(string.Format("Attempting initialization on remote server {0}:{1}", settings.RemoteIP, settings.RemotePort.ToString())); return(Initialize(settings.RemoteIP, settings.RemotePort)); } }
protected CommBase(DllSettings settings, Logger log) { _mainSettings = settings; _log = log; }
public OBDDeviceELM327(DllSettings settings, Logger log, int[] xattr) : base(settings, log, xattr) { _iProtocol = ProtocolType.Unknown; _iStandard = StandardType.Automatic; }
public OBDCommELM(DllSettings settings, Logger log) : base(settings, log) { _RxFilterWithSpace = new byte[] { 0x0A, 0x20, 0 }; _RxFilterNoSpace = new byte[] { 0x0A, 0 }; }
public abstract bool InitializeAuto(DllSettings settings);
protected OBDDevice(DllSettings settings, Logger log, int[] xattr) { _log = log; _CommELM = new OBDCommELM(settings, log); _xattr = xattr; }
protected CommLine(DllSettings settings, Logger log) : base(settings, log) { }