02-07-2011 03:37 PM
I configured a DO task in MAX that writes to lines 0-3 and 5 of port 1 (dev2). The reason I do it this way is because I don't want to mess with the states of the other lines in the port.
Using VB2008, how do I write to each of these lines? Can it be done so all lines change states simultaneously?
Thanks!
02-08-2011 03:53 PM
Hi Steverino,
I've attached a modified version of the VB examples that are included with NI-DAQ (you can find the unmodified ones at Start»Programs»National Instruments»NI-DAQ»Text-Based Code Support). What I have modified is the number of lines to write out. For the line definition you can include noncontiguous line by using a comma in between. For example for your system you can select "Dev2/Port1/line0:3,Dev2/Port1/line5" This will control lines 0-3 and 5 on port 1. From this example, you should be able to create a program that writes individual lines as well.
02-10-2011 09:52 AM
Thanks, Steven.
I tried the example you provided and it does what I hoped.
A follow-up question, however: In MAX I defined an NI-DAQmx Task under Data Neighborhood. I have a digital out task called, taskSetGain. I set up four channels in the task called Gain1, Gain2, Gain3 and Gain4. These are assigned to Port1/Line0, Port1/Line1, Port1/Line2, and Port1/Line5, respectively. When I change gain I'd like them all to switch at the same time. Obviously, the beauty behind defining tasks in MAX is the code becomes device independent. My code no longer cares if I am using Dev1 or Dev8, Port0 or Port3, etc.
In VB2008, how do I address the lines of a MAX-defined task?
Thanks!
02-11-2011 09:36 AM
Hi Steverino,
You can access the tasks in Measurement & Automation (MAX) using the DaqSystem.Local.LoadTask("<taskname>"). This will pull a reference to your DAQmx task created in MAX. For example if you wanted to call your task myTask using an task in MAX called aiTask, you would use:
Dim myTask As Task = DaqSystem.Local.LoadTask("aiTask")
Hope this helps.
02-11-2011 09:57 AM
Thanks, Steven.
I understand that I can reference the task in the way you describe. Having done that, how do I read from or write to the various lines in the task?
02-14-2011 02:34 PM
Hi Steverino,
In this example that Steven sent to you, the writing is done as follows:
Dim writer As New
DigitalSingleChannelWriter(digitalWriteTask.Stream)
writer.WriteSingleSampleMultiLine(True,
dataArray)
It pulls in the values from the boolean array on the form into the stream, and then writes the array to hte lines.
best,
02-16-2011 11:53 AM
Adam,
This is my code:
Dim dataArray() As Boolean = {False, False, False, False, False, False, False, False} digitalWriteTask = DaqSystem.Local.LoadTask(_diTaskName) Dim writer As New DigitalSingleChannelWriter(digitalWriteTask.Stream) writer.WriteSingleSampleMultiLine(True, dataArray)
_doTaskName refers to a digital out task defined in MAX having 8 seperate, non-consecutive DO lines. When I execute this code, I get error -200524.
What am I doing wrong?
Thanks!
02-17-2011 12:17 PM
Hi Steverino,
The programming is slightly different if you are using a Measurement & Automation Explorer (MAX) task. Since each line is a different channel, you need to use a DigitalMultipleChannelWriter. I've written some code in C#. The structure should be almost the same for VB
bool[,] dataArray = new bool[4,1];
dataArray[0,0] = bit0CheckBox.Checked;
dataArray[1,0] = bit1CheckBox.Checked;
dataArray[2,0] = bit2CheckBox.Checked;
dataArray[3,0] = bit3CheckBox.Checked;
DigitalMultiChannelWriter writer = new DigitalMultiChannelWriter(digitalWriteTask.Stream);
writer.WriteSingleSampleMultiLine(true, dataArray);
The array format that WriteSingleSampleMultiLine takes is a 2D array. The first index is the channel index, which is in the order of how the channels were arranged in MAX. The next index is the line index within the channel. Since there is only one physical line in each channel, keep this index 0.