示例#1
0
        /// <summary>
        /// "High-speed mode get profiles" button pressed.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void _btnGetProfile_Click(object sender, EventArgs e)
        {
            LJV7IF_GET_PROFILE_REQ req = new LJV7IF_GET_PROFILE_REQ();

            req.byTargetBank = ProfileBank.Active;
            req.byPosMode    = ProfilePos.Current;
            req.dwGetProfNo  = 0;
            req.byGetProfCnt = 10;
            req.byErase      = 0;

            LJV7IF_GET_PROFILE_RSP rsp         = new LJV7IF_GET_PROFILE_RSP();
            LJV7IF_PROFILE_INFO    profileInfo = new LJV7IF_PROFILE_INFO();

            int profileDataSize = MAX_PROFILE_COUNT +
                                  (Marshal.SizeOf(typeof(LJV7IF_PROFILE_HEADER)) + Marshal.SizeOf(typeof(LJV7IF_PROFILE_FOOTER))) / sizeof(int);

            int[] receiveBuffer = new int[profileDataSize * req.byGetProfCnt];

            using (ProgressForm progressForm = new ProgressForm())
            {
                Cursor.Current = Cursors.WaitCursor;

                progressForm.Status = Status.Communicating;
                progressForm.Show(this);
                progressForm.Refresh();

                // Get profiles.
                using (PinnedObject pin = new PinnedObject(receiveBuffer))
                {
                    Rc rc = (Rc)NativeMethods.LJV7IF_GetProfile(DEVICE_ID, ref req, ref rsp, ref profileInfo, pin.Pointer,
                                                                (uint)(receiveBuffer.Length * sizeof(int)));
                    if (!CheckReturnCode(rc))
                    {
                        return;
                    }
                }

                // Output profile data
                List <ProfileData> profileDatas = new List <ProfileData>();
                int unitSize = ProfileData.CalculateDataSize(profileInfo);
                for (int i = 0; i < rsp.byGetProfCnt; i++)
                {
                    profileDatas.Add(new ProfileData(receiveBuffer, unitSize * i, profileInfo));
                }

                progressForm.Status = Status.Saving;
                progressForm.Refresh();

                // Save file
                SaveProfile(profileDatas, _txtSavePath.Text);
            }
        }
示例#2
0
        /// <summary>
        /// "Advanced mode get batch profiles" button pressed.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void _btnGetBatchProfileAdvance_Click(object sender, EventArgs e)
        {
            MessageBox.Show("Start advanced mode get batch profiles.\r\nCheck that LJ-Navigator 2 is not starting up");
            LJV7IF_GET_BATCH_PROFILE_ADVANCE_REQ req = new LJV7IF_GET_BATCH_PROFILE_ADVANCE_REQ();

            req.byPosMode    = BatchPos.Commited;
            req.dwGetBatchNo = 0;
            req.dwGetProfNo  = 0;
            req.byGetProfCnt = byte.MaxValue;

            LJV7IF_GET_BATCH_PROFILE_ADVANCE_RSP rsp = new LJV7IF_GET_BATCH_PROFILE_ADVANCE_RSP();
            LJV7IF_PROFILE_INFO profileInfo          = new LJV7IF_PROFILE_INFO();

            LJV7IF_MEASURE_DATA[] batchMeasureData = new LJV7IF_MEASURE_DATA[NativeMethods.MesurementDataCount];
            LJV7IF_MEASURE_DATA[] measureData      = new LJV7IF_MEASURE_DATA[NativeMethods.MesurementDataCount];

            int profileDataSize = MAX_PROFILE_COUNT +
                                  (Marshal.SizeOf(typeof(LJV7IF_PROFILE_HEADER)) + Marshal.SizeOf(typeof(LJV7IF_PROFILE_FOOTER))) / sizeof(int);
            int measureDataSize = Marshal.SizeOf(typeof(LJV7IF_MEASURE_DATA)) * NativeMethods.MesurementDataCount / sizeof(int);

            int[] receiveBuffer = new int[(profileDataSize + measureDataSize) * req.byGetProfCnt];

            using (ProgressForm progressForm = new ProgressForm())
            {
                Cursor.Current      = Cursors.WaitCursor;
                progressForm.Status = Status.Communicating;
                progressForm.Show(this);
                progressForm.Refresh();

                List <ProfileData> profileDatas = new List <ProfileData>();
                // Get profiles.
                using (PinnedObject pin = new PinnedObject(receiveBuffer))
                {
                    Rc rc = (Rc)NativeMethods.LJV7IF_GetBatchProfileAdvance(DEVICE_ID, ref req, ref rsp, ref profileInfo, pin.Pointer,
                                                                            (uint)(receiveBuffer.Length * sizeof(int)), batchMeasureData, measureData);
                    if (!CheckReturnCode(rc))
                    {
                        return;
                    }

                    // Output profile data
                    int unitSize = ProfileData.CalculateDataSize(profileInfo) + measureDataSize;
                    for (int i = 0; i < rsp.byGetProfCnt; i++)
                    {
                        profileDatas.Add(new ProfileData(receiveBuffer, unitSize * i, profileInfo));
                    }

                    // Get all profiles in the batch.
                    req.byPosMode    = BatchPos.Spec;
                    req.dwGetBatchNo = rsp.dwGetBatchNo;
                    do
                    {
                        // Update get profile position.
                        req.dwGetProfNo  = rsp.dwGetBatchTopProfNo + rsp.byGetProfCnt;
                        req.byGetProfCnt = (byte)Math.Min((uint)(byte.MaxValue), (rsp.dwGetBatchProfCnt - req.dwGetProfNo));

                        rc = (Rc)NativeMethods.LJV7IF_GetBatchProfileAdvance(DEVICE_ID, ref req, ref rsp, ref profileInfo, pin.Pointer,
                                                                             (uint)(receiveBuffer.Length * sizeof(int)), batchMeasureData, measureData);
                        if (!CheckReturnCode(rc))
                        {
                            return;
                        }
                        for (int i = 0; i < rsp.byGetProfCnt; i++)
                        {
                            profileDatas.Add(new ProfileData(receiveBuffer, unitSize * i, profileInfo));
                        }
                    } while (rsp.dwGetBatchProfCnt != (rsp.dwGetBatchTopProfNo + rsp.byGetProfCnt));
                }

                progressForm.Status = Status.Saving;
                progressForm.Refresh();

                // Save file
                SaveProfile(profileDatas, _txtSavePath.Text);
            }
        }
示例#3
0
        /// <summary>
        /// "High-speed mode get batch profiles" button pressed.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void _btnGetBatchProfile_Click(object sender, EventArgs e)
        {
            // Specify get target batch.
            LJV7IF_GET_BATCH_PROFILE_REQ req = new LJV7IF_GET_BATCH_PROFILE_REQ();

            req.byTargetBank = ProfileBank.Active;
            req.byPosMode    = BatchPos.Commited;
            req.dwGetBatchNo = 0;
            req.dwGetProfNo  = 0;
            req.byGetProfCnt = byte.MaxValue;
            req.byErase      = 0;

            LJV7IF_GET_BATCH_PROFILE_RSP rsp         = new LJV7IF_GET_BATCH_PROFILE_RSP();
            LJV7IF_PROFILE_INFO          profileInfo = new LJV7IF_PROFILE_INFO();

            int profileDataSize = MAX_PROFILE_COUNT +
                                  (Marshal.SizeOf(typeof(LJV7IF_PROFILE_HEADER)) + Marshal.SizeOf(typeof(LJV7IF_PROFILE_FOOTER))) / sizeof(int);

            int[] receiveBuffer = new int[profileDataSize * req.byGetProfCnt];

            using (ProgressForm progressForm = new ProgressForm())
            {
                Cursor.Current = Cursors.WaitCursor;

                progressForm.Status = Status.Communicating;
                progressForm.Show(this);
                progressForm.Refresh();

                List <ProfileData> profileDatas = new List <ProfileData>();
                // Get profiles.
                using (PinnedObject pin = new PinnedObject(receiveBuffer))
                {
                    Rc rc = (Rc)NativeMethods.LJV7IF_GetBatchProfile(DEVICE_ID, ref req, ref rsp, ref profileInfo, pin.Pointer,
                                                                     (uint)(receiveBuffer.Length * sizeof(int)));
                    if (!CheckReturnCode(rc))
                    {
                        return;
                    }

                    // Output profile data
                    int unitSize = ProfileData.CalculateDataSize(profileInfo);
                    for (int i = 0; i < rsp.byGetProfCnt; i++)
                    {
                        profileDatas.Add(new ProfileData(receiveBuffer, unitSize * i, profileInfo));
                    }

                    // Get all profiles in the batch.
                    req.byPosMode    = BatchPos.Spec;
                    req.dwGetBatchNo = rsp.dwGetBatchNo;
                    do
                    {
                        // Update get profile position.
                        req.dwGetProfNo  = rsp.dwGetBatchTopProfNo + rsp.byGetProfCnt;
                        req.byGetProfCnt = (byte)Math.Min((uint)(byte.MaxValue), (rsp.dwCurrentBatchProfCnt - req.dwGetProfNo));

                        rc = (Rc)NativeMethods.LJV7IF_GetBatchProfile(DEVICE_ID, ref req, ref rsp, ref profileInfo, pin.Pointer,
                                                                      (uint)(receiveBuffer.Length * sizeof(int)));
                        if (!CheckReturnCode(rc))
                        {
                            return;
                        }
                        for (int i = 0; i < rsp.byGetProfCnt; i++)
                        {
                            profileDatas.Add(new ProfileData(receiveBuffer, unitSize * i, profileInfo));
                        }
                    } while (rsp.dwGetBatchProfCnt != (rsp.dwGetBatchTopProfNo + rsp.byGetProfCnt));
                }

                progressForm.Status = Status.Saving;
                progressForm.Refresh();
                // Save file
                SaveProfile(profileDatas, _txtSavePath.Text);
            }
        }
示例#4
0
        /// <summary>
        /// 「高機能モードバッチプロファイル取得」ボタン押下
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void _btnGetBatchProfileAdvance_Click(object sender, EventArgs e)
        {
            MessageBox.Show("高機能モードバッチプロファイル取得を開始します。\nLJ-Navigator 2 が起動していないことをご確認のうえ、OKを押してください。");
            LJV7IF_GET_BATCH_PROFILE_ADVANCE_REQ req = new LJV7IF_GET_BATCH_PROFILE_ADVANCE_REQ();

            req.byPosMode    = BatchPos.Commited;
            req.dwGetBatchNo = 0;
            req.dwGetProfNo  = 0;
            req.byGetProfCnt = byte.MaxValue;

            LJV7IF_GET_BATCH_PROFILE_ADVANCE_RSP rsp = new LJV7IF_GET_BATCH_PROFILE_ADVANCE_RSP();
            LJV7IF_PROFILE_INFO profileInfo          = new LJV7IF_PROFILE_INFO();

            LJV7IF_MEASURE_DATA[] batchMeasureData = new LJV7IF_MEASURE_DATA[NativeMethods.MesurementDataCount];
            LJV7IF_MEASURE_DATA[] measureData      = new LJV7IF_MEASURE_DATA[NativeMethods.MesurementDataCount];

            int profileDataSize = MAX_PROFILE_COUNT +
                                  (Marshal.SizeOf(typeof(LJV7IF_PROFILE_HEADER)) + Marshal.SizeOf(typeof(LJV7IF_PROFILE_FOOTER))) / sizeof(int);
            int measureDataSize = Marshal.SizeOf(typeof(LJV7IF_MEASURE_DATA)) * NativeMethods.MesurementDataCount / sizeof(int);

            int[] receiveBuffer = new int[(profileDataSize + measureDataSize) * req.byGetProfCnt];

            using (ProgressForm progressForm = new ProgressForm())
            {
                Cursor.Current      = Cursors.WaitCursor;
                progressForm.Status = Status.Communicating;
                progressForm.Show(this);
                progressForm.Refresh();

                List <ProfileData> profileDatas = new List <ProfileData>();
                // プロファイルを取得
                using (PinnedObject pin = new PinnedObject(receiveBuffer))
                {
                    Rc rc = (Rc)NativeMethods.LJV7IF_GetBatchProfileAdvance(DEVICE_ID, ref req, ref rsp, ref profileInfo, pin.Pointer,
                                                                            (uint)(receiveBuffer.Length * sizeof(int)), batchMeasureData, measureData);
                    if (!CheckReturnCode(rc))
                    {
                        return;
                    }

                    // 各プロファイルデータを出力
                    int unitSize = ProfileData.CalculateDataSize(profileInfo) + measureDataSize;
                    for (int i = 0; i < rsp.byGetProfCnt; i++)
                    {
                        profileDatas.Add(new ProfileData(receiveBuffer, unitSize * i, profileInfo));
                    }

                    // バッチ内のプロファイルをすべて取得
                    req.byPosMode    = BatchPos.Spec;
                    req.dwGetBatchNo = rsp.dwGetBatchNo;
                    do
                    {
                        // 取得プロファイル位置を更新
                        req.dwGetProfNo  = rsp.dwGetBatchTopProfNo + rsp.byGetProfCnt;
                        req.byGetProfCnt = (byte)Math.Min((uint)(byte.MaxValue), (rsp.dwGetBatchProfCnt - req.dwGetProfNo));

                        rc = (Rc)NativeMethods.LJV7IF_GetBatchProfileAdvance(DEVICE_ID, ref req, ref rsp, ref profileInfo, pin.Pointer,
                                                                             (uint)(receiveBuffer.Length * sizeof(int)), batchMeasureData, measureData);
                        if (!CheckReturnCode(rc))
                        {
                            return;
                        }
                        for (int i = 0; i < rsp.byGetProfCnt; i++)
                        {
                            profileDatas.Add(new ProfileData(receiveBuffer, unitSize * i, profileInfo));
                        }
                    } while (rsp.dwGetBatchProfCnt != (rsp.dwGetBatchTopProfNo + rsp.byGetProfCnt));
                }

                progressForm.Status = Status.Saving;
                progressForm.Refresh();

                // ファイル保存
                SaveProfile(profileDatas, _txtSavePath.Text);
            }
        }
示例#5
0
        void ReadFlash(object sender, DoWorkEventArgs e)
        {
            try
            {
                if (!Connect())
                {
                    MessageBox.Show("Failed to connect to a J2534 device", "Error", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                    return;
                }
                backgroundWorker.ReportProgress(0, "Connected");

                float voltHigh = 15000;
                float voltLow  = 1000;

                if (ignoreProrgammingVoltageCheckBox.Checked)
                {
                    voltHigh = -1;
                    voltLow  = 100000;
                }
                //Ensure the programming voltage is 0v as the PCM needs to see a transition from 0 -> 18v
                float voltage = _comm.ReadProgrammingVoltage();
                backgroundWorker.ReportProgress(0, "ReadProgrammingVoltage = " + voltage + " mV");
                if (voltage > voltLow)
                {
                    voltage = _comm.PassThruSetProgrammingVoltage(PinNumber.PIN_13, PinVoltage.VOLTAGE_OFF);

                    backgroundWorker.ReportProgress(0, "SetProgrammingVoltage VOLTAGE_OFF");
                    backgroundWorker.ReportProgress(0, "ReadProgrammingVoltage = " + voltage + " mV");
                    if (voltage > voltLow)
                    {
                        MessageBox.Show("Failed to set programming voltage (pin 13) to 0 volts, measured: " + voltage + " mV");
                        return;
                    }
                }

                voltage = _comm.PassThruSetProgrammingVoltage(PinNumber.PIN_13, PinVoltage.FEPS_VOLTAGE);
                backgroundWorker.ReportProgress(0, "SetProgrammingVoltage 18000 mV");
                backgroundWorker.ReportProgress(0, "ReadProgrammingVoltage = " + voltage + " mV");
                if (voltage < voltHigh)
                {
                    MessageBox.Show("Failed to set programming voltage (pin 13) to 18 volts, measured: " + voltage + " mV");
                    return;
                }
                MessageBox.Show("Please turn the ignition off, wait 3 seconds, then turn it back on before pressing OK.");

                //Ensure the programming voltage is still high after an ignition cycle
                voltage = _comm.ReadProgrammingVoltage();
                backgroundWorker.ReportProgress(0, "ReadProgrammingVoltage = " + voltage + " mV");
                if (voltage < voltHigh)
                {
                    MessageBox.Show("Programming voltage did not persist after ignition power cycle), measured: " + voltage + " mV");
                    return;
                }


                //Enter level 1 seecurity mode
                _comm.SecurityAccess(0x01);
                backgroundWorker.ReportProgress(0, "Unlocked Controller");

                this.Invoke((MethodInvoker) delegate {
                    progressForm.Show();
                });
                var stopwatch = new Stopwatch();
                stopwatch.Start();
                flashMemory = _comm.ReadFlashMemory(backgroundWorker);
                stopwatch.Stop();
                var timeTaken = TimeSpan.FromMilliseconds(stopwatch.ElapsedMilliseconds);

                backgroundWorker.ReportProgress(0, $"Successfully read {flashMemory.Length} bytes of flash memory in {timeTaken.Minutes}:{timeTaken.Seconds}");

                voltage = _comm.PassThruSetProgrammingVoltage(PinNumber.PIN_13, PinVoltage.VOLTAGE_OFF);
                backgroundWorker.ReportProgress(0, "SetProgrammingVoltage DISCONNECT");
                backgroundWorker.ReportProgress(0, "ReadProgrammingVoltage = " + voltage + " mV");
            }
            catch (OBDException obdEx)
            {
                MessageBox.Show("Error entering reading flash due to OBD error: " + obdEx.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
            }
            catch (UDSException udsEx)
            {
                MessageBox.Show("Error entering reading flash due to UDS error: " + udsEx.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
            }
            catch (J2534Exception j2534Ex)
            {
                MessageBox.Show("Error entering security level due to J2534 error: " + j2534Ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Unknown error occured whilst entering security level: " + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
            }
            finally
            {
                Disconnect();
                backgroundWorker.ReportProgress(0, "Disconnected");
            }
        }