Write data back to VNA(8753) using MATLAB

Question asked by deejay on Jul 3, 2013
i manage to read data from the VNA, however i can not write complex data back to it.
here is the code i use

% Create a GPIB object.

% Find a GPIB object.
obj1 = instrfind('Type', 'gpib', 'BoardIndex', 7, 'PrimaryAddress', 16, 'Tag', '');

% Create the GPIB object if it does not exist

if isempty(obj1)
obj1 = gpib('AGILENT', 7, 16);
else % otherwise use the object that was found.
fclose(obj1);
obj1 = obj1(1);
end

%max out buffer size for largest possible read points
set(obj1,'InputBufferSize', 80050);
set(obj1,'OutputBufferSize', 90000);

% Connect to instrument object, obj1.
fopen(obj1);

%% Communicating with instrument object, obj1.
data1 = query(obj1, 'OUTPIDEN');
fprintf(1, 'Connected to: %s\n', data1);

points_str = query(obj1, 'POIN?');
points = str2num(points_str);

fwrite(obj1, 'FORM4; OPC?; SING');
opc_comp = fscanf(obj1);

%% Read data back from analyzer
fwrite(obj1, 'OUTPDATA');
data1 = scanstr(obj1);

%Allocate space for data array
data = zeros(points,2);

%Convert output cell array into a standard two dimensional array
for i=1:1:points
data(i,1) = data1{(2*i)-1};
data(i,2) = data1{2*i};
end

%% Calculate Amplitude and Plot

%Allocate space for magnitude array
mag = zeros(points,1);

%Calculate Magnitude
for i = 1:1:points
mag(i,:)=20*log10(sqrt(data(i,1)^2 + data(i,2)^2));
end

plot(mag);
hold on;

%% Prepare Data and Write back to Analyzer

%-----------Standard Parameters------------------------
%R2 = Opend
%R3 = Short

%-----------Measured Parameters for the reflection coefficient--------------------------

Rm1 = 0.0500 + 0.7400j;
Rm2 = -0.5745 + 1.4454j;
Rm3 = 0.4410 + 0.8231j;

%-----------3*3 matrix------------------------------------
Z = Rm1; Rm2; Rm3;
Y = 1 0 -R1*Rm1; 1 1 -R2*Rm2; 1 -1 -R3*Rm3;
A = inv(Y);
X = A*Z;
%-----------Output values-------------------------------
D = X(1);
B = X(2);
M = X(3);
T = B-D*M;
DMT = X(1);X(3);T;

%Put sweep in HOLD mode
fwrite(obj1,'HOLD');

%Write new formatted data to analyzer
fwrite(obj1, 'INPUCALC01 ', DMT);

%Allocate space for data array
data2 = zeros(points,2);

fwrite(obj1, 'OUTPCALC01');
tmpdata = scanstr(obj1);

%Convert output cell array into a standard two dimensional array
for i=1:1:points
data2(i,1)=tmpdata{(2*i)-1};
data2(i,2)=tmpdata{2*i};
end

mag2 = zeros(points,1);

%% Calculate Amplitude and Plot
for i = 1:1:points
mag2(i,:) = 20*log10(sqrt(data2(i,1)^2 + data2(i,2)^2));%Calculate Magnitude
end

Moreover the 2nd raw of data2 values are 0 or it should have 2 row of values (real/imag)

any help will be a life saver. Thanks in advance

Edited by: DeeJay on Jul 3, 2013 4:21 AM