|
18 | 18 |
|
19 | 19 | properties (Hidden) |
20 | 20 | listeners |
21 | | - % These properties hold information relevant to the plot window |
| 21 | + |
| 22 | + % These properties hold information relevant to the plot window |
22 | 23 | hFig %The handle to the figure which shows the data is stored here |
23 | 24 | axis_A %Handles for the two axes |
24 | 25 | axis_B |
| 26 | + axis_C |
25 | 27 |
|
26 | 28 | end |
27 | 29 |
|
28 | 30 |
|
29 | 31 | methods |
30 | 32 |
|
31 | 33 | function obj=phaseMonitor(DAQ_ID_A, DAQ_ID_B) |
32 | | - % Build the figure window and have it shut off the acquisition when closed. |
33 | | - % See: basicConcepts/windowCloseFunction.m |
| 34 | + |
| 35 | + % Connect to DAQ |
| 36 | + obj.taskA=vidrio.sync.sine_AO_AI(DAQ_ID_A); |
| 37 | + obj.taskB=vidrio.sync.sine_AO_AI(DAQ_ID_B); |
| 38 | + |
| 39 | + |
34 | 40 | obj.hFig = clf; |
35 | 41 | obj.hFig.Position(3)=obj.hFig.Position(3)*1.5; %Make figure a little wider |
36 | 42 | obj.hFig.Name='Close figure to stop acquisition'; %This is just the OO notation. We could also use the set command. |
37 | 43 | obj.hFig.CloseRequestFcn = @obj.windowCloseFcn; |
38 | 44 |
|
39 | 45 |
|
40 | 46 | %Make two empty axes which we fill in the method readAndPlotData |
41 | | - obj.axis_A = axes('Parent', obj.hFig, 'Position', [0.1 0.12 0.4 0.8]); |
42 | | - xlabel('Voltage (V)') |
43 | | - ylabel('Samples') |
44 | | - obj.axis_B = axes('Parent', obj.hFig, 'Position', [0.58 0.12 0.4 0.8]); |
| 47 | + obj.axis_A = axes('Parent', obj.hFig, 'Position', [0.1 0.12 0.4 0.4]); |
| 48 | + obj.axis_B = axes('Parent', obj.hFig, 'Position', [0.1 0.55 0.4 0.4]); |
| 49 | + obj.axis_C = axes('Parent', obj.hFig, 'Position', [0.55 0.12 0.4 0.8]); |
45 | 50 |
|
46 | 51 | % Plot some empty data which we will later modify in readAndPlotData |
47 | | - % in the first plot we show the two waveforms as a function of time |
48 | | - plot(obj.axis_A, zeros(round(obj.sampleRate*obj.updatePeriod),2)) |
| 52 | + % in the first two plots we show the two waveforms as a function of time |
| 53 | + plot(obj.axis_A, zeros(round(obj.taskA.sampleRate*obj.taskA.updatePeriod),1)) |
| 54 | + plot(obj.axis_B, zeros(round(obj.taskA.sampleRate*obj.taskA.updatePeriod),1)) |
49 | 55 |
|
50 | | - % In the second plot we will show AI 1 as a function of AI 0 |
51 | | - plot(obj.axis_B, zeros(round(obj.sampleRate*obj.updatePeriod),1),'.-') |
| 56 | + % In the third plot we will show AI 1 as a function of AI 0 |
| 57 | + plot(obj.axis_C, zeros(round(obj.taskA.sampleRate*obj.taskA.updatePeriod),1),'.-') |
52 | 58 |
|
53 | 59 | %Make plots look nice |
54 | | - obj.axis_A.XLabel.String='Voltage (V)'; |
55 | | - obj.axis_A.YLabel.String='Samples'; |
| 60 | + obj.axis_A.YLabel.String='Voltage (V)'; |
| 61 | + obj.axis_A.XLabel.String='Samples'; |
| 62 | + |
| 63 | + obj.axis_B.YLabel.String='Voltage (V)'; |
| 64 | + obj.axis_B.XLabel.String=''; |
| 65 | + obj.axis_B.XTickLabel=[]; |
| 66 | + |
| 67 | + % Set properties of axes together |
| 68 | + set([obj.axis_A,obj.axis_B], 'Box', 'On', 'XGrid', 'On', 'YGrid', 'On', 'YLim', [obj.taskA.minVoltage,obj.taskA.maxVoltage]) |
| 69 | + set(obj.axis_C, 'XLim', [obj.taskA.minVoltage,obj.taskA.maxVoltage]) |
56 | 70 |
|
57 | | - obj.axis_B.XLabel.String='Voltage (V)'; |
58 | | - obj.axis_B.YLabel.String='Samples'; |
59 | 71 |
|
60 | | - % Set properties of both axes together |
61 | | - set([obj.axis_A,obj.axis_B], 'Box', 'On', 'XGrid', 'On', 'YGrid', 'On', 'YLim', [obj.minVoltage,obj.maxVoltage]) |
62 | | - set(obj.axis_B, 'XLim', [obj.minVoltage,obj.maxVoltage]) |
63 | 72 |
|
64 | | - obj.taskA=vidrio.sync.sine_AO_AI(DAQ_ID_A); |
65 | | - obj.taskB=vidrio.sync.sine_AO_AI(DAQ_ID_B); |
66 | 73 |
|
67 | 74 |
|
68 | | - addlistener(obj.taskA,'acquiredData', @obj.plotIt(src,eventData)); %TODO: confirm that's valic |
| 75 | + addlistener(obj.taskA,'acquiredData', 'PostSet', @(src,eventData) obj.plotIt(src,eventData) ); |
69 | 76 |
|
70 | 77 |
|
71 | 78 | obj.taskA.startAcquisition; |
|
77 | 84 | function delete(obj) |
78 | 85 | delete(obj.taskA) |
79 | 86 | delete(obj.taskB) |
| 87 | + delete(obj.hFig) |
80 | 88 | end %close destructor |
81 | 89 |
|
82 | 90 |
|
83 | 91 | function plotIt(obj,src,eventData) |
| 92 | + |
| 93 | + AIdata=eventData.AffectedObject.acquiredData; %Get the data |
84 | 94 | %We keep the plot objects the same and just change their data properties |
85 | 95 | C=get(obj.axis_A, 'Children'); |
86 | | - C(1).YData=inData(:,1); |
87 | | - C(2).YData=inData(:,2); |
| 96 | + C(1).YData=AIdata(:,1); |
88 | 97 |
|
89 | 98 | C=get(obj.axis_B, 'Children'); |
90 | | - C.XData=inData(:,1); |
91 | | - C.YData=inData(:,2); |
| 99 | + C.YData=AIdata(:,2); |
92 | 100 |
|
93 | | - end %close readAndPlotData |
| 101 | + C=get(obj.axis_C, 'Children'); |
| 102 | + C.YData=AIdata(:,1); |
| 103 | + C.YData=AIdata(:,2); |
| 104 | + end %close plotIt |
94 | 105 |
|
95 | 106 |
|
96 | 107 | function windowCloseFcn(obj,~,~) |
97 | | - % This runs when the user closes the figure window or if there is an error |
98 | | - % Note it's also possible to run a clean-up callback function with hTask.registerDoneEvent |
99 | | - |
100 | 108 | fprintf('You closed the window. Shutting down DAQ.\n') |
101 | 109 | obj.delete % simply call the destructor |
102 | 110 | end %close windowCloseFcn |
|
0 commit comments