Пример #1
0
 private void MainForm_FormClosed(object sender, FormClosedEventArgs e)
 {
     //Disconnect from the connected instrument
     CL.CA2DSDK_DisconnectInstrument();
     //End usage of the SDK
     CL.CA2DSDK_Disable();
 }
Пример #2
0
        private Boolean initInstrument()
        {
            int ret = 0;

            //Enable the SDK
            log("Initializing SDK and instrument . . . ", 1);
            ret = CL.CA2DSDK_Enable();
            if ((ret < CL.CA2D_OK))
            {
                log("Initializing SDK and instrument", ret);
                return(false);
            }
            log("Initialization of the SDK completed", 1);

            //Connect to the specified instrument
            log("Connecting to the instrument . . . ", 1);
            ret = CL.CA2DSDK_ConnectInstrument(0);
            if ((ret < CL.CA2D_OK))
            {
                log("Connection to the instrument", ret);
                return(false);
            }
            log("Connection to the instrument completed", 1);

            return(true);
        }
Пример #3
0
        private Boolean setAutoEvaluationArea()
        {
            int ret = 0;

            //Clear the evaluation areas
            ret = CL.CA2DSDK_ClearEvaluationArea();
            if (ret < 0)
            {
                log("Clear evaluation area", ret);
                return(false);
            }
            log("Clear evaluation area completed", 1);

            //Set the evaluation area layout conditions
            short t = 1;

            if (this.top > 0 && this.left > 0 && this.right > 0 && this.bottom > 0)
            {
                t = 0;
            }
            CL.tagEvaluationCond cond_e = tagEvaluationCond(t);
            ret = CL.CA2DSDK_SetEvaluationAreaCondition(ref cond_e);
            if (ret < 0)
            {
                log("Set evaluation area condition", ret);
                return(false);
            }

            log("Set evaluation area condition completed", 1);
            return(true);
        }
Пример #4
0
        private Boolean processSpotLayouts(Boolean isOne)
        {
            int ret = 0;

            if (this.top > 0 && this.left > 0 && this.right > 0 && this.bottom > 0)
            {
                CL.tagEvaluationArea pMan = new CL.tagEvaluationArea();
                pMan.top    = this.top;
                pMan.left   = this.left;
                pMan.right  = this.right;
                pMan.bottom = this.bottom;
                ret         = CL.CA2DSDK_AddEvaluationArea(ref pMan);
                if (ret < 0)
                {
                    log("Add evaluation area", ret);
                }
            }

            foreach (KeyValuePair <string, List <Spot> > pair in Definitions.instance(screenSize.Text).Measures)
            {
                if (!processSpots(pair.Key, pair.Value))
                {
                    return(false);
                }

                if (isOne)
                {
                    return(true);
                }
            }
            return(true);
        }
Пример #5
0
        private void setInstrumentCondition(short additional)
        {
            //Set the measurement conditions
            log("Set instrument condition . . . ", 1);
            CL.tagInstrumentCond cond = instrumentCondition(this.screenSize.Text, additional);
            int ret = CL.CA2DSDK_SetInstrumentCondition(ref cond);

            if (ret < 0)
            {
                log("Set instrument condition", ret);
                return;
            }
            log("Set instrument condition completed", 1);
        }
Пример #6
0
        private Boolean getAllData()
        {
            int ret = 0;

            // Get image data
            log("Start getting image data . . . ", 1);
            CL.tagDataCond     cond_d    = tagDataCondition();
            CL.tagGetDataParam paramArea = tagGetParam();
            hash.Clear();
            ranges.Clear();

            for (int j = CL.VALTYPE_X; j <= CL.VALTYPE_PURITY; j++)
            {
                if (j == CL.VALTYPE_TCP_JIS || j == CL.VALTYPE_DUV_JIS)
                {
                    continue;
                }
                float[] pData = new float[CL.MAXDATAROW * CL.MAXDATACOL];

                //Set the conditions to calculate data
                cond_d.valueType = (short)j;
                ret = CL.CA2DSDK_SetDataCondition(ref cond_d);
                if ((ret < 0))
                {
                    log("Set data condition for " + j.ToString(), ret);
                    return(false);
                }

                //Get the data for the specified area
                ret = CL.CA2DSDK_GetAreaData(ref paramArea, pData);
                if ((ret < 0))
                {
                    log("Get area data for " + j.ToString(), ret);
                    return(false);
                }

                // Remove and flag over and under error pixels
                for (int z = 0; z < CL.MAXDATACOL * CL.MAXDATAROW; z++)
                {
                    pData[z] = pixelUO(pData[z], j);
                }
                hash.Add(j, pData);
            }
            log("Get image data completed", 1);
            return(true);
        }
Пример #7
0
        private Boolean measure()
        {
            int ret = 0;

            //Start the measurement
            log("Start measurements . . . ", 1);
            ret = CL.CA2DSDK_DoMeasurement();
            if ((ret < 0))
            {
                log("Start measurement ", ret);
                return(false);
            }
            while (true)
            {
                ret = CL.CA2DSDK_PollingMeasurement();
                if ((ret == CL.CA2D_OK))
                {
                    //When measurement is complete
                    log("Poll measurement completed", 1);
                    break; // TODO: might not be correct. Was : Exit While
                }
                else if ((ret >= CL.CA2D_OK))
                {
                    log("Poll measurement in progress . . . ", 1);
                }
                else
                {
                    //When an error has occurred
                    log("Poll measurement", ret);
                    return(false);
                }
                //wait 2 secs
                System.Threading.Thread.Sleep(2000);
            }
            return(true);
        }
Пример #8
0
        private Boolean processSpots(String spotName, List <Spot> spotsLayout)
        {
            int ret = 0;
            // Dictionary for output. Key represents spot index, value is map of variable names and values
            SortedDictionary <int, Dictionary <string, float> > output = new SortedDictionary <int, Dictionary <string, float> >();

            foreach (Spot spotLayout in spotsLayout)
            {
                ret = CL.CA2DSDK_SetAlignedSpotCondition(ref spotLayout._cond);
                if ((ret < 0))
                {
                    log("Set aligned spot conditions for " + spotName, ret);
                    return(false);
                }
                log("Set aligned spot conditions completed for " + spotName, 1);

                ret = CL.CA2DSDK_GetEvaluationArea(0, ref pArea);
                if (ret < 0)
                {
                    log("Get evaluation area", ret);
                    return(false);
                }
                log("Evaluation area T: " + pArea.top.ToString() + " L: " + pArea.left.ToString() + " B: " + pArea.bottom.ToString() + " R: " + pArea.right.ToString(), 1);

                //Calculate the spot results
                ret = CL.CA2DSDK_CalculateSpotValue();
                if ((ret < 0))
                {
                    log("Calculate spot value for " + spotName, ret);
                    return(false);
                }
                log("Calculate spot value completed for " + spotName, 1);


                // Draw gray area with crosshairs to check alignment
                Draw(pictureGray, -1);
                // Draw colors for Lv, x, y and tcp
                Draw(picLv, 3);
                Draw(picx, 4);
                Draw(picy, 5);
                Draw(picTcp, 8);

                //Get the spot results for 0 -> X Y Z, 1 -> Lv x y, 2 -> Y u' v', 3 -> tcp duv, 5 -> dw pur
                for (short color = 0; color <= 5; color++)
                {
                    if (color == 4)
                    {
                        continue;
                    }
                    CL.tagSpotValue spot_val = new CL.tagSpotValue();
                    spot_val.color  = color;
                    spot_val.result = new float[3];
                    for (short i = 0; i < spotLayout._cond.row * spotLayout._cond.col; i++)
                    {
                        ret = CL.CA2DSDK_GetSpotValue((short)0, (short)i, ref spot_val);
                        if ((ret < 0))
                        {
                            log("Retrieve spot value " + spotName + ", " + color.ToString(), ret);
                            return(false);
                        }

                        // Remove over and under values
                        for (int z = 0; z <= 2; z++)
                        {
                            spot_val.result[z] = pixelUO(spot_val.result[z], -1);
                        }

                        // Create entry in map if not existent
                        if (!output.ContainsKey(spotLayout._order[i]))
                        {
                            output.Add(spotLayout._order[i], new Dictionary <string, float>());
                        }
                        switch (color)
                        {
                        case 0:
                            output[spotLayout._order[i]].Add("X", spot_val.result[0]);
                            output[spotLayout._order[i]].Add("Y", spot_val.result[1]);
                            output[spotLayout._order[i]].Add("Z", spot_val.result[2]);
                            break;

                        case 1:
                            output[spotLayout._order[i]].Add("Lv", spot_val.result[0]);
                            output[spotLayout._order[i]].Add("x", spot_val.result[1]);
                            output[spotLayout._order[i]].Add("y", spot_val.result[2]);
                            break;

                        case 2:
                            output[spotLayout._order[i]].Add("u", spot_val.result[1]);
                            output[spotLayout._order[i]].Add("v", spot_val.result[2]);
                            break;

                        case 3:
                            output[spotLayout._order[i]].Add("tcp", spot_val.result[1]);
                            output[spotLayout._order[i]].Add("duv", spot_val.result[2]);
                            break;

                        case 5:
                            output[spotLayout._order[i]].Add("dw", spot_val.result[1]);
                            output[spotLayout._order[i]].Add("pur", spot_val.result[2]);
                            break;
                        }
                    }
                }
            }

            results.Add(spotName, output);

            return(true);
        }