09-22-2009 05:43 PM
Hi everyone,
I'm using LabWindows/CVI 9.0 with a NI PCI-6220 MIO and have to test a voltage converter. Due to high output voltage we keep it locked in a drawer. If the drawer is unlocked a switch goes off.
Before I start my test I explicitly check the switch with the following function which works reliably:
int is_drawer_open()
{
// prepare DAQmx error handling
int32 error = 0;
char errBuff[2048]={'\0'};
int32 read = -1;
uInt8 data = 2; // anything positive from 0 or 1
// read Dev3 port 0 and check line 0
DAQmxErrChk (DAQmxCreateTask("RailLatchCheck",&RailLatchCheck));
DAQmxErrChk (DAQmxCreateDIChan(RailLatchCheck,"Dev3/port0/line0","",DAQmx_Val_ChanPerLine));
DAQmxErrChk (DAQmxStartTask(RailLatchCheck));
DAQmxErrChk (DAQmxReadDigitalU8(RailLatchCheck,1,10.0,DAQmx_Val_GroupByChannel,&data,1,&read,NULL));
DAQmxStopTask(RailLatchCheck);
DAQmxClearTask(RailLatchCheck);
RailLatchCheck = 0;
if(data == 1){
return -1;
}else{
return 0;
}
Error:
if( DAQmxFailed(error) ){
DAQmxGetExtendedErrorInfo(errBuff,2048);
MessagePopup("DAQmx Error",errBuff);
}
return 0;
}
To efficiently monitor the switch I checked out the "Read Dig Chan-Change Detection Event"-Example. However I get static and my ChangeDetectionCallback goes off several times and if I check the actual bit, checking data says the drawer was opened while it's actually still closed:
int CVICALLBACK ChangeDetectionCallback(TaskHandle taskHandle, int32 signalID, void *callbackData)
{
int32 error=0;
uInt8 data=2;
int32 numRead;
int32 bytesPerSamp;
int i=0;
char errBuff[2048]={'\0'};
Delay(1);
if( gTaskHandle ) {
DAQmxErrChk (DAQmxReadDigitalU8(taskHandle,1,10.0,DAQmx_Val_GroupByChannel,&data,1,&numRead,NULL));
}
if(data == 1)
{
DRAWER_OPEN = -1;
setUBatt0V();
write_port(SETTING28);
}
Error:
if( DAQmxFailed(error) ){
DAQmxGetExtendedErrorInfo(errBuff,2048);
MessagePopup("DAQmx Error",errBuff);
}
return 0;
}
I suppose that the sample is dirty due to the static and would like to know if there is a way to delay the measurement of what DAQmxReadDigitalU8 actually reads into data? I had also sporadically gotten an error -200284. Explicit checks with is_drawer_open() work reliable, however not as instantly as I would expect the ChangeDetectionCallback to work. Or is there maybe a way to monitor a digital line that is more appropriate than DAQmxCfgChangeDetectionTiming?
Appreciate your help!
Best regards
Markus
09-22-2009 08:54 PM
whitenoiz wrote:Hi everyone,
I'm using LabWindows/CVI 9.0 with a .............
Then you may want to post to the LabWindows LabWindows board.
09-23-2009 02:27 AM