06-19-2013 12:15 AM
Hi All,
I'm programming in VB.NET 2010 with Measurement Studio. I've got a cDAQ9188 with a NI9401 digital I/O module. I want to be able to individually control 3 separate output lines to turn relays on and off. My form has 3 switches, each to control it's own relay.
My code looks like this:
Dim DORelays as Task
DORelays = New Task
DORelays.DOChannels.CreateChannel("/BDIO/Port0/Line0:2", "", ChannelLineGrouping.OneChannelForEachLine)
Dim DORelaysWriter as New DigitalSingleChannelWriter(DORelays.Stream)
If Switch.Value = True Then
DORelaysWriter.WriteSingleSampleSingleLine(True, 1)
ElseIf Switch.Value = False Then
DORelaysWriter.WriteSingleSampleSingleLine(True, 0)
EndIf
At this point it throws an error:
"Write cannot be performed, because the number of channels in the data does not match the number of channels in the task. When writing, supply data for all channels in the task. Alternatively, modify the task to contain the same number of channels as the data written.
Number of channels in Task: 3
Number of channels in Data:1
If I modify the line where I create the channels to have ""/BDIO/Port0/Line0" then my DIO line will toggle between 0 and 5 volts correctly.
How do I code so that my one task can individually control three separate relays each with it's own switch on the form? What am I doing wrong?
Much appreciation here,
Mike
06-20-2013 10:37 AM
Hello Mike,
It looks like the error is coming from your array size not being consistent with the number of lines. You need to initialize your array with 3 total elements. Currently it only has 1 element and you're writing to 3 lines.
I hope this helps,
Eric E.