C#:
/****************************************************************************
*
* EXAMPLE DESCRIPTION:
*
* Binary_Arb is a sample program that demonstrates how to send binary waveforms to the Agilent function generators
* Waveforms over 64Kpoints must be sent using binary
*
* Sample Rate: 400000 Samples/sec
* Amplitude: 2 Volt Peak to Peak
* Offset: 0 Volt
* Output Impedance: 50 Ohm
* Channel1 Output: Enabled
*
* Caution: All un-saved data present in volatile memory will be erased.
* Save information before proceeding to this example program.
*
******************************************************************************
*
* BUILDING THIS EXAMPLE:
*
* This sample program is intended to be used with Microsoft Visual C# 2005,
* or later, and the VISA COM library.
*
* Sample program execution requires the VISA COM library as a prerequisite,
* which is installed by the Agilent IO Libraries Suite.
* Sample program uses VISA COM 3.0 Type Library as a reference to the
* VISA COM library:
*
* $(VXIPNPPATH)\VisaCom\Primary Interop Assemblies\Ivi.Visa.Interop.dll
*
******************************************************************************
*
* Copyright © 2012 Agilent Technologies Inc. All rights
* reserved.
*
* You have a royalty-free right to use, modify, reproduce and distribute
* the Sample Application Files (and/or any modified version) in any way
* you find useful, provided that you agree that Agilent has no
* warranty, obligations or liability for any Sample Application Files.
*
* Agilent Technologies provides programming examples for illustration only,
* This sample program assumes that you are familiar with the programming
* language being demonstrated and the tools used to create and debug
* procedures. Agilent support engineers can help explain the
* functionality of Agilent software components and associated
* commands, but they will not modify these samples to provide added
* functionality or construct procedures to meet your specific needs.
*
*******************************************************************************/
using System;
using System.Collections.Generic;
using System.Text;
//Add VISA COM library reference.
using Ivi.Visa.Interop;
namespace Binary_Arb
{
class Program
{
const string noErrString = "+0,\"No error\"\n";
static void Main(string[] args)
{
try
{
BinaryArb();
}
catch (Exception oExp)
{
Console.WriteLine(oExp.Message);
}
Console.WriteLine("Press [Enter] to exit");
Console.ReadKey();
}
public static void BinaryArb()
{
const int NUM_DATA_POINTS = 100000;
float[] z = new float[NUM_DATA_POINTS];
string instAddress = "TCPIP0::156.140.113.206::inst0::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;
//Query Idendity string and report.
oFio.WriteString("*IDN?", true);
string strResult = oFio.ReadString();
Console.WriteLine("Instrument Identity String: " + strResult);
//Clear and reset instrument
oFio.WriteString("*CLS;*RST;*OPC?", true);
oFio.ReadString();
//Clear volatile memory
oFio.WriteString("SOURce1:DATA:VOLatile:CLEar", true);
//Create simple ramp waveform
for (int i = 0; i < NUM_DATA_POINTS; i++)
z[i] = (i - 1) / (float)NUM_DATA_POINTS;
// swap the endian format
oFio.WriteString("FORM:BORD NORM", true);
//Downloading
Console.WriteLine("Downloading Waveform...");
oFio.WriteIEEEBlock("SOURce1:DATA:ARBitrary testarb, ", z, true);
// wait for the operation to complete before moving on
oFio.WriteString("*WAI", true);
Console.WriteLine("Download Complete", true);
//Set desired configuration
oFio.WriteString("SOURce1:FUNCtion:ARBitrary testarb", true); // set current arb waveform to defined arb pulse
oFio.WriteString("SOURce1:FUNCtion ARB", true); // turn on arb function
oFio.WriteString("SOURCE1:FUNCtion:ARB:SRATe 400000", true); // set sample rate
oFio.WriteString("SOURCE1:VOLT 2", true); // set max waveform amplitude to 2 Vpp
oFio.WriteString("SOURCE1:VOLT:OFFSET 0", true); // set offset to 0 V
oFio.WriteString("OUTPUT1:LOAD 50", true); // set output load to 50 ohms
//Enable Output
oFio.WriteString("OUTPUT1 ON", true); // turn on channel 1 output
//Read Error/s
oFio.WriteString("SYSTEM:ERROR?", true);
strResult = oFio.ReadString();
if (strResult == noErrString)
{
Console.WriteLine("Output set without any error\n");
}
else
{
Console.WriteLine("Error reported: " + strResult);
}
}
}
}
/****************************************************************************
*
* EXAMPLE DESCRIPTION:
*
* Binary_Arb is a sample program that demonstrates how to send binary waveforms to the Agilent function generators
* Waveforms over 64Kpoints must be sent using binary
*
* Sample Rate: 400000 Samples/sec
* Amplitude: 2 Volt Peak to Peak
* Offset: 0 Volt
* Output Impedance: 50 Ohm
* Channel1 Output: Enabled
*
* Caution: All un-saved data present in volatile memory will be erased.
* Save information before proceeding to this example program.
*
******************************************************************************
*
* BUILDING THIS EXAMPLE:
*
* This sample program is intended to be used with Microsoft Visual C# 2005,
* or later, and the VISA COM library.
*
* Sample program execution requires the VISA COM library as a prerequisite,
* which is installed by the Agilent IO Libraries Suite.
* Sample program uses VISA COM 3.0 Type Library as a reference to the
* VISA COM library:
*
* $(VXIPNPPATH)\VisaCom\Primary Interop Assemblies\Ivi.Visa.Interop.dll
*
******************************************************************************
*
* Copyright © 2012 Agilent Technologies Inc. All rights
* reserved.
*
* You have a royalty-free right to use, modify, reproduce and distribute
* the Sample Application Files (and/or any modified version) in any way
* you find useful, provided that you agree that Agilent has no
* warranty, obligations or liability for any Sample Application Files.
*
* Agilent Technologies provides programming examples for illustration only,
* This sample program assumes that you are familiar with the programming
* language being demonstrated and the tools used to create and debug
* procedures. Agilent support engineers can help explain the
* functionality of Agilent software components and associated
* commands, but they will not modify these samples to provide added
* functionality or construct procedures to meet your specific needs.
*
*******************************************************************************/
using System;
using System.Collections.Generic;
using System.Text;
//Add VISA COM library reference.
using Ivi.Visa.Interop;
namespace Binary_Arb
{
class Program
{
const string noErrString = "+0,\"No error\"\n";
static void Main(string[] args)
{
try
{
BinaryArb();
}
catch (Exception oExp)
{
Console.WriteLine(oExp.Message);
}
Console.WriteLine("Press [Enter] to exit");
Console.ReadKey();
}
public static void BinaryArb()
{
const int NUM_DATA_POINTS = 100000;
float[] z = new float[NUM_DATA_POINTS];
string instAddress = "TCPIP0::156.140.113.206::inst0::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;
//Query Idendity string and report.
oFio.WriteString("*IDN?", true);
string strResult = oFio.ReadString();
Console.WriteLine("Instrument Identity String: " + strResult);
//Clear and reset instrument
oFio.WriteString("*CLS;*RST;*OPC?", true);
oFio.ReadString();
//Clear volatile memory
oFio.WriteString("SOURce1:DATA:VOLatile:CLEar", true);
//Create simple ramp waveform
for (int i = 0; i < NUM_DATA_POINTS; i++)
z[i] = (i - 1) / (float)NUM_DATA_POINTS;
// swap the endian format
oFio.WriteString("FORM:BORD NORM", true);
//Downloading
Console.WriteLine("Downloading Waveform...");
oFio.WriteIEEEBlock("SOURce1:DATA:ARBitrary testarb, ", z, true);
// wait for the operation to complete before moving on
oFio.WriteString("*WAI", true);
Console.WriteLine("Download Complete", true);
//Set desired configuration
oFio.WriteString("SOURce1:FUNCtion:ARBitrary testarb", true); // set current arb waveform to defined arb pulse
oFio.WriteString("SOURce1:FUNCtion ARB", true); // turn on arb function
oFio.WriteString("SOURCE1:FUNCtion:ARB:SRATe 400000", true); // set sample rate
oFio.WriteString("SOURCE1:VOLT 2", true); // set max waveform amplitude to 2 Vpp
oFio.WriteString("SOURCE1:VOLT:OFFSET 0", true); // set offset to 0 V
oFio.WriteString("OUTPUT1:LOAD 50", true); // set output load to 50 ohms
//Enable Output
oFio.WriteString("OUTPUT1 ON", true); // turn on channel 1 output
//Read Error/s
oFio.WriteString("SYSTEM:ERROR?", true);
strResult = oFio.ReadString();
if (strResult == noErrString)
{
Console.WriteLine("Output set without any error\n");
}
else
{
Console.WriteLine("Error reported: " + strResult);
}
}
}
}
/****************************************************************************
*
* EXAMPLE DESCRIPTION:
*
* Binary_Arb is a sample program that demonstrates how to send binary waveforms to the Agilent function generators
* Waveforms over 64Kpoints must be sent using binary
*
* Sample Rate: 400000 Samples/sec
* Amplitude: 2 Volt Peak to Peak
* Offset: 0 Volt
* Output Impedance: 50 Ohm
* Channel1 Output: Enabled
*
* Caution: All un-saved data present in volatile memory will be erased.
* Save information before proceeding to this example program.
*
******************************************************************************
*
* BUILDING THIS EXAMPLE:
*
* This sample program is intended to be used with Microsoft Visual C# 2005,
* or later, and the VISA library.
*
* Sample program execution requires the VISA library as a prerequisite,
* which is installed by the Agilent IO Libraries Suite.
*
* visa.h is located at:
* $(VXIPNPPATH)\winnt\include
*
* visa32.lib/visa64.lib is located at:
* 32-bit
* $(VXIPNPPATH)\winnt\lib\msc
* 64-bit
* $(VXIPNPPATH)\winnt\lib_x64\msc
*
******************************************************************************
*
* Copyright © 2012 Agilent Technologies Inc. All rights
* reserved.
*
* You have a royalty-free right to use, modify, reproduce and distribute
* the Sample Application Files (and/or any modified version) in any way
* you find useful, provided that you agree that Agilent has no
* warranty, obligations or liability for any Sample Application Files.
*
* Agilent Technologies provides programming examples for illustration only,
* This sample program assumes that you are familiar with the programming
* language being demonstrated and the tools used to create and debug
* procedures. Agilent support engineers can help explain the
* functionality of Agilent software components and associated
* commands, but they will not modify these samples to provide added
* functionality or construct procedures to meet your specific needs.
*
*******************************************************************************/
#include "stdafx.h"
#include "visa.h"
#include "string.h"
static void BinaryArb();
int _tmain(int argc, _TCHAR* argv[])
{
BinaryArb();
char buffer[100];
printf("Press [Enter] to exit\n");
scanf("%c", buffer);
return 0;
}
static void BinaryArb()
{
const char noErrString[] = "+0,\"No error\"\n";
const int NUM_DATA_POINTS = 100000;
float z[NUM_DATA_POINTS];
char tBuffer[100];
tBuffer[0] = '\0';
ViRsrc instAddress = "TCPIP0::156.140.113.206::inst0::INSTR";
ViSession rm = 0,
vi = 0;
//Open session for instrument.
viOpenDefaultRM(&rm);
viOpen(rm, instAddress, 0, 0, &vi);
viSetAttribute(vi, VI_ATTR_TMO_VALUE, 10000);
//Query Identity string and report.
viPrintf(vi, "*IDN?\n");
viScanf(vi, "%t", tBuffer);
printf("Instrument Identity String: %s\n", tBuffer);
//Clear and reset instrument
viPrintf(vi, "*CLS;*RST\n");
viPrintf(vi, "*OPC?\n");
viScanf(vi, "%t", tBuffer);
//Clear volatile memory
viPrintf(vi, "SOURce1:DATA:VOLatile:CLEar\n");
//Create simple ramp waveform
for (int i = 0; i < NUM_DATA_POINTS; i++)
z[i] = (i-1)/(float)NUM_DATA_POINTS;
// swap the endian format
viPrintf(vi, "FORM:BORD NORM\n");
//Downloading
printf("Downloading Waveform...\n");
viPrintf(vi, "SOURce1:DATA:ARBitrary testarb, %*zb\n", NUM_DATA_POINTS, z);
// wait for the operation to complete before moving on
viPrintf(vi, "*WAI\n");
printf("Download Complete\n");
//Set desired configuration
viPrintf(vi, "SOURce1:FUNCtion:ARBitrary testarb\n"); // set current arb waveform to defined arb pulse
viPrintf(vi, "SOURce1:FUNCtion ARB\n"); // turn on arb function
viPrintf(vi, "SOURCE1:FUNCtion:ARB:SRATe 400000\n"); // set sample rate
viPrintf(vi, "SOURCE1:VOLT 2\n"); // set max waveform amplitude to 2 Vpp
viPrintf(vi, "SOURCE1:VOLT:OFFSET 0\n"); // set offset to 0 V
viPrintf(vi, "OUTPUT1:LOAD 50\n"); // set output load to 50 ohms
//Enable Output
viPrintf(vi, "OUTPUT1 ON\n"); // turn on channel 1 output
//Read Error/s
viPrintf(vi, "SYSTEM:ERROR?\n");
viScanf(vi, "%t", tBuffer);
if (strcmp(tBuffer, noErrString) == 0)
{
printf("Output set without any error\n");
}
else
{
printf("Error reported: %s\n", tBuffer);
}
//OPTIONAL: Save Arb to USB stick, and/or internal memory titled TEST ARB.barb
//viPrintf(vi, "MMEM:STOR:DATA \"USB:\TEST ARB.barb\"\n");
//viPrintf(vi, "MMEM:STOR:DATA \"INT:\TEST ARB.barb\"\n");
return;
}