DIAdem

cancel
Showing results for 
Search instead for 
Did you mean: 

Binary Data Plugin

Could anyone help with preapring a data plugin for a binary input file. The rough Data format is as shown in the document.

I am able to read the header information and first sub header information. But unable to read in the Calibration/Test data, and move on with the next subheader.
Can you please help me with the same?

Expecting your mail at the earliest.
0 Kudos
Message 1 of 11
(5,154 Views)
Hi,

If you know how long the data sections are, then you'll probably want to create a binary block to read them, and set its length, like this:


Dim Block : Set Block = File.GetBinaryBlock()
Block.Channels.Add("MyChannel")
Block.BlockLength = BlockLength 'You probably got this length out of the header.


This will make sure the block will stop reading after it's reached the number of values you have available. BlockLength is calculated as the number of values in one channel in the block. It is not calculated as the number of bytes in the block.

To read the next block you have to create a block at the position where the values for that block starts. You can do this, either by moving the file pointer there before creating the block or by setting the position of the block directly. This goes like this:


File.Position = Position 'You'll calculate this position from the info in the headers.
Set Block = File.GetBinaryBlock()


Or like this:


Block.Position = Position 'You'll calculate this position from the info in the headers.
******************
For tips and tricks on creating VBScript DataPlugins go to http://dataplugins.blogspot.com.
0 Kudos
Message 2 of 11
(5,132 Views)
Hi Again,

This is how I have written the code for the described format. Can anyone tell me where I am wrong. I am not able to read the correct data, and move with reading the inputs for the next channel.
Test header is 80 byte record.
SubHeader is 160 byte record.
The unused bytes are spaces.

If assume the blocklength and the datatype if specified correctly can make things clear.
Can anyone help me out with this.


Sub ReadStore(File)

Dim i, Block, Group, Channel, ChannelName, Channelcount
Dim count, intblockwidth, intcount
' Dim chnrefno(),daschnno(),dassubchnn0(),chnsamples(),datasamples(),
File.Position = 0
'The first 8 bytes gives the test ID
Set Group = Root.ChannelGroups.Add(File.GetCharacters(8))
'next 6 bytes are irrelevent so skip them
'8 + 3 + 3 = 14
File.position = 15
'The next 3 bytes tells the number of channels present in the file
Channelcount = File.GetCharacters(3)
'the rest bytes are unused, hence skip to subheader now.
File.position = 81
' intblockwidth = 0
' msgbox Channelcount
' for intcount = 1 to Channelcount
' intblockwidth = intblockwidth + 2
' Next
'intblockwidth = 2


Dim intchnrefno, strDASchno, intDASsubchno,intscalingsamples, intdatasamples
Dim intprezero, floatsamplerate, intcalptcon1conv, intcalptcon1eng, intca2ptcon1conv, intca2ptcon1eng
Dim intdataresolution

For count = 1 to Channelcount
intchnrefno = File.getcharacters(5)
strDASchno = File.getcharacters(4)
intDASsubchno = File.getcharacters(3)
intscalingsamples = File.getcharacters(10) 'if zero cal data in cal 1 and 2
intdatasamples = File.getcharacters(10) ' Gives the number of Data samples in the channel.
intprezero = File.getcharacters(10)
floatsamplerate = File.getcharacters(11)
intcalptcon1conv = File.getcharacters(6)
intcalptcon1eng = File.getcharacters(11)
intcalptcon2conv = File.getcharacters(6)
intcalptcon2eng = File.getcharacters(11)
intdataresolution = File.getcharacters(3)
'80+160 = 240 test header is 60 byte and subheader is 160 so 90 bytes are used under subheader, hence 160-90
'so setting the file position to the next byte. to start reading data.
File.position = File.position + 71
File.Formatter.ByteOrder = eLittleEndian
' File.Formatter.ByteOrder = eBigEndian
Set Block = File.GetBinaryBlock()
' Block.BlockWidth = intblockwidth
'Block.BlockLength = intdatasamples
Set Channel = Block.Channels.Add(strDASchno, er32)
Call Group.Channels.AddDirectAccessChannel(Channel)
Next

End Sub


Thanks,
Priya
0 Kudos
Message 3 of 11
(5,127 Views)
Hi Myrle,

Thanks for your reply, I did try setting up the block length to the number of channel values I recive from the file but gives me an error teeling, cannot load the Data file wit hthe specifdied Plugin, check log file.

Priya
0 Kudos
Message 4 of 11
(5,126 Views)
Would you mind to send a little example file ? This would make it much easier to see what is missing.

Thanks
0 Kudos
Message 5 of 11
(5,120 Views)
Hi,

I have zipped and attached the example file.
Expecting for your early response

Thanks,
0 Kudos
Message 6 of 11
(5,114 Views)
Hi,

I have looked into the example file and into your source code. I found a few small things when going through the code in the debugger. There was a small error in the offset calculation and the data type is probably 16-Bit Integer instead of 32-Bit Real. I have updated the code to reflect this. For clarity I have converted the numbers to numeric values (integer or float). I assume what is missing now is the appropriate scaling based on the other values in the channel header.

I guessed that "floatsamplerate" is the sampling rate used for a channel. I added a function called "MakeWaveform". What MakeWaveform does it to apply the right attributes to the channel so that DIAdem knows that this channel was acquired with a certain sampling rate. Based on this piece of information, DIAdem creates additional channels with time stamps as needed. In your case the sampling rate is the same for all channel. With that DIAdem creates one channel only for time stamps.

Please let me know whether this helps.

Andreas
0 Kudos
Message 7 of 11
(5,102 Views)
Please see the following forum link that should be helpful.
http://forums.ni.com/ni/board/message?board.id=60&message.id=2078&requireLogin=False

Thank you

Nandini Subramaniam
NI
0 Kudos
Message 8 of 11
(5,098 Views)
Hi Andreas,

Thanks a lot for the help, it works fine now. But only issue is that the data would be in real format. Do we need to do anything using the data resolution or calibration data information?

Thanks,
Priya
0 Kudos
Message 9 of 11
(5,079 Views)
The one thing which is probably missing is to apply a factor and an offset :

oChannel.Factor = Factor
oChannel.Offset = Offset

I wasn't sure which of the variables from the channel header keeps factor and offset. If you apply both, the following formula is used to calculate the values :

Value = RawValue*Factor + Offset

with "RawValue" being the value retrieved from your file.

Andreas
0 Kudos
Message 10 of 11
(5,073 Views)