LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

DAQmx Read DIO and then CHANGEDETECTION

Hi,
 
I want to read a Digital channel and then detect changes on the same channel. I can make this operations separately but I want to make it in one program.
 
this is the first part. It works separately.
DAQmxCreateTask("",&taskHandle);
DAQmxCreateDIChan(taskHandle,chan,"",DAQmx_Val_ChanForAllLines);
DAQmxStartTask(taskHandle);
DAQmxReadDigitalLines(taskHandle,1,10.0,DAQmx_Val_GroupByChannel,data,100,&read,&bytesPerSamp,NULL);
DAQmxStopTask(taskHandle);
DAQmxClearTask(taskHandle);
 
this is the second part.It works separately.
DAQmxCreateTask("",&gTaskHandle);
DAQmxCreateDIChan(gTaskHandle,chan,"",DAQmx_Val_ChanPerLine);
DAQmxCfgChangeDetectionTiming(gTaskHandle,risingEdgeChan,fallingEdgeChan,DAQmx_Val_ContSamps,1);
DAQmxRegisterSignalEvent(gTaskHandle,DAQmx_Val_ChangeDetectionEvent,DAQmx_Val_SynchronousEventCallbacks,ChangeDetectionCallback,NULL);
DAQmxGetTaskAttribute(gTaskHandle,DAQmx_Task_NumChans,&gNumLines);
for(;i<gNumLines;cachedData[i++]=-1);
DAQmxStartTask(gTaskHandle);
and somewhere is the ChangeDetectionCallback;
 
Problem is when I perform the first part then the second part doesn't works. No change detection.
 
Can somebody Help my?
0 Kudos
Message 1 of 10
(5,078 Views)

Hi,

When you say that the "second part doesn't work," are you getting an error, or does the program not detect any change?  Are you attempting to read on all of the digital lines in the first task, then attempting to use change detection on one of the lines?

You can try to use some breakpoints to make sure you are executing the code for the second task.  You could try to insert a delay between the two tasks to make sure that it’s not an issue with timing. 

Keep me posted on your progress.





Best Regards

Hani R.
Applications Engineer
National Instruments
0 Kudos
Message 2 of 10
(5,040 Views)

Hi,

the program doesn't detect any change. In the first task I read Dev1/port0/line0:7 and in the second task I read the same Dev1/port0/line0:7.

I tried to use some Delay() between the tasks but it didn't work.

When I don't use the first part (/*     first part */) then the changedetection is functionaly but I need to know what is on the port when the program starts.

Best Regards

Martin K.

0 Kudos
Message 3 of 10
(5,032 Views)
Hi Martin,

We may be able to help you better if you provide some details about your application (what you are trying to do).  I would also like to know what hardware and driver you are using.  What happens when you run the example program "..Documents and Settings\All Users\Documents\National Instruments\NI-DAQ\Examples\DAQmx ANSI C\Digital\Read Values\Read Dig Chan-Change Detection,"  instead of running the "second part" of your program? 




Best Regards

Hani R.
Applications Engineer
National Instruments
0 Kudos
Message 4 of 10
(5,003 Views)

Hi Hani,

1 - I have one device(filter) and I need 3 ports for set-up and one port for reading info from the device. The ports for set-up are functional. I have problems with the port for reading. I need to know the init state on the port and then check the change.

2 - I use the NI6528, DAQmx8.1 and Labwindows CVI 7.1

3 - My program is created from the examples. The example is functional. I tried to run the ReadDigChan example and then the Read Dig Chan-Change Detection example. Both were functional. But I need the information from the ReadDigChan in the Read Dig Chan-Change Detection.

I made one program for reading. This program reads the state and saves it in a file. In my second program I call the reading program (LaunchExecutable)and then I read the state from the file. It works but I'm not sure that this is the righ way how to use the NI products.

I will know why doesn't work it in one program.

Best Regards.

Martin K.

0 Kudos
Message 5 of 10
(4,982 Views)

Hi UDS

Why do you want to read and then detect changes? Why not simple detect changes? Detecting the changes is basically reading the channel using the rising or falling edge of any of the specified channel as a clock. The change detection timing captures samples from digital physical channels when NI-DAQmx detects a change—a rising edge, a falling edge, or both rising and falling edges—on one or more digital lines or ports. Change detection timing reduces the digital data an application has to process. The ReadDigChan-ChangeDetection.c example makes a read every time there is a change in of the lines I might be misunderstanding you problem but why does this not help?

I tried your code and I was able to do the "ReadDigChan" close the task and then run the "Read Dig Chan-Change Detection" in the same code so I was not able to replicate your issue.

I hope it helps

Jaime Hoffiz
National Instruments
Product Expert
0 Kudos
Message 6 of 10
(4,948 Views)

Hi Jaime,

I need to know the init state of my device (ReadDigChan) and then check the operation of my device(ReadDigChan-ChangeDetection). I send you part of my application in attachment. Problem is in the CVICALLBACK CmbfStart. The part in /* */ is responsible for ReadDigChan. Now works the ChangeDetection. But when you delete the /* */ then works only ReadDigChan nothing else.

Can you try my application on you computer? Maybe you can find my mistake. Thanks

Best Regards

Martin K.

0 Kudos
Message 7 of 10
(4,931 Views)

Hi UDS,

I’m still investigation the reason why the “Read Change Detection vi” does not work if the “Read Chan vi” is run first in the same CVI code. I have two works around: first if you take your code and comment out the lines: DAQmxErrChk (DAQmxStartTask (taskHandle)), DAQmxStopTask (taskHandle) and DAQmxClearTask (taskHandle); you will be able to read the first value and then detect the changes.  (See picture attach).

Second, since your clock is been controlled by the changes on the lines the only line you won’t be able to read as it is; is the value of the line where the change was detected, but since the value is latch after the change is detected the value is always going to be the inverse of what you read, this will be true in the case that you are detecting changes in rising and falling edges.

I hope it helps



Message Edited by Jaime F on 11-05-2007 01:10 PM
Jaime Hoffiz
National Instruments
Product Expert
0 Kudos
Message 8 of 10
(4,886 Views)

Hi Jaime,

thank you for your help. I took the code out and it works.

Can you give my a short explanation about my problem?

Once more Thanks.

Best regards.

Martin

0 Kudos
Message 9 of 10
(4,838 Views)

Hi UDS,

I think it is a bug and the previous code should have worked. If I found the information why I'll make sure to post it.

Regards

 

Jaime Hoffiz
National Instruments
Product Expert
0 Kudos
Message 10 of 10
(4,814 Views)