XD01 CSV like file reader

Content outdated

We are in the process of migrating all content to impulse version 2.0.

This scripted reader reads a CSV like file with 4 columns (a,b,c,d). As its a text file, the first step is to create a BufferedReader object from the input stream. This allows to read the input line by line.
Each line will be splitted and its values are written into the signal writers.

// generator: of ISingleDomainRecordGenerator  (http://toem.de/index.php/projects/impulse/scripts/reference)
// inputStream: input stream of type java.io.InputStream
// console: console output of type MessageConsoleStream
 
importPackage(java.io);
 
 
// Init the record
generator.initRecord("Example Record", TimeBase.ns);
var a = generator.addSignal(null, "a", "", ProcessType.Discrete, SignalType.Integer, SignalDescriptor.DEFAULT);
var b = generator.addSignal(null, "b", "", ProcessType.Discrete, SignalType.Integer, SignalDescriptor.DEFAULT);
var c = generator.addSignal(null, "c", "", ProcessType.Discrete, SignalType.Integer, SignalDescriptor.DEFAULT);
var d = generator.addSignal(null, "d", "", ProcessType.Discrete, SignalType.Integer, SignalDescriptor.DEFAULT);
var wa <:IIntegerSamplesWriter:> = generator.getWriter(a);
var wb <:IIntegerSamplesWriter:> = generator.getWriter(b);
var wc <:IIntegerSamplesWriter:> = generator.getWriter(c);
var wd <:IIntegerSamplesWriter:> = generator.getWriter(d);
 
var current = 0;
generator.open(current);
 
try {
    var reader <:BufferedReader:> = new BufferedReader(new InputStreamReader(inputStream));
    var line <:String:> = reader.readLine(); // skip empty header
    while ((line = reader.readLine()) != null) {
        var splitted = line.split(";");
        var current = TimeBase.ns.parseUnits(splitted[0]+"ms");
        console.println(current+" "+line+" "+line.length());
        wa.writeInt(current, false, splitted[1]);
        wb.writeInt(current, false, splitted[2]);
        wc.writeInt(current, false, splitted[3]);
        wd.writeInt(current, false, splitted[4]);
    }
} catch (e) {
    console.println(e); // pass exception object to error handler
}
 
 
generator.close(current + 1);





About the scripted reader Open JavaDoc Reference
toem

technical software and tooling

Company

Contact Us

This email address is being protected from spambots. You need JavaScript enabled to view it.