Tektronix Technical Forums are maintained by community involvement. Feel free to post questions or respond to questions by other members. Should you require a time-sensitive answer, please contact your local Tektronix support center here.

c# / TekVISA / SEL:CHn requires retry?

Post Reply
cfebrian
Posts: 1
Joined: May 8th, 2019, 8:48 am
Country: United States

c# / TekVISA / SEL:CHn requires retry?

Post by cfebrian » May 8th, 2019, 8:58 am

I'm writing code to integrate a Fn Gen and a Scope (sine sweep and data collection of a transducer). I'm using:
  • Win 10/64-bit
    c#
    Visual Studio 2019
    TekVISA from NI
I've had limited success. I created a class (classOscilloscopeTektronix) to handle the low level communication. Some methods work... some don't

This method works great:

Code: Select all

        public bool IsPluggedIn()
        {
            bool isFound = false;

            TekVISANet.VISA TVA = new TekVISANet.VISA();
            System.Collections.ArrayList instrlist;
            TVA.FindResources("?*", out instrlist);

            foreach (string nameFoundInList in instrlist)
            {
                if ((nameFoundInList.IndexOf(nameScopeModel) != - -1) &&
                    (nameFoundInList.IndexOf(nameScopeVendorID) != -1))
                {
                    isFound = true;
                    nameFound = nameFoundInList;
                }
            }
            TVA.Clear();
            TVA.Close();
            return (isFound);
        }
These (x2) do not:

Code: Select all

        public void WriteToScope(string command)
        {
            TekVISANet.VISA TVA = new TekVISANet.VISA();
            TVA.Open(nameFound);
            TVA.Write(command);
            TVA.Clear();
            TVA.Close();
        }
        public void WriteToScopeWaitForPrior(string command)
        {
            TekVISANet.VISA TVA = new TekVISANet.VISA();
            TVA.Open(nameFound);
            TVA.Write("*OPC?");
            TVA.Write(command);
            TVA.Clear();
            TVA.Close();
        }
For my unit test, I've tried the code below and not all the channels show up on the display! When I type it in by hand using telnet, it works just fine. Seems like there is some handshaking missing?

Code: Select all

        [TestMethod]
        public void TestLowLevelCommunications()
        {
            ClassOscilloscopeTektronix scope = new ClassOscilloscopeTektronix();

            string response;

            scope.WriteToScope("*RST");

            scope.WriteToScope("SELECT:CH2 ON");
            scope.WriteToScope("SELECT:CH1 ON");
            scope.WriteToScope("SELECT:CH3 ON");
            scope.WriteToScope("SELECT:CH4 ON");
        }
So, I tried a variation. This still does not work. In fact, the SEL:CH2? results in false. So, I issued the command and it did not seem to stick.

Code: Select all

        [TestMethod]
        public void TestLowLevelCommunications()
        {
            ClassOscilloscopeTektronix scope = new ClassOscilloscopeTektronix();

            string response;

            scope.WriteToScope("*RST");
            response = scope.QueryScope("BUSY?");
            while (response.Contains("1"))
                response = scope.QueryScope("BUSY?");

            scope.WriteToScope("SELECT:CH2 ON");
            response = scope.QueryScope("BUSY?");
            while (response.Contains("1"))
                response = scope.QueryScope("BUSY?");
            response = scope.QueryScope("SELECT:CH2?");

            scope.WriteToScope("SELECT:CH1 ON");
            response = scope.QueryScope("BUSY?");
            while (response.Contains("1"))
                response = scope.QueryScope("BUSY?");

            scope.WriteToScope("SELECT:CH3 ON");
            response = scope.QueryScope("BUSY?");
            while (response.Contains("1"))
                response = scope.QueryScope("BUSY?");

            scope.WriteToScope("SELECT:CH4 ON");
            response = scope.QueryScope("BUSY?");
            while (response.Contains("1"))
                response = scope.QueryScope("BUSY?");

        }
In frustration, I implemented a retry and this works. However, no other examples on the web seem to show that retries are necessary. What's going on here?

Code: Select all

            scope.WriteToScope("SELECT:CH1 ON");
            response = scope.QueryScope("SELECT:CH1?");
            while (response.Contains("1"))
            {
                scope.WriteToScope("SELECT:CH1 ON");
                response = scope.QueryScope("SELECT:CH1?");
            }

Post Reply

Return to “Programming Support”

Who is online

Users browsing this forum: No registered users and 18 guests