/// <summary> /// Get the byte size of the structure. /// </summary> /// <param name="profileHeader">Structure whose byte size you want to get.</param> /// <returns>Byte size</returns> public static int GetByteSize(TypeOfStruct type) { switch (type) { case TypeOfStruct.PROFILE_HEADER: LJV7IF_PROFILE_HEADER profileHeader = new LJV7IF_PROFILE_HEADER(); return(Marshal.SizeOf(profileHeader)); case TypeOfStruct.PROFILE_FOOTER: LJV7IF_PROFILE_FOOTER profileFooter = new LJV7IF_PROFILE_FOOTER(); return(Marshal.SizeOf(profileFooter)); case TypeOfStruct.MEASURE_DATA: LJV7IF_MEASURE_DATA measureData = new LJV7IF_MEASURE_DATA(); return(Marshal.SizeOf(measureData)); } return(0); }
/// <summary> /// Get the string for log output. /// </summary> /// <param name="obj">Structure that you want to convert to a string</param> /// <returns>String for log output</returns> public static StringBuilder ConvertToLogString(LJV7IF_MEASURE_DATA measureData) { StringBuilder sb = new StringBuilder(); string dataInfo = string.Empty; switch (measureData.byDataInfo) { case (int)LJV7IF_MEASURE_DATA_INFO.LJV7IF_MEASURE_DATA_INFO_VALID: dataInfo = @"Valid "; break; case (int)LJV7IF_MEASURE_DATA_INFO.LJV7IF_MEASURE_DATA_INFO_ALARM: dataInfo = @"Alarm value "; break; case (int)LJV7IF_MEASURE_DATA_INFO.LJV7IF_MEASURE_DATA_INFO_WAIT: dataInfo = @"Judgment wait value "; break; default: dataInfo = @"Unexpected value "; break; } sb.Append(dataInfo); string judge = string.Empty; switch (measureData.byJudge) { case 0: judge = @"______ "; break; case (int)LJV7IF_JUDGE_RESULT.LJV7IF_JUDGE_RESULT_HI: judge = @"HI____ "; break; case (int)LJV7IF_JUDGE_RESULT.LJV7IF_JUDGE_RESULT_GO: judge = @"__GO__ "; break; case (int)LJV7IF_JUDGE_RESULT.LJV7IF_JUDGE_RESULT_LO: judge = @"____LO "; break; case (int)(LJV7IF_JUDGE_RESULT.LJV7IF_JUDGE_RESULT_HI | LJV7IF_JUDGE_RESULT.LJV7IF_JUDGE_RESULT_LO): judge = @"HI__LO "; break; case (int)(LJV7IF_JUDGE_RESULT.LJV7IF_JUDGE_RESULT_HI | LJV7IF_JUDGE_RESULT.LJV7IF_JUDGE_RESULT_GO | LJV7IF_JUDGE_RESULT.LJV7IF_JUDGE_RESULT_LO): judge = @"ALL BIT "; break; default: judge = @"UNEXPECTED "; break; } sb.Append(judge); sb.Append(measureData.fValue.ToString()); return(sb); }
/// <summary> /// "Get advanced 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 advanced mode. /// </remarks> private void btnGetBatchProfileAdvanceEx_Click(object sender, EventArgs e) { MessageBox.Show("We will start Advanced mode get batch profiles."); LJV7IF_GET_BATCH_PROFILE_ADVANCE_REQ req = new LJV7IF_GET_BATCH_PROFILE_ADVANCE_REQ(); // Get request structure req.byPosMode = (byte)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.MeasurementDataCount]; LJV7IF_MEASURE_DATA[] measureData = new LJV7IF_MEASURE_DATA[NativeMethods.MeasurementDataCount]; int profileDataSize = Define.MAX_PROFILE_COUNT + (Marshal.SizeOf(typeof(LJV7IF_PROFILE_HEADER)) + Marshal.SizeOf(typeof(LJV7IF_PROFILE_FOOTER))) / Marshal.SizeOf(typeof(int)); int measureDataSize = Marshal.SizeOf( typeof(LJV7IF_MEASURE_DATA) ) * NativeMethods.MeasurementDataCount / Marshal.SizeOf(typeof(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(Define.DEVICE_ID, ref req, ref rsp, ref profileInfo, pin.Pointer, (uint)(receiveBuffer.Length * Marshal.SizeOf(typeof(int))), 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. // # 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) + measureDataSize; 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.dwGetBatchProfCnt - req.dwGetProfNo)); rc = (Rc)NativeMethods.LJV7IF_GetBatchProfileAdvance(Define.DEVICE_ID, ref req, ref rsp, ref profileInfo, pin.Pointer, (uint)(receiveBuffer.Length * Marshal.SizeOf(typeof(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 the file SaveProfile(profileDatas, _txtSavePath.Text); } }
/// <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!!"); } } } } } }
/// <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())); } } } }
/// <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)); } } } } }
/// <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); }
/// <summary> /// "Get current values" button clicked /// </summary> /// <param name="sender"></param> /// <param name="e"></param> /// <remarks>Get the latest measurement values of OUT1 to OUT16.</remarks> private void btnGetMeasureValueEx_Click(object sender, EventArgs e) { LJV7IF_MEASURE_DATA[] measureData = new LJV7IF_MEASURE_DATA[NativeMethods.MeasurementDataCount]; Rc rc = (Rc)NativeMethods.LJV7IF_GetMeasurementValue(Define.DEVICE_ID, measureData); if (!CheckReturnCode(rc)) return; MeasureData data = new MeasureData(measureData); StringBuilder sb = new StringBuilder(); for (int i = 0; i < NativeMethods.MeasurementDataCount; i++) { sb.Append(string.Format("OUT {0:d2}:\t{1,0:f4}\r\n", (i + 1), measureData[i].fValue)); } _txtMeasureData.Text = sb.ToString(); }
/// <summary> /// "GetMeasurementValue" button clicked. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnGetMeasurementValue_Click(object sender, EventArgs e) { _sendCommand = SendCommand.GetMeasurementValue; LJV7IF_MEASURE_DATA[] measureData = new LJV7IF_MEASURE_DATA[NativeMethods.MeasurementDataCount]; int rc = NativeMethods.LJV7IF_GetMeasurementValue(_currentDeviceId, measureData); AddLogResult(rc, Resources.SID_GET_MEASUREMENT_VALUE); if (rc == (int)Rc.Ok) { _measureDatas.Clear(); _measureDatas.Add(new MeasureData(0, measureData)); for (int i = 0; i < NativeMethods.MeasurementDataCount; i++) { AddLog(string.Format(" OUT{0:00}: {1}", (i + 1), Utility.ConvertToLogString(measureData[i]).ToString())); } } }
/// <summary> /// Get the byte size of the structure. /// </summary> /// <param name="profileHeader">Structure whose byte size you want to get.</param> /// <returns>Byte size</returns> public static int GetByteSize(TypeOfStruct type) { switch (type) { case TypeOfStruct.PROFILE_HEADER: LJV7IF_PROFILE_HEADER profileHeader = new LJV7IF_PROFILE_HEADER(); return Marshal.SizeOf(profileHeader); case TypeOfStruct.PROFILE_FOOTER: LJV7IF_PROFILE_FOOTER profileFooter = new LJV7IF_PROFILE_FOOTER(); return Marshal.SizeOf(profileFooter); case TypeOfStruct.MEASURE_DATA: LJV7IF_MEASURE_DATA measureData = new LJV7IF_MEASURE_DATA(); return Marshal.SizeOf(measureData); } return 0; }
/// <summary> /// Get the string for log output. /// </summary> /// <param name="obj">Structure that you want to convert to a string</param> /// <returns>String for log output</returns> public static StringBuilder ConvertToLogString(LJV7IF_MEASURE_DATA measureData) { StringBuilder sb = new StringBuilder(); string dataInfo = string.Empty; switch (measureData.byDataInfo) { case (int)LJV7IF_MEASURE_DATA_INFO.LJV7IF_MEASURE_DATA_INFO_VALID: dataInfo = @"Valid "; break; case (int)LJV7IF_MEASURE_DATA_INFO.LJV7IF_MEASURE_DATA_INFO_ALARM: dataInfo = @"Alarm value "; break; case (int)LJV7IF_MEASURE_DATA_INFO.LJV7IF_MEASURE_DATA_INFO_WAIT: dataInfo = @"Judgment wait value "; break; default: dataInfo = @"Unexpected value "; break; } sb.Append(dataInfo); string judge = string.Empty; switch (measureData.byJudge) { case 0: judge = @"______ "; break; case (int)LJV7IF_JUDGE_RESULT.LJV7IF_JUDGE_RESULT_HI: judge = @"HI____ "; break; case (int)LJV7IF_JUDGE_RESULT.LJV7IF_JUDGE_RESULT_GO: judge = @"__GO__ "; break; case (int)LJV7IF_JUDGE_RESULT.LJV7IF_JUDGE_RESULT_LO: judge = @"____LO "; break; case (int)(LJV7IF_JUDGE_RESULT.LJV7IF_JUDGE_RESULT_HI | LJV7IF_JUDGE_RESULT.LJV7IF_JUDGE_RESULT_LO): judge = @"HI__LO "; break; case (int)(LJV7IF_JUDGE_RESULT.LJV7IF_JUDGE_RESULT_HI | LJV7IF_JUDGE_RESULT.LJV7IF_JUDGE_RESULT_GO | LJV7IF_JUDGE_RESULT.LJV7IF_JUDGE_RESULT_LO): judge = @"ALL BIT "; break; default: judge = @"UNEXPECTED "; break; } sb.Append(judge); sb.Append(measureData.fValue.ToString()); return sb; }