Let's say you have a file which contains eight one-bit channels. This can be read by creating eight eight-bit channels which cover the same file space and masking in a different bit for each channel. The code looks like this:
Option Explicit
Sub ReadStore(File)
Dim ChannelGroup : Set ChannelGroup = Root.ChannelGroups.Add("ChannelGroup")
Dim i, Block, DAChannel
For i = 0 to 7
Set Block = File.GetBinaryBlock()
Set DAChannel = Block.Channels.Add("bit" & i, eByte)
DAChannel.Formatter.BitMask = 2^i
DAChannel.Factor = 1 / 2^i
Call ChannelGroup.Channels.AddDirectAccessChannel(DAChannel)
Next
End Sub
Here are a couple of points which might not be obvious:
Because you must create a channel the size of which is measured in bytes, it is only possible to read out bits which are spaced in multiples of eight using this method. Up until now I haven't seen a spacing which made this a problem. If anyone else has go ahead and let me know.
When you call GetBinaryBlock, it does not advance the file pointer. That means that calling GetBinaryBlock multiple times from the same file position results in multiple blocks which read starting at that same file position.
It's important that you use an unsigned datatype (eByte, eU16, or eU32) to create the channels. For the signed types we've implemented sign extension (first available in DIAdem 10.0). Since you are masking out all but one of the bits, two's complement means that when the last (in this case only) un-masked bit is a one, the number is negative. You probably want a channel of 0's and 1's, and not a channel of 0's and -1's.
For this example, I set the BitMask property using a decimal number. However, sometimes it is more readable to set the BitMask using a hexidecimal number. Something like 0xff00 is difficult to input into VBScript. We've made it easier by making the BitMask property also accept strings. This means you could set it to "0xFF00", and it would behave the same as if you set the BitMask property to 65280.