Beispiel #1
0
        /// <summary>
        /// Service start
        /// </summary>
        protected override void Start()
        {
            _httpUtilities = DsspHttpUtilitiesService.Create(this.Environment);

            // initialize state
            if (_state == null)
            {
                // No persisted state file, initialize with default values.
                _state = new PololuMaestroState();
                _state.Channels = new List<ChannelInfo>();
                _state.PollingInterval = 100; // default interval 100msec

                // Save state to file.
                SaveState(_state);
            }
            base.Start();

            MainPortInterleave.CombineWith(
                Arbiter.Interleave(
                    new TeardownReceiverGroup(),
                    new ExclusiveReceiverGroup(
                        Arbiter.Receive<SetChannel>(true, _mainPort, SetChannelHandler),
                        /*// http://social.msdn.microsoft.com/Forums/en-US/roboticsccr/thread/c3c27886-9cce-437e-b7bc-f0c1c0d5d9d9
                        Arbiter.JoinedReceiveWithIterator<DateTime, SetChannel>(true,
                            _setChannelThrotling, _mainPort, SetChannelHandler),*/
                        Arbiter.ReceiveWithIterator(true, _servoPollingPort, PollChannelStatus)
                        ),
                    new ConcurrentReceiverGroup())
            );

            // Display browser accesible Service URI
            LogInfo("Service uri: " + ServiceInfo.Service);

            if (ConnectToDevice())
            {
                // notify state has changed
                SendNotification(_submgrPort, new Replace());

                // start polling
                _servoPollingPort.Post(DateTime.Now);
            }
        }
Beispiel #2
0
        public void UpdateState(PololuMaestroState state)
        {
            DeviceSerialNumber = state.SerialNumber;
            IsConnected = state.Connected;

            if (Servos == null || Servos.Count != state.Channels.Count)
            {
                Servos = new ObservableCollection<ServoStateViewModel>();
                for (int i = 0; i < state.Channels.Count; i++)
                {
                    var vm = new ServoStateViewModel();
                    vm.PropertyChanged += OnServoStatePropertyChanged;
                    Servos.Add(vm);
                }
            }

            try
            {
                _updatingServoState = true;

                for (int i = 0; i < _servos.Count; i++)
                    Servos[i].Update(state.Channels[i]);
            }
            finally
            {
                _updatingServoState = false;
            }
        }