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