Esempio n. 1
0
        public Boolean doRequest(byte[] req, out byte[] result)
        {
            string res;

            result = null;
            if (!doRequest(HexUtils.byteArrayToHexString(req), out res))
            {
                return(false);
            }

            result = HexUtils.hexStringToByteArray(res);
            return(true);
        }
Esempio n. 2
0
        public Boolean getDataByLocalId(int id, out byte[] data)
        {
            string resp;

            //resp = "61 01 00 00 00 00 00 00 00 FF 01 00 02 00 02 71 7A 23 12 00 00 FD 8F 40 00 02 02 42 00";
            if (doRequest("21" + id.ToString("X02"), out resp))
            //if ( true )
            {
                data = HexUtils.hexStringToByteArray(resp);
            }
            else
            {
                data = null;
            }
            return(resp.StartsWith("61"));
        }
Esempio n. 3
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);
        }
Esempio n. 4
0
        public Boolean readMemory(int address, int length, int chunksize, out byte[] data)
        {
            data = new byte[length];
            string resp;

            for (int offset = 0; offset < length; offset += chunksize)
            {
                if (doRequest("23" + (address + offset).ToString("X6") + chunksize.ToString("X2"), out resp) &&
                    resp.StartsWith("63"))
                {
                    byte[] rba = HexUtils.hexStringToByteArray(resp);
                    Array.Copy(rba, 1, data, offset, rba.Length - 1);
                }
                else
                {
                    data = null;
                    return(false);
                }
            }

            return(true);
        }
Esempio n. 5
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();
        }