10-10-2014 07:24 AM - edited 10-10-2014 07:28 AM
We have a NI PXIe-6535 module. We want to monitor all 32 DIO lines as inputs in a single Task() using the ConfigureChangeDetection technique to receive a callback whenever a value changes. We started by modifying the NI C# sample application called:
"NI-DAQ\Examples\DotNET4.5\Digital\Read Values\ReadDigChan_ChangeDetection_Events"
The modified start button click handler is in the next reply.(10,000 char post limit). The only real change we made was the hard coding of the device and edge parameters. We did this simply for this post.
It works for some amount of time and the callback stops firing. The amount of time varies between a few seconds and up to 30 seconds. Each callback simply echoes out how many elements are in the boolean array using Trace.WriteLine(). We do not attempt to update the UI as it is set up for 8 bits not all 32.
I created another post about not being able to use multiple tasks per device. It's unanswered so far:
Bottom line is we need a way to monitor all 32 bits from a single task or multiple tasks. Right now we are only doing Digital inputs. Eventually we will need a mix of inputs monitored continously while writing to outputs.
Is this not supported? Are tasks not supposed to be long lived? Should we create a task every time we need to do something? The confusing part is that the test Panels for the NI PXIe-6535 support this exact thing. Why can't we do it from a C# application?
10-10-2014 07:26 AM
private void startButton_Click(object sender, System.EventArgs e) { Cursor.Current = Cursors.WaitCursor; try { // Create the task. port0Task = new Task(); // Create channel port0Task.DIChannels.CreateChannel("PXI1Slot2/port0_32", "", ChannelLineGrouping.OneChannelForAllLines); // Configure digital change detection timing port0Task.Timing.ConfigureChangeDetection("PXI1Slot2/port0_32", "PXI1Slot2/port0_32", SampleQuantityMode.ContinuousSamples, 10000); // Add the digital change detection event handler // Use SynchronizeCallbacks to specify that the object // marshals callbacks across threads appropriately. port0Task.SynchronizeCallbacks = true; port0Task.DigitalChangeDetection += new DigitalChangeDetectionEventHandler(port0Task_DigitalChangeDetection); // Create the reader port0DigitalReader = new DigitalSingleChannelReader(port0Task.Stream); // Start the task port0Task.Start(); startButton.Enabled = false; stopButton.Enabled = true; physicalChannelComboBox.Enabled = false; risingEdgeLinesComboBox.Enabled = false; fallingEdgeLinesComboBox.Enabled = false; } catch (DaqException exception) { port0Task.Dispose(); MessageBox.Show(exception.Message); startButton.Enabled = true; stopButton.Enabled = false; physicalChannelComboBox.Enabled = true; risingEdgeLinesComboBox.Enabled = true; fallingEdgeLinesComboBox.Enabled = true; } Cursor.Current = Cursors.Default; }
10-13-2014 07:01 PM
When you use the original NI example, does it behave as you would expect it to, or is there any unexpected behavior with that as well?
10-14-2014 05:36 AM
It does not behave as expected. That's how we started, I modifed it simply to make the post easier to understand.
10-15-2014 04:06 PM
Does the exception handler return an error? The onboard buffer could be filling up if the read isn't executed properly.
Other than an error being thrown, I can't think of any reason that it would work a few times then stop.