From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.
We appreciate your patience as we improve our online experience.
From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.
We appreciate your patience as we improve our online experience.
08-26-2014 09:06 PM
I'm writing an application in C on Windows 7, using the DAQmx 9.6 API and the USB-6509 device. The digital input is configured with change detection:
DAQmxErrChk (DAQmxCreateTask("",&taskHandle_NI_R));
DAQmxErrChk (DAQmxCreateDIChan(taskHandle_NI_R, deviceStringFull,"",DAQmx_Val_ChanPerLine));
DAQmxErrChk (DAQmxCfgChangeDetectionTiming(taskHandle_NI_R,deviceStringFull, deviceStringFull,DAQmx_Val_ContSamps,1));
DAQmxErrChk (DAQmxStartTask(taskHandle_NI_R));
while(1){
DAQmxErrChk (DAQmxReadDigitalLines (taskHandle_NI_R,1,-1,DAQmx_Val_GroupByScanNumber,data_NI_R,1,&numRead_NI_R,&bytesPerSamp_NI_R,NULL));
//some other code
}
But the pattern of signals that I am reading from one device follows this pattern: 001001001. I would like to know why the method DAQmxReadDigitalLines reads the second 0 on this input line. I thought it was only supposed to read the line when a change in state occurred and block otherwise.
Thanks,
Danielle
08-27-2014 11:37 AM
Hello Danielle,
The way you currently have this set up with a while(1), your code is just going to read continuously. That said, your task should only acquire a sample during a change.
From what I understand, you are looking to get an output that looks something like this: 0101010101, reflecting the change in state. I think what may be happening instead is that you are reading an sample from your port larger than the portion you are checking for a change.
However, without knowing what variables you are using, it's difficult to tell exactly what you've input into your functions.
I think the next step is to define the variables you've used.
Also, you might refer to these links for more information on what you're trying to do:
Digital Change Detection in NI DAQmx
http://www.ni.com/white-paper/4102/en/
DAQmxCfgChangeDetectionTiming
http://zone.ni.com/reference/en-XX/help/370471W-01/daqmxcfunc/daqmxcfgchangedetectiontiming/
DAQmxReadDigitalLines
http://zone.ni.com/reference/en-XX/help/370471W-01/daqmxcfunc/daqmxreaddigitallines/
Best wishes!
08-30-2014 03:50 AM
Hi Amanda,
Thanks for your answer. Here's my variables
TaskHandle taskHandle_NI_R=0;
uInt8 data_NI_R[1];
int32 numRead_NI_R;
int32 bytesPerSamp_NI_R;
deviceStringFull is a string created dynamically to represent a single line ie "Dev4/port2/line7"
(In future the program will be reading from more than 1 line, but right here I am just trying to understand the behavior of change detection with one line.)
I have been changing the method DAQmxCfgChangeDetectionTiming so that it is configured only for the rising edge change detection:
DAQmxErrChk (DAQmxCfgChangeDetectionTiming(taskHandle_NI_R,deviceStringFull,"",DAQmx_Val_ContSamps,1));
This does give me the pattern 010101... but now, since it is configured to look for the changes that are rising edges, why is it reading any zeros? Wouldn't it now read 111.. only reading after it detects a positive edge?
Thanks again,
Danielle
09-02-2014 06:12 PM
Hello Danielle,
It appears you have set up the timing correctly. The problem might instead be in your DAQmxReadDigitalLines function. Can you please define the variables listed there as well?
09-03-2014 04:00 AM
DAQmxErrChk (DAQmxReadDigitalLines
(taskHandle_NI_R,1,-1,DAQmx_Val_GroupByScanNumber,data_NI_R,1,&numRead_NI_R,&bytesPerSamp_NI_R,NULL));
taskHandle_NI_R is the name of the task
data_NI_R is the uInt8 array of size 1 mentioned above. I did not initialize it in this code, but later have initialized it to 0.
Though this does not seem to make a difference as initial value is replaced by data read in.
output vars are same ones mentioned above
int32 numRead_NI_R;
int32 bytesPerSamp_NI_R
Best,
Danielle
09-04-2014 12:15 PM
Hi Danielle,
You are right. Theoretically, you should be seeing 1111... with everything properly set-up. I think if you've checked both your timing and read methods, you might also try checking that your DAQmxCreateDIChan is properly set-up within your task. This could also be leading to the unexpected extra 0s.