How to obtain output from instrument callback function?
2 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
Walter Roberson
2016-4-5
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.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Migrate GUIDE Apps 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!