Digital I/O

cancel
Showing results for 
Search instead for 
Did you mean: 

Reading from a single line instead of entire port using 6509 or 6501

Hi,

I am trying to read from a single line using either a 6509 or 6501. Below is my code:

 

Dim digitalReadAlarm1Task As New Task()
Dim digitalReadAlarm2Task As New Task()
Dim InputChannel As DIChannel
Dim bInvertLines As Boolean
Dim iPortBSlashPos As Integer = sPort(2).IndexOf("/")
Dim sPortBName As String = sPort(2).Substring(iPortBSlashPos + 1, sPort(2).Length - (iPortBSlashPos + 1))
Dim iPortCSlashPos As Integer = sPort(2).IndexOf("/")
Dim sPortCName As String = sPort(2).Substring(iPortCSlashPos + 1, sPort(2).Length - (iPortCSlashPos + 1))
Dim readDataAlarm1() As Boolean
Dim readDataAlarm2() As Boolean


Dim myDigitalReader As DigitalSingleChannelReader

InputChannel = digitalReadAlarm1Task.DIChannels.CreateChannel(sPort(1) & "/line7:7", sPortBName, ChannelLineGrouping.OneChannelForAllLines)
digitalReadAlarm1Task.Start()
bInvertLines = InputChannel.InvertLines
digitalReadAlarm1Task.Stop()
InputChannel.InvertLines = Not chkPortInversion.Checked
myDigitalReader = New DigitalSingleChannelReader(digitalReadAlarm1Task.Stream)
readDataAlarm1 = myDigitalReader.ReadSingleSampleMultiLine()

 

InputChannel = digitalReadAlarm2Task.DIChannels.CreateChannel(sPort(2) & "/line5:5", sPortCName, ChannelLineGrouping.OneChannelForAllLines)
digitalReadAlarm2Task.Start()
bInvertLines = InputChannel.InvertLines
digitalReadAlarm2Task.Stop()
InputChannel.InvertLines = Not chkPortInversion.Checked
myDigitalReader = New DigitalSingleChannelReader(digitalReadAlarm2Task.Stream)
readDataAlarm2 = myDigitalReader.ReadSingleSampleMultiLine()

 

digitalReadAlarm1Task.Dispose()
digitalReadAlarm2Task.Dispose()

 

In both cases I get only one line back but it is always false. Anything obviously wrong with my code?

 

0 Kudos
Message 1 of 2
(1,117 Views)

I don't know the text API syntax at all, but here are a few things that catch my eye:

 

- your channel grouping is set for 'OneChannelForAllLines'.  I know that when I set a DIO task this way in LabVIEW, the data I get back is an unsigned int with individual lines from the port mapped to individual bits within the int.  And I believe that any unconfigured lines would return a default 0 bit. 

    You should instead configure to have a separate channel for each line in the task.  Then you can read the channel as an array of Booleans, one element per configured channel.

 

- I'd expect you to need to do some bit-masking to discover the value of the specific bits you configured (5 & 7).  Again, I don't know your text language, but it kinda looks like you might be trying to read a Boolean array of the various digital lines though you configured the task to (seemingly) deliver a single bit-mapped integer.

    Even if the read function gives you the array, it may well be the case that you need to explicitly extract the 5th or 7th element.  Might you only be considering the 1st element when you declare that your result is always False?    

 

- I notice that you've got a couple lines of code that deal with lines or ports being inverted.  Better make sure you've got that right.

 

 

-Kevin P

ALERT! LabVIEW's subscription-only policy came to an end (finally!). Unfortunately, pricing favors the captured and committed over new adopters -- so tread carefully.
0 Kudos
Message 2 of 2
(1,058 Views)