Updating variable from another place in the code
Ältere Kommentare anzeigen
I know the phrasing of the question is a bit poor, but I didn't know how to explain it better. To sum up the code down below, this function starts and stops the recording mode of an external DAQ. It starts decoding the messages once I press the "Start" button, which then changes to "Stop", and I want to stop decoding the messages that I get from the DAQ once I press "Stop". Hence the recordingActive variable, which will make the code exit the while loop in the if condition. The problem is that I need to update the value of recordingActive in the elsif condition, because that's what is run when pressing "Stop".
I tried using the drawnow function, which in the documentation says it updates callbacks, but I didn't obtain any results. Any ideas on how could I solve this issue?
function StartRecordingButtonPushed(app, event)
if app.StartRecordingButton.Text == "Start Recording"
% Change the text in the button
app.StartRecordingButton.Text = "Stop Recording";
% Determine the total number of active input channels
numberOfActiveChannels = 0;
for i = 1:length(app.newChannelSetup.channels)
if app.newChannelSetup.channels(i).enabled == true
numberOfActiveChannels = numberOfActiveChannels + 1;
end
end
% Get the TCP destination port
recorderPort = GetRecorderDestinationSocketPort(app.ip, app.timeOut);
% Start recording
RecorderMeasure(app.ip, app.timeOut);
% Open the TCP stream
app.binaryStream = tcpclient(app.ip, recorderPort.tcpPort);
recordingActive = true;
bufferDraining = true;
% Read and decode the messages
while bufferDraining == true
for i = 1:numberOfActiveChannels
[app.interpretationMessages,app.signalDataMessages] = MasterMessageDecoder(app.binaryStream, app.interpretationMessages, app.signalDataMessages);
end
if recordingActive == false
if toc >= 0.5
bufferDraining = false;
end
end
end
% Stop recording
RecorderStop(app.ip, app.timeOut);
% Clear the buffer
clear app.binaryStream;
elseif app.StartRecordingButton.Text == "Stop Recording"
% Start calculating time to stop draining the buffer
tic
% Change the text in the button
app.StartRecordingButton.Text = "Start Recording";
recordingActive = false;
end
end
Akzeptierte Antwort
Weitere Antworten (0)
Kategorien
Mehr zu Scripts finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!