Exemple #1
0
        private void SetParas()
        {
            CommunicationParams paras = (CommunicationParams)ProjectPropertyManager.ProjectPropertyDic["CommunicationParams"];

            paras.SerialPortIndex = PORTNAMES.ToList().IndexOf(port.PortName);
            paras.BaudRateIndex   = BAUDRATES.ToList().IndexOf(port.BaudRate);
            paras.StopBitIndex    = STOPBITS.ToList().IndexOf(GetStopBits(port.StopBits));
            paras.Timeout         = Timeout;
            paras.CheckCodeIndex  = PARITYS.ToList().IndexOf(GetParity(port.Parity));
        }
        /// <summary>
        /// Основной цикл работы устройства наведения
        /// дожидается инициалиации порта, калбировки устройства и отправляет комманды наведения, если таковые имеются
        /// </summary>
        protected virtual IEnumerator EWork()
        {
            yield return(_untilPortOpened);

            _serialPortController.Send(CommunicationParams.GetCalibrationMessage());
            yield return(new WaitUntil(() => _calibrateDone));

            var setUpMessage = CommunicationParams.GetSetupMessage(new SetupInfo(), new SetupInfo(), new SetupInfo(1000));

            _serialPortController.Send(setUpMessage);
            yield return(_loopWait);

            while (!_isDisabled)
            {
                var success        = false;
                var moveInfosArray = new MoveInfo[LowLevelUtils.Params.DEVICES_COUNT];
                var index          = 0;
                foreach (var controller in CameraBaseControllers)
                {
                    var enumMoveInfos = controller.PositionController.TowardsInfos(ref success);
                    foreach (var mi in enumMoveInfos)
                    {
                        moveInfosArray[index++] = mi;
                    }
                }

                if (success)
                {
                    //Если какая-то из координат была обновлена, тогда отправляем команду наведения
                    var moveMessage = CommunicationParams.GetMoveMessage(moveInfosArray);
                    _serialPortController.Send(moveMessage);
                    _trackModeController.Reset();
                }
                else if (!_trackModeController.SetUp())
                {
                    //если режим слежения не нужно запускать, то запрашивает текущие координаты для уточнения
                    _positionRequested = true;
                    _serialPortController.Send(CommunicationParams.GetPositionRequestMessage());
                }

                // foreach (var controller in CameraBaseControllers)
                //     controller.updateCurrentPosition = success;

                yield return(_loopWait);

                if (_positionRequested)
                {
                    yield return(new WaitUntil(() => !_positionRequested));
                }
            }
        }
 /// <summary>
 /// Обработка полученного сообщения
 /// </summary>
 private void OnMessageReceived(string message)
 {
     if (message.Equals(CommunicationParams.CALIBRATION_RESPONSE))
     {
         _calibrateDone = true;
     }
     else if (message.StartsWith(CommunicationParams.POSITION_FLAG.ToString()))
     {
         var newPositions = CommunicationParams.ParsePositionResponse(message);
         SetUpNewPositions(in newPositions);
         LogPositionController.UpdateInfo(in newPositions);
         _positionRequested = false;
     }
 }
Exemple #4
0
        public void InitializePort()
        {
            if (port.IsOpen)
            {
                port.Close();
            }
            CommunicationParams paras = (CommunicationParams)ProjectPropertyManager.ProjectPropertyDic["CommunicationParams"];

            PortName = PORTNAMES[paras.SerialPortIndex];
            BaudRate = BAUDRATES[paras.BaudRateIndex];
            DataBits = DATABITS[paras.DataBitIndex];
            StopBits = STOPBITS[paras.StopBitIndex];
            Timeout  = paras.Timeout;
            Parity   = PARITYS[paras.CheckCodeIndex];
        }