示例#1
0
        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();
            }
        }
示例#2
0
 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);
 }
示例#3
0
 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);
 }
示例#4
0
 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));
     }
 }
示例#5
0
 protected CommBase(DllSettings settings, Logger log)
 {
     _mainSettings = settings;
     _log          = log;
 }
示例#6
0
 public OBDDeviceELM327(DllSettings settings, Logger log, int[] xattr) : base(settings, log, xattr)
 {
     _iProtocol = ProtocolType.Unknown;
     _iStandard = StandardType.Automatic;
 }
示例#7
0
 public OBDCommELM(DllSettings settings, Logger log) : base(settings, log)
 {
     _RxFilterWithSpace = new byte[] { 0x0A, 0x20, 0 };
     _RxFilterNoSpace   = new byte[] { 0x0A, 0 };
 }
示例#8
0
 public abstract bool InitializeAuto(DllSettings settings);
示例#9
0
 protected OBDDevice(DllSettings settings, Logger log, int[] xattr)
 {
     _log     = log;
     _CommELM = new OBDCommELM(settings, log);
     _xattr   = xattr;
 }
示例#10
0
 protected CommLine(DllSettings settings, Logger log) : base(settings, log)
 {
 }