01-31-2009 10:20 AM
I am using the PCI 6534 to do a buffered digital output, and want to start that output using an external digital trigger.
Using Matlab, calling NIDAQmx C library functions, I am able to load data to the buffer, and then output the data after calling the DAQmxStartTask function. However, I now want to use a start trigger instead of just calling DAQmxStartTask to start the data output. Unfortunately, I keep getting an error,
DAQmxErrorInvalidTerm_Routing (-89129)
when I call the DAQmxStartTask function. Below is my test code. Note that if the 'DAQmxCfgDigEdgeStartTrig' function is not used, this code works fine; data is written to buffer and output when the DAQmxStartTask function is called. I must be doing something wrong with implementing the 'DAQmxCfgDigEdgeStartTrig' function. Any suggestions are much appreciated!
%% load NIDAQmx function library and give it alias 'myni'
funclist = loadlibrary('nicaiu.dll','NIDAQmx.h','alias','myni')
%input data is already loaded into workspace
% g_stimulus_matrix{ch}{stim,2}={SR, y}; %sample rate and sample data
CIch = 1;inputDATA = g_stimulus_matrix{1}{CIch,2}{2};
%% Set sampling output rate (Hz)
rate = g_stimulus_matrix{1}{CIch,2}{1} ;
%% define a task handle
taskh1 = uint32(1);
[errCode,taskName,DOtaskhandle] = calllib('myni','DAQmxCreateTask','',taskh1)
%% Paramater values set according to NIDAQmx.h file
DAQmx_Val_ChanForAllLines=int32(1);
DAQmx_Val_Rising = int32(10280);
DAQmx_Val_FiniteSamps = int32(10178);
DAQmx_Val_GroupByChannel = uint32(0);
%% set total number of samples to output. should be length of data array
sampsPerChanToAcquire = uint64(length(inputDATA)); %% if output is uInt8, must be multiple of 4
sperchan = int32(sampsPerChanToAcquire); %% should be same, but different form%% data format is binary number uInt32. Output will be to a combination of
%% 4 ports, (32 lines)
data = uint32(inputDATA);
[errCode,lineNames,nameoflines] = calllib('myni','DAQmxCreateDOChan',uint32(DOtaskhandle),['Dev1/port0:3'],'',DAQmx_Val_ChanForAllLines)[errCode,clockType] = calllib('myni','DAQmxCfgSampClkTiming',uint32(DOtaskhandle),'OnboardClock',rate,DAQmx_Val_Rising,DAQmx_Val_FiniteSamps,sampsPerChanToAcquire)
numSampsPerChannelWritten = libpointer('int32Ptr',0)
reserved = libpointer('uint32Ptr',[])data2 = libpointer(
'uint32Ptr',data)% int32 DAQmxCfgDigEdgeStartTrig (TaskHandle taskHandle, const char triggerSource[], int32 triggerEdge);
[errCode zz] = calllib('myni','DAQmxCfgDigEdgeStartTrig',uint32(DOtaskhandle), ['Dev1/PFI6'], DAQmx_Val_Rising)errCode
%% write data to the buffer of the DIO card.
[errCode,writeArray,numSampsPerChan,zz] = calllib('myni','DAQmxWriteDigitalU32',uint32(DOtaskhandle),sperchan,0,double(10),DAQmx_Val_GroupByChannel,data2,numSampsPerChannelWritten,reserved);
[errCode] = calllib('myni','DAQmxStartTask',uint32(DOtaskhandle))
01-31-2009 11:03 AM
Shortly after posting, I solved this issue myself
it seems the ['Dev1/PFI6'], in th e following code:
[errCode zz] = calllib('myni','DAQmxCfgDigEdgeStartTrig',uint32(DOtaskhandle), ['Dev1/PFI6'], DAQmx_Val_Rising)
just needed to be changed to ['/Dev1/PFI6']
stupid mistake.
just as a note, for people who use matlab for controlling devices, this thread is most helpful:
http://forums.ni.com/ni/board/message?board.id=250&thread.id=10165&view=by_date_ascending&page=1