Contact an Expert

Thread: Agilent 33500A/33500B function gen ASCII ARB example program


Permlink Replies: 2 - Pages: 1 - Last Post: Aug 30, 2012 3:56 PM Last Post By: lhornburg
lhornburg

Posts: 477
Registered: 01/15/10
Agilent 33500A/33500B function gen ASCII ARB example program
Posted: Aug 30, 2012 3:53 PM
Click to report abuse...   Click to reply to this thread Reply
Attachment AsciiArb_vb.zip (3.7 KB)
VB:

'****************************************************************************
' Copyright © 2010 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.
'****************************************************************************

'****************************************************************************
'This sample program is intended to use with Microsoft Visual studio 6.0
'and Agilent Visa Object library.
'
'Sample program execution requires VISA library installation as pre requisites.
'
'Add below libraries in project reference in Project\reference menu prior to execution of sample 'program:
'VISA COM 3.0 Type Library, Location: <visa install location>\VisaCom\GlobMgr.dll
'VISA COM 488.2 Formatted I/O 1.0, Location: <visa install location>\VisaCom\BasFrmIO.dll
'VISA COM Resource Manager 1.0, Location: <Agilent IO Library install>\bin\AgtRM.dll
' ****************************************************************************

' """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
'AsciiArb is a sample program that demonstrates how to download an arbitrary waveform
'into instrument volatile memory and play back the same with the configuration below:
'This arb generates a 4000 point pulse waveform, of which the first 200 points define a
'positive pulse from 0 volts to the maximum defined voltage amplitude.
'
'Wave Shape: Arb
'Frequency: 40 KSa/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.
' """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""

Private Sub Command1_Click()

Dim io_mgr As VisaComLib.ResourceManager
Dim mFio As VisaComLib.FormattedIO488

Set io_mgr = New AgilentRMLib.SRMCls
Set mFio = New FormattedIO488
Set mFio.IO = io_mgr.Open(Text1.Text, NO_LOCK, 2000, "")

Dim Waveform() As String
Dim I As Integer
Dim DataStr As String
ReDim Waveform(1 To 4000)

On Error GoTo MyError

'Compute waveform

Text2.Text = ""
Text2.Text = Text2.Text & "Computing Waveform..." & vbCrLf

For I = 1 To 5
Waveform(I) = Str$((I - 1) / 5) ' Set rise time (5 points)
Next I

For I = 6 To 205
Waveform(I) = "1" ' Set pulse width (200 points)
Next I

For I = 206 To 210
Waveform(I) = Str$((210 - I) / 5) ' Set fall time (5 points)
Next I

For I = 211 To 4000
Waveform(I) = "0" ' Set remaining points to zero
Next I

DataStr = Join(Waveform, ",") ' Create string from data array


With mFio

'Clear and reset instrument & increase timeout of Visa Connection to 40 Seconds for downloading long waveform
.WriteString "*CLS"
.WriteString "*RST"
.IO.Timeout = 40000

Sleep 1000

Call WaitForOPC(mFio)

'
' * Clearing Volatile memory.
' * Cautions: All un-saved data present in volatile memory will be erased.
' * Save information before proceeding to this example program.
'

.WriteString "DATA:VOLatile:CLEar"

End With

'Downloading Waveform.
Text2.SelStart = Len(Text2.Text)
Text2.SelText = "Downloading Waveform..." & vbCrLf

With mFio
.WriteString "SOURce1:DATA:ARBitrary TestArb," & DataStr
End With

Call WaitForOPC(mFio)

Text2.Text = Text2.Text & "Download Complete" & vbCrLf

With mFio

'Send Command to set the desired configuration
.WriteString "SOURce1:FUNCtion:ARBitrary TestArb" ' set current arb waveform to defined arb pulse
.WriteString "SOURce1:FUNCtion ARB" ' turn on arb function
.WriteString "SOURCE1:VOLT 2" ' set max waveform amplitude to 2 Vpp
.WriteString "SOURCE1:VOLT:OFFSET 0" ' set offset to 0 V
.WriteString "OUTPUT1:LOAD 50" ' set output load to 50 ohms
.WriteString "SOURCE1:FUNCtion:ARB:SRATe 40000" ' set sample rate


'Enable output.
.WriteString "OUTPUT1 ON" 'turn on channel 1 output

Sleep 1000

End With

Text2.Text = Text2.Text & "Arb Wave output set on Channel1" & vbCrLf

Exit Sub

MyError:

Text2 = Err.Description
Resume Next

End Sub

Private Sub Form_Load()

Text2.Text = ""

End Sub

Private Function WaitForOPC(mFio As VisaComLib.FormattedIO488)

Do
Dim strResult As String

With mFio
.WriteString "*OPC?"
strResult = .ReadString()
End With

If (InStr(strResult, "1") > 0) Then
Exit Do
End If

Loop

End Function

lhornburg

Posts: 477
Registered: 01/15/10
Re: Agilent 33500A/33500B function gen ASCII ARB example program
Posted: Aug 30, 2012 3:55 PM   in response to: lhornburg in response to: lhornburg
Click to report abuse...   Click to reply to this thread Reply
Attachment AsciiArb_C.zip (4.2 KB)
C:

/****************************************************************************
' Copyright © 2010 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.
****************************************************************************/

/****************************************************************************
'This sample program is intended to use with Microsoft Visual C++ 2005
'and Agilent Visa Object library.
'
'Sample program execution requires VISA library installation as prerequisite.
'
'Header file <visa.h> used as reference in the project should be available
'at VISA install location. User must point to the file, if not detected
'automatically. Add above header file containing directory as additional
'dependencies for C/C++ project compilation.
'
'Add visa32.lib library reference as additional dependencies for linker
'in this project. This library can be located at <VISA Install location>\WinNT\lib\msc
'
****************************************************************************/

/* AsciiArb is a sample program that demonstrates how to download an arbitrary waveform
into instrument volatile memory and play back the same with the configuration below:
This arb generates a 4000 point pulse waveform, of which the first 200 points define a
positive pulse from 0 volts to the maximum defined voltage amplitude.

Wave Shape: Arb
Frequency: 40 KSa/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.
*/

#include <visa.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <time.h>

void main()
{
ViSession oRm, oMIO;
char strResult256 = {0};
char noErrString256 = {"+0,\"No error\"\n"};
char buf256;
char data10000;
int i;

//Mention Visa connection string here.
char instAdd[] = "TCPIP0::146.223.123.106::inst0::INSTR";

//Open a resource manager and create a visa session for communication
viOpenDefaultRM(&oRm);
viOpen(oRm,instAdd,VI_NULL,VI_NULL,&oMIO);

//Query Idendity string and report.
viPrintf(oMIO,"*IDN?\n");
viScanf(oMIO,"%t",&buf);

printf("Instrument Identity String: %s \n", buf);

//Clear and reset instrument
viPrintf(oMIO,"*CLS\n");
viPrintf(oMIO,"*RST\n");
wait(1000);

//Clear volatile memory
viPrintf(oMIO,"DATA:VOLatile:CLEar\n");

// Create arb waveform named "TestArb" with 4000 points of 0-1 data
printf("Generating Waveform\n\n");
strcpy(data, "SOURce1:DATA:ARBitrary TestArb");
for(i = 1; i <= 5; i++) /* Set rise time (5 points) */
sprintf(data, "%s,%3.1f", data, (double)(i - 1)/5);

for(i = 6; i <= 205; i++)
strcat(data, ",1"); /* Set pulse width (200 points) */

for(i = 206; i <= 210; i++) /* Set fall time (5 points) */
sprintf(data, "%s,%3.1f", data, (double)(210 - i)/5);

for(i = 211; i <= 4000; i++)
strcat(data, ",0"); /* Set remaining points to zero */

strcat(data,"\n");

//Send Command to set the desired configuration
printf("Downloading Waveform...\n\n");
viPrintf(oMIO,data);
WaitOperComplete(oMIO);
printf("Download Complete\n\n");

//Set desired configuration.
viPrintf(oMIO,"SOURce1:FUNCtion:ARBitrary TestArb\n"); // set current arb waveform to defined arb pulse
viPrintf(oMIO,"SOURce1:FUNCtion ARB\n"); // turn on arb function
viPrintf(oMIO,"SOURCE1:VOLT 2\n"); // set max waveform amplitude to 2 Vpp
viPrintf(oMIO,"SOURCE1:VOLT:OFFSET 0\n"); // set offset to 0 V
viPrintf(oMIO,"OUTPUT1:LOAD 50\n"); // set output load to 50 ohms
viPrintf(oMIO,"SOURCE1:FUNCtion:ARB:SRATe 40000\n"); // set sample rate


//Enable Output
viPrintf(oMIO,"OUTPUT1 ON\n"); // turn on channel 1 output

//Verify error output.
viQueryf(oMIO,"SYST:ERR?\n","%t",&strResult);

if(!(strcmp(strResult,noErrString)))
{
printf("Arbitrary wave generated without any error\n");
}
else
{
printf("Error reported: %s",strResult);
}

//Exit
printf("\nPress Enter to exit");
getchar();

viClose(oRm);
viClose(oMIO);

}
wait(clock_t wait)
{
clock_t goal;
goal = wait + clock();
while( goal > clock() )
;
}
WaitOperComplete(ViSession oIo)
{
char strResult128 = "";
while(1)
{
viQueryf(oIo,"*OPC?\n","%t",&strResult);
if(strResult)
break;
}
}

lhornburg

Posts: 477
Registered: 01/15/10
Re: Agilent 33500A/33500B function gen ASCII ARB example program
Posted: Aug 30, 2012 3:56 PM   in response to: lhornburg in response to: lhornburg
Click to report abuse...   Click to reply to this thread Reply
C#:

/****************************************************************************
' Copyright © 2010 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.
'****************************************************************************

'****************************************************************************
'This sample program is intended to use with Microsoft Visual C# 2005
'and Agilent Visa Object library.
'
'Sample program execution requires VISA library installation as prrequisite.
'
'Sample program uses VISA COM 3.0 Type Library as reference to VISA library at below location:
'<visa install location>\VisaCom\Primary Interop Assemblies\Ivi.Visa.Interop.dll
'User must point to the file, if not detected automatically.
' ****************************************************************************/

using System;
using System.Collections.Generic;
using System.Text;
//Add visa library reference.
using Ivi.Visa.Interop;

/* AsciiArb is a sample program that demonstrates how to download an arbitrary waveform
* into instrument volatile memory and play back the same with the configuration below:
* This arb generates a 4000 point pulse waveform, of which the first 200 points define a
* positive pulse from 0 volts to the maximum defined voltage amplitude.

Wave Shape: Arb
Frequency: 400 KSa/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.

*/

namespace AsciiArb
{
class Program
{
const string noErrString = "+0,\"No error\"\n";

static void Main(string[] args)
{
try
{
AsciiArb();
}
catch (Exception oExp)
{
Console.WriteLine(oExp.Message);
}

Console.WriteLine("Press Enter to exit");
Console.ReadLine();

}
public static void AsciiArb()
{
string strDataCommand = string.Empty;
string instAddress = "TCPIP0::156.140.95.225::inst0::INSTR";
ResourceManagerClass oRm = new ResourceManagerClass();
FormattedIO488Class oFio = new FormattedIO488Class();

//Open session for instrument.
oFio.IO = (IMessage)oRm.Open(instAddress, AccessMode.NO_LOCK, 2000, "");

//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", true);
waitForOPC(oFio);

//Clear volatile memory
oFio.WriteString("DATA:VOLatile:CLEar", true);

// Create arb waveform named "TestArb" with 4000 points of 0-1 data
strDataCommand = "SOURce1:DATA:ARBitrary TestArb";
//Generating waveforms
for (double i = 1; i <= 5; i++) /* Set rise time (5 points) */
strDataCommand = strDataCommand + "," + ((i - 1) / 5).ToString();
for (double i = 6; i <= 205; i++) /* Set pulse width (200 points) */
strDataCommand = strDataCommand + ",1";
for (double i = 206; i <= 210; i++) /* Set fall time (5 points) */
strDataCommand = strDataCommand + "," + ((210 - i) / 5).ToString();
for (double i = 211; i <= 4000; i++)
strDataCommand = strDataCommand + ",0"; /* Set remaining points to zero */

//Downloading waveform
Console.WriteLine("Downloading Waveform...");

oFio.WriteString(strDataCommand, true);
waitForOPC(oFio);

Console.WriteLine("Download Complete\n");

//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: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
oFio.WriteString("SOURCE1:FUNCtion:ARB:SRATe 40000", true); // set sample rate


//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);
}

}
public static void waitForOPC(FormattedIO488Class oFio)
{
while(true)
{
string strResult = string.Empty;
oFio.WriteString("*OPC?",true);
strResult = oFio.ReadString();
if (strResult == "1\n")
break;
}
}
}
}


Point your RSS reader here for a feed of the latest messages in all forums