how to combine two callback function together in one callback function?

Hi everyone, I am new to Matlab I do not have much experience I collecting and acquisition different data the first is 3 signal from DAQ device And the second data from serial port. i have 2 callback function for starting collecting data Now I want to combine the 2 callback function in one Could you please help me? the first callback function listed below and the second after it :
function plotDataSer(src,event)
% DR YAZED; call back function collect serial data
%data = char(fread(src, src.BytesAvailableFcnCount));
global I2 DATA_S2 s2 T_OLD_S2 DAT;
data = char(fread(src, src.BytesAvailableFcnCount));
%PLOTDATA Summary of this function goes here
% Detailed explanation goes here
% Determine the type of event.
%EventType = event.Type;
% Determine the time of the error event.
%EventData = event.Data;
%EventDataTime = EventData.AbsTime;
%plot(EventDataTime,EventData)
%hold on;
I2 = I2 + 1;
%{
DATA{I,1}=src.BytesAvailable;
DATA{I,2}=s2.BytesAvailable;
%DATA{I,1}=EventDataTime;
%DATA{I,4}=fscanf(src,'%c',s2.BytesAvailable);
data = char(fread(src, src.bytesavailable)); %ref-> https://www.mathworks.com/matlabcentral/answers/224783-how-can-i-read-the-whole-input-buffer-of-a-serial-port-object
DATA{I,3} = data;
DATA{I,4}=sscanf(data,['%d' char(13) char(10)]); %sscanf(data,'%s');
%}
tnow = toc;
dif = tnow - T_OLD_S2;
DATA_S2{I2,1} = tnow;
DATA_S2{I2,2} = dif;
DATA_S2{I2,3}=s2.BytesAvailable;
%data = char(fread(src, src.bytesavailable));
%data = fread(src, src.bytesavailable,'*char');
DATA_S2{I2,4}=s2.BytesAvailable;
%DATA_S2{I2,5}=%sscanf(data,['%d' char(13) char(10)]); %sscanf(data,'%s');
DATA_S2{I2,5}=data; %fread(s2, s.bytesavailable,'*char')
DATA_S2{I2,6}=sscanf(data,['%f' char(13) char(10)]); %sscanf(data,'%s');
DAT=data;
T_OLD = tnow;
end
%mynum = sscanf(dp,['%d' char(13) char(10)])
the second callback function
function plotData(src,event)
% DR YAZED; call back function collect DAQ data
global I1 I2 DATA_S1 s2 T_OLD_S1;
%PLOTDATA Summary of this function goes here
% Detailed explanation goes here
plot(event.TimeStamps,event.Data)
hold on;
I1 = I1 + 1;
tnow = toc; dif = tnow - T_OLD_S1;
DATA_S1{I1,1} = tnow;
DATA_S1{I1,2} = dif;
DATA_S1{I1,3}=event.TimeStamps;
DATA_S1{I1,4}=event.Data;
T_OLD_S1 = tnow;
end
I want to add the first callback function to the second one I am sorry for the bad explanation and writing. Thanks for reading my question

4 Commenti

What do you mean by combining two callback function into one? Callback functions are event-driven (automatically executed when a certain event happen). You cannot call a callback function yourself.
"You cannot call a callback function yourself"
Why on earth not?
I do this sometimes, without any problems.
You can see an example in my FEX submission colornames, where inside the function colornames_view the figure resize callback function cnvResize gets called at the very end of the main function code, in order to set the size of the figure. It worked properly for years, indeed over several MATLAB versions, so it is a bit of surprise to now be told that I " cannot call a callback function" myself.
I also called callbacks myself in my FEX submission la resistance (see functions pnsSerFun and bndNumFun), which also worked entirely as expected (i.e. the functions run when I call them).
Can you provide a link to the documentation where this restriction is stated, or any threads on this forum where experienced MATLAB users have stated this?
"You cannot call a callback function yourself".
Well, you can but that's not usually what they're designed for indeed.
@omar, I too am confused by what is being asked. Rather than asking for a solution to what you think is the way to resolve your overall problem, tell us what the overall problem and we'll tell you how to solve it.
Yes, a callback function, by definition, is just a normal function, with a few extra inputs. Attaching them to a listener is what make them automatically calledback whenever the event occur. My comment was especially related to OP's case, where both callback functions are linked to hardware device events, DAQ device and serial port (Hardware most probably). So manually calling these callback function does not make much sense.

Accedi per commentare.

Risposte (0)

Categorie

Scopri di più su Interactive Control and Callbacks in Centro assistenza e File Exchange

Richiesto:

il 26 Apr 2018

Modificato:

il 26 Apr 2018

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by