Digital I/O

cancel
Showing results for 
Search instead for 
Did you mean: 

writer.WriteMultiSamplePort

Hello,

I am currently porting my VB6 app to VB.NET 2005.  I have been looking at the example under the c:\Program Files\National Instruments\MeasurementStudioVS2005\DotNET\Examples\DAQmx\Digital\Generate Values\WriteDigPort\vb My question is in my "new" code and the
writer.WriteMultiSamplePort statement.  The NI example uses the statement writer.WriteSingleSamplePort (only opening one port to write sample to).  However, since I have ports 0:7 to open and write sample to, I was not sure how to do this.  Any help or guidance much appreciated.  Thanks!

My "old" VB6 code:
------------------------

                On Error GoTo ErrorHandler

                arraySizeInBytes = 8
                '  Re-initialize an array that holds the digital values to be written
                ReDim writeArray(arraySizeInBytes)
                For i = 0 To arraySizeInBytes - 1
                    writeArray(i) = chkDeviceOnePortTwo(i).CheckState
                Next

                ' Create the DAQmx task.
                DAQmxErrChk(NIDAQmxCAPI.DAQmx.DAQmxCreateTask("", taskHandle))

                ' Add a digital output channel to the task.
                DAQmxErrChk(NIDAQmxCAPI.DAQmx.DAQmxCreateDOChan(taskHandle, "Dev1/port2/line0:7", "",       NIDAQmxCAPI.DAQmxLineGrouping.DAQmx_Val_ChanForAllLines))

                ' Start the task running, and write to the digital lines.
                DAQmxErrChk(NIDAQmxCAPI.DAQmx.DAQmxStartTask(taskHandle))

                DAQmxErrChk(NIDAQmxCAPI.DAQmx.DAQmxWriteDigitalLines(taskHandle, 1, True, 10#, NIDAQmxCAPI.DAQmxFillMode.DAQmx_Val_GroupByChannel, writeArray(0), sampsPerChanWritten, 0))

                ' All done!
                StopTask()

                Exit Sub

        ErrorHandler:
                If taskIsRunning = True Then
                    NIDAQmxCAPI.DAQmx.DAQmxStopTask(taskHandle)
                    DAQmxErrChk(NIDAQmxCAPI.DAQmx.DAQmxStopTask(taskHandle))
                    DAQmxErrChk(NationalInstruments.DAQmx.TaskAction.Stop)

                    NIDAQmxCAPI.DAQmx.DAQmxClearTask(taskHandle)

                    taskIsRunning = False
                End If

                MsgBox("Error: " & Err.Number & " " & Err.Description,  , "Error")


My "new" code:
--------------------
        arraySizeInBytes = 8
        '  Re-initialize an array that holds the digital values to be written
        ReDim writeArray(arraySizeInBytes)
        For i = 0 To arraySizeInBytes - 1
            writeArray(i) = chkDeviceOnePortTwo(i).CheckState
        Next

        Windows.Forms.Cursor.Current = Cursors.WaitCursor
        Try
            '  Create an Digital Output channel and name it.
            digitalWriteTask.DOChannels.CreateChannel("Dev1/port2/line0:7", "", _
                ChannelLineGrouping.OneChannelForAllLines)

            '  Write digital port data. WriteDigitalSingChanSingSampPort writes a single sample
            '  of digital data on demand, so no timeout is necessary.
            Dim writer As DigitalSingleChannelWriter = New DigitalSingleChannelWriter(digitalWriteTask.Stream)
            ''''''writer.WriteSingleSamplePort(True, Decimal.ToUInt32(dataToWriteNumericUpDown.Value))
            writer.WriteMultiSamplePort(True, Decimal.ToUInt32(dataToWriteNumericUpDown.Value))

        Catch ex As System.Exception
            MessageBox.Show(ex.Message)
        Finally
            System.Windows.Forms.Cursor.Current = Cursors.Default
            digitalWriteTask.Dispose()
        End Try




0 Kudos
Message 1 of 2
(3,480 Views)
Hi jsrMN,
 
You meantion that you are using Ports 0:7 but in your "old" code you are using port2/line0:7. If this former is a typo then I believe the appropiate example to look at would be writedigchan which can be found.
C:\Documents and Settings\All Users\Documents\National Instruments\NI-DAQ\Examples\DotNET2.0\Digital\Generate Values\WriteDigChan\vb
This example uses writer.WriteSingleSampleMultiLine, which will allow you to write different values to each line in the port.
 
I hope this helps
JaceD
Signal Sources Product Support Engineer
National Instruments
0 Kudos
Message 2 of 2
(3,461 Views)