Digital I/O

cancel
Showing results for 
Search instead for 
Did you mean: 

Holding a Digital Channel High Until Another Channel Goes High Using VB.NET

I am trying to use the following code to hold a channel high until another channel goes high using a PCI-6229/VB.NET/MS.NET.  Both channels are on the same port and I can't find examples that show how to use a single channel.  I am using a channel constant of Dev1/Port0/Line8.  Is this correct?  Is my code correct?

    Private Sub DOTimer_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles DOTimer.Tick
        Dim digitalWriteTask As Task
        Dim digitalReadTask As Task
        Dim myDigitalReader As DigitalSingleChannelReader
        Dim readData As Boolean
        Dim writeData As Boolean

        Dim outChannel, inChannel As String

        outChannel = "Dev1/Port0/line9"
        inChannel = "Dev1/Port0/line10"

        Try
            'Create a task such that it will be disposed after
            'we are done using it.
            DigitalReadTask = New Task("DItask")
            digitalWriteTask = New Task("DigitalWriteTask")

            'Create channel
            digitalReadTask.DIChannels.CreateChannel(inChannel, "DigRead", _
                ChannelLineGrouping.OneChannelForEachLine)
            digitalWriteTask.DOChannels.CreateChannel(outChannel, "port0", _
                ChannelLineGrouping.OneChannelForEachLine)

            myDigitalReader = New DigitalSingleChannelReader(digitalReadTask.Stream)

            'Read the digital channel
            readData = myDigitalReader.ReadSingleSampleSingleLine

            If readData Then
                writeData = False
                Dim writer As New DigitalSingleChannelWriter(digitalWriteTask.Stream)
                writer.WriteSingleSampleSingleLine(True, writeData)
                DOTimer.Enabled = False
            Else
                writeData = True
                Dim writer As New DigitalSingleChannelWriter(digitalWriteTask.Stream)
                writer.WriteSingleSamplesingleLine(True, writeData)
            End If
            digitalReadTask.Dispose()
            digitalWriteTask.Dispose()
        Catch exception As DaqException
            DOTimer.Enabled = False
            MessageBox.Show(exception.Message)

            'dispose task
            digitalReadTask.Dispose()
        End Try
    End Sub
0 Kudos
Message 1 of 2
(3,100 Views)
Hello Joe,

I glanced over your code and it looks like you are setting up the channels properly.  Have you tested your code out?  What were the results?  If you are running into some snags, it is sometimes easier to open up one of the example programs, and then modify it until it does what you want it to.


Eric
DE For Life!
0 Kudos
Message 2 of 2
(3,084 Views)