LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

LABWINDOWS/CVI read digital input

Hello, I'm new to this software, and I still have some basic questions.

I want to perform a simple read of a Digital Input, but my code is not working.

Can you help me?

Here's the code below.

Thank you in advance.



//----------------------------Defined in Header file

 
#define Nest1_Overcurrent PXI_6289_SLOT"/port0/line26" //TC 2023/07/07  
#define Nest2_Overcurrent PXI_6289_SLOT"/port0/line27" //TC 2023/07/07  
#define Nest3_Overcurrent PXI_6289_SLOT"/port0/line11" //TC 2023/07/07  
#define Nest4_Overcurrent PXI_6289_SLOT"/port0/line15" //TC 2023/07/07  
 

//----------------------------Function to read Digital input

 void FC_NEST_Overcurrent(int nestIndex)//TC 2023/07/07 OVERCURRENT Detected
{
 #define DAQmxErrChk(functionCall) 
 
int32 error=0;
TaskHandle taskHandle=0;
uInt8 data[100];
char errBuff[2048]={'\0'};
int32 i;
int32 read,bytesPerSamp;
 
/*********************************************/
// DAQmx Configure Code
/*********************************************/
DAQmxErrChk (DAQmxCreateTask("",&taskHandle));
//DAQmxErrChk (DAQmxCreateDIChan(taskHandle,"PXI_6289_SLOT /port0/line26","",DAQmx_Val_ChanPerLine));
DAQmxErrChk (DAQmxCreateDIChan(taskHandle,Nest1_Overcurrent,"",DAQmx_Val_ChanPerLine)); 
 
/*********************************************/
// DAQmx Start Code
/*********************************************/
DAQmxErrChk (DAQmxStartTask(taskHandle));
 
/*********************************************/
// DAQmx Read Code
/*********************************************/
DAQmxErrChk (DAQmxReadDigitalLines(taskHandle,1,10.0,DAQmx_Val_GroupByChannel,data,100,&read,&bytesPerSamp,NULL));
 
// assuming 1 channels acquired
for(i=0;i<1;++i)
printf("Data acquired, channel %d: 0x%X\n",i,data[i]);
 
}

 

 

 

 

 

0 Kudos
Message 1 of 2
(1,034 Views)

I would double check the channel definition: that quotation mark in the middle of the channel name seems not correct.

 

The golden rule in these cases is not to limit yourself to "it does not work" but go a bit further verifying the return code from the functions; I see you are extensively using DAQmxErrChk macro: in case of error this macro jumps to Error: label where you can decode 'error' variable using some code like this (taken from a sample program shipped with DAQMx):

 

if( DAQmxFailed(error) ) {
	DAQmxGetExtendedErrorInfo(errBuff,2048);
	MessagePopup("DAQmx Error",errBuff);
}

 

 



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 2 of 2
(993 Views)