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