11-05-2013 12:05 AM - edited 11-05-2013 12:16 AM
Hello
Today, I need to import data from a mixed binary/text file. Structure is
Ch1 Byte1 Ch1 Byte2 Ch2 Byte1 Ch2 Byte2 CrLf
Ch1 Byte1 Ch1 Byte2 Ch2 Byte1 Ch2 Byte2 CrLf
Ch1 Byte1 Ch1 Byte2 Ch2 Byte1 Ch2 Byte2 CrLf
My first attempt was a modified DataPluginExample3.VBS
Sub ReadStore(File)
Dim Block : SetBlock = File.GetBinaryBlock()
Dim Channel1 : Set Channel1 = Block.Channels.Add("Low-Timer",eU16)
Dim Channel2 : Set Channel2 = Block.Channels.Add("High-Timer", eU16)
Dim Channel3 : Set Channel3 = Block.Channels.Add("CrLf", eU16)
Dim ChannelGroup : Set ChannelGroup = Root.Channelgroups.Add("ESR_Timing")
ChannelGroup.Channels.AddDirectAccessChannel(Channel1)
ChannelGroup.Channels.AddDirectAccessChannel(Channel2)
ChannelGroup.Channels.AddDirectAccessChannel(Channel3)
'Kanal 3 ist nur $OD$OA CrLf)
End Sub
Unfortunately, every odd sample, the data are corrupted and then become misaligned. And the beginning of datalogging may not start exactly at a new line.
So I'd like to use the CrLF to re-synch.
How can I mix the ASCII-readline approach with the binary data?
The following does not work: I try to tell the Formatter to use vbNewLine (=CrLf = $0d$0a) to separate lines and use direct access channels with U16 data type. But when using linefeed, apparently the import filter also expects delimiters instead of raw binary values.
Sub ReadStore(File)
File.Formatter.LineFeeds = vbNewLine
File.SkipLine()'Sicherstellen, dass unvollständige erste Zeile ignoriert wird
Dim Block : SetBlock = File.GetStringBlock()
Dim Channel1 : Set Channel1 = Block.Channels.Add("Low-Timer",eU16)
Dim Channel2 : Set Channel2 = Block.Channels.Add("High-Timer", eU16)
'Dim Channel3 : Set Channel3 = Block.Channels.Add("CrLf", eU16)
Dim ChannelGroup : Set ChannelGroup = Root.Channelgroups.Add("ESR_Timing")
ChannelGroup.Channels.AddDirectAccessChannel(Channel1)
ChannelGroup.Channels.AddDirectAccessChannel(Channel2)
End Sub
Thank you for your input.
Michael
Solved! Go to Solution.
11-05-2013 10:49 AM
Hi Michael,
It looks like you're already on the right track, but you need to ignore all the ASCII formatting options and proceed purely with binary formatting. Can you send me the file in question? It looks like your approach should have more success than you're reporting.
Brad Turpin
DIAdem Product Support Engineer
National Instruments
11-06-2013 12:48 AM
Hi Brad
Please find attached my datalog as recorded by Hterm. As it is a terminal recorded session, starting point is arbitrary....
Thanx in advance for your assistance.
Michael
11-06-2013 11:35 AM
Hi Michael,
I think this DataPlugin does the trick. I had to ignore any partial first line values in order to preserve the line correspondence of the low and high timer values. Also note that by default the U16s are read with LittleEndian byte order-- you can change that with File.Formatter.ByteOrder=eBigEndian.
Brad Turpin
DIAdem Product Support Engineer
National Instruments