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
2. Add Reference to the VISA COM Type Library
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:
Hello, of course this post is genuinely pleasant and I have learned lot of things from it on the topic of blogging. thanks.|