Thursday, June 30, 2016

Tektronix oscilloscopes Office from Visual Studio

With similar problems faced rare, but if it happens, it is very nice to read a comprehensive article that will quickly begin productive work, not to break the whole day head the question "What to download?", "Where can I find?", "How is it working?" . I have a similar problem arose in the development of automated test bench for testing boards. In the process of solving a number of problems, and information on the internet about this fairly small due to the narrowness of the problem. This article is the most detailed and clearly describes the main points for a quick start working with Tektronix oscilloscopes from Visual Studio.

First you need to download and install TekVISA driver (need to be registered, otherwise you will not be able to download the necessary drivers).




After installing the driver TekVISA need to go to the directory C: \ Windows \ assembly, it is there will be the need for TekVISANet.dll library. Next, add the library to the project (Project> Add Reference ...> Browse ...) and ... everything!

And it would seem that everything is so simple! However, it has spent half a day in order to understand where this miracle was saved library. After all, following the voice of reason, you would expect to find it in a very different directories, for example, C: \ Program Files (x86) \ IVI Foundation or C: \ Program Files (x86) \ Tektronix.

Interact with an oscilloscope as simple as possible. For example, the following code snippet allows you to connect to the device and read its identity:

using System;
using System.Collections;
using TekVISANet;
namespace TekVISAExample
{
    class Program
    {
        static void Main (string [] args)
        {
            string response;
            ArrayList resources = new ArrayList ();
            VISA tekVISA = new VISA ();
            tekVISA.FindResources (, out resources "*?");
            Console.WriteLine ( "RESOURCES:");
            foreach (string s in resources)
                Console.WriteLine (s);
            tekVISA.Open (resources [0] .ToString ());
            tekVISA.Write ( "* IDN?");
            bool status = tekVISA.Read (out response);
            if (status)
                Console.WriteLine ( "IDN (device information): {0}", response);
            Console.ReadKey ();
        }
    }
}

OUTPUT:
RESOURCES:
USB0 :: 0x0699 :: 0x0376 :: C011053 :: INSTR
ASRL7 :: INSTR
ASRL8 :: INSTR
IDN (device information):
TEKTRONIX, MSO2012, C011053, CF: 91.1CT FV: v1.52 DPO2COMP: V1.00

To communicate with the device you want to use SCPI (Standard Commands for Programmable Instruments) command. Read them here: sdphca.ucsd.edu/Lab_Equip_Manuals/SCPI-99.pdf. However, all the devices have different settings and functionality, so you need to find a set of SCPI commands, it is applicable to your particular device. As a rule, they can be found in the Programmer Manual device.

You can also download the OpenChoice Desktop free application for oscilloscopes Tektronix. After downloading and installing, you need to connect the device to a computer (USB), run the application, go to the Get & Send Settings tab and press the Get Settings button. The screen displays all available commands to configure devices with their current settings.

Example 1. Measurement of RMS values ​​of the second channel:

using System;
using System.Collections;
using TekVISANet;
namespace TekVISAExample
{
    class Program
    {
        private const string OSCILLOSCOPE = "USB0 :: 0x0699 :: 0x0376 :: C011053 :: INSTR";
        static void Main (string [] args)
        {
            VISA tekVISA = new VISA ();
            ArrayList resources = new ArrayList ();
            tekVISA.FindResources (, out resources "*?");
            bool opened = false;
            if (resources.Contains (OSCILLOSCOPE))
                opened = tekVISA.Open (OSCILLOSCOPE);
            if (opened)
            {
                /// Configure channel 2
                tekVISA.Write ( "CH2: COUPLING AC");
                tekVISA.Write ( "CH2: SCALE 20.000E-3");
                tekVISA.Write ( "CH2: BANDWIDTH 20.000E + 6");
                /// What we want to measure?
                tekVISA.Write ( "MEASUREMENT: MEAS1: TYPE RMS");
                tekVISA.Write ( "MEASUREMENT: MEAS1: SOURCE1 CH2");
                tekVISA.Write ( "MEASUREMENT: MEAS1: STATE ON");
                /// Read request RMS values
                tekVISA.Write ( "MEASUREMENT: MEAS1: VALUE?");
                string response = "";
                /// Read data
                tekVISA.Read (out response);
                Console.WriteLine ( "RMS CH2 VALUE: {0}", response);
            }
            Console.ReadKey ();
        }
    }

Example 2. Preparation of the waveform in the form of dots stored in .csv file for future use:

using System;
using System.Linq;
using System.Collections;
using System.Globalization;
using TekVISANet;
using System.Threading;
namespace TekVISAExample
{
    class Program
    {
        private const string OSCILLOSCOPE = "USB :: 0x0699 :: 0x0376 :: C011053 :: INSTR";
        static void Main (string [] args)
        {
            Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture ( "en-US");
            VISA tekVISA = new VISA ();
            ArrayList resources = new ArrayList ();
            tekVISA.FindResources (, out resources "*?");
            bool opened = false;
            if (resources.Contains (OSCILLOSCOPE))
                opened = tekVISA.Open (OSCILLOSCOPE);
            if (opened)
            {
                NumberStyles styles = NumberStyles.AllowExponent | NumberStyles.Number;
                string response = "";
               
                tekVISA.Write ( "DATA: SOU CH2");
                tekVISA.Write ( "DATA: WIDTH 1");
                tekVISA.Write ( "DATA: ENC ASCII");
                tekVISA.Write ( "DATA: STOP 5208");
                tekVISA.Query ( "WFMPRE: YMULT?", out response);
                response = response.Replace ( ": WFMPRE: YMULT", "");
                float ymult = float.Parse (response, styles);
                tekVISA.Query ( "WFMPRE: YZERO?", out response);
                response = response.Replace ( ": WFMPRE: YZERO", "");
                float yzero = float.Parse (response, styles);
                tekVISA.Query ( "WFMPRE: YOFF?", out response);
                response = response.Replace ( ": WFMPRE: YOFF", "");
                float yoff = float.Parse (response, styles);
                tekVISA.Query ( "WFMPRE: XINCR?", out response);
                response = response.Replace ( ": WFMPRE: XINCR", "");
                float xincr = float.Parse (response, styles);
                tekVISA.Write ( "CURVE?");
                tekVISA.Read (out response);
                response = response.Replace ( ": CURVE", "");
                . Sbyte [] rawwave = response.Split ( ',') Select (n => Convert.ToSByte (n)) ToArray ().;
                float [] wave = new float [rawwave.Count ()];
                for (int j = 0; j <rawwave.Count (); j ++)
                    wave [j] = (rawwave [j] - yoff) * ymult + yzero;
                System.IO.StreamWriter file = new System.IO.StreamWriter ( "waveform.csv");
                file.WriteLine ( "V, S");
                for (int j = 0; j <wave.Count (); j ++)
                {
                    float timepoint = j * xincr;
                    file.WriteLine (wave [j] .ToString () + "," + timepoint.ToString ());
                }
                file.Close ();
                tekVISA.Close ();
            }
            Console.ReadKey ();
        }
    }
}

No comments:

Post a Comment