Beispiel #1
0
        public Logger(ELM327 elm, int period, LogValues[] logValues)
        {
            this.elm       = elm;
            this.period    = period;
            this.logValues = logValues;
            currentState   = new int[logValues.Length];

            for (int idx = 0; idx < logValues.Length; idx++)
            {
                currentState[idx] = -1;
            }
        }
Beispiel #2
0
        private bool readDataWithProgress(int address, int size, out byte[] data)
        {
            byte[] dump    = new byte[size];
            bool   success = false;

            data = null;

            ELM327 elm = new ELM327(GetCOMPort());

            elm.Open();
            if (elm.adapterInit() &&
                elm.startConnection())
            {
                for (int chunksize = 128; (chunksize > 4) && !success; chunksize >>= 1)
                {
                    bool attemptFailed = false;
                    for (int offset = 0; (offset < size) && !attemptFailed; offset += chunksize)
                    {
                        string resp;
                        if (elm.doRequest("23" + (address + offset).ToString("X6") + chunksize.ToString("X2"), out resp) &&
                            resp.StartsWith("63"))
                        {
                            byte[] rba = HexUtils.hexStringToByteArray(resp);
                            Array.Copy(rba, 1, dump, offset, rba.Length - 1);
                            progBar.Value = 100 * (offset + chunksize) / size;
                        }
                        else
                        {
                            attemptFailed = true;
                        }
                    }

                    success = !attemptFailed;
                }

                if (success)
                {
                    data = dump;
                }
                elm.closeConnection();
            }
            elm.Close();

            return(success);
        }
Beispiel #3
0
        private void startToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (elm == null)
            {
                elm = new ELM327(GetCOMPort());
            }

            if (!elm.IsOpen)
            {
                elm.Open();
            }

            if (!(elm.adapterInit() && elm.startConnection()))
            {
                MessageBox.Show("Could not initialize connection", "Logging failed");
                return;
            }

            Logger.LogValues[] logValues = new Logger.LogValues[]
            {
                Logger.LogValues.IGNITION_54,
                Logger.LogValues.IGNITION_15,
                Logger.LogValues.ENGINE_RUNNING_FROM_TRIONIC,
                Logger.LogValues.ACC_IN_BUS_FROM_ACC,
                Logger.LogValues.EVAPORATOR_TEMPERATURE,
                Logger.LogValues.AC_PRESSURE,
                Logger.LogValues.VEHICLE_SPEED,
                Logger.LogValues.COOLANT_TEMPERATURE,
                Logger.LogValues.COOLING_FAN_HIGH_RELAY_2,
                Logger.LogValues.COOLING_FAN_HIGH_RELAY_1,
                Logger.LogValues.COOLING_FAN_LOW_RELAY,
                Logger.LogValues.OUTSIDE_TEMPERATURE
            };

            loggerObject = new Logger(elm, 800, logValues);
            loggerThread = new Thread(loggerObject.DoLogging);
            loggerThread.Start();
            while (!loggerThread.IsAlive)
            {
                ;
            }
            Thread.Sleep(1);
        }
Beispiel #4
0
        private void uploadEEPROMToolStripMenuItem_Click(object sender, EventArgs e)
        {
            ELM327 elm = new ELM327(GetCOMPort());

            elm.Open();
            if (elm.adapterInit() &&
                elm.startConnection())
            {
                //byte[] newEEPROM = byteViewer.GetBytes();
                byte[] newEEPROM = ((DynamicByteProvider)hexBox.ByteProvider).Bytes.ToArray();
                for (int offset = 0; offset < storedEEPROM.Length; offset++)
                {
                    if (storedEEPROM[offset] != newEEPROM[offset])
                    {
                        string resp;
                        do
                        {
                            if (elm.doRequest("3D" + (0x100 + offset).ToString("X6") + "01" + storedEEPROM[offset].ToString("X2"), out resp) &&
                                resp.StartsWith("7D"))
                            {
                                storedEEPROM[offset] = newEEPROM[offset];
                            }
                        } while (
                            !(elm.doRequest("23" + (0x100 + offset).ToString("X6") + "01", out resp) &&
                              resp.StartsWith("63") && HexUtils.hexStringToByteArray(resp)[1] == newEEPROM[offset])
                            );
                    }

                    progBar.Value = 100 * offset / storedEEPROM.Length;
                }
                //byteViewer.SetBytes(storedEEPROM);
                hexBox.ByteProvider = new DynamicByteProvider(storedEEPROM);

                elm.closeConnection();
            }
            elm.Close();
        }
Beispiel #5
0
 public LoggerThread(ELM327 elm, int period)
 {
     this.elm    = elm;
     this.period = period;
 }