Attached are two programs that do the same thing. One is written in C# using Visa Com, the second using C# and Visa.
The purpose of this program is to take a handful of readings using the data type DINT. Why would you want to use DINT? It is the fastest method for removing data with all 8.5 digits of resolution. From the user's manual page 135:
• For DCV digitizing, you should use the SINT memory/output format when
the integration time is 1.4μs. Use the DINT memory/output format when
the integration time is >1.4μs. (These formats are discussed in detail in
Chapter 4.)
To achieve the fastest possible transfer of samples to reading memory and/or the
controller, you can use the SINT output/memory format for integration times up to
10.8u s. However when the integration time is >1.4 us, the A/D converter is
producing more bits of resolution than can be accommodated by the SINT format
(the least significant bit(s) are discarded). Whenever using the SINT
output/memory format with integration times >10.8u s, the multimeter must
convert the data coming from the A/D converter and cannot maintain the
high-speed mode. You should use the DINT memory/output format (which is
compatible with the high-speed mode) when the integration time is >10.8u s.
Program 1:
using System;
using System.Collections.Generic;
using System.Text;
using Ivi.Visa.Interop;
namespace DINT_3458A
{
class Program
{
public static void Main()
{
StringBuilder strDataCommand = new StringBuilder();
string instAddress = "GPIB0::22::INSTR";
ResourceManagerClass oRm = new ResourceManagerClass();
FormattedIO488Class oFio = new FormattedIO488Class();
//Open session for instrument.
oFio.IO = (IMessage)oRm.Open(instAddress, AccessMode.NO_LOCK, 2000, "");
oFio.IO.Timeout = 10000; //set timeout to 10 seconds
//Reset instrument
oFio.WriteString("RESET", true);
//Query Idendity string and report.
oFio.WriteString("END ALWAYS", true); //Set endline termination so you can retrieve data from instrument
oFio.WriteString("ID?", true); // Identify Instrument and print to screen
string strResult = oFio.ReadString();
Console.WriteLine("Instrument Identity String: " + strResult);
//Turn off memory, take data directly over bus
oFio.WriteString("MEM OFF", true);
// Specify DATA FORMAT
oFio.WriteString("MFORMAT DINT", true);
oFio.WriteString("OFORMAT DINT", true);
//Configure the instrument
oFio.WriteString("DCV 10", true);
oFio.WriteString("TRIG AUTO", true);
oFio.WriteString("NRDGS 5", true); //Set number of readings per trigger to desired value
oFio.WriteString("NPLC 1", true); //Set desired number of NPLCs, increase for greater accuracy
oFio.WriteString("ISCALE?", true); //Get scale value so you can convert DINT data
double scale = 0;
string scalestring;
scalestring = oFio.ReadString();
scale = double.Parse(scalestring);//Convert string result to double
oFio.WriteString("END ON", true); //Have to use END ON with multiple readings
oFio.WriteString("TARM SGL", true); //Triggers the instrument 1 time then becomes hold
byte[] rawdata = new byte[22]; //size should be at least nrdgs*4 +2
double[] scaleddata = new double[5]; //size should be at least nrdgs
//Read the DINT data
rawdata = oFio.IO.Read(22); //nrdgs*4 + 2
byte[] tempBuffer = new byte[4];
//Convert the DINT reading data and scale it with ISCALE then output to screen
for (int i = 0; i < 5; i++)
{
tempBuffer[3] = rawdata[i * 4];
tempBuffer[2] = rawdata[i * 4 + 1];
tempBuffer[1] = rawdata[i * 4 + 2];
tempBuffer[0] = rawdata[i * 4 + 3];
scaleddata[i] = System.BitConverter.ToInt32(tempBuffer, 0) * scale;
Console.WriteLine(scaleddata[i]);
}
Console.WriteLine("Measurement Finished\n");
Console.WriteLine("Press any key to close...");
Console.ReadLine();
oFio.IO.Close();
}
}
}
The purpose of this program is to take a handful of readings using the data type DINT. Why would you want to use DINT? It is the fastest method for removing data with all 8.5 digits of resolution. From the user's manual page 135:
• For DCV digitizing, you should use the SINT memory/output format when
the integration time is 1.4μs. Use the DINT memory/output format when
the integration time is >1.4μs. (These formats are discussed in detail in
Chapter 4.)
To achieve the fastest possible transfer of samples to reading memory and/or the
controller, you can use the SINT output/memory format for integration times up to
10.8u s. However when the integration time is >1.4 us, the A/D converter is
producing more bits of resolution than can be accommodated by the SINT format
(the least significant bit(s) are discarded). Whenever using the SINT
output/memory format with integration times >10.8u s, the multimeter must
convert the data coming from the A/D converter and cannot maintain the
high-speed mode. You should use the DINT memory/output format (which is
compatible with the high-speed mode) when the integration time is >10.8u s.
Program 1:
using System;
using System.Collections.Generic;
using System.Text;
using Ivi.Visa.Interop;
namespace DINT_3458A
{
class Program
{
public static void Main()
{
StringBuilder strDataCommand = new StringBuilder();
string instAddress = "GPIB0::22::INSTR";
ResourceManagerClass oRm = new ResourceManagerClass();
FormattedIO488Class oFio = new FormattedIO488Class();
//Open session for instrument.
oFio.IO = (IMessage)oRm.Open(instAddress, AccessMode.NO_LOCK, 2000, "");
oFio.IO.Timeout = 10000; //set timeout to 10 seconds
//Reset instrument
oFio.WriteString("RESET", true);
//Query Idendity string and report.
oFio.WriteString("END ALWAYS", true); //Set endline termination so you can retrieve data from instrument
oFio.WriteString("ID?", true); // Identify Instrument and print to screen
string strResult = oFio.ReadString();
Console.WriteLine("Instrument Identity String: " + strResult);
//Turn off memory, take data directly over bus
oFio.WriteString("MEM OFF", true);
// Specify DATA FORMAT
oFio.WriteString("MFORMAT DINT", true);
oFio.WriteString("OFORMAT DINT", true);
//Configure the instrument
oFio.WriteString("DCV 10", true);
oFio.WriteString("TRIG AUTO", true);
oFio.WriteString("NRDGS 5", true); //Set number of readings per trigger to desired value
oFio.WriteString("NPLC 1", true); //Set desired number of NPLCs, increase for greater accuracy
oFio.WriteString("ISCALE?", true); //Get scale value so you can convert DINT data
double scale = 0;
string scalestring;
scalestring = oFio.ReadString();
scale = double.Parse(scalestring);//Convert string result to double
oFio.WriteString("END ON", true); //Have to use END ON with multiple readings
oFio.WriteString("TARM SGL", true); //Triggers the instrument 1 time then becomes hold
byte[] rawdata = new byte[22]; //size should be at least nrdgs*4 +2
double[] scaleddata = new double[5]; //size should be at least nrdgs
//Read the DINT data
rawdata = oFio.IO.Read(22); //nrdgs*4 + 2
byte[] tempBuffer = new byte[4];
//Convert the DINT reading data and scale it with ISCALE then output to screen
for (int i = 0; i < 5; i++)
{
tempBuffer[3] = rawdata[i * 4];
tempBuffer[2] = rawdata[i * 4 + 1];
tempBuffer[1] = rawdata[i * 4 + 2];
tempBuffer[0] = rawdata[i * 4 + 3];
scaleddata[i] = System.BitConverter.ToInt32(tempBuffer, 0) * scale;
Console.WriteLine(scaleddata[i]);
}
Console.WriteLine("Measurement Finished\n");
Console.WriteLine("Press any key to close...");
Console.ReadLine();
oFio.IO.Close();
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace _3458A_DINT_Visa32cs
{
class Program
{
static void Main(string[] args)
{
int RM;
int DMM;
string id;
byte[] byteid = new byte[100];
visa32.viOpenDefaultRM(out RM);
visa32.viOpen(RM, "GPIB0::22::INSTR", visa32.VI_NULL, 20000, out DMM);
visa32.viPrintf(DMM,"END ALWAYS\n"); //Set endline termination so you can retrieve data from instrument
visa32.viPrintf(DMM,"ID?\n"); // Identify Instrument and print to screen
visa32.viScanf(DMM,"%t",byteid);
id = Encoding.ASCII.GetString(byteid);
Console.WriteLine("Instrument Identity String: " + id);
//Turn off memory, take data directly over bus
visa32.viPrintf(DMM,"MEM OFF\n");
// Specify DATA FORMAT
visa32.viPrintf(DMM,"MFORMAT DINT\n");
visa32.viPrintf(DMM,"OFORMAT DINT\n");
//Configure the instrument
visa32.viPrintf(DMM,"DCV 10\n");
visa32.viPrintf(DMM,"TRIG AUTO\n");
visa32.viPrintf(DMM,"NRDGS 5\n"); //Set number of readings per trigger to desired value
visa32.viPrintf(DMM,"NPLC 1\n"); //Set desired number of NPLCs, increase for greater accuracy
visa32.viPrintf(DMM,"ISCALE?\n"); //Get scale value so you can convert DINT data
double scale = 0;
string scalestring;
visa32.viRead(DMM, out scalestring,100);
scale = double.Parse(scalestring);//Convert string result to double
visa32.viPrintf(DMM,"END ON\n"); //Have to use END ON with multiple readings
visa32.viPrintf(DMM,"TARM SGL\n"); //Triggers the instrument 1 time then becomes hold
byte[] rawdata = new byte[22]; //size should be at least nrdgs*4 +2
double[] scaleddata = new double[5]; //size should be at least nrdgs
//Read the DINT data
visa32.viScanf(DMM,"%5ly", rawdata); // nrdgs*4 + 2
//Convert the DINT reading data and scale it with ISCALE then output to screen
for (int i = 0; i < 5; i++)
{
scaleddata[i] = System.BitConverter.ToInt32(rawdata, (i*4)) * scale; //converting 4 byte readings by scaling factor
Console.WriteLine(scaleddata[i]);
}
Console.WriteLine("Measurement Finished\n");
Console.WriteLine("Press any key to close...");
Console.ReadLine();
visa32.viClose(DMM);
visa32.viClose(RM);
}
}
}