Code covered by the BSD License  

Highlights from
MATLAB GUI Example for Agilent N8241A Arbitrary Waveform Generator

image thumbnail
agilentN8241A(visaRsrcString)
function functionStruct = agilentN8241A(visaRsrcString)

deviceObj = icdevice('AGN6030A',visaRsrcString);
connect(deviceObj);
functionStruct.initialize = @initializeArb;
functionStruct.setWaveform = @setWaveform;
functionStruct.startPlay = @startPlay;
functionStruct.stopPlay = @stopPlay;
functionStruct.close = @close;
functionStruct.generateTestWave = @generateSineWave;
waveformHandle = [];
channel1 = '1';

    function initializeArb

        % Set the mode to arbitrary
        % Valid values are:
        %           1 - waveform output in normal mode.
        %           2 - enables the sequencer mode.
        %           1001 - enables the advance sequencer mode.
        %                   Note:  Waveforms must be stored prior to enabling this
        %                   mode.  Once enabled, sequence may be:  created, stored,
        %                   and played.
        outputMode = 1;
        invoke(deviceObj.Configuration,'configureoutputmode',outputMode);

        % Configure the output as single-ended
        %       Valid values are:
        %           0 - selects passive differential output configuration.
        %           1 - selects passive single-ended output configuration.
        %           2 - selects amplified (active) single-ended output configuration.
        %       If chan is specified, only that channel is effected.
        %       If chan is not specified, both channels will be effected.
        outputType = 1;
        filterEnabled = 1;
        filterBandwith = 250e6;
        invoke(deviceObj.Configuration,'configureoutputconfiguration',channel1,outputType,filterEnabled,filterBandwith);

        % Configure operation mode
        %       Valid values are:
        %           0 - enables the continuous mode.
        %           1 - enables burst mode (external trigger required).
        operationMode = 0;
        invoke(deviceObj.Configuration,'configureoperationmode',channel1,operationMode);

        % Enable the instrument output
        %       Valid values are:
        %           true - to enable the output.
        %           false - to disable the output.
        %       If chan is specified, only that channel is effected.
        %       If chan is not specified, both channels will be effected.
        invoke(deviceObj.Configuration,'configureoutputenabled',channel1,true);

    end

    function setWaveform(data)
        
        invoke(deviceObj.Actionstatus,'abortgeneration');
        if ~isempty(waveformHandle)
            invoke(deviceObj.Arbitrarywaveform,'cleararbwaveform',waveformHandle);
        end
        waveformHandle = invoke(deviceObj.Arbitrarywaveform,'createarbwaveform',numel(data),data);

        gain = 0.25;
        offset = 0.0;
        invoke(deviceObj.Arbitrarywaveform,'configurearbwaveform',channel1,waveformHandle,gain,offset);

    end

    function startPlay
        invoke(deviceObj.Actionstatus,'initiategeneration');
    end

    function stopPlay
        invoke(deviceObj.Actionstatus,'abortgeneration');
    end

    function close
        invoke(deviceObj.Actionstatus,'abortgeneration');

        % Disable the instrument output
        invoke(deviceObj.Configuration,'configureoutputenabled',channel1,false);

        if ~isempty(waveformHandle)
            invoke(deviceObj.Arbitrarywaveform,'cleararbwaveform',waveformHandle);
        end

        % Disconnect the instrument
        disconnect(deviceObj);
        
        % Clear the variable
        delete(deviceObj);
    end

    function generateSineWave
        sampleRate = 1250e6;
        frequency = 100e6;
        time = 0:3199;
        signal = sin(2*pi*(frequency/sampleRate)*time);
        setWaveform(signal);
    end
   
end

Contact us at files@mathworks.com