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