Digital I/O

cancel
Showing results for 
Search instead for 
Did you mean: 

DAQmx 6516 write multiple ports

We are trying to write to 24 (first three ports) of the 32 lines at once.  Currently I am writing too one port at a time.  See below.  Is this even possible and if so can someone steer me in the right direction.  Thanks.

Public

Sub WriteDigPort(ByVal iPortValue0 As Integer, ByVal iPortValue1 As Integer, ByVal iPortValue2 As Integer, ByVal iPortValue3 As Integer)

Dim digitalWriteTask As Task = New Task()

Windows.Forms.Cursor.Current = Cursors.WaitCursor

Try

' Create an Digital Output channel and name it.

If iPortValue0 <> -1 Then

digitalWriteTask.DOChannels.CreateChannel(

"Dev1/port0", "port0", ChannelLineGrouping.OneChannelForAllLines)

Dim writer As DigitalSingleChannelWriter = New DigitalSingleChannelWriter(digitalWriteTask.Stream)

writer.WriteSingleSamplePort(

True, Decimal.ToUInt32(iPortValue0))

ElseIf iPortValue1 <> -1 Then

digitalWriteTask.DOChannels.CreateChannel(

"Dev1/port1", "port1", ChannelLineGrouping.OneChannelForAllLines)

Dim writer As DigitalSingleChannelWriter = New DigitalSingleChannelWriter(digitalWriteTask.Stream)

writer.WriteSingleSamplePort(

True, Decimal.ToUInt32(iPortValue1))

ElseIf iPortValue2 <> -1 Then

digitalWriteTask.DOChannels.CreateChannel(

"Dev1/port2", "port2", ChannelLineGrouping.OneChannelForAllLines)

Dim writer As DigitalSingleChannelWriter = New DigitalSingleChannelWriter(digitalWriteTask.Stream)

writer.WriteSingleSamplePort(

True, Decimal.ToUInt32(iPortValue2))

ElseIf iPortValue3 <> -1 Then

digitalWriteTask.DOChannels.CreateChannel(

"Dev1/port3", "port3", ChannelLineGrouping.OneChannelForAllLines)

Dim writer As DigitalSingleChannelWriter = New DigitalSingleChannelWriter(digitalWriteTask.Stream)

writer.WriteSingleSamplePort(

True, Decimal.ToUInt32(iPortValue3))

End If

Catch ex As System.Exception

MessageBox.Show(ex.Message)

Finally

System.Windows.Forms.Cursor.Current = Cursors.Default

digitalWriteTask.Dispose()

End Try

End Sub

 
0 Kudos
Message 1 of 3
(4,943 Views)

Hi Mr,

The first thing I noticed about your code is that you only specified one of the ports when you created the task.  Normally you would specify all three by saying, "digitalWriteTask.DOChannels.CreateChannel("Dev1/port0:2",...)

I recommend that you check out one of the .NET shipping examples to get started writing to digital ports.  I'd recommend the example which installs with DAQmx to the following default location:

C:\Program Files\National Instruments\MeasurementStudioVS2005\DotNET\Examples\DAQmx\Digital\Generate Values\WriteDigPort\cs

Let us know how that goes for you.

Thanks,

Luke
Applications Engineer
National Instruments
0 Kudos
Message 2 of 3
(4,934 Views)

Thanks Luke,

The digitalWriteTask.DOChannels.CreateChannel("Dev1/port0:2",...) part was what I had been missing.  Works great now!

 

 

0 Kudos
Message 3 of 3
(4,915 Views)