コード例 #1
0
 private void addChannel()
 {
     lock (lockChannels)
     {
         foreach (TreeNode node in tvPlotVariables.Nodes)
         {
             if (node.Checked)
             {
                 bool dontAdd = false;
                 foreach (ScopeChannel scopeChannel in scope1.Channels)
                 {
                     if (node.Text == scopeChannel.Name)
                     {
                         dontAdd = true;
                     }
                 }
                 if (!dontAdd)
                 {
                     ScopeChannel a = new ScopeChannel();
                     a.Name = node.Text;
                     scope1.Channels.Add(a);
                     return;
                 }
             }
             else
             {
                 foreach (ScopeChannel scopeChannel in scope1.Channels)
                 {
                     if (node.Text == scopeChannel.Name)
                     {
                         scope1.Channels.Remove(scopeChannel);
                         return;
                     }
                 }
             }
         }
     }
 }
コード例 #2
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
            });
        }