Пример #1
0
        /// <summary>
        /// "Get high-speed mode batch profiles" button clicked
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        /// <remarks>
        /// Read one batch worth of committed profiles that have been acquired with batch measurement in high-speed mode.
        /// </remarks>
        private void btnGetBatchProfileEx_Click(object sender, EventArgs e)
        {
            // Specify the target batch to get.
            LJV7IF_GET_BATCH_PROFILE_REQ req = new LJV7IF_GET_BATCH_PROFILE_REQ();
            req.byTargetBank = (byte)ProfileBank.Active;
            req.byPosMode = (byte)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 = Define.MAX_PROFILE_COUNT +
                (Marshal.SizeOf(typeof(LJV7IF_PROFILE_HEADER)) + Marshal.SizeOf(typeof(LJV7IF_PROFILE_FOOTER))) / Marshal.SizeOf(typeof(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(Define.DEVICE_ID, ref req, ref rsp, ref profileInfo, pin.Pointer,
                        (uint)(receiveBuffer.Length * Marshal.SizeOf(typeof(int))));
                    // @Point
                    // # When reading all the profiles from a single batch, the specified number of profiles may not be read.
                    // # To read the remaining profiles after the first set of profiles have been read, set the specification method (byPosMode)to 0x02,
                    //   specify the batch number (dwGetBatchNo), and then set the number to start reading profiles from (dwGetProfNo) and
                    //   the number of profiles to read (byGetProfCnt) to values that specify a range of profiles that have not been read to read the profiles in order.
                    // # In more detail, this process entails:
                    //   * First configure req as listed below and call this function again.
                    //      byPosMode = LJV7IF_BATCH_POS_SPEC
                    //      dwGetBatchNo = batch number that was read
                    //      byGetProfCnt = Profile number of unread in the batch
                    //   * Furthermore, if all profiles in the batch are not read,update the starting position for reading profiles (req.dwGetProfNo) and
                    //     the number of profiles to read (req.byGetProfCnt), and then call LJV7IF_GetBatchProfile again. (Repeat this process until all the profiles have been read.)

                    if (!CheckReturnCode(rc)) return;

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

                    // Get all profiles within the batch.
                    req.byPosMode = (byte)BatchPos.Spec;
                    req.dwGetBatchNo = rsp.dwGetBatchNo;
                    do
                    {
                        // Update the 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(Define.DEVICE_ID, ref req, ref rsp, ref profileInfo, pin.Pointer,
                            (uint)(receiveBuffer.Length * Marshal.SizeOf(typeof(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 the file
                SaveProfile(profileDatas, _txtSavePath.Text);
            }
        }
Пример #2
0
        /// <summary>
        /// "GetBatchProfile" button clicked.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnGetBatchProfile_Click(object sender, EventArgs e)
        {
            _sendCommand = SendCommand.GetBatchProfile;

            using (GetBatchProfileForm getBatchProfileForm = new GetBatchProfileForm())
            {
                if (DialogResult.OK == getBatchProfileForm.ShowDialog())
                {
                    _deviceData[_currentDeviceId].ProfileData.Clear();
                    _deviceData[_currentDeviceId].MeasureData.Clear();
                    // Set the command function
                    LJV7IF_GET_BATCH_PROFILE_REQ req = getBatchProfileForm.Req;
                    LJV7IF_GET_BATCH_PROFILE_RSP rsp = new LJV7IF_GET_BATCH_PROFILE_RSP();
                    LJV7IF_PROFILE_INFO profileInfo = new LJV7IF_PROFILE_INFO();
                    uint oneDataSize = GetOneProfileDataSize();
                    uint allDataSize = oneDataSize * getBatchProfileForm.Req.byGetProfCnt;
                    int[] profileData = new int[allDataSize / Marshal.SizeOf(typeof(int))];

                    using (PinnedObject pin = new PinnedObject(profileData))
                    {
                        // Send the command
                        int rc = NativeMethods.LJV7IF_GetBatchProfile(_currentDeviceId, ref req, ref rsp, ref profileInfo, pin.Pointer, allDataSize);
                        // @Point
                        // # When reading all the profiles from a single batch, the specified number of profiles may not be read.
                        // # To read the remaining profiles after the first set of profiles have been read,
                        //    set the specification method (byPosMode)to 0x02, specify the batch number (dwGetBatchNo),
                        //    and then set the number to start reading profiles from (dwGetProfNo) and the number of profiles to read (byGetProfCnt) to values
                        //    that specify a range of profiles that have not been read to read the profiles in order.
                        // # For the basic code, see "btnGetBatchProfileEx_Click."

                        // Result output
                        AddLogResult(rc, Resources.SID_GET_BATCH_PROFILE);
                        if (rc == (int)Rc.Ok)
                        {
                            // Response data display
                            AddLog(Utility.ConvertToLogString(rsp).ToString());
                            AddLog(Utility.ConvertToLogString(profileInfo).ToString());

                            AnalyzeProfileData((int)rsp.byGetProfCnt, ref profileInfo, profileData);

                            // Profile export
                            if (DataExporter.ExportOneProfile(_deviceData[_currentDeviceId].ProfileData.ToArray(), 0, _txtboxProfileFilePath.Text))
                            {
                                AddLog(@"###Saved!!");
                            }

                        }
                    }
                }
            }
        }
Пример #3
0
        /// <summary>
        /// "SetSetting" button clicked.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnSetSetting_Click(object sender, EventArgs e)
        {
            using (SettingForm settingForm = new SettingForm(true))
            {
                if (DialogResult.OK == settingForm.ShowDialog())
                {
                    LJV7IF_TARGET_SETTING targetSetting = settingForm.TargetSetting;
                    using (PinnedObject pin = new PinnedObject(settingForm.Data))
                    {
                        uint dwError = 0;
                        int rc = NativeMethods.LJV7IF_SetSetting(_currentDeviceId, settingForm.Depth, targetSetting,
                            pin.Pointer, (uint)settingForm.Data.Length, ref dwError);
                        // @Point
                        // # There are three setting areas: a) the write settings area, b) the running area, and c) the save area.
                        //   * Specify a) for the setting level when you want to change multiple settings. However, to reflect settings in the LJ-V operations, you have to call LJV7IF_ReflectSetting.
                        //	 * Specify b) for the setting level when you want to change one setting but you don't mind if this setting is returned to its value prior to the change when the power is turned off.
                        //	 * Specify c) for the setting level when you want to change one setting and you want this new value to be retained even when the power is turned off.

                        // @Point
                        //  As a usage example, we will show how to use SettingForm to configure settings such that sending a setting, with SettingForm using its initial values,
                        //  will change the sampling period in the running area to "100 Hz."
                        //  Also see the GetSetting function.

                        AddLogResult(rc, Resources.SID_SET_SETTING);
                        if (rc != (int)Rc.Ok)
                        {
                            AddError(dwError);
                        }
                    }
                }
            }
        }
Пример #4
0
        /// <summary>
        /// "GetBatchProfileAdvance" button clicked.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnGetBatchProfileAdvance_Click(object sender, EventArgs e)
        {
            _sendCommand = SendCommand.GetBatchProfileAdvance;

            using (GetBatchprofileAdvanceForm getBatchprofileAdvanceForm = new GetBatchprofileAdvanceForm())
            {
                if (DialogResult.OK == getBatchprofileAdvanceForm.ShowDialog())
                {
                    _deviceData[_currentDeviceId].ProfileData.Clear();
                    _deviceData[_currentDeviceId].MeasureData.Clear();
                    _measureDatas.Clear();

                    // Set the command function
                    LJV7IF_GET_BATCH_PROFILE_ADVANCE_REQ req = getBatchprofileAdvanceForm.Req;
                    LJV7IF_GET_BATCH_PROFILE_ADVANCE_RSP rsp = new LJV7IF_GET_BATCH_PROFILE_ADVANCE_RSP();
                    LJV7IF_PROFILE_INFO profileInfo = new LJV7IF_PROFILE_INFO();
                    uint oneDataSize = GetOneProfileDataSize() + (uint)Utility.GetByteSize(Utility.TypeOfStruct.MEASURE_DATA) * (uint)NativeMethods.MeasurementDataCount;
                    uint allDataSize = oneDataSize * getBatchprofileAdvanceForm.Req.byGetProfCnt;
                    int[] profileData = new int[allDataSize / Marshal.SizeOf(typeof(int))];
                    LJV7IF_MEASURE_DATA[] measureData = new LJV7IF_MEASURE_DATA[NativeMethods.MeasurementDataCount];
                    LJV7IF_MEASURE_DATA[] batchMeasureData = new LJV7IF_MEASURE_DATA[NativeMethods.MeasurementDataCount];

                    using (PinnedObject pin = new PinnedObject(profileData))
                    {
                        // Send the command
                        int rc = NativeMethods.LJV7IF_GetBatchProfileAdvance(_currentDeviceId, ref req, ref rsp,
                            ref profileInfo, pin.Pointer, allDataSize, batchMeasureData, measureData);
                        // @Point
                        // # When reading all the profiles from a single batch, the specified number of profiles may not be read.
                        // # To read the remaining profiles after the first set of profiles have been read,
                        //    set the specification method (byPosMode)to 0x02, specify the batch number (dwGetBatchNo),
                        //    and then set the number to start reading profiles from (dwGetProfNo) and the number of profiles to read (byGetProfCnt) to values
                        //    that specify a range of profiles that have not been read to read the profiles in order.
                        // # For the basic code, see "btnGetBatchProfileEx_Click."

                        // Result output
                        AddLogResult(rc, Resources.SID_GET_BATCH_PROFILE_ADVANCE);
                        if (rc == (int)Rc.Ok)
                        {
                            _measureDatas.Add(new MeasureData(0, measureData));
                            AddLog(Utility.ConvertToLogString(rsp).ToString());
                            AddLog(Utility.ConvertToLogString(profileInfo).ToString());
                            for (int i = 0; i < NativeMethods.MeasurementDataCount; i++)
                            {
                                AddLog(string.Format("  OUT{0:00}: {1}", (i + 1), Utility.ConvertToLogString(measureData[i]).ToString()));
                            }

                            AnalyzeBatchData((int)rsp.byGetProfCnt, ref profileInfo, false, profileData, 0);

                            // Profile export
                            if (DataExporter.ExportOneProfile(_deviceData[_currentDeviceId].ProfileData.ToArray(), 0, _txtboxProfileFilePath.Text))
                            {
                                AddLog(@"###Saved!!");
                            }
                        }
                    }
                }
            }
        }
Пример #5
0
        /// <summary>
        /// "GetStorageProfile" button clicked.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnGetStorageProfile_Click(object sender, EventArgs e)
        {
            _sendCommand = SendCommand.GetStorageProfile;

            using (GetStorageDataForm getStorageData = new GetStorageDataForm())
            {
                if (DialogResult.OK == getStorageData.ShowDialog())
                {
                    _deviceData[_currentDeviceId].ProfileData.Clear();
                    _deviceData[_currentDeviceId].MeasureData.Clear();
                    _measureDatas.Clear();
                    LJV7IF_GET_STORAGE_REQ req = getStorageData.Req;
                    // @Point
                    // # dwReadArea is the target surface to read.
                    //   The target surface to read indicates where in the internal memory usage area to read.
                    // # The method to use in specifying dwReadArea varies depending on how internal memory is allocated.
                    //   * Double buffer
                    //      0 indicates the active surface, 1 indicates surface A, and 2 indicates surface B.
                    //   * Entire area (overwrite)
                    //      Fixed to 1
                    //   * Entire area (do not overwrite)
                    //      After a setting modification, data is saved in surfaces 1, 2, 3, and so on in order, and 0 is set as the active surface.
                    // # For details, see "9.2.9.2 Internal memory."

                    LJV7IF_STORAGE_INFO storageInfo = new LJV7IF_STORAGE_INFO();
                    LJV7IF_GET_STORAGE_RSP rsp = new LJV7IF_GET_STORAGE_RSP();
                    LJV7IF_PROFILE_INFO profileInfo = new LJV7IF_PROFILE_INFO();

                    uint oneDataSize = (uint)(Marshal.SizeOf(typeof(uint)) + (uint)Utility.GetByteSize(Utility.TypeOfStruct.MEASURE_DATA)
                        * (uint)NativeMethods.MeasurementDataCount * 2 + GetOneProfileDataSize());
                    uint allDataSize = Math.Min(Define.READ_DATA_SIZE, oneDataSize * getStorageData.Req.dwDataCnt);
                    byte[] receiveData = new byte[allDataSize];
                    using (PinnedObject pin = new PinnedObject(receiveData))
                    {
                        int rc = NativeMethods.LJV7IF_GetStorageProfile(_currentDeviceId, ref req, ref storageInfo, ref rsp, ref profileInfo, pin.Pointer, allDataSize);
                        // @Point
                        // # Terminology
                        //  * Base time … time expressed with 32 bits (<- the time when the setting was changed)
                        //  * Accumulated date and time	 … counter value that indicates the elapsed time, in units of 10 ms, from the base time
                        // # The accumulated date and time are stored in the accumulated data.
                        // # The accumulated time of read data is calculated as shown below.
                        //   Accumulated time = "base time (stBaseTime of LJV7IF_GET_STORAGE_RSP)" + "accumulated date and time × 10 ms"

                        // @Point
                        // # When reading multiple profiles, the specified number of profiles may not be read.
                        // # To read the remaining profiles after the first set of profiles have been read,
                        //   set the number to start reading profiles from (dwStartNo) and the number of profiles to read (byDataCnt)
                        //   to values that specify a range of profiles that have not been read to read the profiles in order.
                        // # For the basic code, see "btnGetBatchProfileEx_Click."

                        AddLogResult(rc, Resources.SID_GET_STORAGE_PROFILE);
                        if (rc == (int)Rc.Ok)
                        {
                            // Temporarily retain the get data.
                            int measureDataSize = MeasureData.GetByteSize();
                            int profileDataSize = ProfileData.CalculateDataSize(profileInfo) * Marshal.SizeOf(typeof(int));
                            int profileMeasureDataSize = Utility.GetByteSize(Utility.TypeOfStruct.MEASURE_DATA) * NativeMethods.MeasurementDataCount;
                            int byteSize = measureDataSize + profileDataSize + profileMeasureDataSize;
                            byte[] tempRecvieMeasureData = new byte[profileMeasureDataSize];

                            for (int i = 0; i < (int)rsp.dwDataCnt; i++)
                            {
                                _measureDatas.Add(new MeasureData(receiveData, byteSize * i));
                                _deviceData[_currentDeviceId].ProfileData.Add(new ProfileData(receiveData, (measureDataSize + byteSize * i), profileInfo));
                                Buffer.BlockCopy(receiveData, (measureDataSize + profileDataSize + byteSize * i), tempRecvieMeasureData, 0, profileMeasureDataSize);
                                _deviceData[_currentDeviceId].MeasureData.Add(new MeasureData(tempRecvieMeasureData));
                            }

                            // Response data display
                            AddLog(Utility.ConvertToLogString(storageInfo).ToString());
                            AddLog(Utility.ConvertToLogString(rsp).ToString());
                            AddLog(Utility.ConvertToLogString(profileInfo).ToString());
                        }
                    }
                }
            }
        }
Пример #6
0
        /// <summary>
        /// "Sending settings (PC -> LJ)" button clicked
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        /// <remarks>Send settings in the file to the controller</remarks>
        private void btnSetSettingEx_Click(object sender, EventArgs e)
        {
            if (_txtProgramFilePath.Text.Length == 0) return;
            if (File.Exists(_txtProgramFilePath.Text) == false) return;

            // Parameter
            LJV7IF_TARGET_SETTING setting = GetSelectedProgramTargetSetting();
            UInt32 size = GetSelectedProgramDataSize();

            // Allocate buffer
            byte[] receiveBuffer = new byte[size];
            // Load program data
            using (FileStream fs = new FileStream(_txtProgramFilePath.Text, FileMode.Open))
            {
                //It is a very simple validation method.
                if (fs.Length != size)
                {
                    MessageBox.Show("File size is not match.");
                    return;
                }
                using (BinaryReader reader = new BinaryReader(fs))
                {
                    reader.Read(receiveBuffer, 0, (int)size);
                }
            }

            using (PinnedObject pin = new PinnedObject(receiveBuffer))
            {
                // Upload
                uint error = 0;
                Rc rc = (Rc)NativeMethods.LJV7IF_SetSetting(Define.DEVICE_ID, (byte)SettingDepth.Running, setting, pin.Pointer, size, ref error);
                if (!CheckReturnCode(rc)) return;
            }
        }
Пример #7
0
        /// <summary>
        /// "GetStorageBatchProfile" button clicked.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnGetStorageBatchProfile_Click(object sender, EventArgs e)
        {
            _sendCommand = SendCommand.GetStorageBatchProfile;

            using (GetStorageBatchProfileForm getStorageBatchProfileForm = new GetStorageBatchProfileForm())
            {
                if (DialogResult.OK == getStorageBatchProfileForm.ShowDialog())
                {
                    _deviceData[_currentDeviceId].ProfileData.Clear();
                    _deviceData[_currentDeviceId].MeasureData.Clear();
                    _measureDatas.Clear();
                    // Set the function data
                    LJV7IF_GET_BATCH_PROFILE_STORAGE_REQ req = getStorageBatchProfileForm.Req;
                    LJV7IF_STORAGE_INFO storageInfo = new LJV7IF_STORAGE_INFO();
                    LJV7IF_GET_BATCH_PROFILE_STORAGE_RSP rsp = new LJV7IF_GET_BATCH_PROFILE_STORAGE_RSP();
                    LJV7IF_PROFILE_INFO profileInfo = new LJV7IF_PROFILE_INFO();
                    uint oneDataSize = GetOneProfileDataSize() + (uint)(Utility.GetByteSize(Utility.TypeOfStruct.MEASURE_DATA) * (uint)NativeMethods.MeasurementDataCount);
                    uint allDataSize = oneDataSize * getStorageBatchProfileForm.Req.byGetProfCnt;
                    LJV7IF_MEASURE_DATA[] measureData = new LJV7IF_MEASURE_DATA[NativeMethods.MeasurementDataCount];
                    int[] profileData = new int[allDataSize / Marshal.SizeOf(typeof(int))];
                    uint offsetTime = 0;

                    using (PinnedObject pin = new PinnedObject(profileData))
                    {
                        // Send the command
                        int rc = NativeMethods.LJV7IF_GetStorageBatchProfile(_currentDeviceId, ref req, ref storageInfo,
                            ref rsp, ref profileInfo, pin.Pointer, allDataSize, ref offsetTime, measureData);
                        // @Point
                        // # Terminology
                        //  * Base time … time expressed with 32 bits (<- the time when the setting was changed)
                        //  * Accumulated date and time	 … counter value that indicates the elapsed time, in units of 10 ms, from the base time
                        // # The accumulated date and time are stored in the accumulated data.
                        // # The accumulated time of read data is calculated as shown below.
                        //   Accumulated time = "base time (stBaseTime of LJV7IF_GET_STORAGE_RSP)" + "accumulated date and time × 10 ms"

                        // @Point
                        // # When reading all the profiles from a single batch, the specified number of profiles may not be read.
                        // # To read the remaining profiles after the first set of profiles have been read,
                        //   specify the batch number (dwGetBatchNo), and then set the number to start reading profiles
                        //   from (dwGetTopProfNo) and the number of profiles to read (byGetProfCnt) to values
                        //   that specify a range of profiles that have not been read to read the profiles in order.
                        // # For the basic code, see "btnGetBatchProfileEx_Click."

                        // Result output
                        AddLogResult(rc, Resources.SID_GET_STORAGE_BATCH_PROFILE);
                        if (rc == (int)Rc.Ok)
                        {
                            AnalyzeBatchData((int)rsp.byGetProfCnt, ref profileInfo, false, profileData, 0);

                            _measureDatas.Add(new MeasureData(offsetTime, measureData));
                            // Response data display
                            AddLog(Utility.ConvertToLogString(storageInfo).ToString());
                            AddLog(Utility.ConvertToLogString(rsp).ToString());
                            AddLog(Utility.ConvertToLogString(profileInfo).ToString());
                            AddLog(string.Format(@"offsetTime	:{0}", offsetTime));
                        }
                    }
                }
            }
        }
Пример #8
0
        /// <summary>
        /// "GetStorageData" button clicked.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnGetStorageData_Click(object sender, EventArgs e)
        {
            _sendCommand = SendCommand.GetStorageData;

            using (GetStorageDataForm getStorageData = new GetStorageDataForm())
            {
                if (DialogResult.OK == getStorageData.ShowDialog())
                {
                    _measureDatas.Clear();
                    LJV7IF_GET_STORAGE_REQ req = getStorageData.Req;
                    // @Point
                    // # dwReadArea is the target surface to read.
                    //    The target surface to read indicates where in the internal memory usage area to read.
                    // # The method to use in specifying dwReadArea varies depending on how internal memory is allocated.
                    //   * Double buffer
                    //      0 indicates the active surface, 1 indicates surface A, and 2 indicates surface B.
                    //   * Entire area (overwrite)
                    //      Fixed to 1
                    //   * Entire area (do not overwrite)
                    //      After a setting modification, data is saved in surfaces 1, 2, 3, and so on in order, and 0 is set as the active surface.
                    // # For details, see "9.2.9.2 Internal memory."

                    LJV7IF_STORAGE_INFO storageInfo = new LJV7IF_STORAGE_INFO();
                    LJV7IF_GET_STORAGE_RSP rsp = new LJV7IF_GET_STORAGE_RSP();
                    uint oneDataSize = (uint)(Marshal.SizeOf(typeof(uint)) + (uint)Utility.GetByteSize(Utility.TypeOfStruct.MEASURE_DATA) * (uint)NativeMethods.MeasurementDataCount);
                    uint allDataSize = Math.Min(Define.READ_DATA_SIZE, oneDataSize * getStorageData.Req.dwDataCnt);
                    byte[] receiveData = new byte[allDataSize];
                    using (PinnedObject pin = new PinnedObject(receiveData))
                    {
                        int rc = NativeMethods.LJV7IF_GetStorageData(_currentDeviceId, ref req, ref storageInfo, ref rsp, pin.Pointer, allDataSize);
                        AddLogResult(rc, Resources.SID_GET_STORAGE_DATA);
                        // @Point
                        // # Terminology
                        //  * Base time … time expressed with 32 bits (<- the time when the setting was changed)
                        //  * Accumulated date and time	 … counter value that indicates the elapsed time, in units of 10 ms, from the base time
                        // # The accumulated date and time are stored in the accumulated data.
                        // # The accumulated time of read data is calculated as shown below.
                        //   Accumulated time = "base time (stBaseTime of LJV7IF_GET_STORAGE_RSP)" + "accumulated date and time × 10 ms"

                        if (rc == (int)Rc.Ok)
                        {
                            // Temporarily retain the get data.
                            int byteSize = MeasureData.GetByteSize();
                            for (int i = 0; i < (int)rsp.dwDataCnt; i++)
                            {
                                _measureDatas.Add(new MeasureData(receiveData, byteSize * i));
                            }

                            // Response data display
                            AddLog(Utility.ConvertToLogString(storageInfo).ToString());
                            AddLog(Utility.ConvertToLogString(rsp).ToString());
                        }
                    }
                }
            }
        }
Пример #9
0
        /// <summary>
        /// "Receiving settings (LJ -> PC)" button clicked.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        /// <remarks>Receive settings from the controller, and then write these settings to the file</remarks>
        private void btnGetSettingEx_Click(object sender, EventArgs e)
        {
            if (_txtProgramFilePath.Text.Length == 0) return;

            // Parameter
            LJV7IF_TARGET_SETTING setting = GetSelectedProgramTargetSetting();
            UInt32 size = GetSelectedProgramDataSize();							 // Environment:60, Common:12, Program number:10932

            // Allocate buffer
            byte[] receiveBuffer = new byte[size];
            using (PinnedObject pin = new PinnedObject(receiveBuffer))
            {
                // Download
                Rc rc = (Rc)NativeMethods.LJV7IF_GetSetting(Define.DEVICE_ID, (byte)SettingDepth.Running, setting, pin.Pointer, size);
                if (!CheckReturnCode(rc)) return;
            }
            // Save program data
            using (FileStream fs = new FileStream(_txtProgramFilePath.Text, FileMode.Create))
            using (BinaryWriter writer = new BinaryWriter(fs))
            {
                writer.Write(receiveBuffer);
            }
        }
Пример #10
0
        /// <summary>
        /// "GetSetting" button clicked.
        /// </summary>
        /// <param name="sender"></param>
        private void btnGetSetting_Click(object sender, EventArgs e)
        {
            using (SettingForm settingForm = new SettingForm(false))
            {
                if (DialogResult.OK == settingForm.ShowDialog())
                {
                    LJV7IF_TARGET_SETTING targetSetting = settingForm.TargetSetting;
                    byte[] data = new byte[settingForm.DataLength];
                    using (PinnedObject pin = new PinnedObject(data))
                    {
                        int rc = NativeMethods.LJV7IF_GetSetting(_currentDeviceId, settingForm.Depth, targetSetting,
                            pin.Pointer, (uint)settingForm.DataLength);
                        // @Point
                        //  We have prepared an object for reading the sampling period into the setting's initial value.
                        //  Also see the SetSetting function.

                        AddLogResult(rc, Resources.SID_GET_SETTING);
                        if (rc == (int)Rc.Ok)
                        {
                            AddLog("\t    0  1  2  3  4  5  6  7");
                            StringBuilder sb = new StringBuilder();
                            // Get data display
                            for (int i = 0; i < settingForm.DataLength; i++)
                            {
                                if ((i % 8) == 0) sb.Append(string.Format("  [0x{0:x4}] ", i));

                                sb.Append(string.Format("{0:x2} ", data[i]));
                                if (((i % 8) == 7) || (i == settingForm.DataLength - 1))
                                {
                                    AddLog(sb.ToString());
                                    sb.Remove(0, sb.Length);
                                }
                            }
                        }
                    }
                }
            }
        }
Пример #11
0
        /// <summary>
        /// "GetProfile" button clicked.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnGetProfile_Click(object sender, EventArgs e)
        {
            _sendCommand = SendCommand.GetProfile;

            using (ProfileForm profileForm = new ProfileForm())
            {
                if (DialogResult.OK == profileForm.ShowDialog())
                {
                    _deviceData[_currentDeviceId].ProfileData.Clear();
                    _deviceData[_currentDeviceId].MeasureData.Clear();
                    LJV7IF_GET_PROFILE_REQ req = profileForm.Req;
                    LJV7IF_GET_PROFILE_RSP rsp = new LJV7IF_GET_PROFILE_RSP();
                    LJV7IF_PROFILE_INFO profileInfo = new LJV7IF_PROFILE_INFO();
                    uint oneProfDataBuffSize = GetOneProfileDataSize();
                    uint allProfDataBuffSize = oneProfDataBuffSize * req.byGetProfCnt;
                    int[] profileData = new int[allProfDataBuffSize / Marshal.SizeOf(typeof(int))];

                    using (PinnedObject pin = new PinnedObject(profileData))
                    {
                        int rc = NativeMethods.LJV7IF_GetProfile(_currentDeviceId, ref req, ref rsp, ref profileInfo, pin.Pointer, allProfDataBuffSize);
                        AddLogResult(rc, Resources.SID_GET_PROFILE);
                        if (rc == (int)Rc.Ok)
                        {
                            // Response data display
                            AddLog(Utility.ConvertToLogString(rsp).ToString());
                            AddLog(Utility.ConvertToLogString(profileInfo).ToString());

                            AnalyzeProfileData((int)rsp.byGetProfCnt, ref profileInfo, profileData);

                            // Profile export
                            if (DataExporter.ExportOneProfile(_deviceData[_currentDeviceId].ProfileData.ToArray(), 0, _txtboxProfileFilePath.Text))
                            {
                                AddLog(@"###Saved!!");
                            }
                        }
                    }
                }
            }
        }
Пример #12
0
        /// <summary>
        /// "Get high-speed mode profiles" button clicked
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        /// <remarks>
        /// Get profiles in high-speed mode, and then output profile data to file.
        /// </remarks>
        private void btnGetProfileEx_Click(object sender, EventArgs e)
        {
            LJV7IF_GET_PROFILE_REQ req = new LJV7IF_GET_PROFILE_REQ();
            req.byTargetBank = (byte)ProfileBank.Active;
            req.byPosMode = (byte)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 = Define.MAX_PROFILE_COUNT +
                (Marshal.SizeOf(typeof(LJV7IF_PROFILE_HEADER)) + Marshal.SizeOf(typeof(LJV7IF_PROFILE_FOOTER))) / Marshal.SizeOf(typeof(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(Define.DEVICE_ID, ref req, ref rsp, ref profileInfo, pin.Pointer,
                        (uint)(receiveBuffer.Length * Marshal.SizeOf(typeof(int))));
                    if (!CheckReturnCode(rc)) return;
                }

                // Output the data of each profile
                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 the file
                SaveProfile(profileDatas, _txtSavePath.Text);
            }
        }
Пример #13
0
        /// <summary>
        /// "GetProfileAdvance" button clicked.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnGetProfileAdvance_Click(object sender, EventArgs e)
        {
            _sendCommand = SendCommand.GetProfileAdvance;
            _deviceData[_currentDeviceId].ProfileData.Clear();
            _deviceData[_currentDeviceId].MeasureData.Clear();
            _measureDatas.Clear();

            // Set the command function
            LJV7IF_PROFILE_INFO profileInfo = new LJV7IF_PROFILE_INFO();
            uint dataSize = GetOneProfileDataSize();
            int[] profileData = new int[dataSize / Marshal.SizeOf(typeof(int))];
            LJV7IF_MEASURE_DATA[] measureData = new LJV7IF_MEASURE_DATA[NativeMethods.MeasurementDataCount];

            using (PinnedObject pin = new PinnedObject(profileData))
            {
                // Send the command
                int rc = NativeMethods.LJV7IF_GetProfileAdvance(_currentDeviceId, ref profileInfo, pin.Pointer, dataSize, measureData);

                // Result output
                AddLogResult(rc, Resources.SID_GET_PROFILE_ADVANCE);
                if (rc == (int)Rc.Ok)
                {
                    // Response data display
                    AddLog(Utility.ConvertToLogString(profileInfo).ToString());

                    _measureDatas.Add(new MeasureData(0, measureData));
                    AnalyzeProfileData(1, ref profileInfo, profileData);
                    for (int i = 0; i < NativeMethods.MeasurementDataCount; i++)
                    {
                        AddLog(string.Format("  OUT{0:00}: {1}", (i + 1), Utility.ConvertToLogString(measureData[i]).ToString()));
                    }
                }
            }
        }
Пример #14
0
        /// <summary>
        /// "Get advanced mode profiles" button clicked
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        /// <remarks>
        /// Get profiles in advanced mode, and then output profile data to file.
        /// </remarks>
        private void btnGetProfileAdvanceEx_Click(object sender, EventArgs e)
        {
            LJV7IF_PROFILE_INFO profileInfo = new LJV7IF_PROFILE_INFO();
            LJV7IF_MEASURE_DATA[] measureData = new LJV7IF_MEASURE_DATA[NativeMethods.MeasurementDataCount];		 // OUT1 to OUT16 measurement value

            int profileDataSize = Define.MAX_PROFILE_COUNT +
                (Marshal.SizeOf(typeof(LJV7IF_PROFILE_HEADER)) + Marshal.SizeOf(typeof(LJV7IF_PROFILE_FOOTER))) / Marshal.SizeOf(typeof(int));
            int[] receiveBuffer = new int[profileDataSize];	 // 3,207 (total of the header, the footer, and the 3,200 data entries)

            using (PinnedObject pin = new PinnedObject(receiveBuffer))
            {
                Rc rc = (Rc)NativeMethods.LJV7IF_GetProfileAdvance(Define.DEVICE_ID, ref profileInfo, pin.Pointer,
                (uint)(receiveBuffer.Length * Marshal.SizeOf(typeof(int))), measureData);

                if (!CheckReturnCode(rc)) return;
            }

            List<ProfileData> profileDatas = new List<ProfileData>();
            // Output the data of each profile
            profileDatas.Add(new ProfileData(receiveBuffer, 0, profileInfo));

            // Save the file
            SaveProfile(profileDatas, _txtSavePath.Text);
        }
Пример #15
0
 /// <summary>
 /// "GetError" button clicked.
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void btnGetError_Click(object sender, EventArgs e)
 {
     using (GetErrorForm getErrorForm = new GetErrorForm())
     {
         if (DialogResult.OK == getErrorForm.ShowDialog())
         {
             byte errCnt = 0;
             ushort[] errCode = new ushort[Math.Max((int)getErrorForm.RcvMax, 1)];
             using (PinnedObject pin = new PinnedObject(errCode))
             {
                 int rc = NativeMethods.LJV7IF_GetError(_currentDeviceId, getErrorForm.RcvMax, ref errCnt, pin.Pointer);
                 AddLogResult(rc, Resources.SID_GET_ERROR);
                 if (rc == (int)Rc.Ok)
                 {
                     AddLog(string.Format(@"ErrCnt:{0}", errCnt.ToString("x")));
                     for (int i = 0; i < errCnt; i++)
                     {
                         AddLog(string.Format(@"ErrCode[{0}]:0x{1:0000}", i, errCode[i].ToString("x4")));
                     }
                 }
             }
         }
     }
 }