예제 #1
0
        static void PerformMeasurement(string in_com)
        {
            Int32 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;
            }

            // Set measurement mode (color & gloss)
            _CMMISDK_MeasMode mode = _CMMISDK_MeasMode.MEASMODE_COLORANDGLOSS;

            ret = CMMISDK_API.CMMISDK_SetMeasurementMode(instrumentNo, (int)mode);
            if (!IsNormalCode(ret))
            {
                Console.WriteLine("Error:{0} CMMISDK_SetMeasurementMode", ret);
                CMMISDK_API.CMMISDK_Disconnect(instrumentNo);
                return;
            }

            // Check Calibration
            bool calComplete = false;

            do
            {
                int calStatus = 0;
                ret = CMMISDK_API.CMMISDK_GetCalibrationStatus(instrumentNo, ref calStatus);
                if (!IsNormalCode(ret))
                {
                    Console.WriteLine("Error:{0} CMMISDK_GetCalibrationStatus", ret);
                    CMMISDK_API.CMMISDK_Disconnect(instrumentNo);
                    break;
                }

                switch ((_CMMISDK_CalStatus)calStatus)
                {
                case _CMMISDK_CalStatus.StatusZero:
                    // Zero calibration
                    Console.WriteLine("Please set the zero calibration box.");
                    Console.ReadKey();
                    ret = CMMISDK_API.CMMISDK_PerformZeroCalibration(instrumentNo);
                    if (!IsNormalCode(ret))
                    {
                        Console.WriteLine("Error:{0} CMMISDK_PerformZeroCalibration", ret);
                        CMMISDK_API.CMMISDK_Disconnect(instrumentNo);
                    }
                    break;

                case _CMMISDK_CalStatus.StatusWhite:
                    // White calibration
                    Console.WriteLine("Please set the white calibration box.");
                    Console.ReadKey();
                    ret = CMMISDK_API.CMMISDK_PerformWhiteCalibration(instrumentNo);
                    if (!IsNormalCode(ret))
                    {
                        Console.WriteLine("Error:{0} CMMISDK_PerformWhiteCalibration", ret);
                        CMMISDK_API.CMMISDK_Disconnect(instrumentNo);
                    }
                    break;

                case _CMMISDK_CalStatus.StatusGloss:
                    // Gloss calibration
                    Console.WriteLine("Please set the gloss calibration box.");
                    Console.ReadKey();
                    ret = CMMISDK_API.CMMISDK_PerformGlossCalibration(instrumentNo);
                    if (!IsNormalCode(ret))
                    {
                        Console.WriteLine("Error:{0} PerformGlossCalibration", ret);
                        CMMISDK_API.CMMISDK_Disconnect(instrumentNo);
                        return;
                    }
                    break;

                case _CMMISDK_CalStatus.StatusUser:
                    // User calibration
                    Console.WriteLine("Please set the User calibration box.");
                    Console.ReadKey();
                    ret = CMMISDK_API.CMMISDK_PerformUserCalibration(instrumentNo);
                    if (!IsNormalCode(ret))
                    {
                        Console.WriteLine("Error:{0} PerformUserCalibration", ret);
                        CMMISDK_API.CMMISDK_Disconnect(instrumentNo);
                        return;
                    }
                    break;

                default:
                    calComplete = true;
                    break;
                }
            } while (!calComplete);

            // Perform measurement
            Console.WriteLine("Please set the sample plate.");
            Console.ReadKey();
            ret = CMMISDK_API.CMMISDK_PerformMeasurement(instrumentNo);
            if (!IsNormalCode(ret))
            {
                Console.WriteLine("Error:{0} CMMISDK_PerformMeasurement", ret);
                CMMISDK_API.CMMISDK_Disconnect(instrumentNo);
                return;
            }

            // Polling measurement
            int measStatus = (int)_CMMISDK_MeasStatus.Measuring;

            do
            {
                ret = CMMISDK_API.CMMISDK_PollingMeasurement(instrumentNo, ref measStatus);
                if (!IsNormalCode(ret))
                {
                    Console.WriteLine("Error:{0} CMMISDK_PollingMeasurement", ret);
                    CMMISDK_API.CMMISDK_Disconnect(instrumentNo);
                    break;
                }
            } while ((_CMMISDK_MeasStatus)measStatus != _CMMISDK_MeasStatus.Idling);

            // Get sample data
            ret = CMMISDK_API.CMMISDK_LoadLatestData(instrumentNo);
            if (!IsNormalCode(ret))
            {
                Console.WriteLine("Error:{0} CMMISDK_LoadLatestData", ret);
                CMMISDK_API.CMMISDK_Disconnect(instrumentNo);
                return;
            }

            // Get sample 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 measurementColorData = new CMMISDK_Data();

            ret = CMMISDK_API.CMMISDK_GetLatestDataColor(instrumentNo, (int)_CMMISDK_DataType.DATATYPE_SPEC, ref cond, ref measurementColorData);
            if (!IsNormalCode(ret))
            {
                Console.WriteLine("Error:{0} CMMISDK_GetLatestDataColor", ret);
                CMMISDK_API.CMMISDK_Disconnect(instrumentNo);
                return;
            }
            // Color data display
            Console.WriteLine("L*:{0,6:f2} a*:{1,6:f2} b*:{2,6:f2}", measurementColorData.data[0], measurementColorData.data[1], measurementColorData.data[2]);

            // Get sample spectral data
            CMMISDK_Data[] measurementSpecData = new CMMISDK_Data[(int)_CMMISDK_DataType.DATATYPE_SPEC + 1];
            for (_CMMISDK_DataType inDataType = _CMMISDK_DataType.DATATYPE_GLOSS; inDataType <= _CMMISDK_DataType.DATATYPE_SPEC; inDataType = (_CMMISDK_DataType)(inDataType + 1))
            {
                ret = CMMISDK_API.CMMISDK_GetLatestDataSpec(instrumentNo, (int)inDataType, ref measurementSpecData[(int)inDataType]);
                if (!IsNormalCode(ret))
                {
                    Console.WriteLine("Error:{0} CMMISDK_GetLatestDataSpec", ret);
                }
            }

            // Spectral data display
            Console.WriteLine("       GLOSS   SPEC");
            int count = 0;

            for (int waveLength = instInfo.WaveLengthStart; waveLength <= instInfo.WaveLengthEnd; waveLength += instInfo.WaveLengthPitch)
            {
                Console.Write("{0} :", waveLength);
                for (_CMMISDK_DataType inDataType = _CMMISDK_DataType.DATATYPE_GLOSS; inDataType <= _CMMISDK_DataType.DATATYPE_SPEC; inDataType = (_CMMISDK_DataType)(inDataType + 1))
                {
                    Console.Write(" {0,6:f2}", measurementSpecData[(int)inDataType].data[count]);
                }
                Console.WriteLine("");
                count++;
            }

            // Disconnect
            CMMISDK_API.CMMISDK_Disconnect(instrumentNo);

            return;
        }