Code covered by the BSD License  

Highlights from
MATLAB Support Package for Velleman PCSGU250 Oscilloscope + Function Generator

MATLAB Support Package for Velleman PCSGU250 Oscilloscope + Function Generator

by

 

25 Jul 2011 (Updated )

MATLAB library for controlling a Velleman PCSGU250 scope and generator

vellscope.makeLibFile(data, filename)
% vellscope.makeLibFile(data, filename)
%   Makes an arbirary waveform library (.lib) file from a MATLAB vector and
%   stores it in the PCSGU250's lib directory. Takes two arguments. Data is
%   the vector containing the waveform data. The length of this vector is
%   arbitrary, though the PCSGU250 may reject particularly low-resolution
%   waveforms. The vector will be normalized to a (-1 1) range. Note that
%   amplitude and period are determined by the function generator settings,
%   not the library file.
%
%   filename is a filename string for the library file. It should be a
%   standard Windows filename without an extension (ie. 'step', not
%   'step.lib'). Do not include a full file path; the function will
%   automatically store the file in the appropriate location.
%
%   Library files are stored in the lib directory on the main SDK
%   directory. This SDK directory is location in C:\Velleman if setup
%   automatically installed it.

%   MATLAB Support Package for Velleman PCSGU250
%   Version 1.0
%   Copyright 2011 The MathWorks, Inc.

function makeLibFile(data, filename)

if nargin < 2
    nl = char(10);
    msg = ['Syntax: '  nl ...
           '  vellscope.makeLibfile(data, filename); ' nl ...
           '    data is a vector (the waveform to be saved)' nl ...
           '    filename is a string (the name of the .lib file)' nl ...
           'Example: ' nl ...
           '  vellscope.makeLibfile(sin(1:0.1:10), ''mysine''); ' ];
    error(msg);
end

validateattributes(data, {'numeric'}, {'real', 'vector'}, 'makeLibFile', 'data');
validateattributes(filename, {'char'}, {'vector'}, 'makeLibFile', 'filename');

[pathstr,nameroot,ext] = fileparts(filename);
if ~isempty(pathstr)
    error('filename should not include any path information (it should just be ''%s'')', nameroot); 
end

% find out where to save it
if ~ispref('vellscope', 'SDKDir')
    error('You need to run vellscope.setup first');
end
SDKDir = getpref('vellscope', 'SDKDir');
fullfname = fullfile(SDKDir, 'lib', [nameroot '.lib']);


% normalize data to be between -1 and 1. don't change zero level
% the multiplication by 1.05 ensures that we don't hit the extreme value
scale = max(abs(data)) * 1.05;
data = data / scale;

% create the file and save the data
fid = fopen(fullfname, 'wt');
if fid < 0
    error('Unable to create %s\n', fullfname);
end
fprintf(fid, '%6.4f\n', data(:));
fclose(fid);

fprintf('Saved %s\n%d points, scaled down by %.3f\n', fullfname, numel(data), scale);

Contact us