Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

Change detection with unique callback for multiple inputs?

Hello,
 
I am experimenting with change detection for digital inputs on a PCI-6220 card and the latest version of NI-DAQmx.  I am using LabWindows/CVI ver 7.  So far I have been able to setup change detection for a single digital input.  When this input transitions high a callback function is called.  Now I would like to setup change detection for two or more digital inputs such that a unique callback is called depending on which input transitions high.  Here is my NI-DAQmx task configuration code:
 
// DAQmx Configure Code
DAQmxCreateTask ("", &task_handle1);
  
DAQmxCreateDIChan (task_handle1, "Dev2/port0/line0", "", DAQmx_Val_ChanPerLine);
  
DAQmxCfgChangeDetectionTiming (task_handle1, "Dev2/port0/line0", NULL,
      DAQmx_Val_FiniteSamps, 1);
   
DAQmxRegisterSignalEvent (task_handle1, DAQmx_Val_ChangeDetectionEvent,
      DAQmx_Val_SynchronousEventCallbacks, change_detected1_CB, NULL);
   
   
// DAQmx Configure Code
DAQmxCreateTask ("", &task_handle2);
  
DAQmxCreateDIChan (task_handle2, "Dev2/port0/line1", "", DAQmx_Val_ChanPerLine);
  
DAQmxCfgChangeDetectionTiming (task_handle2, "Dev2/port0/line1", NULL,
      DAQmx_Val_FiniteSamps, 1);
   
DAQmxRegisterSignalEvent (task_handle2, DAQmx_Val_ChangeDetectionEvent,
      DAQmx_Val_SynchronousEventCallbacks, change_detected2_CB, NULL);
  
// DAQmx Start Code
DAQmxStartTask (task_handle1);
DAQmxStartTask (task_handle2);
 
When this executes I get the following error when the StartTask function is called for task_handle2:
"Function DAQmxStartTask: return value = -50103.  The specified resource is reserved.  The operation could not be completed as specified."
 
Like I said, the configure code and start code works fine for a single task but generates the above error when I duplicated it for two tasks.  How do I properly create a unique change detection callback for multiple digital input lines?
 
Thanks for the assistance.
 
0 Kudos
Message 1 of 4
(2,997 Views)
Hi Aaron,

In your post you said that you are trying to make a Change Detection task, but have some sort of logic determine which lines to notify and when.

Unfortunately for your situation, that's not how change detection works.  You can only have one change detection task per M Series board, and when you use that you can only show which lines you want to monitor.  If there is any change on those lines, then it will notice the change and notify your program. 

The reason that you are getting the error is because the resources for change detection have already been employed on the one line, and therefore are reserved and cannot be addressed at the same time by a different task.
0 Kudos
Message 2 of 4
(2,980 Views)

I would like to roll up this topic again.

I have the same problem. I use change detection for multiply lines. The problem is now that I get a conflict with the change detection. I have a square-wave-signal where the change detection gets fired on the rising edge and the falling edge. Now the problem is that I have a stop signal. When I get the signal the same change detection function reacts. Following I have a failure because the two signals overleap. Is there a possibility to separate the to change detections (priority, function, etc.)?

 

Best regards

0 Kudos
Message 3 of 4
(2,396 Views)

When two different digital lines transition pretty much simultaneously, you'll get only one change detection event.  As I recall from a previous discussion on the forums, there's some kind of internal clock used to sync the available instants for a change detection event.  If two changes occur within the same minimum interval, only one change detection can and will be asserted.

 

I do not recall whether the digital values are latched at the instant of change or on the next clock edge after a change.  If the former, your data won't show the 2nd of two near-simultaneous changes.  If the latter, I expect it would.

 

 

-Kevin P

CAUTION! New LabVIEW adopters -- it's too late for me, but you *can* save yourself. The new subscription policy for LabVIEW puts NI's hand in your wallet for the rest of your working life. Are you sure you're *that* dedicated to LabVIEW? (Summary of my reasons in this post, part of a voluminous thread of mostly complaints starting here).
0 Kudos
Message 4 of 4
(2,391 Views)