Esempio n. 1
0
        public void CreateChipTemplate(ChipTemplate template)
        {
            Rectangle featureRectangle = template.FeatureRectangle;
            Rectangle objectRectangle  = template.ObjectRectangle;

            mChipTemplate = template;
            InitializeChipCaptureRange();
        }
Esempio n. 2
0
        public void LoadOptionFile()
        {
            mOptionFile = GetAssemblyPath() + OPENFILENAME;
            // LoadOptionFile();
            // int serialPort;
            try
            {
                mDAQIP = AccessIniFile.ReadValue(mOptionFile, "DAQ", "IP");
            }
            catch (System.Exception ex)
            {
                mDAQIP = "192.168.1.126";

                System.Console.Out.WriteLine(ex.Message);
            }

            try
            {
                mDAQPort = Convert.ToInt32(AccessIniFile.ReadValue(mOptionFile, "DAQ", "Port"));
            }
            catch (System.Exception ex)
            {
                mDAQPort = 8000;
                System.Console.Out.WriteLine(ex.Message);
            }
            try
            {
                mWaitResponseDelay = Convert.ToInt32(AccessIniFile.ReadValue(mOptionFile, "DAQ", "WaitResponseDelay"));
            }
            catch (System.Exception ex)
            {
                mWaitResponseDelay = 500;
                System.Console.Out.WriteLine(ex.Message);
            }
            try
            {
                mWaitResponseLoop = Convert.ToInt32(AccessIniFile.ReadValue(mOptionFile, "DAQ", "WaitResponseLoop"));
            }
            catch (System.Exception ex)
            {
                mWaitResponseLoop = 25;
                System.Console.Out.WriteLine(ex.Message);
            }
            try
            {
                mRetry = Convert.ToInt32(AccessIniFile.ReadValue(mOptionFile, "DAQ", "ReTry"));
            }
            catch (System.Exception ex)
            {
                mRetry = 3;
                System.Console.Out.WriteLine(ex.Message);
            }
            try
            {
                mCheckDataCountDelay = Convert.ToInt32(AccessIniFile.ReadValue(mOptionFile, "DAQ", "CheckDataCountDelay"));
            }
            catch (System.Exception ex)
            {
                mCheckDataCountDelay = 50;
                System.Console.Out.WriteLine(ex.Message);
            }
            try
            {
                mCameraID = Convert.ToInt32(AccessIniFile.ReadValue(mOptionFile, "Camera", "ID"));
            }
            catch (System.Exception ex)
            {
                mCameraID = 0;
                System.Console.Out.WriteLine(ex.Message);
            }
            try
            {
                mWidthPixels = Convert.ToInt32(AccessIniFile.ReadValue(mOptionFile, "Camera", "WidthPixels"));
            }
            catch (System.Exception ex)
            {
                mWidthPixels = 1280;
                System.Console.Out.WriteLine(ex.Message);
            }
            try
            {
                mHeightPixels = Convert.ToInt32(AccessIniFile.ReadValue(mOptionFile, "Camera", "HeightPixels"));
            }
            catch (System.Exception ex)
            {
                mHeightPixels = 960;
                System.Console.Out.WriteLine(ex.Message);
            }
            try
            {
                mTriggerInterval = Convert.ToInt32(AccessIniFile.ReadValue(mOptionFile, "Camera", "TriggerInterval"));
            }
            catch (System.Exception ex)
            {
                mTriggerInterval = 100;
                System.Console.Out.WriteLine(ex.Message);
            }
            try
            {
                mReelDiameter = Convert.ToDouble(AccessIniFile.ReadValue(mOptionFile, "Reel", "Diameter"));
            }
            catch (System.Exception ex)
            {
                mReelDiameter = 100;
                System.Console.Out.WriteLine(ex.Message);
            }
            try
            {
                mChipLength = Convert.ToDouble(AccessIniFile.ReadValue(mOptionFile, "Reel", "ChipLength"));
            }
            catch (System.Exception ex)
            {
                mChipLength = 10;
                System.Console.Out.WriteLine(ex.Message);
            }
            try
            {
                mScanSpeed = Convert.ToDouble(AccessIniFile.ReadValue(mOptionFile, "Reel", "ScanSpeed"));
            }
            catch (System.Exception ex)
            {
                mScanSpeed = 2;
                System.Console.Out.WriteLine(ex.Message);
            }

            try
            {
                mPulsesOneCycle = Convert.ToInt32(AccessIniFile.ReadValue(mOptionFile, "Motor", "PulsesOneCycle"));
            }
            catch (System.Exception ex)
            {
                mPulsesOneCycle = 10000;
                System.Console.Out.WriteLine(ex.Message);
            }

            try
            {
                mMotorDirection = Convert.ToInt32(AccessIniFile.ReadValue(mOptionFile, "Motor", "Direction"));
            }
            catch (System.Exception ex)
            {
                mMotorDirection = 1;
                System.Console.Out.WriteLine(ex.Message);
            }
            try
            {
                mMotorDefaultRate = Convert.ToDouble(AccessIniFile.ReadValue(mOptionFile, "Motor", "DefaultRate"));
            }
            catch (System.Exception ex)
            {
                mMotorDefaultRate = 2;
                System.Console.Out.WriteLine(ex.Message);
            }
            try
            {
                mMotorRateThreshold = Convert.ToDouble(AccessIniFile.ReadValue(mOptionFile, "Motor", "RateThreshold"));
            }
            catch (System.Exception ex)
            {
                mMotorRateThreshold = 0.3;
                System.Console.Out.WriteLine(ex.Message);
            }
            try
            {
                mMotorRateDecreaseValue = Convert.ToDouble(AccessIniFile.ReadValue(mOptionFile, "Motor", "RateDecreaseValue"));
            }
            catch (System.Exception ex)
            {
                mMotorRateDecreaseValue = 0.1;
                System.Console.Out.WriteLine(ex.Message);
            }
            try
            {
                mEmptyReelMotorRate = Convert.ToDouble(AccessIniFile.ReadValue(mOptionFile, "Motor", "EmptyReelRate"));
            }
            catch (System.Exception ex)
            {
                mEmptyReelMotorRate = 4;
                System.Console.Out.WriteLine(ex.Message);
            }
            try
            {
                mMotorRateTestInterval = Convert.ToInt32(AccessIniFile.ReadValue(mOptionFile, "Motor", "RateTestInterval"));
            }
            catch (System.Exception ex)
            {
                mMotorRateTestInterval = 10;
                System.Console.Out.WriteLine(ex.Message);
            }
            try
            {
                mMotorAutoStopInterval = Convert.ToInt32(AccessIniFile.ReadValue(mOptionFile, "Motor", "AutoStopInterval"));
            }
            catch (System.Exception ex)
            {
                mMotorAutoStopInterval = 3;
                System.Console.Out.WriteLine(ex.Message);
            }

            try
            {
                mCaptureTop = Convert.ToInt32(AccessIniFile.ReadValue(mOptionFile, "Capture", "Top"));
            }
            catch (System.Exception ex)
            {
                mCaptureTop = 0;
                System.Console.Out.WriteLine(ex.Message);
            }
            try
            {
                mCaptureLeft = Convert.ToInt32(AccessIniFile.ReadValue(mOptionFile, "Capture", "Left"));
            }
            catch (System.Exception ex)
            {
                mCaptureLeft = 0;
                System.Console.Out.WriteLine(ex.Message);
            }
            try
            {
                mCaptureWidth = Convert.ToInt32(AccessIniFile.ReadValue(mOptionFile, "Capture", "Width"));
            }
            catch (System.Exception ex)
            {
                mCaptureWidth = 0;
                System.Console.Out.WriteLine(ex.Message);
            }
            try
            {
                mCaptureHeight = Convert.ToInt32(AccessIniFile.ReadValue(mOptionFile, "Capture", "Height"));
            }
            catch (System.Exception ex)
            {
                mCaptureHeight = 0;
                System.Console.Out.WriteLine(ex.Message);
            }
            try
            {
                mFrameThreshold = Convert.ToInt32(AccessIniFile.ReadValue(mOptionFile, "Capture", "FrameThreshold"));
            }
            catch (System.Exception ex)
            {
                mFrameThreshold = 220;
                System.Console.Out.WriteLine(ex.Message);
            }
            try
            {
                mChipThreshold = Convert.ToInt32(AccessIniFile.ReadValue(mOptionFile, "Capture", "ChipThreshold"));
            }
            catch (System.Exception ex)
            {
                mChipThreshold = 90;
                System.Console.Out.WriteLine(ex.Message);
            }
            try
            {
                mFrameWidthHigh = Convert.ToInt32(AccessIniFile.ReadValue(mOptionFile, "Capture", "FrameWidthHigh"));
            }
            catch (System.Exception ex)
            {
                mFrameWidthHigh = 650;
                System.Console.Out.WriteLine(ex.Message);
            }
            try
            {
                mFrameWidthLow = Convert.ToInt32(AccessIniFile.ReadValue(mOptionFile, "Capture", "FrameWidthLow"));
            }
            catch (System.Exception ex)
            {
                mFrameWidthLow = 610;
                System.Console.Out.WriteLine(ex.Message);
            }
            try
            {
                mFrameHeightHigh = Convert.ToInt32(AccessIniFile.ReadValue(mOptionFile, "Capture", "FrameHeightHigh"));
            }
            catch (System.Exception ex)
            {
                mFrameHeightHigh = 320;
                System.Console.Out.WriteLine(ex.Message);
            }
            try
            {
                mFrameHeightLow = Convert.ToInt32(AccessIniFile.ReadValue(mOptionFile, "Capture", "FrameHeightLow"));
            }
            catch (System.Exception ex)
            {
                mFrameHeightLow = 280;
                System.Console.Out.WriteLine(ex.Message);
            }

            try
            {
                mChipRatioHigh = Convert.ToInt32(AccessIniFile.ReadValue(mOptionFile, "Capture", "ChipRatioHigh"));
            }
            catch (System.Exception ex)
            {
                mChipRatioHigh = 15;
                System.Console.Out.WriteLine(ex.Message);
            }
            try
            {
                mChipRatioLow = Convert.ToInt32(AccessIniFile.ReadValue(mOptionFile, "Capture", "ChipRatioLow"));
            }
            catch (System.Exception ex)
            {
                mChipRatioLow = 5;
                System.Console.Out.WriteLine(ex.Message);
            }


            try
            {
                mChangeToNAStatusDelayCount = Convert.ToInt32(AccessIniFile.ReadValue(mOptionFile, "Capture", "ChangeToNAStatusDelayCount"));
            }
            catch (System.Exception ex)
            {
                mChangeToNAStatusDelayCount = 2;
                System.Console.Out.WriteLine(ex.Message);
            }
            try
            {
                mExcelFileName = AccessIniFile.ReadValue(mOptionFile, "Output", "FileName");
            }
            catch (System.Exception ex)
            {
                mExcelFileName = "Data summary-1.xlsx";
                System.Console.Out.WriteLine(ex.Message);
            }
            try
            {
                mStartCellRow = Convert.ToInt32(AccessIniFile.ReadValue(mOptionFile, "Output", "StartCellRow"));
            }
            catch (System.Exception ex)
            {
                mStartCellRow = 5;
                System.Console.Out.WriteLine(ex.Message);
            }
            try
            {
                mStartCellCol = Convert.ToInt32(AccessIniFile.ReadValue(mOptionFile, "Output", "StartCellCol"));
            }
            catch (System.Exception ex)
            {
                mStartCellCol = 8;
                System.Console.Out.WriteLine(ex.Message);
            }
            try
            {
                mIsSaveRemoteFile = (AccessIniFile.ReadValue(mOptionFile, "Output", "SaveRemoteFile") == "1");
            }
            catch (System.Exception ex)
            {
                mIsSaveRemoteFile = false;
                System.Console.Out.WriteLine(ex.Message);
            }
            try
            {
                mRemoteFilePath = AccessIniFile.ReadValue(mOptionFile, "Output", "RemoteFilePath");
            }
            catch (System.Exception ex)
            {
                mIsSaveRemoteFile = false;
                System.Console.Out.WriteLine(ex.Message);
            }


            try
            {
                mRowCells = Convert.ToInt32(AccessIniFile.ReadValue(mOptionFile, "Output", "RowCells"));
            }
            catch (System.Exception ex)
            {
                mRowCells = 50;
                System.Console.Out.WriteLine(ex.Message);
            }
            try
            {
                mPassLabel = AccessIniFile.ReadValue(mOptionFile, "Output", "PassLabel");
            }
            catch (System.Exception ex)
            {
                mPassLabel = "1";
                System.Console.Out.WriteLine(ex.Message);
            }
            try
            {
                mFailLabel = AccessIniFile.ReadValue(mOptionFile, "Output", "FailLabel");
            }
            catch (System.Exception ex)
            {
                mFailLabel = "0";
                System.Console.Out.WriteLine(ex.Message);
            }
            try
            {
                mSpaceInterval = Convert.ToInt32(AccessIniFile.ReadValue(mOptionFile, "Output", "SpaceInterval"));
            }
            catch (System.Exception ex)
            {
                mSpaceInterval = 10;
                System.Console.Out.WriteLine(ex.Message);
            }
            try
            {
                mSpaceLength = Convert.ToInt32(AccessIniFile.ReadValue(mOptionFile, "Output", "SpaceLength"));
            }
            catch (System.Exception ex)
            {
                mSpaceLength = 1;
                System.Console.Out.WriteLine(ex.Message);
            }
            try
            {
                mReportDirectory = (AccessIniFile.ReadValue(mOptionFile, "Output", "ReportDirectory"));
            }
            catch (System.Exception ex)
            {
                mReportDirectory = "Report";
                System.Console.Out.WriteLine(ex.Message);
            }
            try
            {
                mIsControlMotor = (AccessIniFile.ReadValue(mOptionFile, "Other", "ControlMotor") == "1");
            }
            catch (System.Exception ex)
            {
                mIsControlMotor = true;
                System.Console.Out.WriteLine(ex.Message);
            }
            try
            {
                mIsSaveExcel = (AccessIniFile.ReadValue(mOptionFile, "Other", "SaveExcel") == "1");
            }
            catch (System.Exception ex)
            {
                mIsSaveExcel = false;
                System.Console.Out.WriteLine(ex.Message);
            }
            try
            {
                mIsShowDebug = (AccessIniFile.ReadValue(mOptionFile, "Other", "ShowDebug") == "1");
            }
            catch (System.Exception ex)
            {
                mIsShowDebug = true;
                System.Console.Out.WriteLine(ex.Message);
            }
            try
            {
                mIsSavePhoto = (AccessIniFile.ReadValue(mOptionFile, "Other", "SavePhoto") == "1");
            }
            catch (System.Exception ex)
            {
                mIsSavePhoto = false;
                System.Console.Out.WriteLine(ex.Message);
            }
            mChipTemplate = new ChipTemplate();
            Rectangle featureRectangle = new Rectangle();
            Rectangle objectRectangle  = new Rectangle();

            try
            {
                mDefaultTemplateName = AccessIniFile.ReadValue(mOptionFile, "Template", "DefaultName");
            }
            catch (System.Exception ex)
            {
                mDefaultTemplateName = "(默认模板)";
                System.Console.Out.WriteLine(ex.Message);
            }

            try
            {
                mChipTemplate.PhotoFile = mAssemblyPath + (AccessIniFile.ReadValue(mOptionFile, "Template", "DefaultPhotoFile"));
            }
            catch (System.Exception ex)
            {
                mChipTemplate.PhotoFile = mAssemblyPath + "template.bmp";
                System.Console.Out.WriteLine(ex.Message);
            }
            try
            {
                featureRectangle.X = Convert.ToInt32(AccessIniFile.ReadValue(mOptionFile, "Template", "FeatureLeft"));
            }
            catch (System.Exception ex)
            {
                featureRectangle.X = 1;
                System.Console.Out.WriteLine(ex.Message);
            }
            try
            {
                featureRectangle.Y = Convert.ToInt32(AccessIniFile.ReadValue(mOptionFile, "Template", "FeatureTop"));
            }
            catch (System.Exception ex)
            {
                featureRectangle.Y = 1;
                System.Console.Out.WriteLine(ex.Message);
            }
            try
            {
                featureRectangle.Width = Convert.ToInt32(AccessIniFile.ReadValue(mOptionFile, "Template", "FeatureWidth"));
            }
            catch (System.Exception ex)
            {
                featureRectangle.Width = 1;
                System.Console.Out.WriteLine(ex.Message);
            }
            try
            {
                featureRectangle.Height = Convert.ToInt32(AccessIniFile.ReadValue(mOptionFile, "Template", "FeatureHeight"));
            }
            catch (System.Exception ex)
            {
                featureRectangle.Height = 1;
                System.Console.Out.WriteLine(ex.Message);
            }
            mChipTemplate.FeatureRectangle = featureRectangle;
            try
            {
                mChipTemplate.FeatureGreyDelta = Convert.ToInt32(AccessIniFile.ReadValue(mOptionFile, "Template", "FeatureGreyDelta"));
            }
            catch (System.Exception ex)
            {
                mChipTemplate.FeatureGreyDelta = 30;
                System.Console.Out.WriteLine(ex.Message);
            }
            try
            {
                mChipTemplate.FeatureSimilarity = Convert.ToDouble(AccessIniFile.ReadValue(mOptionFile, "Template", "FeatureSimilarity"));
            }
            catch (System.Exception ex)
            {
                mChipTemplate.FeatureSimilarity = 0.6;
                System.Console.Out.WriteLine(ex.Message);
            }
            try
            {
                objectRectangle.X = Convert.ToInt32(AccessIniFile.ReadValue(mOptionFile, "Template", "ObjectLeft"));
            }
            catch (System.Exception ex)
            {
                objectRectangle.X = 1;
                System.Console.Out.WriteLine(ex.Message);
            }
            try
            {
                objectRectangle.Y = Convert.ToInt32(AccessIniFile.ReadValue(mOptionFile, "Template", "ObjectTop"));
            }
            catch (System.Exception ex)
            {
                objectRectangle.Y = 1;
                System.Console.Out.WriteLine(ex.Message);
            }
            try
            {
                objectRectangle.Width = Convert.ToInt32(AccessIniFile.ReadValue(mOptionFile, "Template", "ObjectWidth"));
            }
            catch (System.Exception ex)
            {
                objectRectangle.Width = 1;
                System.Console.Out.WriteLine(ex.Message);
            }
            try
            {
                objectRectangle.Height = Convert.ToInt32(AccessIniFile.ReadValue(mOptionFile, "Template", "ObjectHeight"));
            }
            catch (System.Exception ex)
            {
                objectRectangle.Height = 1;
                System.Console.Out.WriteLine(ex.Message);
            }
            mChipTemplate.ObjectRectangle = objectRectangle;
            try
            {
                mChipTemplate.ObjectGreyDelta = Convert.ToInt32(AccessIniFile.ReadValue(mOptionFile, "Template", "ObjectGreyDelta"));
            }
            catch (System.Exception ex)
            {
                mChipTemplate.ObjectGreyDelta = 30;
                System.Console.Out.WriteLine(ex.Message);
            }
            try
            {
                mChipTemplate.ObjectSimilarity = Convert.ToDouble(AccessIniFile.ReadValue(mOptionFile, "Template", "ObjectSimilarity"));
            }
            catch (System.Exception ex)
            {
                mChipTemplate.ObjectSimilarity = 0.6;
                System.Console.Out.WriteLine(ex.Message);
            }
            try
            {
                mTemplateDirectory = AccessIniFile.ReadValue(mOptionFile, "Template", "Directory");
            }
            catch (System.Exception ex)
            {
                mTemplateDirectory = string.Empty;
                System.Console.Out.WriteLine(ex.Message);
            }

            Rectangle featureCaptureRectangle = new Rectangle();
            Rectangle objectCaptureRectangle  = new Rectangle();

            try
            {
                mFeatureCaptureLeft = Convert.ToInt32(AccessIniFile.ReadValue(mOptionFile, "Template", "FeatureCaptureLeft"));
            }
            catch (System.Exception ex)
            {
                mFeatureCaptureLeft = 1;
                System.Console.Out.WriteLine(ex.Message);
            }
            featureCaptureRectangle.X = mChipTemplate.FeatureRectangle.Left - mFeatureCaptureLeft;

            try
            {
                mFeatureCaptureTop = Convert.ToInt32(AccessIniFile.ReadValue(mOptionFile, "Template", "FeatureCaptureTop"));
            }
            catch (System.Exception ex)
            {
                mFeatureCaptureTop = 1;
                System.Console.Out.WriteLine(ex.Message);
            }
            featureCaptureRectangle.Y = mChipTemplate.FeatureRectangle.Top - mFeatureCaptureTop;

            try
            {
                mFeatureCaptureRight = Convert.ToInt32(AccessIniFile.ReadValue(mOptionFile, "Template", "FeatureCaptureRight"));
            }
            catch (System.Exception ex)
            {
                mFeatureCaptureRight = 1;
                System.Console.Out.WriteLine(ex.Message);
            }
            featureCaptureRectangle.Width = mChipTemplate.FeatureRectangle.Width + mFeatureCaptureLeft + mFeatureCaptureRight;

            try
            {
                mFeatureCaptureBottom = Convert.ToInt32(AccessIniFile.ReadValue(mOptionFile, "Template", "FeatureCaptureBottom"));
            }
            catch (System.Exception ex)
            {
                mFeatureCaptureBottom = 1;
                System.Console.Out.WriteLine(ex.Message);
            }
            featureCaptureRectangle.Height        = mChipTemplate.FeatureRectangle.Height + mFeatureCaptureTop + mFeatureCaptureBottom;
            mChipTemplate.FeatureCaptureRectangle = featureCaptureRectangle;
            try
            {
                mObjectCaptureLeft = Convert.ToInt32(AccessIniFile.ReadValue(mOptionFile, "Template", "ObjectCaptureLeft"));
            }
            catch (System.Exception ex)
            {
                mObjectCaptureLeft = 1;
                System.Console.Out.WriteLine(ex.Message);
            }
            objectCaptureRectangle.X = mChipTemplate.ObjectRectangle.Left - mObjectCaptureLeft;

            try
            {
                mObjectCaptureTop = Convert.ToInt32(AccessIniFile.ReadValue(mOptionFile, "Template", "ObjectCaptureTop"));
            }
            catch (System.Exception ex)
            {
                mObjectCaptureTop = 1;
                System.Console.Out.WriteLine(ex.Message);
            }
            objectCaptureRectangle.Y = mChipTemplate.ObjectRectangle.Top - mObjectCaptureTop;
            try
            {
                mObjectCaptureRight = Convert.ToInt32(AccessIniFile.ReadValue(mOptionFile, "Template", "ObjectCaptureRight"));
            }
            catch (System.Exception ex)
            {
                mObjectCaptureRight = 1;
                System.Console.Out.WriteLine(ex.Message);
            }
            objectCaptureRectangle.Width = mChipTemplate.ObjectRectangle.Width + mObjectCaptureLeft + mObjectCaptureRight;
            try
            {
                mObjectCaptureBottom = Convert.ToInt32(AccessIniFile.ReadValue(mOptionFile, "Template", "ObjectCaptureBottom"));
            }
            catch (System.Exception ex)
            {
                mObjectCaptureBottom = 1;
                System.Console.Out.WriteLine(ex.Message);
            }
            objectCaptureRectangle.Height        = mChipTemplate.ObjectRectangle.Height + mObjectCaptureTop + mObjectCaptureBottom;
            mChipTemplate.ObjectCaptureRectangle = objectCaptureRectangle;
        }