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에서 Interactive Control and Callbacks에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!