Esempio n. 1
0
        public RunVM()
        {
            Activator = new ViewModelActivator();
            Protocol  = new RootProtocol();

            AutoScale     = new ScopeCommand <string>(this, Protocol.AutoScale);
            Clear         = new ScopeCommand <string>(this, Protocol.Clear);
            Run           = new ScopeCommand <string>(this, Protocol.Run);
            Stop          = new ScopeCommand <string>(this, Protocol.Stop);
            SingleTrigger = new ScopeCommand <string>(this, Protocol.Single);
            ForceTrigger  = new ScopeCommand <string>(this, Protocol.Force);

            Status = new ScopeCommand <string>(this, Protocol.Status, "AUTO");

            AllScopeCommands = new List <IScopeCommand>
            {
                AutoScale, Clear, Run, Stop, SingleTrigger, ForceTrigger,
            };

            this.WhenActivated(disposables =>
            {
                this.HandleActivation();

                Disposable
                .Create(() => this.HandleDeactivation())
                .DisposeWith(disposables);

                var statusTimer = Observable.Interval(TimeSpan.FromMilliseconds(1000))
                                  .ToSignal()
                                  .ObserveOn(RxApp.MainThreadScheduler)
                                  .InvokeCommand(Status.GetCommand);
            });
        }
Esempio n. 2
0
        public TimebaseVM()
        {
            Activator = new ViewModelActivator();
            Protocol  = new TimebaseProtocol(null);

            Offset       = new ScopeCommand <double>(this, Protocol.Offset, "0.0");
            Offset.Value = SI.Parse("0V");
            Scale        = new ScopeCommand <double>(this, Protocol.Scale, "1u".ToReal()); // 1us/div
            Scale.Value  = SI.Parse("1u");
            Mode         = new ScopeCommand <string>(this, Protocol.Mode, "MAIN");

            AllCommands = new List <IScopeCommand>()
            {
                Offset, Scale, Mode,
            };

            var GetAllMessage = ReactiveCommand.Create(() =>
                                                       Debug.WriteLine("------- Retrieving all TIMEBASE values from device ---------"));

            GetAll = ReactiveCommand
                     .CreateCombined(new[]
            {
                // TODO: Should also get items that are dependencies of these
                //   like sample rate, memory depth, etc.
                GetAllMessage,
                Offset.GetCommand,
                Scale.GetCommand,
                Mode.GetCommand,
            });

            var SetAllMessage = ReactiveCommand.Create(() =>
                                                       Debug.WriteLine("------- Setting all TIMEBASE values on device ---------"));

            SetAll = ReactiveCommand.CreateCombined(new[]
            {
                SetAllMessage,
                Offset.SetCommand,
                Scale.SetCommand,
                Mode.SetCommand,
            });

            this.WhenActivated(disposables =>
            {
                this.HandleActivation();

                Disposable
                .Create(() => this.HandleDeactivation())
                .DisposeWith(disposables);

                foreach (var scopeCommand in AllCommands)
                {
                    scopeCommand.WhenActivated(disposables);
                }
            });
        }
Esempio n. 3
0
        public ScopeChannelVM(int channelNumber)
        {
            Activator = new ViewModelActivator();
            Protocol  = new ChannelProtocol(null, channelNumber);
            Model     = new ScopeChannel();

            if (App.Mock)
            {
                MockModel = new ScopeChannel();
            }

            ChannelNumber = channelNumber;
            Name          = $"CH{channelNumber}";
            switch (channelNumber)
            {
            case 1: Color = "#F8FC00"; break;

            case 2: Color = "#00FCF8"; break;

            case 3: Color = "#F800F8"; break;

            case 4: Color = "#007CF8"; break;
            }

            Display  = new ScopeCommand <bool>(this, Protocol.Display, "OFF");
            BWLimit  = new ScopeCommand <bool>(this, Protocol.BWLimit, "OFF");
            Coupling = new ScopeCommand <string>(this, Protocol.Coupling, "AC");
            Invert   = new ScopeCommand <bool>(this, Protocol.Invert, "OFF");
            Offset   = new ScopeCommand <double>(this, Protocol.Offset, "0V".ToReal());
            // Use Scale //Range = new ScopeCommand<double>(this, Protocol.Range, "8V".ToReal());
            TCal    = new ScopeCommand <double>(this, Protocol.TCal, "0s".ToReal());
            Scale   = new ScopeCommand <double>(this, Protocol.Scale, "1V".ToReal());
            Probe   = new ScopeCommand <string>(this, Protocol.Probe, "10".ToReal());
            Vernier = new ScopeCommand <bool>(this, Protocol.Vernier, "OFF");
            Units   = new ScopeCommand <string>(this, Protocol.Units, "VOLT");

            AllCommands = new List <IScopeCommand>()
            {
                Display, BWLimit, Coupling, Invert, Offset, TCal,
                Scale, Probe, Units, Vernier
            };

            SelectChannel = ReactiveCommand.CreateFromTask(SelectChannelExecute);

            // Offset units, based on Units
            this.WhenValueChanged(x => x.Units)
            .Subscribe(x => UpdateUnits());

            #region Get/Set All
            var GetAllMessage = ReactiveCommand.Create(() =>
                                                       Debug.WriteLine($"------- Retrieving all CHANNEL{ChannelNumber} values from device ---------"));
            GetAll = ReactiveCommand.Create(async() =>
            {
                AppLocator.TelnetService.AutoGetScreenshotAfterCommand = false;
                try
                {
                    await GetAllMessage.Execute();
                    foreach (var command in AllCommands)
                    {
                        await command.GetCommand.Execute();
                    }
                }
                finally
                {
                    AppLocator.TelnetService.AutoGetScreenshotAfterCommand = true;
                }
            });

            var SetAllMessage = ReactiveCommand.Create(() =>
                                                       Debug.WriteLine($"------- Setting all CHANNEL{ChannelNumber} values on device ---------"));
            SetAll = ReactiveCommand.Create(async() =>
            {
                AppLocator.TelnetService.AutoGetScreenshotAfterCommand = false;
                try
                {
                    await GetAllMessage.Execute();
                    foreach (var command in AllCommands)
                    {
                        await command.SetCommand.Execute();
                    }
                }
                finally
                {
                    AppLocator.TelnetService.AutoGetScreenshotAfterCommand = true;
                }
            });
            #endregion

            // watch our own properties and call commands that update the model

            //this.WhenPropertyChanged(x => x.IsActive)
            //    .InvokeCommand(SetIsActiveCommand);
            this.WhenActivated(disposables =>
            {
                this.HandleActivation();

                Disposable
                .Create(() => this.HandleDeactivation())
                .DisposeWith(disposables);

                foreach (var scopeCommand in AllCommands)
                {
                    scopeCommand.WhenActivated(disposables);
                }

                // update Offset when probe or scale are changed
                this.WhenAnyValue(x => x.Probe.Value, y => y.Scale.Value)
                .Where(x => x.Item1 != null && x.Item1.Length > 0)
                .SubscribeOnUI()
                .Subscribe(x =>
                {
                    var options = this.Protocol.Offset.Options as RealOptions;
                    options.SetChannelOffset(x.Item1, x.Item2);
                });

                // update Scale when probe is changed
                this.WhenAnyValue(vm => vm.Probe.Value)
                .Where(x => x != null && x.Length > 0)
                .SubscribeOnUI()
                .Subscribe((x) => {
                    var options = Protocol.Scale.Options as RealOptions;
                    options.SetChannelScale(x);
                });
#if TCAL
                this.WhenValueChanged(x => x.TCal)
                .ToSignal()
                .InvokeCommand(this, x => x.SetTCalCommand)
                .DisposeWith(disposables);
#endif
            });
        }
Esempio n. 4
0
        public TriggerVM()
        {
            Activator = new ViewModelActivator();
            Protocol  = new TriggerProtocol(null);

            Sweep      = new ScopeCommand <string>(this, Protocol.Sweep, "AUTO");
            Mode       = new ScopeCommand <string>(this, Protocol.Mode, nameof(ModeStringOptions.Edge));
            EdgeSource = new ScopeCommand <string>(this, Protocol.Edge.Source, "CHAN1");
            EdgeSlope  = new ScopeCommand <string>(this, Protocol.Edge.Slope, "POS");
            EdgeLevel  = new ScopeCommand <double>(this, Protocol.Edge.Level, "0");

            AllScopeCommands = new List <IScopeCommand>()
            {
                Sweep, Mode, EdgeSource, EdgeSlope, EdgeLevel,
            };

            var GetAllMessage = ReactiveCommand.Create(() =>
                                                       Debug.WriteLine("------- Retrieving all TRIGGER values from device ---------"));

            GetAll = ReactiveCommand.CreateCombined(new[]
            {
                GetAllMessage,
                Sweep.GetCommand,
                Mode.GetCommand,
                EdgeSource.GetCommand,
                EdgeSlope.GetCommand,
                EdgeLevel.GetCommand,
            });

            var SetAllMessage = ReactiveCommand.Create(() =>
                                                       Debug.WriteLine("------- Setting all TRIGGER values on device ---------"));

            SetAll = ReactiveCommand.CreateCombined(new[]
            {
                SetAllMessage,
                Sweep.SetCommand,
                Mode.SetCommand,
                EdgeSource.SetCommand,
                EdgeSlope.SetCommand,
                EdgeLevel.SetCommand,
            });


            this.WhenActivated(disposables =>
            {
                this.HandleActivation();

                Disposable
                .Create(() => this.HandleDeactivation())
                .DisposeWith(disposables);

                foreach (var scopeCommand in AllScopeCommands)
                {
                    scopeCommand.WhenActivated(disposables);
                }

                // Make visible the panel that corresponds to the selected trigger mode
                this.WhenAnyValue(
                    x => x.Mode.Value,
                    x => x == nameof(ModeStringOptions.Edge))
                .ToPropertyEx(this, x => x.IsEdgeMode);

                // Range of edge level trigger is:
                //   (-5x Vertical Scale - Offset) to (+5x Vertical Scale - Offset)
                Timebase.WhenAnyValue(
                    vm => vm.Scale.Value,
                    vm => vm.Offset.Value,
                    (x, y) => {
                    Protocol.Edge.SetLevelRange(x, y);
                    return(0.0);
                });
            });
        }