フィルターのクリア

Info

この質問は閉じられています。 編集または回答するには再度開いてください。

How to write asynchronously to instrument?

1 回表示 (過去 30 日間)
Leor Greenberger
Leor Greenberger 2013 年 5 月 23 日
閉鎖済み: MATLAB Answer Bot 2021 年 8 月 20 日
Hi all,
I am trying to control an oscilloscope, and I have the following code for setting it up.
for Chan = 1:4
fprintf(visaObj,[ChanNumStr{Chan} ':TRA ON'],'async');
fprintf(visaObj,['PACU ' num2str(2*Chan-1) ',SDEV,' ChanNumStr{Chan} ',OFF'],'async');
fprintf(visaObj,['PACU ' num2str(2*Chan) ',PKPK,' ChanNumStr{Chan}],'async');
end
What I am trying to do here is set up channels 1 - 4 and some measurement parameters. When you send commands using fprintf to an instrument, MATLAB by default sends them synchronously. That is, it puts the data in the output buffer and waits until the buffer is empty before processing the next line in MATLAB. I would prefer that in this loop, all the commands be queued in the output buffer and for them to be sent asynchronously - that is, not wait for the output buffer to empty. Then later in my code, I could check to see if the output buffer is 0 before proceeding with a block of code that relies on the scope being set up with the commands I sent asynchronously.
Any ideas how I can accomplish this? With my current code, I get an error because if I try to write to the instrument while there is data still in the output buffer, I get a
Error using icinterface/fprintf (line 147)
An asynchronous write is already in progress.
Thus, this is not the way to queue several fprintf statements in the output buffer and have them sent asynchronously.
  3 件のコメント
Luke Rumbaugh
Luke Rumbaugh 2013 年 5 月 29 日
parallel loops? one for writing the data and one for continuing your processing without waiting for the data?
Luke Rumbaugh
Luke Rumbaugh 2013 年 5 月 29 日
you could sort of do your own queuing, too, with some (admittedly ugly) solution like
--get set up--
--> send the first command
while [the output buffer isn't 0]
--do some more stuff--
end
--> send next command
while [waiting for command to clear] ... do stuff
--> send next command
etc
I mean, I wouldn't show it to anyone, but it might work. if you figured out the approximate time it takes to get a command sent then you could load up your while loops with an approximately matching amount of processing (i.e. if it takes 100 ms to clear, you don't want 1 ms of processing or you'll waste time).

回答 (0 件)

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by