필터 지우기
필터 지우기

How to work around "invoke" error

조회 수: 8 (최근 30일)
W Ima
W Ima 2023년 11월 29일
편집: Walter Roberson 2024년 8월 21일
Dear. All,
I have trouble occasionally failing to execute invoke commands.
I use the invoke command to retrieve measured waveform data from a digital oscilloscope, Tektronix DPO7254 for more than ten thousand times. But, I encountered with VISA communication error and the execution of the m-script file was stopped. It seems this error happens only once over thousands of executions. It is very helpful if someone explains how to workaround VISA error and retry invoke commands by using mscript.
My program include scripts as follows,
deviceObj = icdevice('DPO7254.mdd', interfaceObj);
set(interfaceObj, 'OutputBufferSize', 2*DSO_DATA_SIZE+10000);
connect(deviceObj);
groupObj = get(deviceObj, 'Waveform');
set(deviceObj.Waveform(1), 'Precision', 'int16');
[CH1,T_measure] = invoke(groupObj, 'readwaveform', 'channel1',true);
[CH2,T_measure] = invoke(groupObj, 'readwaveform', 'channel2',true);
[CH3,T_measure] = invoke(groupObj, 'readwaveform', 'channel3',true);
[CH4,T_measure] = invoke(groupObj, 'readwaveform', 'channel4',true);
Best Regards
W. I.

답변 (1개)

Amith
Amith 2024년 8월 21일
Hi Ima,
To handle VISA errors and retry invoke commands in MATLAB, you can use a combination of error handling and retry logic. Here’s a basic example of how you might structure your script to achieve this:
  1. Define your device and connection settings:
deviceObj = icdevice('DPO7254.mdd', interfaceObj);
set(interfaceObj, 'OutputBufferSize', 2*DSO_DATA_SIZE + 10000);
connect(deviceObj);
groupObj = get(deviceObj, 'Waveform');
set(deviceObj.Waveform(1), 'Precision', 'int16');
2. You can Implement error handling and retry logic similar to the below logic:
maxRetries = 3; % Maximum number of retries
retryCount = 0;
success = false;
while ~success && retryCount < maxRetries
try
[CH1, T_measure] = invoke(groupObj, 'readwaveform', 'channel1', true);
[CH2, T_measure] = invoke(groupObj, 'readwaveform', 'channel2', true);
[CH3, T_measure] = invoke(groupObj, 'readwaveform', 'channel3', true);
[CH4, T_measure] = invoke(groupObj, 'readwaveform', 'channel4', true);
success = true; % If no error, set success to true
catch ME
retryCount = retryCount + 1;
fprintf('Error occurred: %s\n', ME.message);
fprintf('Retrying %d/%d...\n', retryCount, maxRetries);
pause(1); % Pause before retrying
end
end
if ~success
error('Failed to read waveform after %d attempts.', maxRetries);
end
The above code attempts to read waveforms from the oscilloscope up to three times if an error occurs. If the command fails after the maximum number of retries, it throws an error.
To resolve VISA issues you can refer to these documentation provided by MathWorks:
Hope this helps!

태그

제품


릴리스

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by