コード例 #1
0
 public void ToMagPos(eMagType mag_type)
 {
     if (_cur_mag == mag_type)
     {
         _log.Debug("ToMagPos at the right pos");
         return;
     }
     try
     {
         _log.Debug("ToMagPos:" + Thread.CurrentThread.ManagedThreadId);
         MoveEventArgs moveEventArgs;
         if (mag_type == eMagType.MaxMag)
         {
             _camera.MaxMagSet();
             moveEventArgs = new MoveEventArgs('Z', _maxMagFocusPos, false);
         }
         else
         {
             _camera.MinMagSet();
             moveEventArgs = new MoveEventArgs('Z', _minMagFocusPos, false);
         }
         AsyncMove(this, moveEventArgs);
         AsyncMoveWait();
         SetLight(mag_type);
         _cur_mag = mag_type;
     }
     catch (Exception ex)
     {
         _cur_mag = eMagType.UnknownMag;
         SynOpErrorArgs arg = new SynOpErrorArgs();
         arg.Ex      = ex;
         arg.Message = "SynOp.ToMagPos()";
         FindAngleOK = false;
         OnError(this, arg);
     }
 }
コード例 #2
0
        public void MeasureScan(List <string> pathname, List <PointF> pos
                                , eScanType scan_type, int measureDistance
                                , Bitmap mymap, double[] die_size, int threshold)
        {
            MeasureOK = false;
            Alignment(mymap, die_size, threshold);
            if (!AlignmentOK)
            {
                return;
            }
            char[]   axisZ               = { 'Z' };
            char[]   axisXY              = { 'X', 'Y' };
            char[]   axisXYZ             = { 'X', 'Y', 'Z' };
            double[] CLStoBaslerDistance = { -40200 };


            try
            {
                MoveEventArgs moveEventArgs;
                moveEventArgs = new MoveEventArgs(axisZ, CLStoBaslerDistance, _motion.GetAxisDefaultSpeed(axisZ), false);
                AsyncMove(this, moveEventArgs);
                AsyncMoveWait();
                for (int i = 0; i < pos.Count; i++)
                {
                    ScanFileName  = pathname[i];
                    ScanFileIndex = i;
                    _log.Debug("MeasureScan filename:" + ScanFileName);
                    double[] distance = { pos[i].X, pos[i].Y };
                    moveEventArgs = new MoveEventArgs(axisXY, distance, _motion.GetAxisDefaultSpeed(axisXY), false);
                    AsyncMove(this, moveEventArgs);
                    AsyncMoveWait();
                    _camera.SaveImage(pathname + ".bmp");
                    double[] relative2Measure = { _paraReader.RelToMeasureCameraX
                                                  , _paraReader.RelToMeasureCameraY };//放外面relative2Measure經過一次for loop會*10倍
                    moveEventArgs = new MoveEventArgs(axisXY, relative2Measure, _motion.GetAxisDefaultSpeed(axisXY), true);
                    AsyncMove(this, moveEventArgs);
                    AsyncMoveWait();
                    moveEventArgs = new MoveEventArgs('X', _paraReader.RelToMeasureCameraX, _motion.GetAxisDefaultSpeed('X'), true);
                    EncoderSet.Reset();
                    ScanParamSet(this, moveEventArgs);
                    EncoderSet.WaitOne();
                    if (EncoderParamSetOk)
                    {
                        DataSaved.Reset();
                        if (scan_type == eScanType.Scan5Um)
                        {
                            AsyncMove5um(measureDistance);
                        }
                        else
                        {
                            AsyncMove1um(measureDistance);
                        }
                        DataSaved.WaitOne();
                    }
                    else
                    {
                        return;
                    }
                }
                MeasureOK = true;
            }
            catch (Exception ex)
            {
                SynOpErrorArgs arg = new SynOpErrorArgs();
                arg.Ex      = ex;
                arg.Message = "MeasureScan()";
                OnError(this, arg);
            }
        }
コード例 #3
0
        private void MagAutoFocus(eMagType mag_type)
        {
            int           beginPosition, endPosition, positionNo, positionId;
            MoveEventArgs moveEventArgs;

            int[]          runPosition;
            IAsyncResult[] result;
            double[]       variance;
            double         maxVariance;

            Object[] runImage;

            _log.Debug("Auto Focusing First Run(" + mag_type + ":" + Thread.CurrentThread.ManagedThreadId);

            try
            {
                if (mag_type == eMagType.MaxMag)
                {
                    beginPosition = _paraReader.MaxMagAutoFocusBegin;
                    endPosition   = _paraReader.MaxMagAutoFocusEnd;
                    _camera.MaxMagSet();
                }
                else
                {
                    beginPosition = _paraReader.MinMagAutoFocusBegin;
                    endPosition   = _paraReader.MinMagAutoFocusEnd;
                    _camera.MinMagSet();
                }

                positionNo = (Math.Abs(endPosition - beginPosition)) / 100 + 1;

                minAFFuncMs = Int32.MaxValue;
                maxAFFuncMs = 0;

                runPosition = new int[positionNo];
                result      = new IAsyncResult[positionNo];
                variance    = new double[positionNo];
                runImage    = new Object[positionNo];

                for (int position = beginPosition, i = 0; position <= endPosition; position += 100, i++)
                {
                    runPosition[i] = position;
                    moveEventArgs  = new MoveEventArgs('Z', position, false);
                    AsyncMove(this, moveEventArgs);
                    AsyncMoveWait();

                    imageFilterDone.Reset();
                    _camera.FilterImage(position, 1);
                    imageFilterDone.WaitOne();

                    runImage[i] = ImgMat;

                    result[i] = computeFocusScoreDelegate.BeginInvoke(runImage[i], null, null);
                }

                for (int i = 0; i < positionNo; i++)
                {
                    result[i].AsyncWaitHandle.WaitOne();
                    variance[i] = computeFocusScoreDelegate.EndInvoke(result[i]);
                    result[i].AsyncWaitHandle.Close();
                }

                maxVariance = variance[0];
                positionId  = 0;
                for (int i = 0; i < positionNo; i++)
                {
                    Console.WriteLine("variance[" + i + "]= " + variance[i]);
                    if (variance[i] > maxVariance)
                    {
                        maxVariance = variance[i];
                        positionId  = i;
                    }
                }

                _log.Debug("position id: " + positionId + ", position: " + runPosition[positionId] + ", variance: " + variance[positionId]);

                _log.Debug("Auto Focusing Second Run:");

                if (positionId == 0)
                {
                    beginPosition = runPosition[0];
                }
                else
                {
                    beginPosition = runPosition[positionId - 1];
                }

                if (positionId == positionNo - 1)
                {
                    endPosition = runPosition[positionNo - 1];
                }
                else
                {
                    endPosition = runPosition[positionId + 1];
                }

                positionNo = (Math.Abs(endPosition - beginPosition)) / 10 + 1;

                runPosition = new int[positionNo];
                result      = new IAsyncResult[positionNo];
                variance    = new double[positionNo];
                runImage    = new Object[positionNo];

                for (int position = beginPosition, i = 0; position <= endPosition; position += 10, i++)
                {
                    runPosition[i] = position;
                    moveEventArgs  = new MoveEventArgs('Z', position, false);
                    AsyncMove(this, moveEventArgs);
                    AsyncMoveWait();

                    imageFilterDone.Reset();
                    _camera.FilterImage(position, 1);
                    imageFilterDone.WaitOne();

                    runImage[i] = ImgMat;

                    result[i] = computeFocusScoreDelegate.BeginInvoke(runImage[i], null, null);
                }

                for (int i = 0; i < positionNo; i++)
                {
                    result[i].AsyncWaitHandle.WaitOne();
                    variance[i] = computeFocusScoreDelegate.EndInvoke(result[i]);
                    result[i].AsyncWaitHandle.Close();
                }

                maxVariance = variance[0];
                positionId  = 0;
                for (int i = 0; i < positionNo; i++)
                {
                    Console.WriteLine("variance[" + i + "]: " + variance[i]);
                    if (variance[i] > maxVariance)
                    {
                        maxVariance = variance[i];
                        positionId  = i;
                    }
                }
                if (mag_type == eMagType.MaxMag)
                {
                    _maxMagFocusPos = runPosition[positionId];
                }
                else
                {
                    _minMagFocusPos = runPosition[positionId];
                }
                _cur_mag      = mag_type;
                moveEventArgs = new MoveEventArgs('Z', runPosition[positionId], false);
                AsyncMove(this, moveEventArgs);
                AsyncMoveWait();
                _log.Debug("position id: " + positionId + ", position: " + runPosition[positionId] + ", variance: " + variance[positionId]);
                _log.Debug("Max AF func elapsed ms: " + maxAFFuncMs + ", Min AF func elapsed ms: " + minAFFuncMs);
                AutoLight(mag_type);
            }
            catch (Exception ex)
            {
                SynOpErrorArgs arg = new SynOpErrorArgs();
                arg.Ex      = ex;
                arg.Message = "SynOp.AutoFocus()";
                FindAngleOK = false;
                OnError(this, arg);
            }
        }