AnsweredAssumed Answered

Matlab importing .bin files then sending to a 33522A

Question asked by lhornburg Employee on Apr 13, 2012
Here is a little program I wrote which opens a .bin file, converts it, and sends it to a 33522A:

% clears all variables, closes all open files

clear all; close all; clc;

%opens and creates a visa session for communication with function generator

fgen = visa('AGILENT','TCPIP0::');
fgen.Timeout = 10;
set (fgen,'OutputBufferSize',2000000000);


%Query Idendity string and report
fprintf (fgen, '*IDN?');
idn = fscanf (fgen);
fprintf (idn)
fprintf ('\n\n')

%Clear and reset instrument
fprintf (fgen, '*RST');
fprintf (fgen, '*CLS');

%Clear volatile memory
fprintf(fgen, 'SOURce1:DATA:VOLatile:CLEar');
fprintf(fgen, 'FORM:BORD SWAP');  %configure the box to correctly accept the binary arb points

bindata = fopen('examplewave.bin');
A = fread(bindata);

binblockwrite(fgen, A, 'float32', 'SOURce1:DATA:ARBitrary:DAC TestArb, ');

fprintf(fgen, '*WAI');   %Make sure no other commands are exectued until arb is done downloading
fprintf('Download Complete\n\n')

%Set desired configuration for channel 1
fprintf(fgen,'SOURce1:FUNCtion:ARBitrary TestArb'); % set current arb waveform to defined arb testrise
fprintf(fgen,'SOURCE1:VOLT 2'); % set max waveform amplitude to 2 Vpp
fprintf(fgen,'SOURCE1:VOLT:OFFSET 0'); % set offset to 0 V
fprintf(fgen,'OUTPUT1:LOAD 50'); % set output load to 50 ohms
fprintf(fgen,'SOURCE1:FUNCtion:ARB:SRATe 80000000'); % set sample rate
fprintf(fgen,'SOURce1:FUNCtion ARB'); % turn on arb function

%Enable Output for channel 1
fprintf(fgen,'OUTPUT1 ON');

% Read Error
fprintf(fgen, 'SYST:ERR?');
errorstr = fscanf (fgen);

% error checking
if strncmp (errorstr, '+0,"No error"',13)
   errorcheck = 'Arbitrary waveform generated without any error';
   fprintf (errorcheck)
   errorcheck = ['Error reported: ', errorstr];
   fprintf (errorcheck)

%Save Arb to USB stick, titled test arb if you want, commented it out for

%fprintf(fgen, 'MMEM:STOR:DATA "USB:\bintoarb.arb"');

%closes the visa session with the function generator
fclose all;