Using Visual Studio for Instrument Programming [Updated for VS 2012]

This post describes how to use Visual Studio 2012 to program and control a measurement instrument. Programming language used is C# and we have used the IVI VISA interop library for communication.

1. Start by creating a new project. You can create a Windows Forms Application or a Console Application

VS2

VS3

2. Add Reference to the VISA COM Type Library

VS4

VS5

3. Write your code and compile. Here is an example program for reference:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Runtime.InteropServices;

using Ivi.Visa;
using Ivi.Visa.Interop;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            
            ResourceManager ioMgr = new ResourceManager();
            FormattedIO488 instrument = new FormattedIO488();

            IVisaSession session = null;

            try
            {
                session = ioMgr.Open("TCPIP::192.168.1.20::inst0::INSTR", AccessMode.NO_LOCK, 3000, "");
            }
            catch (COMException ex)
            {
                Console.WriteLine("Failed to connect to the SCPI interface.");
            }

            instrument.IO = (IMessage)session;
            instrument.IO.SendEndEnabled = false;
            instrument.IO.Timeout = 10000;                       //in milliseconds
            instrument.IO.TerminationCharacterEnabled = true;   //Defaults to false    

            instrument.WriteString("*IDN?");
            string idnString = instrument.ReadString();
            Console.WriteLine("VISA IDN String: " + idnString);

            instrument.IO.Close();

        }
    }
}

4. Build and Run. If everything is properly set up, you will see a response from your instrument similar to that shown below:

VS6

One comment:

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>