How to obtain output from instrument callback function?
Afficher commentaires plus anciens
Is it possible to get output from an instrument callback function in Matlab? I am reading data being sent to the serial port and a callback function is triggered when 1 byte becomes available
s=serial('COM3');
set(s,'BytesAvailableFcn',{@mycallback});
set(s,'BytesAvailableFcnCount',1);
set(s,'BytesAvailableFcnMode','byte');
I would like to record the exact time at which each callback occurs in a vector T. I am able to write the callback function such that I get a vector T, but I don't know to access T and it is not produced after the script has finished executing.
I could also have this vector T to be generated in the main script but I am unsure how to set the condition if the callback occurs. I previously thought that I could use bytes=get(s,'BytesAvailable') and if bytes==1 I could have the time recorded in the vector. But bytes have value = 1 only once and then continues to grow.
I am aware that there is a function record which could automatically record the callback information:
s.RecordMode = 'append';
s.RecordDetail = 'verbose';
s.RecordName = 'test.txt';
record(s)
However whenever I try this, it does not record as I want it to. Although I set s.RecordDetail to verbose, the output in the .txt is the same if I had not set the RecordDetail. In addition, I prefer to write to a vector/array rather than a file as it is faster.
Does anybody have any suggestions for this?
Thanks
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Interactive Control and Callbacks dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!