フィルターのクリア

How to obtain output from instrument callback function?

1 回表示 (過去 30 日間)
Maheen Siddiqui
Maheen Siddiqui 2016 年 4 月 5 日
コメント済み: Maheen Siddiqui 2016 年 4 月 5 日
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

採用された回答

Walter Roberson
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.
  1 件のコメント
Maheen Siddiqui
Maheen Siddiqui 2016 年 4 月 5 日
Thanks for this! Thats very useful. After I wrote this post, it did occur to me that I could try to make the variable global and see if that works. But it also seems like I could save the variable to a mat file and then I will have access to it.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeInstrument Control Toolbox Supported Hardware についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by