11-09-2023 01:25 PM
Hello All,
I have to write a Data plugin for loading a CSV file where the header takes up the first 305 rows then the data starts, using the wizard it caps the line assignments at 200, how do i go beyond that? I have attached a sample file.
11-15-2023 03:06 AM
Hello dkrispin,
Unfortunately, the Text DataPlugin Wizard only shows the first 200 lines in the first step, so that you cannot select your data range, which starts at line 305. The wizard creates an encrypted DataPlugin script so that you cannot edit it later. As the start line of your data block may not always be identical, I recommend creating the DataPlugin yourself.
This could look like this. In this example, which I have created for you, the two areas [Comment Fields] and [Graph Settings] are read in by creating the lines as properties at the root. When the file reader reaches the data area [Data], the channels are read in and created in the Measurements group.
Const HeaderData = "[Data]"
Sub ReadStore(File)
dim FileInfos
set FileInfos = CreateObject("Scripting.Dictionary")
call FileInfos.Add("[Comment Fields]", array(",", eString))
call FileInfos.Add("[Graph Settings]", array("=", eString))
File.Formatter.LineFeeds = vbNewLine
File.Formatter.IgnoreEmptyLines= true
File.Formatter.TrimCharacters = " "
File.Formatter.Delimiters = ","
dim LineText, PropertyName, PropertyValue
dim ChannelGroup, ChnNames, ChnIdx, Chn, Units
dim FilePos
do while (File.Position < File.Size)
LineText = File.GetNextLine()
' Read properties
if FileInfos.Exists(LineText) then
File.Formatter.Delimiters = FileInfos(LineText)(0)
FilePos = File.Position
PropertyName = File.GetNextStringValue(eString)
do while left(PropertyName, 1) <> "["
PropertyValue = File.GetNextStringValue(FileInfos(LineText)(1))
call Root.Properties.Add(replace(PropertyName, ".", "~"), PropertyValue) ' Create grouped property with ~
call File.SkipLine()
FilePos = File.Position
PropertyName = File.GetNextStringValue(eString)
loop
File.Position = FilePos
elseif LineText = HeaderData then
' Read channel data
set ChannelGroup = Root.ChannelGroups.Add("Measurements")
File.Formatter.Delimiters = ","
ChnNames = split(File.GetNextLine(), ",")
Units = split(File.GetNextLine(), ",")
File.Formatter.DecimalPoint = "."
dim Block : set Block = File.GetStringBlock()
for ChnIdx = 0 to ubound(ChnNames)
set Chn = Block.Channels.Add(ChnNames(ChnIdx), eR64)
call Chn.Properties.Add("unit_string", Units(ChnIdx))
call ChannelGroup.Channels.AddDirectAccessChannel(Chn)
next
exit do
end if
loop
End Sub
Save the source code as a VBSD file and register it as a DataPlugin. Customize the code to your needs.
11-15-2023 05:10 AM
Thank you for the help I will work on it today and post the results.