How to obtain output from instrument callback function?
1 view (last 30 days)
Show older comments
Maheen Siddiqui
on 5 Apr 2016
Commented: Maheen Siddiqui
on 5 Apr 2016
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
0 Comments
Accepted Answer
Walter Roberson
on 5 Apr 2016
I have not researched how Record mode works.
With respect to returning a value from the callback: No. Very few callbacks can return a value. The callbacks that can return values are concerned with filtering roi resize changes, or for generating custom text for datatips. None of the I/O or graphical object callbacks can return values.
More Answers (0)
See Also
Categories
Find more on Instrument Control Toolbox Supported Hardware in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!