01-29-2009 08:15 PM
Hi all,
I have a program (VB.net) that reads a whole digital port (8bits) in a certain time interval. Now, I would like to write a function that can extract a certain bit from that port data and check whether the line that corresponds to this bit is 0 or 1.
Right now I am using the command ReadSingleSamplePortByte, also tried it with the one that returns a UInt32. So, from that data I would like to extract the information for line 3, for example. Any ideas how I can do this? I thought about masking, but don't know how I can convert the data into a boolean array.
Thanks,
Adrian
01-30-2009 07:58 AM
"AND" the value returned with the bit value you are looking for. From your example, you can determine bit 3 being 1 or 0 by:
Dim PortValue As Byte
Dim BitValue As Boolean
DIM TestBit as Integer=3
PortValue = ReadSingleSamplePortByte
BitValue = (PortValue And 2 ^ TestBit)
MsgBox(BitValue)
Dimensioning BitValue as a Boolean gives you a TRUE/FALSE value. Dimensioning as a Byte will give you a 1/0 value.