-
Notifications
You must be signed in to change notification settings - Fork 2
/
classKeithley2450.m
2236 lines (1942 loc) · 92.5 KB
/
classKeithley2450.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
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
classdef classKeithley2450 < handle
% create Keithley2450 object
% This function creates a device object for a Keithley 2450 (TSP).
% INPUT:
% connectionType: string containing type of connection (serial or gpib)
% port: cell array of available serial ports (strings, i.e., 'COM[0-255]', '/dev/ttyS[0-255]')
%
% OUTPUT:
% deviceObject: handle to device object
%
% METHODS:
% deviceObject = classKeithley2400
% reset
% connect
% disconnect
% refresh
% connectionHandle = getConnection
% setConnectionType
% type = getConnectionType
% setPort
% [port,portSet] = getPort
% [connectionStatus, ID] = getConnectionStatus
% err = setOutputState
% outputState = getOutputState
% err = abort
% err = abortAll
% err = goIdle
% err = setPointV
% err = updatePointV
% dataPointV = measurePointV
% err = setSweepV
% err = updateSweepV
% dataSweepV = measureSweepV
% dataSweepVPP = measureSweepVPP
% dataSweepCycle = measureCycle
% dataSteadyStateMPP = measureSteadyState
% dataSteadyStateJSC = measureSteadyState
% dataSteadyStateVOC = measureSteadyState
% err = setTimeScan
% err = updateTimeScan
% dataTimeScan = measureTimeScan
% dataTimePointV = measureTimePointV
% dataTimeSweepV = measureTimeSweepV
%
% Tested: Matlab 2015b, Win10, NI GPIB-USB-HS+ Controller, Keithley KUSB-488B Controller, Keithley 2400, Keithley2410, Keithley2401
% Author: Eugen Zimmermann, Konstanz, (C) 2016 eugen.zimmermann@uni-konstanz.de
% Last Modified on 2018-03-23
properties (Constant)
Type = 'device';
functionName = 'classKeithley2450';
%# set default settings
defaultID = 'Keithley2450';
minV = 0;
maxV = 1;
intRate = 1;
compLevel = 2;
spacing = 'lin';
end
properties (Access = private)
id
port
portSet
connected
connectionType
connectionHandle
abortMeasurement
abortAllMeasurements
outputState
defaultSettings
end
methods
function device = classKeithley2450(varargin)
%# get name of function
ST = dbstack;
functionNameTemp = ST.name;
input = inputParser;
addParameter(input,'connectionType','gpib',validationFcn('connectionType',functionNameTemp))
addParameter(input,'port','none',validationFcn('generalPort',functionNameTemp));
parse(input,varargin{:});
%# set device id to ''
device.id = '';
%# set device status to "not connected" and "output deactivated"
device.connected = 0;
device.outputState = 0;
%# set abort triggers to clear = 0
device.abortMeasurement = 0;
device.abortAllMeasurements = 0;
%# set port if available
device.connectionType = input.Results.connectionType;
if strcmpi(input.Results.port,'none')
switch device.connectionType
case 'gpib'
device.portSet = 1;
device.port = 24;
otherwise
device.portSet = 0;
device.port = [];
end
else
%# if this line throws an error, than check your port parameter
check_port = validationFcn([device.connectionType,'Port'],functionNameTemp);
check_port(input.Results.port)
device.portSet = 1;
device.port = input.Results.port;
end
end
function reset(device,varargin)
if device.getConnectionStatus()
device.setOutputState(0);
end
device.disconnect();
end
function connectionHandle = getConnection(device)
connectionHandle = device.connectionHandle;
end
function [status,id] = getConnectionStatus(device)
status = device.connected;
id = device.id;
end
function setConnectionType(device,connectionType)
input = inputParser;
addRequired(input,'device')
addRequired(input,'connectionType',validationFcn('connectionType',device.functionName))
parse(input,device,connectionType);
if ~strcmpi(input.Results.connectionType,device.connectionType)
device.connectionType = input.Results.connectionType;
device.portSet = 0;
end
end
function type = getConnectionType(device)
type = device.connectionType;
end
function setPort(device,port)
input = inputParser;
addRequired(input,'device')
addRequired(input,'port',validationFcn([lower(device.connectionType),'Port'],device.functionName))
parse(input,device,port);
device.port = input.Results.port;
device.portSet = 1;
end
function [port,portSet] = getPort(device)
port = device.port;
portSet = device.portSet;
end
function manConnect(device,state)
input = inputParser;
addRequired(input,'device')
addRequired(input,'state',validationFcn('boolean',device.functionName))
parse(input,device,state);
if state
device.connect();
else
device.disconnect();
end
end
function refresh(device)
device.manConnect(0);
device.manConnect(1);
end
function connect(device)
if device.portSet
try
device_temp = device.initialize(device.connectionType, device.port);
%# check if program is connected to correct device
id_temp = ['Keithley',query(device_temp,'print(localnode.model)')];
device.connected = strfind(lower(id_temp),lower(device.defaultID));
if device.connected
%# assign connection handle to device object
device.connectionHandle = device_temp;
device.id = id_temp;
%# Control auto zero (OFF = disabled; ON = enabled; ONCE = force immediate update of auto zero.)
%# Helpful for drifting zero as, i.e., when the device is heating up
device.setAutoZero(1);
%# reset time at startup
device.resetTimer();
%# Enable/disable timestamp reset when exiting idle.
% fprintf(device.connectionHandle,':SYST:TIME:RES:AUTO OFF');
%# Select timestamp format (ABSolute or DELTa).
% fprintf(device.connectionHandle,':TRAC:TST:FORM ABS');
%# Specify buffer control mode (NEVER or NEXT).
% fprintf(device.connectionHandle,':TRAC:FEED:CONT NEVER');
disp(['connected to ',device.defaultID])
else
errordlg(sprintf(getErrorMessage('deviceNotFound'),device.defaultID,device.port,id_temp))
fclose(device_temp);
delete(device_temp);
return
end
catch err
errordlg(err.message)
try
fclose(device_temp);
delete(device_temp);
catch err2
disp(err2.message)
end
device.connected = 0;
device.connectionHandle = [];
return
end
else
helpdlg(['Please define a ',device.connectionType,'-port first.'],'Port not set')
return
end
end
function disconnect(device)
try
if isa(device.connectionHandle,'serial') || isa(device.connectionHandle,'gpib')
fclose(device.connectionHandle);
device.connectionHandle = [];
disp(['disconnected from ',device.defaultID])
end
device.connected = 0;
device.id = '';
catch error
errordlg(error.message)
end
end
function getEventlogMessages(device)
ec = device.getEventlogCount();
for n1=1:ec
disp(device.readEventlog());
end
end
function state = getOutputState(device)
state = device.outputState;
end
function err = setOutputState(device,varargin)
input = inputParser;
addRequired(input,'device')
addOptional(input,'state',0,validationFcn('boolean',device.functionName))
parse(input,device,varargin{:});
%# check if device is connected, otherwise abort
if ~device.connected
err = 1;
errordlg(sprintf(getErrorMessage('deviceNotConnected'),device.defaultID))
return
end
device.clearDevice();
%# deactivate output
err = device.toggleOutput(input.Results.state);
if ~err
device.outputState = input.Results.state;
device.abortMeasurement = 0;
device.abortAllMeasurements = 0;
end
end
%# set trigger in order to abort/skip current measurement
function err = abort(device)
if ~device.connected
err = 1;
errordlg(sprintf(getErrorMessage('deviceNotConnected'),device.defaultID))
return
end
device.abortMeasurement = 1;
device.clearDevice();
err = device.setOutputState(0);
end
function err = abortAll(device)
if ~device.connected
err = 1;
errordlg(sprintf(getErrorMessage('deviceNotConnected'),device.defaultID))
return
end
device.abortAllMeasurements = 1;
device.clearDevice();
err = device.setOutputState(0);
end
function err = goIdle(device)
if ~device.connected
err = 1;
errordlg(sprintf(getErrorMessage('deviceNotConnected'),device.defaultID))
return
end
device.abortMeasurement = 0;
device.abortAllMeasurements = 0;
% device.clearDevice();
end
function playStarWars(device)
if ~device.connected
errordlg(sprintf(getErrorMessage('deviceNotConnected'),device.defaultID))
return
end
device.startStarWars();
end
%# prepare settings for single point measurement
function err = setPointV(device,sourceV,delay,varargin)
input = inputParser;
addRequired(input,'device')
addRequired(input,'sourceV',validationFcn('keithleySetV',device.functionName));
addRequired(input,'delay',validationFcn('keithleyDelay',device.functionName));
addOptional(input,'integrationRate',device.intRate,validationFcn('keithleyIntegrationRate',device.functionName));
addParameter(input,'complianceLevel',device.compLevel,validationFcn('keithleySetV',device.functionName));
addParameter(input,'points',1,validationFcn('keithleyDuration',device.functionName));
parse(input,device,sourceV,delay,varargin{:})
if ~device.connected
err = 1;
errordlg(sprintf(getErrorMessage('deviceNotConnected'),device.defaultID))
return
end
%# set voltage as source
err = device.setSourceMode('V');
if err
errordlg(sprintf(getErrorMessage('keithleySetSourceV'),device.functionName))
return
end
%# set point parameter as source voltage and delay
err = device.updatePointV(input.Results.sourceV,input.Results.delay,'points',input.Results.points);
if err
return
end
%# set sense function (device, mode [I,V,R], int_rate, prot_lvl, range_auto, range)
err = device.setSense('I', 'integrationRate',input.Results.integrationRate,'complianceLevel',input.Results.complianceLevel);
if err
errordlg(sprintf(getErrorMessage('keithleySetSourceV'),device.functionName))
return
end
% fprintf(device.connectionHandle,':FORM:ELEM:SENS VOLT,CURR,TIME'); % Specify data elements (VOLTage, CURRent,RESistance, TIME, and STATus).
if ~device.outputState
%# activate output if not already active
err = device.toggleOutput(1);
if err
return
end
device.outputState = 1;
end
end
function err = updatePointV(device,sourceV,delay,varargin)
input = inputParser;
addRequired(input,'device')
addRequired(input,'sourceV',validationFcn('keithleySetV',device.functionName));
addRequired(input,'delay',validationFcn('keithleyDelay',device.functionName));
addParameter(input,'mode','V',validationFcn('keithleyMode',device.functionName));
addParameter(input,'points',1,validationFcn('keithleyDuration',device.functionName));
parse(input,device,sourceV,delay,varargin{:})
if ~device.connected
err = 1;
errordlg(sprintf(getErrorMessage('deviceNotConnected'),device.defaultID))
return
end
%# set sweep mode to single point
err = device.setSingle(input.Results.mode, input.Results.sourceV,'points',input.Results.points);
if err
return
end
%# set delay between each measurement point
err = device.setDelay('manual', input.Results.delay);
if err
return
end
end
%# measure function single point
function [outputData,err] = measurePointV(device)
input = inputParser;
addRequired(input,'device')
parse(input,device)
%# initialize default values
outputData = struct();
if ~device.connected
err = 1;
errordlg(sprintf(getErrorMessage('deviceNotConnected'),device.defaultID))
return
elseif ~device.outputState
%# activate output if not already active
err = device.toggleOutput(1);
if err
return
end
device.outputState = 1;
end
%# read measured values
device.initTriggerModel()
device.waitComplete()
%# extract double from scanned string
numStr = device.readBuffer();
nums = str2double(strsplit(numStr(1:end-1),','));
%# assign measured values to variables
outputData.voltage=nums(1);
outputData.current=nums(2);
outputData.time = nums(3);
device.getEventlogMessages();
err = 0;
end
function err = setSweepV(device,start,stop,step,delay,varargin)
input = inputParser;
addRequired(input,'device')
addRequired(input,'start',validationFcn('keithleySetV',device.functionName));
addRequired(input,'stop',validationFcn('keithleySetV',device.functionName));
addRequired(input,'step',validationFcn('keithleySetV',device.functionName));
addRequired(input,'delay',validationFcn('keithleyDelay',device.functionName));
addOptional(input,'integrationRate',device.intRate,validationFcn('keithleyIntegrationRate',device.functionName));
addParameter(input,'spacing',device.spacing,validationFcn('keithleySpacing',device.functionName));
parse(input,device,start,stop,step,delay,varargin{:})
if ~device.connected
err = 1;
errordlg(sprintf(getErrorMessage('deviceNotConnected'),device.defaultID))
return
end
%# set voltage as source
err = device.setSourceMode('V');
if err
errordlg(sprintf(getErrorMessage('keithleySetSourceV'),device.functionName))
return
end
err = device.updateSweepV(input.Results.start,input.Results.stop,input.Results.step,input.Results.delay,input.Results.integrationRate,'spacing',input.Results.spacing);
if err
return
end
if ~device.outputState
%# activate output if not already active
err = device.toggleOutput(1);
if err
return
end
device.outputState = 1;
end
end
function err = updateSweepV(device,start,stop,step,delay,varargin)
input = inputParser;
addRequired(input,'device')
addRequired(input,'start',validationFcn('keithleySetV',device.functionName));
addRequired(input,'stop',validationFcn('keithleySetV',device.functionName));
addRequired(input,'step',validationFcn('keithleySetStepV',device.functionName));
addRequired(input,'delay',validationFcn('keithleyDelay',device.functionName));
addOptional(input,'integrationRate',device.intRate,validationFcn('keithleyIntegrationRate',device.functionName));
addParameter(input,'complianceLevel',device.compLevel,validationFcn('keithleySetV',device.functionName));
addParameter(input,'spacing',device.spacing,validationFcn('keithleySpacing',device.functionName));
parse(input,device,start,stop,step,delay,varargin{:})
if ~device.connected
err = 1;
errordlg(sprintf(getErrorMessage('deviceNotConnected'),device.defaultID))
return
end
%# set sweep with given values for start, stop, step, spacing ('LIN', and 'LOG')
err = device.setSweep('V', input.Results.start, input.Results.stop, input.Results.step,'spacing',input.Results.spacing);
if err
return
end
%# set delay between each measurement point
err = device.setDelay('manual', input.Results.delay);
if err
return
end
%# set sense function (device, mode [I,V,R], int_rate, prot_lvl, range_auto, range)
err = device.setSense('I', 'integrationRate',input.Results.integrationRate,'complianceLevel',input.Results.complianceLevel);
if err
return
end
end
%# measure function sweep
function [outputData,err] = measureSweepV(device,varargin)
input = inputParser;
addRequired(input,'device')
addParameter(input,'plotHandle',0,@(x) (isnumeric(x) && x==0) || isgraphics(x,'axes') || (isstruct(x) && isfield(x,'update')));
parse(input,device,varargin{:});
ax = input.Results.plotHandle;
%# initialize default values
outputData = struct();
outputData.voltage = 0;
outputData.current = 0;
outputData.time = 0;
if device.abortMeasurement
err = 88;
return
elseif device.abortAllMeasurements
err = 99;
return
end
if ~device.connected
err = 1;
errordlg(sprintf(getErrorMessage('deviceNotConnected'),device.defaultID))
return
elseif ~device.outputState
%# activate output if not already active
err = device.toggleOutput(1);
if err
return
end
device.outputState = 1;
end
%# preallocate space for results (Keithley stores internally up to 2500 points)
voltage = zeros(2500,1);
current = zeros(2500,1);
time = zeros(2500,1);
%# read measured values
device.initTriggerModel();
n1 = 1;
%# extract measured values from string while measuring and update plot
while ~device.abortMeasurement && ~device.abortAllMeasurements && n1<=2500
try
%# read 3 values á 13 digits + comma
% tmp = fscanf(device.connectionHandle,'%c',42);
tmp = device.readBuffer('startIndex',n1,'endIndex',n1);
splitted = strsplit(tmp,',');
catch eee
disp(eee.message);
break;
end
%# stop reading if end of transmission is reached
if isempty(tmp) || strcmp(splitted{1},'9.910000e+37')
break;
else
nums = str2double(splitted(1:end));
voltage(n1) = nums(1);
current(n1) = nums(2);
time(n1) = nums(3);
end
if isgraphics(ax,'axes')
plot(ax,voltage(1:n1),current(1:n1))
xlabel(ax,'Voltage (V)')
ylabel(ax,'Current (A)')
elseif isstruct(ax) && isfield(ax,'update')
ax.update(voltage(1:n1),current(1:n1),'xlabel','Voltage (V)','ylabel','Current (A)')
end
drawnow
n1 = n1+1;
end
outputData.voltage = voltage(1:max(n1-1,1));
outputData.current = current(1:max(n1-1,1));
outputData.time = time(1:max(n1-1,1));
device.getEventlogMessages();
%# check if scan was aborted by user and adjust status
if device.abortMeasurement
device.setOutputState(0);
device.abortMeasurement = 0;
err = 88;
return
elseif device.abortAllMeasurements
device.setOutputState(0);
device.abortAllMeasurements = 0;
err = 99;
return
else
device.goIdle();
err = 0;
return
end
end
%# generate prepuls
function err = prebias(device,prepulsV,duration,delay)
input = inputParser;
addRequired(input,'device')
addRequired(input,'prepulsV',validationFcn('keithleySetV',device.functionName));
addRequired(input,'duration',validationFcn('keithleyDuration',device.functionName));
addRequired(input,'delay',validationFcn('keithleyDelay',device.functionName));
parse(input,device,prepulsV,duration,delay)
if ~device.connected
err = 1;
errordlg(sprintf(getErrorMessage('deviceNotConnected'),device.defaultID))
return
end
err = device.setPointV(input.Results.prepulsV,input.Results.delay);
if err
return
end
pause(input.Results.duration);
end
%# measureSweepV with single prepuls
function [outputData,err] = measureSweepVPP(device,start,stop,step,delay,varargin)
input = inputParser;
addRequired(input,'device')
addRequired(input,'start',validationFcn('keithleySetV',device.functionName));
addRequired(input,'stop',validationFcn('keithleySetV',device.functionName));
addRequired(input,'step',validationFcn('keithleySetStepV',device.functionName));
addRequired(input,'delay',validationFcn('keithleyDelay',device.functionName));
addOptional(input,'integrationRate',device.intRate,validationFcn('keithleyIntegrationRate',device.functionName));
addParameter(input,'spacing',device.spacing,validationFcn('keithleySpacing',device.functionName));
addParameter(input,'plotHandle',0,@(x) (isnumeric(x) && x==0) || isgraphics(x,'axes') || (isstruct(x) && isfield(x,'update')));
addParameter(input,'prepulsV',0,validationFcn('keithleySetV',device.functionName));
addParameter(input,'prepulsDuration',0,validationFcn('keithleyDelay',device.functionName));
addParameter(input,'prepulsDelay',0,validationFcn('keithleyDelay',device.functionName));
parse(input,device,start,stop,step,delay,varargin{:})
outputData = struct();
if ~device.connected
err = 1;
errordlg(sprintf(getErrorMessage('deviceNotConnected'),device.defaultID))
return
end
err = device.prebias(input.Results.prepulsV,input.Results.prepulsDuration,input.Results.prepulsDelay);
if err
return
end
err = device.setSweepV(input.Results.start,input.Results.stop,input.Results.step,input.Results.delay,input.Results.integrationRate);
if err
return
end
[outputSweep,err] = device.measureSweepV('plotHandle',input.Results.plotHandle);
device.setOutputState(0);
if err
return
end
outputData = outputSweep;
end
function [outputData,err] = measureCycle(device,vmpp,voc,step,delay,varargin)
input = inputParser;
addRequired(input,'device')
addRequired(input,'vmpp',validationFcn('keithleySetV',device.functionName));
addRequired(input,'voc',validationFcn('keithleySetV',device.functionName));
addRequired(input,'step',validationFcn('keithleySetStepV',device.functionName));
addRequired(input,'delay',validationFcn('keithleyDelay',device.functionName));
addOptional(input,'integrationRate',device.intRate,validationFcn('keithleyIntegrationRate',device.functionName));
addParameter(input,'complianceLevel',device.compLevel,validationFcn('keithleySetV',device.functionName));
addParameter(input,'plotHandle',0,@(x) (isnumeric(x) && x==0) || isgraphics(x,'axes') || (isstruct(x) && isfield(x,'update')));
parse(input,device,vmpp,voc,step,delay,varargin{:})
ax = input.Results.plotHandle;
outputData = struct();
outputData.voltage = 0;
outputData.current = 0;
outputData.time = 0;
if device.abortMeasurement
err = 88;
return
elseif device.abortAllMeasurements
err = 99;
return
end
if ~device.connected
err = 1;
errordlg(sprintf(getErrorMessage('deviceNotConnected'),device.defaultID))
return
end
vmpp = input.Results.vmpp;
voc = input.Results.voc;
step = input.Results.step;
%# MPP->JSC->VOC->JSC
volt = [vmpp:-step:0, 0:step:voc,voc:-step:0];
%# set voltage as source
err = device.setSourceMode('V');
if err
errordlg(sprintf(getErrorMessage('keithleySetSourceV'),device.functionName))
return
end
%# set list as sweep
err = device.setList('V', volt);
if err
return
end
%# set delay between each measurement point
err = device.setDelay('manual', input.Results.delay);
if err
return
end
%# set sense function (device, mode [I,V,R], int_rate, prot_lvl, range_auto, range)
err = device.setSense('I', 'integrationRate',input.Results.integrationRate,'complianceLevel',input.Results.complianceLevel);
if err
log.update(['Could not set integrationRate ',num2str(input.Results.integrationRate),' in cycle!'])
return
end
if ~device.outputState
%# activate output if not already active
err = device.toggleOutput(1);
if err
return
end
device.outputState = 1;
end
%# preallocate space for results (Keithley stores internally up to 2500 points)
voltage = zeros(2500,1);
current = zeros(2500,1);
time = zeros(2500,1);
%# read measured values
device.initTriggerModel();
n1 = 1;
%# extract measured values from string while measuring and update plot
while ~device.abortMeasurement && ~device.abortAllMeasurements && n1<=2500
try
%# read 3 values á 13 digits + comma
% tmp = fscanf(device.connectionHandle,'%c',42);
tmp = device.readBuffer('startIndex',n1,'endIndex',n1);
splitted = strsplit(tmp,',');
catch eee
disp(eee.message);
break;
end
%# stop reading if end of transmission is reached
if isempty(tmp) || strcmp(splitted{1},'9.910000e+37')
break;
else
nums = str2double(splitted(1:end));
voltage(n1) = nums(1);
current(n1) = nums(2);
time(n1) = nums(3);
end
if isgraphics(ax,'axes')
plot(ax,voltage(1:n1),current(1:n1))
xlabel(ax,'Voltage (V)')
ylabel(ax,'Current (A)')
elseif isstruct(ax) && isfield(ax,'update')
ax.update(voltage(1:n1),current(1:n1),'xlabel','Voltage (V)','ylabel','Current (A)')
end
drawnow
n1 = n1+1;
end
device.setOutputState(0);
outputData.voltage = voltage(1:max(n1-1,1));
outputData.current = current(1:max(n1-1,1));
outputData.time = time(1:max(n1-1,1));
device.getEventlogMessages();
%# check if scan was aborted by user and adjust status
if device.abortMeasurement
device.setOutputState(0);
device.abortMeasurement = 0;
err = 88;
return
elseif device.abortAllMeasurements
device.setOutputState(0);
device.abortAllMeasurements = 0;
err = 99;
return
else
device.goIdle();
err = 0;
return
end
end
function err = setDischarge(device,varargin)
err = 404;
disp('Not implemented yet')
return
input = inputParser;
addRequired(input,'device')
addRequired(input,'sourceV',validationFcn('keithleySetV',device.functionName));
addRequired(input,'delay',validationFcn('keithleyDelay',device.functionName));
addOptional(input,'integrationRate',device.intRate,validationFcn('keithleyIntegrationRate',device.functionName));
addParameter(input,'mode','V',validationFcn('keithleyMode',device.functionName));
addParameter(input,'outputMode','HIMP',validationFcn('keithleyOutputMode',device.functionName))
addParameter(input,'wireMode',1,validationFcn('boolean',device.functionName))
parse(input,device,sourceV,delay,varargin{:})
mode = input.Results.mode;
if ~device.connected
err = 1;
errordlg(sprintf(getErrorMessage('deviceNotConnected'),device.defaultID))
return
end
%# clear Trigger events
fprintf(device.connectionHandle,':TRIGger:CLEar');
%# set 4-wire mode
fprintf(device,['SYST:RSEN ', con_a_b(input.Results.wireMode,'ON','OFF')]);
%# set output off-state mode
fprintf(device.connectionHandle ,[':OUTP:SMOD ',input.Results.outputMode]);
%# set voltage as source
err = device.setSourceMode(mode);
if err
errordlg(sprintf(getErrorMessage('keithleySetSourceV'),device.functionName))
return
end
%# set fixed voltage source range
fprintf(device.connectionHandle ,':SOUR:VOLT:MODE FIXED');
err = device.updateTimeScan(input.Results.sourceV,input.Results.delay,input.Results.integrationRate,'resetTime',1,'mode',mode);
if err
return
end
%# set sense functions
% fprintf(device.connectionHandle,':FORM:ELEM:SENS VOLT,CURR,TIME');
fprintf(device.connectionHandle,':FORM:ELEM:SENS CURR,TIME');
fprintf(device.connectionHandle,':SENS:CURR:RANG:AUTO ON');
fprintf(device.connectionHandle,':SENS:CURR:PROT 100E-3');
%# Specify trigger count (1 to 2500).
fprintf(device.connectionHandle,':TRIG:COUN 2500');
device.toggleAutoclear('OFF');
end
function [outputData,err] = measureDischarge(device,duration,varargin)
outputData = struct();
err = 404;
disp('Not implemented yet')
return
input = inputParser;
addRequired(input,'device')
addRequired(input,'duration',validationFcn('keithleyDuration',device.functionName));
addParameter(input,'hold',0,validationFcn('boolean',device.functionName));
addParameter(input,'plotHandle',0,@(x) (isnumeric(x) && x==0) || isgraphics(x,'axes') || (isstruct(x) && isfield(x,'update')));
addParameter(input,'temperatureController',[]);
parse(input,device,duration,varargin{:})
modeYLabel = 'Current (A)';
ax = input.Results.plotHandle;
tC = input.Results.temperatureController;
measureTemperature = ~isempty(tC) && isfield(tC,'startTemp') && isfield(tC,'endTemp') && isfield(tC,'device') && tC.device.getConnectionStatus();
outputData = struct();
outputData.current = 0;
outputData.time = 0;
if device.abortMeasurement
err = 88;
return
elseif device.abortAllMeasurements
err = 99;
return
end
%# preallocate memory for results
endReached = 0;
current = zeros(2500,1);
time = zeros(2500,1);
if measureTemperature
temperature = zeros(2500,1);
tempFactor = tC.startTemp>tC.endTemp;
end
if ~device.connected
err = 1;
errordlg(sprintf(getErrorMessage('deviceNotConnected'),device.defaultID))
return
elseif ~device.outputState
%# activate output if not already active
err = device.toggleOutput(1);
if err
return
end
device.outputState = 1;
end
%# clear Trigger events
fprintf(device.connectionHandle,':TRIGger:CLEar');
fprintf(device.connectionHandle,':TRIG:COUN 2500');
t0 = query(device.connectionHandle,':SYST:TIME?');
if isempty(t0)
fprintf(device.connectionHandle,':ABORt');
device.setOutputState(0);
err = -2;
return
else
t0 = str2double(t0);
end
fprintf(device.connectionHandle,':READ?');
tmp = '';
a = 0;
divisor = 2000;
divisorStep = divisor;
%# extract measured values from string while measuring and update plot
while ~device.abortMeasurement && ~device.abortAllMeasurements && ~endReached && a<duration
if ~device.getOutputState()
outputData.current = 0;
outputData.time = 0;
err = 88;
return;
end
try
tmp = [tmp,fscanf(device.connectionHandle,'%c',56)];
splitted = strsplit(tmp,',');
catch eee
disp(eee.message);
% device.abortAllMeasurements = 1;
% break;
end
%# stop reading if end of transmission is reached
if isempty(tmp)
break;
elseif isspace(tmp(end))
nums = str2double(splitted(1:end));
endReached = 1;
else
nums = str2double(splitted(1:end-1));
end
current = nums(1:2:end-1);
time = nums(2:2:end);
a = time(end)-time(1);
if measureTemperature
b = length(nonzeros(time));
c = length(nonzeros(temperature));
outputTemp = tC.device.getTemp();
temperature(c+1:b) = repmat(outputTemp.temperature,size(c+1:b));
if abs((time(end)-time(1))-tC.delay)<1 && tC.rampActive
tC.device.startRamp(tC.rate);
tC.device.setTemp(tC.endTemp);
disp('ramp started')
pause(2)
end
if con_a_b(tempFactor<0,outputTemp.temperature<tC.endTemp,outputTemp.temperature>tC.endTemp) && (duration-a)>tC.delay