Wednesday, March 12, 2014

SCPI programming with Visual Studio

If you are just starting to program an instrument in Visual Studio, you might not know where to start. Having some source code to compare notes and start with is always very helpful and can get you up and running in a few hours. I find that just getting started in a new programming environment is the hardest step. In this post, I'm going to show you how to get started with some example code to help you to program a SCPI based instrument in Visual Studio. We'll talk about the first steps in SCPI programming, addressing your instrument, and some basic debug techniques too. In this post, I'll be using C# but many of the same techniques can be used in other languages in the Visual Studio environment.

Here's a youtube video that I made that explains many of the same steps that we'll cover in this post

Last year, I developed some example programs for the 34461A DMM. A DMM is one of the most basic instruments that you will find that has a programmatic interface. Measuring a DC voltage is a basic concept in electronics and thus is a good place to start when learning to automate a test instrument. Since you won't get stuck on what the instrument is doing, so you can just focus on what the program steps are.

Start off by downloading the Example C#  34461A code from

This code was developed in Visual Studio (VS) 2005, so it should be compatible with most VS versions that you might have installed on your PC.

I structured the programming examples so that you can open up all of the different examples in one solution file. This way, you can view any of the individual examples in the solution explorer of VS, instead of needing to navigate to each programming example's project or C# file. If this is foreign to you, it'll be apparent if you keep reading.

Let's start off by opening the solution file that is found after you unzip everything from the above link.

This will open up all of the different example programs in VS. My PC has VS2010, so I'll be using that for the rest of this post. The steps that I'm describing should be very similar from VS2005 on up though.  In the image to the right, you'll see all of the different programming examples that we
developed for the 34461A. Many of the examples can also be used with the 34401A, 34410A, and 34411A as well.

In this post, we'll focus on the most basic program, the "BasicFunctions_3446xA" example. In C#, the example programs are organized by project. This project contains .cs file that contains the source code, the project references which allow you to refer to other libraries, and the project properties which determine the build location and other behaviors of the program.

There are a couple of things that we'll want to do before we start looking at the code. First, we'll want to set this project as our startup project, this will allow us to start this programming example when we start debugging vs. starting one of the other programming examples. This is easily accomplished by right clicking on the BasicFunctions_3446xA project file and selecting "Set as Startup Project". You can view this step in the video if you click on this link or at the 1:40 mark in the video above.

Next we'll want to add in a reference to a library called Visa COM. This library is essential for talking to SCPI based instruments using VS, and enables you to "talk" to an instrument with standard I/O's such as  USB, LAN, GPIB, and even RS232. This is installed with Agilent IO libraries.

The library reference has already been added for the example programs, but this could be useful if you are starting a new project or the example program is somehow broken. To add the reference to Visa Com library, right click on the References folder in your project and select Add Reference. In the pop up box, select the COM tab and find the "VISA COM X.X Type Library". The X.X is the version number and gets updated periodically with different versions of IO Libraries. This step can be seen at the 1:58 mark in the video above.

Now let's look at the essential pieces of code. The first code step in communicating with an instrument is to start with some instrument handles. These handles will help you to declare your instrument and use them.
  //For more information on getting started using VISA COM I/O operations see the app note located at:
                Ivi.Visa.Interop.ResourceManager rm = new Ivi.Visa.Interop.ResourceManager(); //Open up a new resource manager
                Ivi.Visa.Interop.FormattedIO488 myDmm = new Ivi.Visa.Interop.FormattedIO488(); //Open a new Formatted IO 488 session 

The variable rm is a resource manager that allows you to manage the IO tools. You only need to use this in one important place in the code.

myDMM will be used as a variable to allow you to read and write to your DMM. We'll be using myDMM anywhere where we want to talk with the DMM.

After declaring these variables, we'll need to connect the myDMM variable with your actual instrument. This is done with the following command:
   string DutAddr = "USB0::0x0957::0x1C07::US00000069::0::INSTR"//String for USB

   myDmm.IO = (IMessage)rm.Open(DutAddr, AccessMode.NO_LOCK, 2000, ""); //Open up a handle to the DMM with a 2 second timeout

The variable DutAddr is a string that can be copied directly from IO libraries. Open up Agilent Connection Expert, find the instrument that you want to talk to and copy the Visa address. The paste the string into the DutAddr space.

You should now be able to talk to your instrument! Let's test the connection by sending a simple *IDN? command. This command is what I normally use to see if my communications to the instrument are working and if I'm talking to the right instrument which is important if your bench or system has a lot of different equipment.

There are two main commands when talking to an instrument. A write command and a read command. Sending a command to the instrument to change a setting is common, and you will just want to write a command. This is commonly done with the WriteString() command. I've shown this below with the *RST command.

When you ask an instrument to send back a reading it is called a query, and the basic structure to do a query is to send the command then read back the response. So it is a two step process. Be careful though, if you don't immediately read the response and you send another command, the instrument will have an error. Here's the basic example

myDmm.WriteString("*RST"); //Reset the device
 myDmm.WriteString("*IDN?"); //Send the command for the DMM to return an IDN string                string IDN = myDmm.ReadString(); //Read the string from the DMM Console.WriteLine(IDN); //report the DMM's identity

That's all there is to basic communications with an instrument in Visual Studio. If you haven't done so already, be sure to watch the video above since it goes a little more in depth on making measurements, best practices when programming, and debugging your program.

Monday, March 3, 2014

33600A Trueform Waveform Generator Introduced

Today Agilent introduces the 33600A Series waveform generators with exclusive Trueform signal generation technology offer more capability, fidelity and flexibility than previous generation Direct Digital Synthesis (DDS) generators. Use them to accelerate your development process from start to finish.

• 1 GSa/s sampling rate and up to 120 MHz bandwidth
• Arbs with sequencing and up to 64 MSa memory
• 1 ps jitter, 200x better than comparable DDS generators
• 5x lower harmonic distortion than DDS
• Compatible with Agilent BenchVue software

Trueform technology

Generate trueform arbitrary waveforms with less jitter, more idelity and greater resolution Over the past two decades, DDS has been the waveform generation technology of choice in function generators and economical arbitrary waveform generators. DDS enables waveform generators with great frequency resolution, convenient custom waveforms, and a low price.

As with any technology, DDS has its limitations. Engineers with exacting requirements have had to either work around the compromised performance or spend up to 5 times more for a high-end, point-per-clock waveform generator.

Agilent’s Trueform technology offers an alternative that blends the best of DDS and point-per-clock architectures, giving you the benefits of both without the limitations of either. Trueform technology uses an exclusive digital sampling technique that delivers unmatched performance at the same low price you are accustomed to with DDS.

For more information go to

The table in Figure 2 below highlights the revolutionary capabilities of Trueform technology.

Here's the overview video