Skip to content

Commit ce70dbf

Browse files
committed
start work on plotting code
1 parent ea8ca9d commit ce70dbf

File tree

1 file changed

+56
-2
lines changed

1 file changed

+56
-2
lines changed

code/+vidrio/+sync/phaseMonitor.m

Lines changed: 56 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,48 @@
1818

1919
properties (Hidden)
2020
listeners
21+
% These properties hold information relevant to the plot window
22+
hFig %The handle to the figure which shows the data is stored here
23+
axis_A %Handles for the two axes
24+
axis_B
25+
2126
end
2227

2328

2429
methods
2530

2631
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+
obj.hFig = clf;
35+
obj.hFig.Position(3)=obj.hFig.Position(3)*1.5; %Make figure a little wider
36+
obj.hFig.Name='Close figure to stop acquisition'; %This is just the OO notation. We could also use the set command.
37+
obj.hFig.CloseRequestFcn = @obj.windowCloseFcn;
38+
39+
40+
%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]);
45+
46+
% 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))
49+
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),'.-')
52+
53+
%Make plots look nice
54+
obj.axis_A.XLabel.String='Voltage (V)';
55+
obj.axis_A.YLabel.String='Samples';
56+
57+
obj.axis_B.XLabel.String='Voltage (V)';
58+
obj.axis_B.YLabel.String='Samples';
59+
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])
2763

2864
obj.taskA=vidrio.sync.sine_AO_AI(DAQ_ID_A);
2965
obj.taskB=vidrio.sync.sine_AO_AI(DAQ_ID_B);
@@ -45,8 +81,26 @@ function delete(obj)
4581

4682

4783
function plotIt(obj,src,eventData)
48-
%TODO: plot both chans
49-
end
84+
%We keep the plot objects the same and just change their data properties
85+
C=get(obj.axis_A, 'Children');
86+
C(1).YData=inData(:,1);
87+
C(2).YData=inData(:,2);
88+
89+
C=get(obj.axis_B, 'Children');
90+
C.XData=inData(:,1);
91+
C.YData=inData(:,2);
92+
93+
end %close readAndPlotData
94+
95+
96+
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+
fprintf('You closed the window. Shutting down DAQ.\n')
101+
obj.delete % simply call the destructor
102+
end %close windowCloseFcn
103+
50104

51105

52106
end %close methods block

0 commit comments

Comments
 (0)