private void Counter_CounterChanged(UI.Components.Counter sender, CounterChangedEventArgs args) { Save(); }
private void CounterEventHandler(object sender, CounterChangedEventArgs e) { var val = e.Value; this.Dispatcher.Invoke((ThreadStart) delegate { ResultTextBlock.Text = val; }); }
public void UpdateValues() { ThrowWhenNotConnected(); if (_configurationChanged) { UpdateConfiguration(); _configurationChanged = false; } var commandExchangeData = new CommandExchangeData(); var responseExchangeData = new ResponseExchangeData(); for (int i = 0; i < _masterInterface.OutputValues.Length; i++) { commandExchangeData.PwmOutputValues[i] = (short)_masterInterface.OutputValues[i]; } for (int i = 0; i < _motorInterface.DistanceValues.Length; i++) { if (_motorInterface.DistanceValues[i] != 0) { commandExchangeData.MotorDistanceValues[i] = (short)_motorInterface.DistanceValues[i]; commandExchangeData.MotorCommandId[i]++; } } commandExchangeData.SoundCommandId = (ushort)_soundPlayIndex; if (_soundChanged) { commandExchangeData.SoundCommandId = (ushort)++_soundPlayIndex; commandExchangeData.SoundIndex = _masterInterface.SoundIndex; commandExchangeData.SoundRepeat = _masterInterface.SountRepeatCount; _soundChanged = false; _soundPlaying = true; } try { TxtCommunication.SendCommand(commandExchangeData, responseExchangeData); } catch (Exception e) { HandleException(e); return; } IList <int> valueChanged = new List <int>(); for (int i = 0; i < responseExchangeData.UniversalInputs.Length; i++) { var newInputValue = responseExchangeData.UniversalInputs[i]; if (_masterInterface.GetInputValue(i) != newInputValue) { _masterInterface.SetInputValue(i, newInputValue); valueChanged.Add(i); } } //Read motor counters if (responseExchangeData.CounterValue != null && (_motorInterface.CounterValue == null || !responseExchangeData.CounterValue.SequenceEqual <short>(_motorInterface.CounterValue))) { _motorInterface.CounterValue = responseExchangeData.CounterValue; CounterChangedEventArgs changedEvent = new CounterChangedEventArgs(_motorInterface.CounterValue); _counuterChanged?.Invoke(this, changedEvent); } if (valueChanged.Count > 0) { // Fire an event when an input value has changed InputValueChangedEventArgs eventArgs = new InputValueChangedEventArgs(valueChanged); _inputValueChanged?.Invoke(this, eventArgs); } if (responseExchangeData.SoundCommandId != _soundPlayIndex - 1 && _soundPlaying) { _soundPlaying = false; // Fire an event when the sound playback has finished _soundPlaybackFinished?.Invoke(this, new EventArgs()); } }