//Notice that the Session Write commands are terminated with a “/n”.
//This is the newline character and is not really needed for GPIB,
//USB or VXI-11, but is needed for Sockets.
//It doesn’t cause any problems to include it.
//Read the response
responseString = mbSession.ReadString();
//Write to Console
Console.WriteLine("Response to *IDN?:");
Console.WriteLine(responseString);
//Return to Local Control
mbSession.Write("RTL\n");
//Close the Session
mbSession.Dispose();
}
catch (VisaException v_exp)
{
Console.WriteLine("Visa caught an error!!");
Console.WriteLine(v_exp.Message);
}
catch (Exception exp)
{
Console.WriteLine("Something didn't work!!");
Console.WriteLine(exp.Message);
Console.WriteLine();
}
keepConsoleUp();
// This is here so the Console stays up until the user hits return.
}
private static void keepConsoleUp()
{
Console.WriteLine("");
Console.WriteLine("Enter to Continue");
Console.ReadLine();
}
}
}
Example 1 – Discussion
1. The program output shown below.
Example 1 – Console Output
The console output should look something like this if everything worked. The result is Manufacturer, Model, Serial Number, and Firmware Version.
2. If it didn’t work then check that the sAddress string matches your setup. This is the error you’ll get if the address is wrong as shown in the figure below.
Example 1 – Exception Message
Results if the connection string is no good.
• The first thing to observe is the VISA connection string. Here are some possible strings:
• The beauty of using VISA is that the only thing that needs to be changed for any of these possible communication protocols is the connection string. The rest of the code should be exactly the same (except for SOCKETS). For TCP/IP we recommend using VXI-11 since it better implements the IEEE 488.2 standard and all status checking.
• But just in case, the connection string for a TCP/IP socket connection is:
• Notice that the mbSession.Write() commands are terminated with a “/n”. This is the newline character. The next example discusses session parameters. Some of the other examples will get into reading binary data and arbitrary block data.
5. Exception Handling
• The VISA driver catches certain types of errors like timeouts and .NET catches the rest.