How to prevent timer from executing code between two lines?
古いコメントを表示
Apparently, a TimerFcn execution can occur between any two lines. This is a major problem for me right now, as I want to push commands to a serial object and immediately query the response. However, since the timer function is also pushing commands, it can occur that between lines
fprintf(serialObj, 'Command');
reply = fscanf(serialObj);
the timer function also issues a command with fprintf to the same serial device. Consequently, the received reply is not necessarily from the command issued on the line before.
Therefore, how can I force the aforementioned two lines to execute consecutively, without the possibility of the timer function executing code between them?
採用された回答
その他の回答 (2 件)
Matthijs V.
2018 年 1 月 18 日
編集済み: Matthijs V.
2018 年 1 月 18 日
Walter Roberson
2018 年 1 月 18 日
You can reduce the problem by literally putting the two statements on the same line:
fprintf(serialObj, 'Command'); reply = fscanf(serialObj);
I say reduce because the if whatever code you have on one line calls functions from .m or .p files (not sure about built-in) then the "between two lines" can apply with respect to the lines in the called functions.
1 件のコメント
Matthijs V.
2018 年 1 月 18 日
編集済み: Matthijs V.
2018 年 1 月 18 日
カテゴリ
ヘルプ センター および File Exchange で Programming Utilities についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!