Script fails in function - instrument control

23 visualizaciones (últimos 30 días)
Jacob Hollebon
Jacob Hollebon el 13 de En. de 2017
Respondida: Sean de Wolski el 13 de En. de 2017
I'm having problems trying to connect an oscilloscope within a function. I have the code below, generated using the instrument control toolbox, to connect a Tektronix TDS2024B oscilloscope via USB Visa. The script connects, reads the waveform of one the channels on the scope and saves the data to the MATLAB workspace as matrices X and Y and then disconnects. The script works fine when called by itself. However, whenever the code is put into a function, it does not save the data to the workspace. There are no error messages.
% Create a VISA-USB object.
interfaceObj = instrfind('Type', 'visa-usb', 'RsrcName', 'USB0::0x0699::0x036A::C030857::0::INSTR', 'Tag', '');
% Create the VISA-USB object if it does not exist
% otherwise use the object that was found.
if isempty(interfaceObj)
interfaceObj = visa('TEK', 'USB0::0x0699::0x036A::C030857::0::INSTR');
else
fclose(interfaceObj);
interfaceObj = interfaceObj(1);
end
% Create a device object.
deviceObj = icdevice('tektronix_tds2024.mdd', interfaceObj);
% Connect device object to hardware.
connect(deviceObj);
% Execute device object function(s).
groupObj = get(deviceObj, 'Waveform');
groupObj = groupObj(1);
[Y,X] = invoke(groupObj, 'readwaveform', 'channel1');
% Disconnect device object from hardware.
disconnect(deviceObj);

Respuestas (1)

Sean de Wolski
Sean de Wolski el 13 de En. de 2017
Are you passing X, Y out of the function?
function [X,Y] = myOscilloscopeReader()
% What you have above
end
Then calling it:
[X,Y] = myOscilloscopeReader();

Community Treasure Hunt

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

Start Hunting!

Translated by