12-01-2009 01:28 PM - edited 12-01-2009 01:37 PM
Hi,
i'm having a problem reading the digital input functions from NI-DAQmx in MATLAB (using calllib functions from the DLL).
I use the NI USB-6251 BNC device.
So, i want to read 4 digital pins (0..3) and stop reading until one of these pins are set HIGH.
To do this, i'm going this way:
1. create DI task
2. create DI channel
3. in a while-loop, use the DAQmxReadDigitalU32 function to read the digital values.
but that doesn't work. i also tried triggering and timing, but it's always the same thing:
I don't get any values (just zeroes), even if all pins have a 5V input. The pvalues1 variable also returns 0, which means that no values have been read.
Digital output and analog input/output works fine!
Did i make a mistake in the source code? I couldn't find any useful information on the NI homepage or on google about digital input in Matlab or ANSI C.
can anybody help me?
Thanks!
Jan P.
Here's my source code:
function [ReadHandle, values] = NI_Start_DITask(values)
DAQmx_Val_ChanForAllLines = 1;
DAQmx_Val_FiniteSamps = 10178;
DAQmx_Val_GroupByChannel = 0;
DAQmx_Val_ChanPerLine = 0;
DAQmx_Val_Rising=int32(10280);
DAQmx_Val_Falling=int32(10171);
DIPtr=libpointer('uint32Ptr', 0);
%int32 DAQmxCreateDIChan (TaskHandle taskHandle, const char lines[], const
%char nameToAssignToLines[], int32 lineGrouping);
[a,b,DIPtr] = calllib('myni','DAQmxCreateTask','',DIPtr); % create task
DIPtr=libpointer('uint32Ptr',DIPtr);
b = calllib('myni','DAQmxCreateDIChan',get(DIPtr,'Value'),'Dev1/port0/line0:3','', ...
DAQmx_Val_ChanForAllLines); % create DI channeld = calllib('myni','DAQmxStartTask',DIPtr);
ReadHandle = DIPtr;
and then in the main function
...
values = zeros(1,1000);
p1=0;
vptr=libpointer('uint32Ptr', values);
pvalues1 = libpointer('int32Ptr',p1);
[ReadHandle, values] = NI_Start_DITask(values); % open function abovepv = libpointer('uint32Ptr', 0);
while 1
calllib('myni','DAQmxReadDigitalU32',ReadHandle,10,10,0,values,4000,...
pvalues1,0);
p1
valuesif pv.Value==1
break
elseif any(values)
break
end
drawnow
end
NI_stopAndClearTask(ReadHandle);
NI_ResetHW('Dev1');
12-02-2009 09:18 AM
i forgot to mention that i get the error code -200088 when i create the DI channel.
i tried adding the "DAQmxIsTaskDone" between creating the task and creating the DI channel, but that function returns the same error code,
even if i use a zero-pointer when opening the DAQmxIsTaskDone function.
12-02-2009 11:34 AM
01-12-2010 07:47 AM
04-26-2010 05:00 PM
04-27-2010 04:19 PM
I finally got it working - no more error -200088 for me!
I had to pass the initial task handle as empty - uint32([]). This is different from code here. This is the code that worked for me:
taskhDO0 = [];
[err,b,taskhDO0] = calllib('myni','DAQmxCreateTask','DO0',uint32(taskhDO0))
[err,b,c,d] = calllib('myni','DAQmxCreateDOChan',taskhDO0,'Dev1/port0/line0','',DAQmx_Val_ChanPerLine)
I am using matlab 7.8.0 (R2009a) on XP.
06-01-2010 07:16 PM - edited 06-01-2010 07:17 PM
nathancolorado wrote:I finally got it working - no more error -200088 for me!
I had to pass the initial task handle as empty - uint32([]). This is different from code here. This is the code that worked for me:
taskhDO0 = [];
[err,b,taskhDO0] = calllib('myni','DAQmxCreateTask','DO0',uint32(taskhDO0))
[err,b,c,d] = calllib('myni','DAQmxCreateDOChan',taskhDO0,'Dev1/port0/line0','',DAQmx_Val_ChanPerLine)
I am using matlab 7.8.0 (R2009a) on XP.
Odd, when I tried that I got error -200604 ("NULL pointer was passed for a required parameter.") when creating the task. I'm running MATLAB R2009b 32-bit on Win 7 32-bit, NI-DAQmx 9.1.0.
06-01-2010 07:20 PM
06-01-2010 07:45 PM
nathancolorado wrote:
The code that works for me is posted here.
Thanks for the reply! Using that code, I get:
??? Error using ==> DAQmxCheckError at 24
DAQmx error - NULL pointer was passed for a required parameter.
Error in ==> DAQmxCreateDOChan at 28
DAQmxCheckError(lib,err);
06-01-2010 07:58 PM
nathancolorado wrote:
The code that works for me is posted here.
Also, which version of NI-DAQmx are you using? Thanks!