static void ReadSampleData(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; } // Get sample count Int32 sampleCount = 0; ret = CMMISDK_API.CMMISDK_GetSavedSampleCount(instrumentNo, ref sampleCount); if (!IsNormalCode(ret)) { Console.WriteLine("Error:{0:d} GetSampleCount", ret); CMMISDK_API.CMMISDK_Disconnect(instrumentNo); return; } Dictionary <_CMMISDK_DataType, string> convertDataTypeTable = new Dictionary <_CMMISDK_DataType, string>() { { _CMMISDK_DataType.DATATYPE_GLOSS, " GLOSS" }, { _CMMISDK_DataType.DATATYPE_SCI, " SPEC " } }; for (Int32 i = 1; i <= sampleCount; i++) { ret = CMMISDK_API.CMMISDK_LoadSampleInfo(instrumentNo, i); if (!IsNormalCode(ret)) { Console.WriteLine("Error:{0:d} CMMISDK_LoadSampleInfo", ret); CMMISDK_API.CMMISDK_Disconnect(instrumentNo); return; } // Get sample property CMMISDK_SampleProperty sampleProperty = new CMMISDK_SampleProperty(); ret = CMMISDK_API.CMMISDK_GetSampleProperty(instrumentNo, ref sampleProperty); if (!IsNormalCode(ret)) { Console.WriteLine("Error:{0:d} CMMISDK_GetSampleProperty", ret); CMMISDK_API.CMMISDK_Disconnect(instrumentNo); return; } // display sample property Console.WriteLine("No.{0:d4} Name:{1} Date:{2}", i, Encoding.ASCII.GetString(sampleProperty.name).TrimEnd('\0'), new DateTime(sampleProperty.date[0], sampleProperty.date[1], sampleProperty.date[2], sampleProperty.date[3], sampleProperty.date[4], sampleProperty.date[5])); Console.WriteLine("{0} {1}", Enum.GetName(typeof(_CMMISDK_MeasMode), sampleProperty.meas_mode), Enum.GetName(typeof(_CMMISDK_MeasArea), sampleProperty.meas_area)); // Get sample spectral data Dictionary <_CMMISDK_DataType, CMMISDK_Data> sampleSpectralData = new Dictionary <_CMMISDK_DataType, CMMISDK_Data>(); if ((sampleProperty.meas_mode == (int)_CMMISDK_MeasMode.MEASMODE_COLORANDGLOSS) || (sampleProperty.meas_mode == (int)_CMMISDK_MeasMode.MEASMODE_COLORONLY)) { CMMISDK_Data sampleData = new CMMISDK_Data(); ret = CMMISDK_API.CMMISDK_GetSampleData(instrumentNo, (int)_CMMISDK_DataType.DATATYPE_SPEC, ref sampleData); if (!IsNormalCode(ret)) { Console.WriteLine("Error:{0:d} CMMISDK_GetSampleData SCI", ret); CMMISDK_API.CMMISDK_Disconnect(instrumentNo); return; } sampleSpectralData.Add(_CMMISDK_DataType.DATATYPE_SCI, sampleData); } if ((sampleProperty.meas_mode == (int)_CMMISDK_MeasMode.MEASMODE_COLORANDGLOSS) || (sampleProperty.meas_mode == (int)_CMMISDK_MeasMode.MEASMODE_GLOSSONLY)) { CMMISDK_Data sampleGlossData = new CMMISDK_Data(); ret = CMMISDK_API.CMMISDK_GetSampleData(instrumentNo, (int)_CMMISDK_DataType.DATATYPE_GLOSS, ref sampleGlossData); if (!IsNormalCode(ret)) { Console.WriteLine("Error:{0:d} CMMISDK_GetSampleData GLOSS", ret); CMMISDK_API.CMMISDK_Disconnect(instrumentNo); return; } sampleSpectralData.Add(_CMMISDK_DataType.DATATYPE_GLOSS, sampleGlossData); } // Display data if (sampleSpectralData.Count != 0) { Console.Write(" , "); foreach (_CMMISDK_DataType key in sampleSpectralData.Keys) { Console.Write("{0:s}, ", convertDataTypeTable[key]); } Console.Write('\n'); // Spectral data display int index = 0; for (Int32 WaveLength = instInfo.WaveLengthStart; WaveLength <= instInfo.WaveLengthEnd; WaveLength = WaveLength + instInfo.WaveLengthPitch) { Console.Write("{0:d3}, ", WaveLength); foreach (_CMMISDK_DataType key in sampleSpectralData.Keys) { Console.Write("{0,6:00.00}, ", sampleSpectralData[key].data[index]); } index++; Console.Write('\n'); } } } // Disconnect CMMISDK_API.CMMISDK_Disconnect(instrumentNo); return; }