10-13-2009 07:37 AM
Hi everybody,
For my application, I have to do a job in case of change on a line, by interrupt, but i have also to read (static mode) the status of these line, on demand...
What is wrong in my code ?
My initalisation is done like this :
DAQmxCreateTask("Task",&TaskHandle)
DAQmxCreateDIChan (TaskHandle, "/dev1/port0", "", DAQmx_Val_ChanForAllLines);
DAQmxCfgChangeDetectionTiming (TaskHandle, "/dev1/port0"," /dev1/port0", DAQmx_Val_ContSamps, 1);
DAQmxRegisterSignalEvent (TaskHandle, DAQmx_Val_ChangeDetectionEvent, 0, ChangeDetectedCallBack, NULL);
DAQmxStartTask (TaskHandle);
The interrupt function fire successfully in case of change... Correct line value is read... no problem here
The problem is, for my application, i have also to read, from another part of my software, completely asynchronously, the value for these line :
To do it, i use something like that :
uInt8 Data = 0;
DAQmxReadDigitalU8 (TaskHandle, DAQmx_Val_Auto, 10.0, DAQmx_Val_GroupByChannel, &Data, 1,&NbElementRead, 0);
Now, inside the interrupt callback function, i read the correct value, (fairly logical because the change event was the condition to trig a sample)...
But from another piece of code, I will ask for a reading but change hasn't occured and reading not trigged. Then, i will read always 0 (i'm surprised to don't receive an error such: Buffer empty... anyway...)
How i could manage to fix this trouble ?
Tanks in advance
Damien
10-15-2009 06:50 AM
Hello Damien,
The ReadDigitalU8 function expects an array to get the points, otherwise you can use the ReadDigitalScalar if you want to get only one value.
The DAQmx ReadDigital for the change detection task waits for change to
occur to fetch the points. If you want to simply read the port, you
would need another task creation. However, you cannot have both Change
detection and on demand DI read tasks on the same port at the same
time.
Regarding your application, you might consider writing the result of your change detection task's reading in a variable so as to read it from another program. Since the change detection gives you the value of the port the last time there was a change on it, reading the port should give the same values as reading the last change detection acquisition.
I hope this help
Have a nice day,
Rémi M.
National Instruments France
>> Les présentations NIDays 2010 déjà disponibles au téléchargement !
01-14-2010 02:04 AM
Hi
I have Same trouble.
My code here.
int32 CVICALLBACK DIChangeDetection(TaskHandle taskHandle, int32 signalID, void *callbackData) { int32 error = 0, nSample = 0, numRead = 0, i; if(!_hTaskNI_DAQ_DI) return 0; DAQmxErrChk (DAQmxReadDigitalLines(_hTaskNI_DAQ_DI,1,2.0,DAQmx_Val_GroupByScanNumber,_dataDIChannels,32,&numRead,NULL,NULL)); Error: return 0; } In Main { ...... (devName = DEV1) sprintf(buf,"%s/port0/line2:11",devName); DAQmxErrChk (DAQmxCreateTask("",&_hTaskNI_DAQ_DI)); DAQmxErrChk (DAQmxCreateDIChan(_hTaskNI_DAQ_DI,buf,"",DAQmx_Val_ChanPerLine)); DAQmxErrChk (DAQmxCfgChangeDetectionTiming(_hTaskNI_DAQ_DI, buf, buf,DAQmx_Val_ContSamps,1)); DAQmxErrChk (DAQmxRegisterSignalEvent(_hTaskNI_DAQ_DI,DAQmx_Val_ChangeDetectionEvent,0,DIChangeDetection,NULL)); ... }
DI changeDetection was fired but when I connect 10 signal to line 2:11 in the same time. DI Change detection event didn't fire after about 60000 time ( once signal occur mycounter += 1;). Can U show me what happend. (I think it seem do not regconize the raising or falling edge after amount of event. Other task in my Application is still ok as reading ai channel)
I Use DAQ M series 6259. Frequence of signal is 100Hz.