Skip to content

Commit 78a9f6b

Browse files
committed
Get basic plotting working
1 parent d7e91c0 commit 78a9f6b

File tree

1 file changed

+37
-29
lines changed

1 file changed

+37
-29
lines changed

code/+vidrio/+sync/phaseMonitor.m

Lines changed: 37 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -18,54 +18,61 @@
1818

1919
properties (Hidden)
2020
listeners
21-
% These properties hold information relevant to the plot window
21+
22+
% These properties hold information relevant to the plot window
2223
hFig %The handle to the figure which shows the data is stored here
2324
axis_A %Handles for the two axes
2425
axis_B
26+
axis_C
2527

2628
end
2729

2830

2931
methods
3032

3133
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+
3440
obj.hFig = clf;
3541
obj.hFig.Position(3)=obj.hFig.Position(3)*1.5; %Make figure a little wider
3642
obj.hFig.Name='Close figure to stop acquisition'; %This is just the OO notation. We could also use the set command.
3743
obj.hFig.CloseRequestFcn = @obj.windowCloseFcn;
3844

3945

4046
%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]);
4550

4651
% 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))
4955

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),'.-')
5258

5359
%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])
5670

57-
obj.axis_B.XLabel.String='Voltage (V)';
58-
obj.axis_B.YLabel.String='Samples';
5971

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])
6372

64-
obj.taskA=vidrio.sync.sine_AO_AI(DAQ_ID_A);
65-
obj.taskB=vidrio.sync.sine_AO_AI(DAQ_ID_B);
6673

6774

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) );
6976

7077

7178
obj.taskA.startAcquisition;
@@ -77,26 +84,27 @@
7784
function delete(obj)
7885
delete(obj.taskA)
7986
delete(obj.taskB)
87+
delete(obj.hFig)
8088
end %close destructor
8189

8290

8391
function plotIt(obj,src,eventData)
92+
93+
AIdata=eventData.AffectedObject.acquiredData; %Get the data
8494
%We keep the plot objects the same and just change their data properties
8595
C=get(obj.axis_A, 'Children');
86-
C(1).YData=inData(:,1);
87-
C(2).YData=inData(:,2);
96+
C(1).YData=AIdata(:,1);
8897

8998
C=get(obj.axis_B, 'Children');
90-
C.XData=inData(:,1);
91-
C.YData=inData(:,2);
99+
C.YData=AIdata(:,2);
92100

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
94105

95106

96107
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-
100108
fprintf('You closed the window. Shutting down DAQ.\n')
101109
obj.delete % simply call the destructor
102110
end %close windowCloseFcn

0 commit comments

Comments
 (0)