public SourceConfigViewModel(IProbeDataReadingService probeDataReadingService, ISerialPortListProviderService serialPortListProviderService, string name, string colorName, string comPort) { _probeDataReadingService = probeDataReadingService; _serialPortListProviderService = serialPortListProviderService; _serialPortListProviderService.SerialPortListUpdated += SerialPortListProviderService_SerialPortListUpdated; _comPortOptions = serialPortListProviderService.GetSerialPortInfos().Select(spi => spi.NameAndDescription).ToList(); _newName = name; _newColor = (Color)ColorConverter.ConvertFromString(colorName); _newColorString = colorName; _newCOMPort = comPort != "" ? serialPortListProviderService.GetSerialPortInfos().First(spi => spi.Name == comPort).NameAndDescription : ""; _newSampleTime = 2; _newXResolution = 1920; _newYResolution = 1080; _newProbeType = "x1"; _newTriggerStatus = "Trigger Off"; _newTriggerType = "Rising Edge"; _newTriggerLevel = 1000; _newAFGStatus = "AFG Off"; _newAFGFrequency = 800; _newAFGAmplitude = 3300; _newAFGWaveform = "Sine Wave"; ApplyChanges(); }
public SourcesTabViewModel(ISourceConfigViewModelFactory sourceConfigViewModelFactory, IDerivedSourceConfigViewModelFactory derivedSourceConfigViewModelFactory, ISerialPortListProviderService serialPortListProviderService) { this._sourceCount = 1; this._colorList = new List <string>() { "Red", "Blue", "Green", "Magenta", "Cyan", "Yellow" }; this._sourceConfigViewModelFactory = sourceConfigViewModelFactory; this._derivedSourceConfigViewModelFactory = derivedSourceConfigViewModelFactory; this._serialPortListProviderService = serialPortListProviderService; this.Sources = new ObservableCollection <ISourceConfigViewModel>(); this.DerivedSources = new ObservableCollection <IDerivedSourceConfigViewModel>(); foreach (SerialPortInfo spi in _serialPortListProviderService.GetSerialPortInfos()) { if (spi.Description == "STMicroelectronics STLink Virtual COM Port") { AddNewSource(spi.Name); } } }
public void ApplyChanges() { try { if (_comPort != _newCOMPort) { if (_newCOMPort != "") { _probeDataReadingService.SetCOMPort(_serialPortListProviderService.GetSerialPortInfos().First(spi => spi.NameAndDescription == _newCOMPort).Name); } else { _probeDataReadingService.SetCOMPort(""); } } if (_triggerStatus != _newTriggerStatus) { _probeDataReadingService.SetReadTriggeredData(_newTriggerStatus == "Trigger On"); } if (_afgStatus != _newAFGStatus || _afgFrequency != _newAFGFrequency || _afgAmplitude != _newAFGAmplitude || _afgWaveform != _newAFGWaveform) { _probeDataReadingService.SetAFGSettings(_newAFGStatus == "AFG On" ? _newAFGFrequency : 0, _newAFGAmplitude, _newAFGWaveform.Replace(" Wave", "").ToLower()); } if (_probeType != _newProbeType) { _probeDataReadingService.SetProbeSetting(_newProbeType == "x10"); } if (_sampleTime != _newSampleTime) { _probeDataReadingService.SetSampleTime(_newSampleTime); } if (_xResolution != _newXResolution) { _probeDataReadingService.SetXResolution(_newXResolution); } if (_yResolution != _newYResolution) { _probeDataReadingService.SetYResolution(_newYResolution); } if (_triggerType != _newTriggerType) { _probeDataReadingService.SetTriggerType(_newTriggerType == "Rising Edge"); } if (_triggerLevel != _newTriggerLevel) { _probeDataReadingService.SetTriggerLevel((int)Math.Round(_newTriggerLevel * 4096 / 3300.0)); } } catch (ApplicationException ex) { } _name = _newName; _color = _newColor; _colorString = _newColorString; _comPort = _newCOMPort; _sampleTime = _newSampleTime; _xResolution = _newXResolution; _yResolution = _newYResolution; _probeType = _newProbeType; _triggerStatus = _newTriggerStatus; _triggerType = _newTriggerType; _triggerLevel = _newTriggerLevel; _afgStatus = _newAFGStatus; _afgFrequency = _newAFGFrequency; _afgAmplitude = _newAFGAmplitude; _afgWaveform = _newAFGWaveform; RaisePropertyChanged(nameof(Name)); RaisePropertyChanged(nameof(Color)); RaisePropertyChanged(nameof(ColorString)); RaisePropertyChanged(nameof(COMPort)); RaisePropertyChanged(nameof(SampleTime)); RaisePropertyChanged(nameof(XResolution)); RaisePropertyChanged(nameof(YResolution)); RaisePropertyChanged(nameof(ProbeType)); RaisePropertyChanged(nameof(TriggerStatus)); RaisePropertyChanged(nameof(TriggerType)); RaisePropertyChanged(nameof(TriggerLevel)); RaisePropertyChanged(nameof(AFGStatus)); RaisePropertyChanged(nameof(AFGFrequency)); RaisePropertyChanged(nameof(AFGAmplitude)); RaisePropertyChanged(nameof(AFGWaveform)); }