-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgetscopedat.m
132 lines (110 loc) · 5.03 KB
/
getscopedat.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
function [data, t] = getscopedat(GPIB, Channel)
%--------------------------------------------------------------------------
% MATLAB Driver for Inif(i)ium Scopes
% Last Update: 2.21.11
% Christopher Tilley, Philip Mease
%--------------------------------------------------------------------------
%
% This function will access the oscilloscope that is located at GPIB
% address 'GPIB(1,1)' and board index 'GPIB(1,2)' and plot the current wave
% form being displayed on channel 'Channel'. The vector of amplitudes will
% be saved to the variable 'data', and the time vector will be saved to
% 't'.
%
% GPIB can be sent in two forms. If 'GPIB' is a single value variable then
% the function will interpuret 'GPIB' as the GPIB address of the scope and
% use the default board index of 8. If the user wishes to designate the
% board index for the GPIB board in the computer they are using then 'GPIB'
% must be saved as a 1x2 vector, where 'GPIB(1,1)' is the GPIB address of
% the instrument and 'GPIB(1,2)' is the board index of the GPIB adapter in
% the computer. This board index can be found by opening the Agilent
% Control Panel in Windows.
%
% The following are the acceptable syntax for this function:
%
%
% [data, t] = getscopedat(GPIB)
%
% This syntax uses the default channel 1 of the scope at GPIB
% address 'GPIB(1,1)' and board index 'GPIB(1,2)'
% eg (bi = 8, gpibaddY = 7): [d t] = getscopedat([7 8])
%
%
% [data, t] = getscopedat(GPIB, Channel)
%
% This syntax uses the channel 'Channel' of the scope at GPIB
% address 'GPIB(1,1)' and board index 'GPIB(1,2)'.
%--------------------------------------------------------------------------
%Determine number of inputs provided by user
if nargin > 2, error('Invalid Number of Arguments for viewscope(). Please type help getscopedat for for proper syntax!'); end
if nargin < 2, Channel = 1; end
if nargin < 1, error('Invalid Number of Arguments for viewscope(). Must enter the GPIB Address of the Scope!'); end
%Create a variable name for the scope object
if (length(GPIB) > 1)
board = num2str(GPIB(1,2));
name = ['obj', num2str(GPIB(1,1))];
obj_name = genvarname(name);
else
board = '8';
name = ['obj', num2str(GPIB)];
obj_name = genvarname(name);
end
% Create a GPIB object:
eval([obj_name, ' = instrfind(','''Type''', ',', '''gpib''', ',', '''BoardIndex''', ',', '''', board, '''', ',', '''PrimaryAddress''', ',', num2str(GPIB(1,1)), ',', '''Tag''', ',', '''''', ');'])
% Create the GPIB object if it does not exist
% otherwise use the object that was found.
if isempty(eval(obj_name))
eval([obj_name, ' = gpib(', '''AGILENT''', ', ', board, ', ', num2str(GPIB(1,1)), ');']);
else
fclose(eval(obj_name));
eval([obj_name, ' = ', obj_name, '(1)'])
end
%Set the Input Buffer size:
% NOTE: this is arbitrary until we check. But you cannot set this
% while the object is open... can only be set with objs closed.
ibs = 2100100;
set(eval(obj_name), 'InputBufferSize', ibs);
% POINts sets req memory depth
% WAVeform:POINts?
% WAVeform:PREamble? query for
% :ACQuire:POINts? returns val of mem depth ctrl
% :ACQuire:SRATe? returns current acquisition sa rate
%Open Scope
fopen(eval(obj_name));
% Check memory:
memdepth = str2double(query(eval(obj_name),':ACQuire:POINts?'));
str = ['You are acquiring ', num2str(memdepth), ' points.']
if (memdepth >= ibs)
disp('READ MEMORY BUFFER TOO SMALL, WAIT WHILE WE INCREASE IT');
ibs = memdepth + 1; % update ibs to fit aquired data
open = instrfind('Status', 'open');
fclose(open);
set(eval(obj_name), 'InputBufferSize', ibs);
fopen(eval(obj_name)); % Reopen the object now buffer is set correctly
end
%Set the Source of the Scope
%fprintf(eval(obj_name), ':ACQ:SRAT 500 E+4');
cha = [':WAVEFORM:SOURCE CHAN', num2str(Channel)];
fprintf(eval(obj_name), cha);
%Acquire X origin and X increment values
xorg = str2double(query(eval(obj_name),':WAVEFORM:XOR?'));
xinc = str2double(query(eval(obj_name),':WAVEFORM:XINC?'));
%Acquire Y origin and Y increment Values
yorg = str2double(query(eval(obj_name),':WAVEFORM:YOR?'));
yinc = str2double(query(eval(obj_name),':WAVEFORM:YINC?'));
yref = str2double(query(eval(obj_name),':WAVEFORM:YREF?'));
%Setup the Scope for proper output format
fprintf(eval(obj_name), 'WAVEFORM:FORMAT BYTE');
fprintf(eval(obj_name), 'ACQUIRE:TYPE NORM');
%Instruct the scope to make current data available to acquire
fprintf(eval(obj_name), 'WAVEFORM:DATA?');
data1 = binblockread(eval(obj_name), 'uint8');
%Create a time variable with the same lenght as "data"
t1 = 0:(length(data1)-1);
%Adjust data and time variables with x/y increments/origins
t = t1 * xinc + xorg;
data = (data1-yref) * yinc + yorg;
plot(t,data);
open = instrfind('Status', 'open');
fclose(open);
end