-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathA8153_control.m
330 lines (292 loc) · 11.1 KB
/
A8153_control.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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
classdef A8153_control < handle
properties
c_gpib
dev_id
end
properties(SetAccess = private)
close_port % open and close connection for each command
end
methods
function obj = A8153_control(resourceName, varargin)
obj.c_gpib = visadev(resourceName);
obj.close_port = false;
while ~isempty(varargin)
switch lower(varargin{1})
case 'close_port'
obj.close_port = varargin{2};
otherwise
error('unknown paraiter')
end
varargin(1:2) = [];
end
% if ~obj.isopen()
% fopen(obj.c_gpib);
% else
% disp('Port was open already!!!');
% end
dev_id = writeread(obj.c_gpib,'*IDN?')
% int_result = fscanf(obj.c_gpib);
% disp(int_result);
% obj.CloseIfNeed();
end
function inform = IDN(obj)
% *IDN? Identication Query
obj.OpenIfNeed();
obj.Fprintf('*IDN?');
inform = obj.Fscanf();
% fprintf(obj.c_gpib,'*IDN?');
% inform = fscanf(obj.c_gpib);
obj.CloseIfNeed();
end
function inform = Propinfo(obj)
inform = propinfo(obj.c_gpib);
end
function satus = Fprintf(obj, varargin)
%Fprintf - send command to device, return result
if isempry(varargin)
error('you need write 1 or more comands')
end
while ~isempty(varargin)
satus = write(obj.c_gpib, varargin{1});
varargin{1} = [];
end
end
function inform = Fscanf(obj)
%Fscanf - return data from bufer of device
inform = read(obj.c_gpib);
end
function info = Fopen(obj)
%Fopen - connect to device
obj.OpenIfNeed();
info = obj.c_gpib.Status;
end
function info = Fclose(obj)
%Fclose - cancel connection to device
fclose(obj.c_gpib);
info = obj.c_gpib.Status;
end
function info = Status(obj)
%Status - return status of connection
info = obj.c_gpib.Status;
end
function inform = EventStatus(obj)
% *ESE? Standard Event Status Enable Query
obj.OpenIfNeed();
inform = writeread(obj.c_gpib,'*ESE?');
% inform = fscanf(obj.c_gpib);
obj.CloseIfNeed();
end
function inform = StandardEventStatus(obj)
% *ESR? Standard Event Status Register Query
obj.OpenIfNeed();
inform = writeread(obj.c_gpib,'*ESR?');
% inform = fscanf(obj.c_gpib);
obj.CloseIfNeed();
end
function inform = OperationCompleteStatus(obj)
% *OPC? Operation Complete Query
obj.OpenIfNeed();
inform = writeread(obj.c_gpib,'*OPC?');
% inform = fscanf(obj.c_gpib);
obj.CloseIfNeed();
end
function inform = ServiceRequestEnableStatud(obj)
% *SRE? Service Request Enable Query
obj.OpenIfNeed();
inform = writeread(obj.c_gpib,'*SRE?');
% inform = fscanf(obj.c_gpib);
obj.CloseIfNeed();
end
function inform = ReadStatusByte(obj)
% *STB? Read Status Byte Query
obj.OpenIfNeed();
inform = writeread(obj.c_gpib,'*STB?');
% inform = fscanf(obj.c_gpib);
obj.CloseIfNeed();
end
function inform = SelfTest(obj)
% *TST? Self Test Query
obj.OpenIfNeed();
inform = writeread(obj.c_gpib,'*TST?');
% inform = fscanf(obj.c_gpib);
obj.CloseIfNeed();
end
function [] = ClearStatus(obj)
% *CLS Clear Status Command
% The *CLS command clears all the event registers
% summarized in the Status Byte register. With the
% exception of the output queue, all queues that are
% summarized in the Status Byte register are emptied. The
% error queue is also emptied. Neither the Standard Event
% Status Enable register, nor the Service Request Enable
% register are affected by this command.
% After the *CLS command the instrument is left in the idle
% state. The command does not alter the instrument setting.
% *OPC/*OPC? actions are canceled.
obj.OpenIfNeed();
write(obj.c_gpib,'*CLS');
obj.CloseIfNeed();
end
function [] = StdEventStatusEnable(obj, value)
% *ESE Standard Event Status Enable Command
% Syntax *ESE <wsp> <value>
% 0 <= value <= 255
% Definition The *ESE command sets bits in the Standard Event Status
% Enable register and thus enables the corresponding bits
% in the Standard Event Status register. A 1 in a bit in the
% enable register enables the same bit in the status register. The value sent as an integer or a
% oating point number
% (NRf).
% The register is cleared at power-on. The *RST and *CLS
% commands do not change the register.
obj.OpenIfNeed();
write(obj.c_gpib,['*ESE' num2str(value)]);
obj.CloseIfNeed();
end
function [] = OperationComplete(obj)
% *OPC Operation Complete Command
% The *OPC command parses all program message units in
% the input queue and sets the operation complete bit in the
% Standard Event Status register, when the contents of the
% input queue have been processed.
obj.OpenIfNeed();
write(obj.c_gpib,'*OPC');
obj.CloseIfNeed();
end
function [] = Reset(obj)
% *RST Reset Command
obj.OpenIfNeed();
write(obj.c_gpib,'*RST');
obj.CloseIfNeed();
end
function [] = ServiceRequestEnable(obj, value)
% *SRE Service Request Enable Command
% Syntax *SRE <wsp> <value>
% 0 <= value <= 255
% Definition The *SRE command sets bits in the Service Request
% Enable register. A 1 in a bit in the enable register enables
% the corresponding bit in the status register. The value sent
% as an integer or a
% oating point number (NRf).
% The register is cleared at power-on. The *RST and *CLS
% commands do not change the register.
obj.OpenIfNeed();
write(obj.c_gpib,['*SRE' num2str(value)]);
obj.CloseIfNeed();
end
function [] = Trigger(obj)
% *TRG Trigger Command
obj.OpenIfNeed();
write(obj.c_gpib,'*TRG');
obj.CloseIfNeed();
end
function [] = Wait(obj)
% *WAI Wait Command
obj.OpenIfNeed();
write(obj.c_gpib,'*TRG');
obj.CloseIfNeed();
end
function [] = Abort(obj)
% *WAI Wait Command
obj.OpenIfNeed();
write(obj.c_gpib,'*ABOR');
obj.CloseIfNeed();
end
function inform = GetCurrentPower(obj)
% *TST? Self Test Query
% obj.OpenIfNeed();
inform = writeread(obj.c_gpib,'read1:pow?');
% inform = (str2double(fscanf(obj.c_gpib)));
% obj.CloseIfNeed();
end
function [] = SetSenseParamiters(obj, varargin)
% Sense commands include most of the functions for setting up
% and using the sensor modules.
comands_list = {};
while ~isempty(varargin)
switch lower(varargin{1})
case 'atime'
comands_list{end+1} =...
['SENS1:POW:ATIME ' num2str(varargin{2}) 'MS'];
case 'autorange'
comands_list{end+1} =...
['SENS:POW:RANG:AUTO ' num2str(varargin{2})];
case 'unit'
comands_list{end+1} =...
['SENS:POW:UNIT ' (varargin{2})];
case 'wavelength'
comands_list{end+1} =...
['SENS:POW:WAVE ' num2str(varargin{2})];
otherwise
error('unknown paramiter')
end
varargin(1:2) = [];
end
obj.OpenIfNeed();
while ~isempty(comands_list)
write(obj.c_gpib,comands_list{1});
comands_list(1) = [];
end
obj.CloseIfNeed();
end
function [inform] = GetSenseParamiters(obj, varargin)
% Sense commands include most of the functions for setting up
% and using the sensor modules.
comands_list = {};
while ~isempty(varargin)
switch lower(varargin{1})
case 'atime' % average
comands_list{end+1} =...
'SENS1:POW:ATIME?';
case 'autorange'
comands_list{end+1} =...
'SENS:POW:RANG:AUTO?';
case 'unit'
comands_list{end+1} =...
'SENS:POW:UNIT?';
case 'wavelength'
comands_list{end+1} =...
'SENS:POW:WAVE?';
otherwise
error('unknown paramiter')
end
varargin(1) = [];
end
obj.OpenIfNeed();
while ~isempty(comands_list)
inform = writeread(obj.c_gpib,comands_list{1});
comands_list(1) = [];
% inform = fscanf(obj.c_gpib);
end
obj.CloseIfNeed();
end
function inform = GetCurrentError(obj)
% get number of current error
obj.OpenIfNeed();
inform = writeread(obj.c_gpib,'syst:err?');
% inform = fscanf(obj.c_gpib);
obj.CloseIfNeed();
end
function state = isopen(obj)
% return true if port is open and false of closed
if string(obj.c_gpib.Status) == "open"
state = true;
elseif string(obj.c_gpib.Status) == "closed"
state = false;
end
end
function OpenIfNeed(obj)
%OpenIfNeed - check tatus of connection and open if it was not oppened
% before
if ~obj.isopen()
obj.Fopen()
end
end
function CloseIfNeed(obj)
%CloseIfNeed - close connection if it need to be closed
if obj.close_port
obj.Fclose();
end
end
end %methods
end