Ejemplo n.º 1
0
 public void AddVisionResultToList(AxisOffset offset)
 {
     lock (_captureResultLocker)
     {
         CaptureResult.Add(offset);
     }
 }
Ejemplo n.º 2
0
        public AxisOffset RequestVisionCalibration(CapturePosition capturePosition, int timeoutMs = 10000)
        {
            if (Connected == false)
            {
                throw new Exception("Vision server not connected.");
            }

            //log.Info("Sending to server:" + Environment.NewLine +
            //    Helper.ConvertToJsonString(capturePosition));

            //Clean the last unhandled vision response.
            while (ResultFound(capturePosition.CaptureId, out AxisOffset offsetResultDump))
            {
            }

            AxisOffset offsetResult = null;
            string     JsonCommand  = Handle.Instance.ObjToJsonstring(capturePosition);

            Send(JsonCommand);

            var stopwatch = new Stopwatch();

            stopwatch.Start();

            while (ResultFound(capturePosition.CaptureId, out offsetResult) == false)
            {
                if (stopwatch.ElapsedMilliseconds > timeoutMs)
                {
                    throw new Exception("RequestVisionCalibration fail, no response from Vision");
                }

                //_visionResponseManualResetEvent.Reset();
                //_visionResponseManualResetEvent.WaitOne();
                Thread.Sleep(50);
            }

            if (offsetResult.ResultOK == false)
            {
                //log.Info("No Recieved to server of :" + Environment.NewLine +
                //Helper.ConvertToJsonString(capturePosition));
                throw new VisionException("Vision NG")
                      {
                          CaptureId = capturePosition.CaptureId,
                      };
            }

            //log.Info("Recieved to server:" + Environment.NewLine +
            //    Helper.ConvertToJsonString(offsetResult));
            return(offsetResult);
        }
Ejemplo n.º 3
0
 private bool ResultFound(CaptureId captureId, out AxisOffset offset)
 {
     lock (_captureResultLocker)
     {
         foreach (var result in CaptureResult)
         {
             if (result.CaptureId == captureId)
             {
                 offset = result;
                 CaptureResult.Remove(result);
                 return(true);
             }
         }
         offset = null;
         return(false);
     }
 }