XD03 Scripted Reader Example: Read a float array

Content outdated

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

The below reader is used to read a float array from an embedded application using the CDT memory adapter. The reader expects 94 words of 4 bytes to read, each with a float value.
IndexBase is used as domain base. To read the values , a DataInputStream object is used. The values are read using the readInt function, than the byte order is changed and finally a float is created from the reverse bytes.

// 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
// reading from float floats[96];
// Init the record
generator.initRecord("Example Record", IndexBase.n);
var a = generator.addSignal(null, "floats", "", ProcessType.Discrete, SignalType.Float, SignalDescriptor.DEFAULT);
var wa <:IIntegerSamplesWriter:> = generator.getWriter(a);
var current = 0;
try {
    var reader <:DataInputStream:> = new DataInputStream(inputStream);
    for (current = 0; current < 96;current++) {
        var val = reader.readInt();
        val = Integer.reverseBytes( val);
        val = Float.intBitsToFloat( val)
        wa.writeFloat(current, false, val);
} catch (e) {
    console.println(e); // pass exception object to error handler
generator.close(current + 1);
About the scripted reader Open JavaDoc Reference


technical software and tooling


Contact Us

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