chr
2026-04-08 53e656200368a983e563550e2cc1acbc6d86b729
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
//Copyright 2012-2019 Keysight Technologies
//
//Licensed under the Apache License, Version 2.0 (the "License");
//you may not use this file except in compliance with the License.
//You may obtain a copy of the License at
//
//http://www.apache.org/licenses/LICENSE-2.0
//
//Unless required by applicable law or agreed to in writing, software
//distributed under the License is distributed on an "AS IS" BASIS,
//WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//See the License for the specific language governing permissions and
//limitations under the License.
using System;
using OpenTap;
 
// Note this template assumes that you have a SCPI based instrument, and accordingly
// extends the ScpiInstrument base class.
 
namespace OpenTap.Plugins.PluginDevelopment
{
    [Display("Scpi Instrument Example", Groups: new[] { "Examples", "Plugin Development" }, Description: "Example of a SCPI Instrument implementation.")]
    // If the instrument is SCPI based, inheriting from the ScpiInstrument base class will simplify implementation.
    public class ScpiInstrumentExample : ScpiInstrument
    {
        // ScpiInstuments provides useful settings for VisaAddress, IdnString and others.
        // Anything not already included in ScpiInstrument can be added here.
 
        public ScpiInstrumentExample()
        {
            // Set the name of the Scpi Instrument Example
            Name = "ScpiEx";
            // Set default values for properties / settings.
            VisaAddress = "Simulate";
        }
 
        /// <summary>
        /// Open procedure for the instrument.
        /// </summary>
        public override void Open()
        {
            base.Open();
 
            // Use this to ensure the correct instrument is being connected to.
            if (!IdnString.Contains("Instrument ID"))
            {
                Log.Error("This instrument driver does not support the connected instrument.");
                throw new ArgumentException("Wrong instrument type.");
            }
        }
 
        // Add wrapper methods as needed.
        public void Configure(double centerFrequency, double frequencySpan, int points)
        {
            // Use ScpiCommand to send SCPI strings to the instrument.
            ScpiCommand("SENSE:FREQ:CENT " + centerFrequency);
            ScpiCommand("SENSE: FREQ:SPAN " + frequencySpan);
            ScpiCommand("SENSE:SWE:POIN " + points);
        }
 
        public double[] SweepMeasurement()
        {
            // Use ScpiQuery to read back from the device.
            return ScpiQuery<double[]>("READ:SAN1?");
        }
 
        /// <summary>
        /// Close procedure for the instrument.
        /// </summary>
        public override void Close()
        {
            // Add code to close the connection to the instrument here.
            base.Close();
        }
    }
}