JigMasta
2008-04-21 10:10:07 UTC
Hi there,
I'm trying to create a digital output with Matlab. The output of the code doesn't report any errors, but there are no signals on any pins. Before running the programm, pins are set as hight, after running the programm, the lines of the channel, which has been created ('Dev1/port1/line0:7') are set as 'low'. So I'm sure that the channel has been created, but I don't know whats going wrong, when I'm trying to WriteDigitalLines. Here's the code....anybody any clue?
clear all
close all
clear global
if ~libisloaded('nicaiu') % checks if library is loaded
loadlibrary('nicaiu.dll', 'NIDAQmx.h', 'mfilename', 'temp')
end
DAQmx_Val_ChanForAllLines=int32(0);
autoStart = uint32(1);
timeout = double(10);
dataLayout = uint32(0);
% writeArray = [1,0,0,1,1,0,0,1];
read=libpointer('int32Ptr',0);
reserved=libpointer('uint32Ptr',[]);
numSampsPerChannelWritten=libpointer('int32Ptr',0);
numSampsPerChan=int32(0);
TaskLoad=0;
if TaskLoad
taskh1=0;
calllib('nicaiu', 'DAQmxLoadTask', 'SpeakerSteuer',taskh1);
else
taskh1=libpointer('uint32Ptr',0);
taskname='SpeakerSteuer';
[TaskCreated TaskName CreatePointer]=calllib('nicaiu', 'DAQmxCreateTask',taskname,taskh1); % create Task taskh1
taskh1=libpointer('uint32Ptr',taskh1);
[ChanCreated lines nameToAssignToLines]=calllib('nicaiu', 'DAQmxCreateDOChan',get(taskh1,'Value'),'Dev1/port1/line0:7', '',DAQmx_Val_ChanForAllLines)
%%int32 DAQmxCreateAIVoltageChan (TaskHandle taskHandle, const char physicalChannel[], const char nameToAssignToChannel[], int32 terminalConfig, float64 minVal, float64 maxVal, int32 units, const char customScaleName[]);
end
StartTask = calllib('nicaiu', 'DAQmxStartTask',get(taskh1,'Value'));
[WriteDigital Data SampsChan ReserPTR] = calllib('nicaiu', 'DAQmxWriteDigitalLines', get(taskh1,'Value'), numSampsPerChan, autoStart, timeout, uint32(0), uint8(255) , numSampsPerChannelWritten, reserved)
%[y,x,c,v]=calllib('lib', function, taskHandle, int32 numSampsPerChan,bool32 autoStart, float64 timeout, bool32 dataLayout, uInt8 writeArray[],int32 *sampsPerChanWritten, bool32 *reserved)
StopTask = calllib('nicaiu', 'DAQmxStopTask',get(taskh1,'Value'))
ClearTask =calllib('nicaiu', 'DAQmxClearTask',get(taskh1,'Value'))
% unloadlibrary 'nicaiu'; % unload library
I'm trying to create a digital output with Matlab. The output of the code doesn't report any errors, but there are no signals on any pins. Before running the programm, pins are set as hight, after running the programm, the lines of the channel, which has been created ('Dev1/port1/line0:7') are set as 'low'. So I'm sure that the channel has been created, but I don't know whats going wrong, when I'm trying to WriteDigitalLines. Here's the code....anybody any clue?
clear all
close all
clear global
if ~libisloaded('nicaiu') % checks if library is loaded
loadlibrary('nicaiu.dll', 'NIDAQmx.h', 'mfilename', 'temp')
end
DAQmx_Val_ChanForAllLines=int32(0);
autoStart = uint32(1);
timeout = double(10);
dataLayout = uint32(0);
% writeArray = [1,0,0,1,1,0,0,1];
read=libpointer('int32Ptr',0);
reserved=libpointer('uint32Ptr',[]);
numSampsPerChannelWritten=libpointer('int32Ptr',0);
numSampsPerChan=int32(0);
TaskLoad=0;
if TaskLoad
taskh1=0;
calllib('nicaiu', 'DAQmxLoadTask', 'SpeakerSteuer',taskh1);
else
taskh1=libpointer('uint32Ptr',0);
taskname='SpeakerSteuer';
[TaskCreated TaskName CreatePointer]=calllib('nicaiu', 'DAQmxCreateTask',taskname,taskh1); % create Task taskh1
taskh1=libpointer('uint32Ptr',taskh1);
[ChanCreated lines nameToAssignToLines]=calllib('nicaiu', 'DAQmxCreateDOChan',get(taskh1,'Value'),'Dev1/port1/line0:7', '',DAQmx_Val_ChanForAllLines)
%%int32 DAQmxCreateAIVoltageChan (TaskHandle taskHandle, const char physicalChannel[], const char nameToAssignToChannel[], int32 terminalConfig, float64 minVal, float64 maxVal, int32 units, const char customScaleName[]);
end
StartTask = calllib('nicaiu', 'DAQmxStartTask',get(taskh1,'Value'));
[WriteDigital Data SampsChan ReserPTR] = calllib('nicaiu', 'DAQmxWriteDigitalLines', get(taskh1,'Value'), numSampsPerChan, autoStart, timeout, uint32(0), uint8(255) , numSampsPerChannelWritten, reserved)
%[y,x,c,v]=calllib('lib', function, taskHandle, int32 numSampsPerChan,bool32 autoStart, float64 timeout, bool32 dataLayout, uInt8 writeArray[],int32 *sampsPerChanWritten, bool32 *reserved)
StopTask = calllib('nicaiu', 'DAQmxStopTask',get(taskh1,'Value'))
ClearTask =calllib('nicaiu', 'DAQmxClearTask',get(taskh1,'Value'))
% unloadlibrary 'nicaiu'; % unload library