An interface between Matlab and the CED-1401.
"Matced" is an interface that allows Matlab to directly control the CED-1401 data acquisition system.
This allows one to have a powerful front-end computing environment to
process and plot data sampled by the CED. At the same time one can
program the CED-1401 using Matlab's M-files. Together with Matlab's
graphical user interface (uicontrol) one can easily build a complete
windows application using M-files.
The interface is very simple to use. The matced.dll file is a
16-bit dynamic loadable library that allows Matlab to have access to
the commands in the CED. The calls to the different CED functions is
mediated by the matced() function.
The basic call to this function has the format:
output = matced('CED_COMMAND_STRING', [parameters]);
For example, the line
matced('cedOpen');
will open the CED box while something like
r = matced('cedFrom',1000,0);
will return in the variable r a vector of length 1000
containing the values of the first 1000 words in the CED users' memory
space.
All you have to do to be able to use it is to download the matced.dll
file and place in somewhere where matlab can
find it (you may want to modify your MATLABPATH environment variable
to do this). You also need to do the same with the use1401.dll
file.
List of All the Commands:
matced('cedOpen');
It will open the CED and will display a
message on the Matlab console specifying if the command was successful
or if it failed (with the appropriate error code).
matced('cedClose');
It will close the CED and display a message on the Matlab console
specifying if the command was successful or if it failed (with the
appropriate error code).
matced('cedReset');
It will reset the CED and display a message on the Matlab console
specifying if the command was successful or if it failed (with the
appropriate error code).
matced('cedTo1401',size,start,X);
It will transfer the data in the vector X to the memory in the CED
with starting address 'start' and length of 'size' words. The
floating point elements in X must be within the limits of the 12bit
precision in the CED (this is your job to check!) The maximum size of
a vector that can be transfer in one call is 4000. Therefore, to
transfer longer vectors a number of calls is necessary. A simple
Matlab M-file to do this is the following:
function cedTo(size,start,r)
%% cedTo Transfer data to 1401.
%% cedTo(length,start,array)
if(size>4000) %% should we split the data?
l = fix(size/4000);
rest = rem(size,4000);
for(i=0:l) %% send data in 4000 blocks...
if(i~=l)
len = 4000;
else
len = rest; %% send the last piece...
end
addr = start+2*4000*i;
from = 1+4000*i;
to = from+len-1;
matced('cedTo1401',len,addr,r(from:to));
end
else %% we can do it in one call...
matced('cedTo1401',size,start,r);
end
r = matced('cedToHost',size,start);
As you guessed this will transfer an array of length 'size' words
(2*size bytes) starting at address 'start'. The result is stored
in the matlab array 'r'. Again, the maximum length of the array
is 4000. If you need to tranfer longer arrays you need to write
a small M-file as the one above for 'cedTo1401'.
matced('cedLd','cmmd1', ... 'cmmdN'));
You use this line to load commands into the CED. Each command string
is the name of one 1401 command. For example,
matced('cedLd','MEMDAC','ADCMEM'); will load the
MEMDAC and adcmem commands. If the command fails it
returns an index into the string that caused the problem (in the above
example an index of 1 would mean that trying to load MEMDAC
caused the error).
matced('cedSendString','command')
Send the string 'command' to the CED.
This is what one uses to execute commands on the CED.
For example, a matlab sequence like:
cmd = sprintf('ADCMEM,I,2,200000,2000,%d,1,CT,10,10;',in);
matced('cedSendString',cmd);
is setting up a command string 'cmd' with an ADCMEM command
and sending it to the CED.
s = matced('cedGetString')
Get a string from the CED. For example, a useful M-file that I have
to check for errors in the CED is the following:
function err = cedErr
%% cedErr Get the CED error codes
matced('cedSendSTring','ERR;');
s = matced('cedGetString');
[a,b]= strtok(s);
err1 = str2num(a);
err2 = str2num(b);
err = [err1 err2];
This cedErr matlab function will return a 2-dimensional vector err
with the values of e1 and e2. If there is nothing to read in the
buffer the function will return with a timeout.
s = matced('cedGetUserMemorySize');
Returns in the variable s the size (in bytes) of the user memory space.
matced('cedStateOf1401');
Prints a message displaying the state of the 1401.
s = matced('cedStat1401');
This returns the code that one obtains by calling the U14Stat1401(0)
function.
r = matced('cedGetTimeOut');
It returns in r the value of the current timeout setting (usually 180).
matced('cedSetTimeOut',value);
It sets the timeout to 'value'.