DIAdem

cancel
Showing results for 
Search instead for 
Did you mean: 

interpreting several channels of type 'eByte' as a string

Hi,
 
I'm using DIAdem 10.1 and writing a data plugin in VBS to read binary data files using a BinaryBlock object. My data set contains floats, integers, etc. and a fixed number of bytes (containing ascii-characters including a terminating '\0') which I would like to display in the DIAdem-VIEW as a string.
 
Is there any possibilty to interpret a number of channels of type 'eByte' as a string?
Or does there exist a different/better way of retrieving an array of bytes from a binary data file and displaying it as a string?
 
Many thanks in advance!
 
Best regards,
Stefan
0 Kudos
Message 1 of 7
(3,609 Views)

Hi Stefan2,

How bizarre.  I just tackled this topic for the first time last week.  I did not find a clean DirectAccessChannel approach for a series of fixed-width binary strings which will both read the data efficiently AND expose the data correctly in the Data Portal.

So, how big are your files?  In particular, how many of these string values are there, and how many characters wide is each one?

What I did last week was to declare a series of eByte DirectAccessChannels in the DataPlugin to span the number of characters of each binary string in the binary block.  Then you have 2 choices how to proceed.  If the file is huge, you should probably load the Byte channels into DIAdem and create the desired String channels out of them with a ChnCalculate() function.  I have code for this.  If, on the other hand, your files are not too big, then you can declare the String channel inside of the DataPlugin and construct and fill its values in a tight VBScript loop-- never exposing the Byte channels to the Data Portal.

Let me know about the file size, and we'll proceed,
Brad Turpin
DIAdem Product Support Engineer
National Instruments

0 Kudos
Message 2 of 7
(3,596 Views)

Hi Brad,

thank you for the quick response!

In one of my files a data set contains 1 string with 80 characters, in another file there are 2 strings with 128 characters each.

When it comes to file size, however, I can't really say how big it will be, since it is logging data and in the worst case the logging is stopped only when the device is full (in this case the file might be 3 GB). 

However, in average a file might contain about 10000 entries, i.e. the overall file size will be 1 MB (in case of the first file type, in which 1 string is contained besides the other binary data).

Maybe I can go for the second solution (since it seems to be the more elegant one) and if I get problems with performance I switch over to the first option?

Thank you so far!

Best regards,

Stefan

0 Kudos
Message 3 of 7
(3,581 Views)

Hi Stefan,

Here's the basic idea of what transpires under the hood in the DataPlugin code.  If this doesn't make any sense to you, feel free to ask clarifying questions and/or to send an example of your binary file.

  Dim i, k, kMax, StrVal, StrChan, ChrChans(80)

  ' Declare each byte in the binary string as its own channel for processing later.
  FOR i = 1 TO UBound(ChrChans)
    Set ChrChans(i) = Block.Channels.Add("Byte Chr " & i, eByte)
  NEXT ' i

 '  Manually concatenate the byte characters and assign them to the String Channel
  Set StrChan = Group.Channels.Add("Mission_ID", eString)
  kMax = ChrChans(1).Size
  StrChan.ReservedSize = kMax
  FOR k = 1 TO kMax
    StrVal = ""
    FOR i = 1 TO UBound(ChrChans)
        StrVal  = StrVal & Chr(ChrChans(i).Values(k))
    NEXT ' i
    StrChan.Values(k) = StrVal
  NEXT ' k

Brad Turpin
DIAdem Product Support Engineer
National Instruments

0 Kudos
Message 4 of 7
(3,561 Views)

Hi Brad,

I copied your code example in my VBS-script but got the error message <Error in line 56: Variable is undefined: "Group"> while loading the binary file.

Since I'm neither a VBS nor DIAdem expert I might have made a naive mistake in my script. I would be very happy if you could look over my VBS-script (see attachment) and tell me what's wrong.

I also attached a sample binary file. Its structure is the following: first come 3 text lines, which shall be skipped, then come the binary data in which one data set contains
- 2 16-bit-integers
- 4 32-bit-inegers
- 80 bytes (which contain the text string)

Many thanks for your help!!

Best regards,

Stefan

0 Kudos
Message 5 of 7
(3,561 Views)

Hi Stefan,

Wow, you were close.  The only non-cosmetic change I made was to use your "ChannelGroupERROR" variable instead of my "Group" variable in the code snippet I sent you, which you had correctly added into your DataPlugin code.  It looks to work perfectly now.

I spoke to R&D about this use-case, and they agreed to expand the DataPlugin API in a future version of DIAdem so that one could create a DirectAccessChannel for fixed-width binary strings.  So in the future we won't have to mess with this workaround, which results in much more code and slower execution.

Brad Turpin
DIAdem Product Support Engineer
National Instruments

0 Kudos
Message 6 of 7
(3,547 Views)

Hi Brad,

now it works!

Thank you very much for your quick help!!

Best regards,

Stefan

0 Kudos
Message 7 of 7
(3,533 Views)