forked from MartinVogel/ALPTool
-
Notifications
You must be signed in to change notification settings - Fork 2
/
alptool.m
1351 lines (1062 loc) · 52.6 KB
/
alptool.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
function varargout = alptool(varargin)
% ALPTOOL M-file for alptool.fig
% ALPTOOL, by itself, creates a new ALPTOOL or raises the existing
% singleton*.
%
% H = ALPTOOL returns the handle to a new ALPTOOL or the handle to
% the existing singleton*.
%
% ALPTOOL('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in ALPTOOL.M with the given input arguments.
%
% ALPTOOL('Property','Value',...) creates a new ALPTOOL or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before alptool_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to alptool_OpeningFcn via varargin.
%
% *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one
% instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES
% Edit the above text to modify the response to help alptool
% Last Modified by GUIDE v2.5 19-Feb-2014 19:04:53
% Begin initialization code - DO NOT EDIT
gui_Singleton = 0;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @alptool_OpeningFcn, ...
'gui_OutputFcn', @alptool_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end
if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT
% ========================================================================
% --- Executes just before alptool is made visible.
function alptool_OpeningFcn(hObject, eventdata, handles, varargin) %#ok<*INUSL,*DEFNU,*INUSD>
% This function has no output args, see OutputFcn.
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% varargin command line arguments to alptool (see VARARGIN)
% Choose default command line output for alptool
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
if length(varargin) < 1
% no API given, select one interactively
api = alpload();
elseif ischar(varargin{1})
if length(varargin) > 1 && islogical(varargin{2})
api = alpload(varargin{1}, varargin{2});
else
api = alpload(varargin{1});
end
end
if ~isa(api, 'alpapi')
alptoolfigure_CloseRequestFcn(hObject, eventdata, handles);
return;
end
set(hObject, 'UserData', api);
% set some control data
set(handles.triggerpolarity, 'String', {'High(D)', 'Low'});
set(handles.triggerpolarity, 'UserData', {api.LEVEL_HIGH, api.LEVEL_LOW});
set(handles.vdedge, 'String', {'Falling(D)', 'Raising'});
set(handles.vdedge, 'UserData', {api.EDGE_FALLING, api.EDGE_RISING});
set(handles.vdtimeout, 'String', {'Enable(D)', 'Disable'});
set(handles.vdtimeout, 'UserData', {api.TIME_OUT_ENABLE, api.TIME_OUT_DISABLE});
set(handles.projectionmode, 'String', {'Master(D)', 'Slave'});
set(handles.projectionmode, 'UserData', {api.MASTER, api.SLAVE_VD});
set(handles.inversion, 'String', {'None(D)', 'Inversion'});
set(handles.inversion, 'UserData', {api.DEFAULT, ~api.DEFAULT});
set(handles.imageflip, 'String', {'None(D)', 'Upside down'});
set(handles.imageflip, 'UserData', {api.DEFAULT, ~api.DEFAULT});
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes alptool wait for user response (see UIRESUME)
% uiwait(handles.alptoolfigure);
% ========================================================================
% --- Outputs from this function are returned to the command line.
function varargout = alptool_OutputFcn(hObject, eventdata, handles)
% varargout cell array for returning output args (see VARARGOUT);
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Get default command line output from handles structure
if isfield(handles, 'output')
varargout{1} = handles.output;
else
varargout{1} = [];
end
% ========================================================================
% --- Executes during object creation, after setting all properties.
function alptoolfigure_CreateFcn(hObject, eventdata, handles)
% hObject handle to alptoolfigure (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% ========================================================================
% --- Executes during object deletion, before destroying properties.
function alptoolfigure_DeleteFcn(hObject, eventdata, handles)
% hObject handle to alptoolfigure (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
if isstruct(handles)
device = get(handles.deviceid, 'UserData');
if ~isempty(device)
device.halt();
device.free();
end
end
% ========================================================================
% --- Executes when user attempts to close alptoolfigure.
function alptoolfigure_CloseRequestFcn(hObject, eventdata, handles)
% hObject handle to alptoolfigure (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hint: delete(hObject) closes the figure
delete(hObject);
% ========================================================================
% --- Executes on button press in devalloc.
function devalloc_Callback(hObject, eventdata, handles)
% hObject handle to devalloc (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
devicenumber = str2double(get(handles.devicenumber, 'String'));
api = get(handles.alptoolfigure, 'UserData');
device = alpdevice(api);
[ret, deviceid] = device.alloc(devicenumber);
if ret ~= device.OK
uiwait(msgbox(sprintf ('ALP device #%i can not be allocated, return value was %i.', devicenumber, ret), ...
'Error allocating device', 'modal'));
return;
end
set(handles.deviceid, 'UserData', device);
set(handles.deviceid, 'String', deviceid_makestr(deviceid));
set(handles.devalloc, 'Enable', 'off');
set(handles.devhalt, 'Enable', 'on');
set(handles.devfree, 'Enable', 'on');
set(handles.alpon, 'Enable', 'on');
set(handles.alpoff, 'Enable', 'on');
set(handles.alphon, 'Enable', 'on');
set(handles.alpqon, 'Enable', 'on');
set(handles.devinquire, 'Enable', 'on');
set(handles.usbreconnect, 'Enable', 'on');
set(handles.devcontrol, 'Enable', 'on');
set(handles.setdefault, 'Enable', 'on');
set(handles.setslave, 'Enable', 'on');
set(handles.filesequence, 'Enable', 'on');
set(handles.varsequence, 'Enable', 'on');
set(handles.devicetows, 'Enable', 'on');
set(handles.sequencetows, 'Enable', 'on');
% inquire current settings
devinquire_Callback(handles.devinquire, eventdata, handles);
% ========================================================================
% --- Executes during object creation, after setting all properties.
function deviceid_CreateFcn(hObject, eventdata, handles)
% hObject handle to deviceid (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
set(hObject, 'String', deviceid_makestr(0));
% ========================================================================
function str = deviceid_makestr(deviceid)
str = sprintf('DeviceID: %i', deviceid);
% ========================================================================
% --- Executes on button press in devhalt.
function devhalt_Callback(hObject, eventdata, handles)
% hObject handle to devhalt (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% halt the device
device = get(handles.deviceid, 'UserData');
ret = device.halt();
if ret ~= device.OK
uiwait(msgbox(sprintf ('ALP device id %i can not be halted, return value was %i.', device.deviceid, ret), ...
'Error halting device', 'modal'));
return;
end
% ========================================================================
% --- Executes during object creation, after setting all properties.
function devhalt_CreateFcn(hObject, eventdata, handles)
% hObject handle to devhalt (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
set(hObject, 'Enable', 'off');
% ========================================================================
% --- Executes on button press in devfree.
function devfree_Callback(hObject, eventdata, handles)
% hObject handle to devfree (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% free the device
device = get(handles.deviceid, 'UserData');
ret = device.free();
if ret ~= device.OK
uiwait(msgbox(sprintf ('ALP device id %i can not be freed, return value was %i.', device.deviceid, ret), ...
'Error freeing device', 'modal'));
return;
end
set(handles.deviceid, 'UserData', []);
set(handles.deviceid, 'String', '0');
set(handles.devalloc, 'Enable', 'on');
set(handles.devhalt, 'Enable', 'off');
set(handles.devfree, 'Enable', 'off');
set(handles.alpon, 'Enable', 'off');
set(handles.alpoff, 'Enable', 'off');
set(handles.alphon, 'Enable', 'off');
set(handles.alpqon, 'Enable', 'off');
set(handles.devinquire, 'Enable', 'off');
set(handles.usbreconnect, 'Enable', 'off');
set(handles.devcontrol, 'Enable', 'off');
set(handles.setdefault, 'Enable', 'off');
set(handles.setslave, 'Enable', 'off');
set(handles.filesequence, 'Enable', 'off');
set(handles.varsequence, 'Enable', 'off');
set(handles.devicetows, 'Enable', 'off');
set(handles.sequencetows, 'Enable', 'off');
% ========================================================================
% --- Executes during object creation, after setting all properties.
function devfree_CreateFcn(hObject, eventdata, handles)
% hObject handle to devfree (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
set(hObject, 'Enable', 'off');
% ========================================================================
% --- Executes on button press in alpon.
function alpon_Callback(hObject, eventdata, handles)
% hObject handle to alpon (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
device = get(handles.deviceid, 'UserData');
device.on();
% ========================================================================
% --- Executes during object creation, after setting all properties.
function alpon_CreateFcn(hObject, eventdata, handles)
% hObject handle to alpon (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
set(hObject, 'Enable', 'off');
% ========================================================================
% --- Executes on button press in alpoff.
function alpoff_Callback(hObject, eventdata, handles)
% hObject handle to alpoff (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
device = get(handles.deviceid, 'UserData');
device.off();
% ========================================================================
% --- Executes during object creation, after setting all properties.
function alpoff_CreateFcn(hObject, eventdata, handles)
% hObject handle to alpoff (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
set(hObject, 'Enable', 'off');
% ========================================================================
% --- Executes on button press in alphon.
function alphon_Callback(hObject, eventdata, handles)
% hObject handle to alphon (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
device = get(handles.deviceid, 'UserData');
half = get(handles.halves, 'Value');
device.half(half);
% ========================================================================
% --- Executes during object creation, after setting all properties.
function alphon_CreateFcn(hObject, eventdata, handles)
% hObject handle to alphon (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
set(hObject, 'Enable', 'off');
% ========================================================================
% --- Executes on button press in alpqon.
function alpqon_Callback(hObject, eventdata, handles)
% hObject handle to alpqon (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
device = get(handles.deviceid, 'UserData');
quarter = get(handles.quarters, 'Value');
device.quarter(quarter);
% ========================================================================
% --- Executes during object creation, after setting all properties.
function alpqon_CreateFcn(hObject, eventdata, handles)
% hObject handle to alpqon (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
set(hObject, 'Enable', 'off');
% ========================================================================
% --- Executes during object creation, after setting all properties.
function halves_CreateFcn(hObject, eventdata, handles)
% hObject handle to halves (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: popupmenu controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
set(hObject, 'String', {'bottom', 'top', 'left', 'right'});
set(hObject, 'Value', 1);
% ========================================================================
% --- Executes during object creation, after setting all properties.
function quarters_CreateFcn(hObject, eventdata, handles)
% hObject handle to quarters (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: popupmenu controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
set(hObject, 'String', {'left bottom', 'right bottom', 'left top', 'right top'});
set(hObject, 'Value', 1);
% ========================================================================
% --- Executes on button press in devinquire.
function devinquire_Callback(hObject, eventdata, handles)
% hObject handle to devinquire (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% device handle
device = get(handles.deviceid, 'UserData');
% device number
[ret, uservar] = device.inquire(device.api.DEVICE_NUMBER);
if ret ~= device.api.OK
uiwait(msgbox(sprintf ('Can not inquire ALP device number of device id %i, return value was %i', device.deviceid, ret), ...
'Error inquiring device', 'modal'));
return;
else
set(handles.devicenumber2, 'String', sprintf('Device Number: %i', uservar));
end
% version number
[ret, uservar] = device.inquire(device.api.VERSION);
if ret ~= device.api.OK
uiwait(msgbox(sprintf ('Can not inquire version number of device id %i, return value was %i', device.deviceid, ret), ...
'Error inquiring device', 'modal'));
return;
else
set(handles.versionnumber, 'String', sprintf('Version Number: %i', uservar));
end
% device state
[ret, uservar] = device.inquire(device.api.DEV_STATE);
if ret ~= device.api.OK
uiwait(msgbox(sprintf ('Can not inquire state of device id %i, return value was %i', device.deviceid, ret), ...
'Error inquiring device', 'modal'));
return;
else
switch(uservar)
case device.api.DEV_BUSY
state = 'ALP_DEV_BUSY';
case device.api.DEV_READY
state = 'ALP_DEV_READY';
case device.api.DEV_IDLE
state = 'ALP_DEV_IDLE';
otherwise
state = 'unknown';
end
set(handles.devicestate, 'String', sprintf('Device State: %s', state));
end
% memory
[ret, uservar] = device.inquire(device.api.AVAIL_MEMORY);
if ret ~= device.api.OK
uiwait(msgbox(sprintf ('Can not inquire memory of device id %i, return value was %i', device.deviceid, ret), ...
'Error inquiring device', 'modal'));
return;
else
set(handles.availablememory, 'String', sprintf('Available Memory (binary images): %i', uservar));
end
% USB connection
[ret, uservar] = device.inquire(device.api.USB_CONNECTION); %#ok<NASGU>
if ret ~= device.api.OK
uiwait(msgbox(sprintf ('Can not inquire USB status of device id %i, return value was %i', device.deviceid, ret), ...
'Error inquiring device', 'modal'));
return;
else
if ret == device.api.OK
set(handles.usbconnection, 'String', 'USB state: connected');
else
set(handles.usbconnection, 'String', 'USB state: device removed');
end
end
% trigger polarity
[ret, uservar] = device.inquire(device.api.TRIGGER_POLARITY);
if ret ~= device.api.OK
uiwait(msgbox(sprintf ('Can not inquire trigger polarity state of device id %i, return value was %i', device.deviceid, ret), ...
'Error inquiring device', 'modal'));
return;
else
entries = get(handles.triggerpolarity, 'UserData');
for i=1:size(entries,2)
if uservar == entries{i}
set(handles.triggerpolarity, 'Value', i);
end
end
end
% VD edge
[ret, uservar] = device.inquire(device.api.VD_EDGE);
if ret ~= device.api.OK
uiwait(msgbox(sprintf ('Can not inquire VD edge state of device id %i, return value was %i', device.deviceid, ret), ...
'Error inquiring device', 'modal'));
return;
else
entries = get(handles.vdedge, 'UserData');
for i=1:size(entries,2)
if uservar == entries{i}
set(handles.vdedge, 'Value', i);
end
end
end
% VD time out
[ret, uservar] = device.inquire(device.api.VD_TIME_OUT);
if ret ~= device.api.OK
uiwait(msgbox(sprintf ('Can not inquire VD time out state of device id %i, return value was %i', device.deviceid, ret), ...
'Error inquiring device', 'modal'));
return;
else
entries = get(handles.vdtimeout, 'UserData');
for i=1:size(entries,2)
if uservar == entries{i}
set(handles.vdtimeout, 'Value', i);
end
end
end
% projection mode
[ret, uservar] = device.projinquire(device.api.PROJ_MODE);
if ret ~= device.api.OK
uiwait(msgbox(sprintf ('Can not inquire projection mode state of device id %i, return value was %i', device.deviceid, ret), ...
'Error inquiring device', 'modal'));
return;
else
entries = get(handles.projectionmode, 'UserData');
for i=1:size(entries,2)
if uservar == entries{i}
set(handles.projectionmode, 'Value', i);
end
end
end
% projection state
[ret, uservar] = device.projinquire(device.api.PROJ_STATE);
if ret ~= device.api.OK
uiwait(msgbox(sprintf ('Can not inquire projection state of device id %i, return value was %i', device.deviceid, ret), ...
'Error inquiring device', 'modal'));
return;
else
switch(uservar)
case device.api.PROJ_ACTIVE
state = 'Projection active';
case device.api.PROJ_IDLE
state = 'no active projection';
otherwise
state = 'state unknown';
end
set(handles.projectionstate, 'String', sprintf('Projection State: %s', state));
end
% inversion
[ret, uservar] = device.projinquire(device.api.PROJ_INVERSION);
if ret ~= device.api.OK
uiwait(msgbox(sprintf ('Can not inquire projection inversion status of device id %i, return value was %i', device.deviceid, ret), ...
'Error inquiring device', 'modal'));
return;
else
entries = get(handles.inversion, 'UserData');
for i=1:size(entries,2)
if uservar == device.api.DEFAULT
if uservar == entries{i}
set(handles.inversion, 'Value', i);
end
else
if entries{i} ~= device.api.DEFAULT
set(handles.inversion, 'Value', i);
end
end
end
end
% flip
[ret, uservar] = device.projinquire(device.api.PROJ_UPSIDE_DOWN);
if ret ~= device.api.OK
uiwait(msgbox(sprintf ('Can not inquire projection image flip status of device id %i, return value was %i', device.deviceid, ret), ...
'Error inquiring device', 'modal'));
return;
else
entries = get(handles.imageflip, 'UserData');
for i=1:size(entries,2)
if uservar == device.api.DEFAULT
if uservar == entries{i}
set(handles.imageflip, 'Value', i);
end
else
if entries{i} ~= device.api.DEFAULT
set(handles.imageflip, 'Value', i);
end
end
end
end
% ========================================================================
% --- Executes during object creation, after setting all properties.
function devinquire_CreateFcn(hObject, eventdata, handles)
% hObject handle to devinquire (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
set(hObject, 'Enable', 'off');
% ========================================================================
% --- Executes on button press in usbreconnect.
function usbreconnect_Callback(hObject, eventdata, handles)
% hObject handle to usbreconnect (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% device handle
device = get(handles.deviceid, 'UserData');
ret = device.control(device.api.USB_CONNECTION, device.api.DEFAULT);
if ret ~= device.api.OK
uiwait(msgbox(sprintf ('Could not reconnect to device %i, return value was %i', device.deviceid, ret), ...
'Error reconnecting to device', 'modal'));
return;
end
% ========================================================================
% --- Executes during object creation, after setting all properties.
function usbreconnect_CreateFcn(hObject, eventdata, handles)
% hObject handle to usbreconnect (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
set(hObject, 'Enable', 'off');
% ========================================================================
% --- Executes on selection change in triggerpolarity.
function triggerpolarity_Callback(hObject, eventdata, handles)
% hObject handle to triggerpolarity (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: contents = get(hObject,'String') returns triggerpolarity contents as cell array
% contents{get(hObject,'Value')} returns selected item from triggerpolarity
device = get(handles.deviceid, 'UserData');
entries = get(hObject, 'UserData');
entry = entries{get(hObject, 'Value')};
ret = device.control(device.api.TRIGGER_POLARITY, entry);
if ret ~= device.api.OK
uiwait(msgbox(sprintf ('Can not set trigger polarity state of device id %i, return value was %i', device.deviceid, ret), ...
'Error controlling device', 'modal'));
return;
end
% ========================================================================
% --- Executes during object creation, after setting all properties.
function triggerpolarity_CreateFcn(hObject, eventdata, handles)
% hObject handle to triggerpolarity (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: popupmenu controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% ========================================================================
% --- Executes on selection change in vdedge.
function vdedge_Callback(hObject, eventdata, handles)
% hObject handle to vdedge (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: contents = get(hObject,'String') returns vdedge contents as cell array
% contents{get(hObject,'Value')} returns selected item from vdedge
device = get(handles.deviceid, 'UserData');
entries = get(hObject, 'UserData');
entry = entries{get(hObject, 'Value')};
ret = device.control(device.api.VD_EDGE, entry);
if ret ~= device.api.OK
uiwait(msgbox(sprintf ('Can not set VD edge state of device id %i, return value was %i', device.deviceid, ret), ...
'Error controlling device', 'modal'));
return;
end
% ========================================================================
% --- Executes during object creation, after setting all properties.
function vdedge_CreateFcn(hObject, eventdata, handles)
% hObject handle to vdedge (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: popupmenu controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% ========================================================================
% --- Executes on selection change in vdtimeout.
function vdtimeout_Callback(hObject, eventdata, handles)
% hObject handle to vdtimeout (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: contents = get(hObject,'String') returns vdtimeout contents as cell array
% contents{get(hObject,'Value')} returns selected item from vdtimeout
device = get(handles.deviceid, 'UserData');
entries = get(hObject, 'UserData');
entry = entries{get(hObject, 'Value')};
ret = device.control(device.api.VD_TIME_OUT, entry);
if ret ~= device.api.OK
uiwait(msgbox(sprintf ('Can not set VD time out state of device id %i, return value was %i', device.deviceid, ret), ...
'Error controlling device', 'modal'));
return;
end
% ========================================================================
% --- Executes during object creation, after setting all properties.
function vdtimeout_CreateFcn(hObject, eventdata, handles)
% hObject handle to vdtimeout (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: popupmenu controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% ========================================================================
% --- Executes on selection change in projectionmode.
function projectionmode_Callback(hObject, eventdata, handles)
% hObject handle to projectionmode (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: contents = get(hObject,'String') returns projectionmode contents as cell array
% contents{get(hObject,'Value')} returns selected item from projectionmode
device = get(handles.deviceid, 'UserData');
entries = get(hObject, 'UserData');
entry = entries{get(hObject, 'Value')};
ret = device.projcontrol(device.api.PROJ_MODE, entry);
if ret ~= device.api.OK
uiwait(msgbox(sprintf ('Can not set projection mode of device id %i, return value was %i', device.deviceid, ret), ...
'Error controlling device', 'modal'));
return;
end
% ========================================================================
% --- Executes during object creation, after setting all properties.
function projectionmode_CreateFcn(hObject, eventdata, handles)
% hObject handle to projectionmode (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: popupmenu controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% ========================================================================
% --- Executes on selection change in inversion.
function inversion_Callback(hObject, eventdata, handles)
% hObject handle to inversion (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: contents = get(hObject,'String') returns inversion contents as cell array
% contents{get(hObject,'Value')} returns selected item from inversion
device = get(handles.deviceid, 'UserData');
entries = get(hObject, 'UserData');
entry = entries{get(hObject, 'Value')};
ret = device.projcontrol(device.api.PROJ_INVERSION, entry);
if ret ~= device.api.OK
uiwait(msgbox(sprintf ('Can not set projection inversion state of device id %i, return value was %i', device.deviceid, ret), ...
'Error controlling device', 'modal'));
return;
end
% ========================================================================
% --- Executes during object creation, after setting all properties.
function inversion_CreateFcn(hObject, eventdata, handles)
% hObject handle to inversion (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: popupmenu controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% ========================================================================
% --- Executes on selection change in imageflip.
function imageflip_Callback(hObject, eventdata, handles)
% hObject handle to imageflip (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: contents = get(hObject,'String') returns imageflip contents as cell array
% contents{get(hObject,'Value')} returns selected item from imageflip
device = get(handles.deviceid, 'UserData');
entries = get(hObject, 'UserData');
entry = entries{get(hObject, 'Value')};
ret = device.projcontrol(device.api.PROJ_UPSIDE_DOWN, entry);
if ret ~= device.api.OK
uiwait(msgbox(sprintf ('Can not set projection flip state of device id %i, return value was %i', device.deviceid, ret), ...
'Error controlling device', 'modal'));
return;
end
% ========================================================================
% --- Executes during object creation, after setting all properties.
function imageflip_CreateFcn(hObject, eventdata, handles)
% hObject handle to imageflip (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: popupmenu controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% ========================================================================
% --- Executes on button press in devcontrol.
function devcontrol_Callback(hObject, eventdata, handles)
% hObject handle to devcontrol (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% device handle
device = get(handles.deviceid, 'UserData');
% trigger polarity
entries = get(handles.triggerpolarity, 'UserData');
entry = entries{get(handles.triggerpolarity, 'Value')};
ret = device.control(device.api.TRIGGER_POLARITY, entry);
if ret ~= device.api.OK
uiwait(msgbox(sprintf ('Can not set trigger polarity state of device id %i, return value was %i', device.deviceid, ret), ...
'Error controlling device', 'modal'));
end
% VD edge
entries = get(handles.vdedge, 'UserData');
entry = entries{get(handles.vdedge, 'Value')};
ret = device.control(device.api.VD_EDGE, entry);
if ret ~= device.api.OK
uiwait(msgbox(sprintf ('Can not set VD edge state of device id %i, return value was %i', device.deviceid, ret), ...
'Error controlling device', 'modal'));
end
% VD time out
entries = get(handles.vdtimeout, 'UserData');
entry = entries{get(handles.vdtimeout, 'Value')};
ret = device.control(device.api.VD_TIME_OUT, entry);
if ret ~= device.api.OK
uiwait(msgbox(sprintf ('Can not set VD time out state of device id %i, return value was %i', device.deviceid, ret), ...
'Error controlling device', 'modal'));
end
% projection mode
entries = get(handles.projectionmode, 'UserData');
entry = entries{get(handles.projectionmode, 'Value')};
ret = device.projcontrol(device.api.PROJ_MODE, entry);
if ret ~= device.api.OK
uiwait(msgbox(sprintf ('Can not set projection mode of device id %i, return value was %i', device.deviceid, ret), ...
'Error controlling device', 'modal'));
end
% inversion
entries = get(handles.inversion, 'UserData');
entry = entries{get(handles.inversion, 'Value')};
ret = device.projcontrol(device.api.PROJ_INVERSION, entry);
if ret ~= device.api.OK
uiwait(msgbox(sprintf ('Can not set projection inversion state of device id %i, return value was %i', device.deviceid, ret), ...
'Error controlling device', 'modal'));
end
% image flip
entries = get(handles.imageflip, 'UserData');
entry = entries{get(handles.imageflip, 'Value')};
ret = device.projcontrol(device.api.PROJ_UPSIDE_DOWN, entry);
if ret ~= device.api.OK
uiwait(msgbox(sprintf ('Can not set projection flip state of device id %i, return value was %i', device.deviceid, ret), ...
'Error controlling device', 'modal'));
end
% ========================================================================
% --- Executes during object creation, after setting all properties.
function devcontrol_CreateFcn(hObject, eventdata, handles)
% hObject handle to devcontrol (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
set(hObject, 'Enable', 'off');
set(hObject, 'Visible', 'off');
% ========================================================================
% --- Executes on button press in filesequence.
function filesequence_Callback(hObject, eventdata, handles)
% hObject handle to filesequence (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
device = get(handles.deviceid, 'UserData');
% read TIFF file
[stack, depth, height, width, bitdepth, filenames] = readstack(); %#ok<NASGU>
if bitdepth > 8
uiwait(msgbox(sprintf ('Device does not support a bit depth of %i, stack will be resampled to 8 bit.', bitdepth), ...
'Image data problem', 'modal'));
stack = uint8(stack/2^(bitdepth-8));
bitdepth = 8;
end
if bitdepth < 8
% shift significant bits to left
stack = bitshift(stack, 8-bitdepth);
end
sz = [depth, height, width];