static void WriteTargetData(string in_com) { int ret; // Connect CMMISDK_Port Port = new CMMISDK_Port(); Port.port_name = new byte[Define.SIZE_PORTNAME]; for (int name_count = 0; name_count < in_com.Length; name_count++) { Port.port_name[name_count] = Convert.ToByte(in_com[name_count]); } int instrumentNo = 0; ret = CMMISDK_API.CMMISDK_Connect(ref Port, ref instrumentNo); if (!IsNormalCode(ret)) { Console.WriteLine("Error:{0} CMMISDK_Connect", ret); CMMISDK_API.CMMISDK_Disconnect(instrumentNo); return; } // Get instrumentInfo CMMISDK_InstrumentInfo instInfo = new CMMISDK_InstrumentInfo(); ret = CMMISDK_API.CMMISDK_GetInstrumentInfo(instrumentNo, ref instInfo); if (!IsNormalCode(ret)) { Console.WriteLine("Error:{0} CMMISDK_GetInstrumentInfo", ret); CMMISDK_API.CMMISDK_Disconnect(instrumentNo); return; } if (Encoding.ASCII.GetString(instInfo.InstrumentName).TrimEnd('\0') != "CM-25cG") { Console.WriteLine("Unsppoted instrument"); CMMISDK_API.CMMISDK_Disconnect(instrumentNo); return; } Console.WriteLine("Please input the target number to be written. 1-2500"); int targetNum = Convert.ToInt32(Console.ReadLine()); //Clear target information ret = CMMISDK_API.CMMISDK_ClearTargetInfo(instrumentNo); if (!IsNormalCode(ret)) { Console.WriteLine("Error:{0} CMMISDK_ClearTargetInfo", ret); CMMISDK_API.CMMISDK_Disconnect(instrumentNo); return; } // Set Target Property CMMISDK_TargetProperty targetProperty = new CMMISDK_TargetProperty(); // Set time targetProperty.date = new int[Define.SIZE_DATE]; DateTime date = DateTime.Now; targetProperty.date[0] = date.Year; targetProperty.date[1] = date.Month; targetProperty.date[2] = date.Day; targetProperty.date[3] = date.Hour; targetProperty.date[4] = date.Minute; targetProperty.date[5] = date.Second; // Set group list targetProperty.group_list = new int[] { 0, 0, 0, 0, 0 }; // Set meas type targetProperty.meas_type = (int)_CMMISDK_MeasType.MEASTYPE_NONE; // Set meas mode targetProperty.meas_mode = (int)_CMMISDK_MeasMode.MEASMODE_COLORANDGLOSS; // Set meas area targetProperty.meas_area = (int)_CMMISDK_MeasArea.AREA_MAV; // Set meas angel targetProperty.meas_angle = (int)_CMMISDK_MeasAngle.MEAS_ANGLE_NONE; // Set light direction targetProperty.meas_ldirection = (int)_CMMISDK_LightDirection.LDIRECTION_NONE; // Set meas specular component targetProperty.meas_scie = (int)_CMMISDK_SpecularComponent.SC_NONE; // Set meas UV targetProperty.meas_uv = (int)_CMMISDK_Uv.UV_NONE; // Set warning level targetProperty.warning_level = 80; // Set warning targetProperty.warning = 0; // Set diagnosis targetProperty.diagnosis = 0; // Set data attribute int specOrColor = 0; Console.WriteLine("Please set 1 for spectral and 2 for colorimetric."); specOrColor = Convert.ToInt32(Console.ReadLine()); if (specOrColor == 1) { // spectral data targetProperty.data_attr = (int)_CMMISDK_DataAttr.DATAATTR_SPEC; } else { // colorimetric data targetProperty.data_attr = (int)_CMMISDK_DataAttr.DATAATTR_LAB; } // Set name (MAX 30 characters) string name = "target:" + targetNum.ToString(); if (name.Length > 30) { name.Remove(30); } targetProperty.name = Encoding.ASCII.GetBytes(name.PadRight(Define.SIZE_DATANAME, '\0')); ret = CMMISDK_API.CMMISDK_SetTargetProperty(instrumentNo, ref targetProperty); if (!IsNormalCode(ret)) { Console.WriteLine("Error:{0} CMMISDK_SetTargetProperty", ret); CMMISDK_API.CMMISDK_Disconnect(instrumentNo); return; } // Set target data if (specOrColor == 1) { // Set spectral data CMMISDK_Data targetData = new CMMISDK_Data() { data = new double[Define.SIZE_DATA] }; CMMISDK_Data targetGloss = new CMMISDK_Data() { data = new double[Define.SIZE_DATA] }; int count = 0; for (int i = instInfo.WaveLengthStart; i <= instInfo.WaveLengthEnd; i += instInfo.WaveLengthPitch) { targetData.data[count] = 100.00; count++; } ret = CMMISDK_API.CMMISDK_SetTargetData(instrumentNo, (int)_CMMISDK_DataType.DATATYPE_SPEC, ref targetData); if (!IsNormalCode(ret)) { Console.WriteLine("Error:{0} CMMISDK_SetTargetData SCI", ret); CMMISDK_API.CMMISDK_Disconnect(instrumentNo); return; } // Set gloss data targetGloss.data[0] = 10.0; ret = CMMISDK_API.CMMISDK_SetTargetData(instrumentNo, (int)_CMMISDK_DataType.DATATYPE_GLOSS, ref targetGloss); if (!IsNormalCode(ret)) { Console.WriteLine("Error:{0} CMMISDK_SetTargetData GLOSS", ret); CMMISDK_API.CMMISDK_Disconnect(instrumentNo); return; } } else { // colorimetric data CMMISDK_ColorCond cond; cond.obs = (int)_CMMISDK_Observer.OBS_10; cond.ill = (int)_CMMISDK_Illuminant.ILL_D65; cond.colorSpace = (int)_CMMISDK_ColorSpace.COLOR_LAB; CMMISDK_Data targetData = new CMMISDK_Data() { data = new double[Define.SIZE_DATA] }; targetData.data[0] = 91.11; targetData.data[1] = -1.11; targetData.data[2] = 1.11; // light source primary ret = CMMISDK_API.CMMISDK_SetTargetDataColor(instrumentNo, (int)_CMMISDK_DataType.DATATYPE_SPEC, 0, ref cond, ref targetData); if (!IsNormalCode(ret)) { Console.WriteLine("Error:{0} CMMISDK_SetTargetData color primary SCI", ret); CMMISDK_API.CMMISDK_Disconnect(instrumentNo); return; } cond.obs = (int)_CMMISDK_Observer.OBS_10; cond.ill = (int)_CMMISDK_Illuminant.ILL_C; // light source secondary targetData.data[0] = 92.22; targetData.data[1] = -2.22; targetData.data[2] = 2.22; ret = CMMISDK_API.CMMISDK_SetTargetDataColor(instrumentNo, (int)_CMMISDK_DataType.DATATYPE_SPEC, 1, ref cond, ref targetData); if (!IsNormalCode(ret)) { Console.WriteLine("Error:{0} CMMISDK_SetTargetData color secondary SCI", ret); CMMISDK_API.CMMISDK_Disconnect(instrumentNo); return; } // gloss data CMMISDK_Data glossData = new CMMISDK_Data() { data = new double[Define.SIZE_DATA] }; glossData.data[0] = 11.00; // light source primary ret = CMMISDK_API.CMMISDK_SetTargetDataColor(instrumentNo, (int)_CMMISDK_DataType.DATATYPE_GLOSS, 0, ref cond, ref glossData); if (!IsNormalCode(ret)) { Console.WriteLine("Error:{0} CMMISDK_SetTargetData color gloss", ret); CMMISDK_API.CMMISDK_Disconnect(instrumentNo); return; } } // Set tolerance for light source primary CMMISDK_ToleranceData tolerancePrimaryData = new CMMISDK_ToleranceData(); tolerancePrimaryData.upper_enable = 1; tolerancePrimaryData.upper_value = 110; tolerancePrimaryData.lower_enable = 1; tolerancePrimaryData.lower_value = -120; ret = CMMISDK_API.CMMISDK_SetToleranceForTarget(instrumentNo, (int)_CMMISDK_ToleranceType.TOLETYPE_SPEC, 0, (int)_CMMISDK_ToleranceId.TOLERANCE_ID_L, ref tolerancePrimaryData); if (!IsNormalCode(ret)) { Console.WriteLine("Error:{0} CMMISDK_SetToleranceForTarget primary L*", ret); CMMISDK_API.CMMISDK_Disconnect(instrumentNo); return; } ret = CMMISDK_API.CMMISDK_SetToleranceForTarget(instrumentNo, (int)_CMMISDK_ToleranceType.TOLETYPE_SPEC, 0, (int)_CMMISDK_ToleranceId.TOLERANCE_ID_A, ref tolerancePrimaryData); if (!IsNormalCode(ret)) { Console.WriteLine("Error:{0} CMMISDK_SetToleranceForTarget primary a*", ret); CMMISDK_API.CMMISDK_Disconnect(instrumentNo); return; } ret = CMMISDK_API.CMMISDK_SetToleranceForTarget(instrumentNo, (int)_CMMISDK_ToleranceType.TOLETYPE_SPEC, 0, (int)_CMMISDK_ToleranceId.TOLERANCE_ID_B, ref tolerancePrimaryData); if (!IsNormalCode(ret)) { Console.WriteLine("Error:{0} CMMISDK_SetToleranceForTarget primary b*", ret); CMMISDK_API.CMMISDK_Disconnect(instrumentNo); return; } // Set tolerance for light source secondary CMMISDK_ToleranceData toleranceSecondaryData = new CMMISDK_ToleranceData(); toleranceSecondaryData.upper_enable = 0; toleranceSecondaryData.upper_value = 150; toleranceSecondaryData.lower_enable = 0; toleranceSecondaryData.lower_value = -160; ret = CMMISDK_API.CMMISDK_SetToleranceForTarget(instrumentNo, (int)_CMMISDK_ToleranceType.TOLETYPE_SPEC, 1, (int)_CMMISDK_ToleranceId.TOLERANCE_ID_L, ref toleranceSecondaryData); if (!IsNormalCode(ret)) { Console.WriteLine("Error:{0} CMMISDK_SetToleranceForTarget secondary L*", ret); CMMISDK_API.CMMISDK_Disconnect(instrumentNo); return; } ret = CMMISDK_API.CMMISDK_SetToleranceForTarget(instrumentNo, (int)_CMMISDK_ToleranceType.TOLETYPE_SPEC, 1, (int)_CMMISDK_ToleranceId.TOLERANCE_ID_A, ref toleranceSecondaryData); if (!IsNormalCode(ret)) { Console.WriteLine("Error:{0} CMMISDK_SetToleranceForTarget secondary a*", ret); CMMISDK_API.CMMISDK_Disconnect(instrumentNo); return; } ret = CMMISDK_API.CMMISDK_SetToleranceForTarget(instrumentNo, (int)_CMMISDK_ToleranceType.TOLETYPE_SPEC, 1, (int)_CMMISDK_ToleranceId.TOLERANCE_ID_B, ref toleranceSecondaryData); if (!IsNormalCode(ret)) { Console.WriteLine("Error:{0} CMMISDK_SetToleranceForTarget secondary b*", ret); CMMISDK_API.CMMISDK_Disconnect(instrumentNo); return; } // Set parametric for tolerance CMMISDK_ParametricCoef parametricData = new CMMISDK_ParametricCoef(); parametricData.coef = new double[Define.SIZE_PARAMETRIC_COEF]; parametricData.coef[0] = 1.1; parametricData.coef[1] = 1.2; ret = CMMISDK_API.CMMISDK_SetParametricForTarget(instrumentNo, (int)_CMMISDK_ToleranceType.TOLETYPE_SPEC, (int)_CMMISDK_ParametricId.PARAMETRIC_ID_CMC, ref parametricData); if (!IsNormalCode(ret)) { Console.WriteLine("Error:{0} CMMISDK_SetParametricForTarget CMC", ret); CMMISDK_API.CMMISDK_Disconnect(instrumentNo); return; } parametricData.coef[0] = 2.1; parametricData.coef[1] = 2.2; parametricData.coef[2] = 2.3; ret = CMMISDK_API.CMMISDK_SetParametricForTarget(instrumentNo, (int)_CMMISDK_ToleranceType.TOLETYPE_SPEC, (int)_CMMISDK_ParametricId.PARAMETRIC_ID_DE94, ref parametricData); if (!IsNormalCode(ret)) { Console.WriteLine("Error:{0} CMMISDK_SetParametricForTarget DE94", ret); CMMISDK_API.CMMISDK_Disconnect(instrumentNo); return; } parametricData.coef[0] = 3.1; parametricData.coef[1] = 3.2; parametricData.coef[2] = 3.3; ret = CMMISDK_API.CMMISDK_SetParametricForTarget(instrumentNo, (int)_CMMISDK_ToleranceType.TOLETYPE_SPEC, (int)_CMMISDK_ParametricId.PARAMETRIC_ID_DE00, ref parametricData); if (!IsNormalCode(ret)) { Console.WriteLine("Error:{0} CMMISDK_SetParametricForTarget DE00", ret); CMMISDK_API.CMMISDK_Disconnect(instrumentNo); return; } // Save Target information ret = CMMISDK_API.CMMISDK_SaveTargetInfo(instrumentNo, targetNum); if (!IsNormalCode(ret)) { Console.WriteLine("Error:{0} CMMISDK_SaveTargetInfo", ret); CMMISDK_API.CMMISDK_Disconnect(instrumentNo); return; } // Disconnect CMMISDK_API.CMMISDK_Disconnect(instrumentNo); }