XR03 recJs Example: Events


Outline

This next script contains events and logs.

Platforms
32/64bit 32/64bit 32/64bit
Requirements
  • None
Parameters:
  • None
Content of example record files
  • recJs/r03_events.recJs


Output



Usage

  1. Copy the script code onto a file resource with "recJs" ending or use the impulse record examples.
  2. Open the impulse viewer with the file resource (e.g. double-click the file in the eclipse explorer).

R003 recJs Reader 10 Signal Script Script Examples impulse JDK Open JavaDoc



Script

The script creates different types of event and struct signals for logs.


//-recjs (keep this line)
// generator   : Record generator (de.toem.impulse.samples.ISingleDomainRecordGenerator)
// file        : File object of the executed recJs file (java.io.File)
// p0..p9      : Parameters from the reader configuration (java.lang.String)
// progress    : Progress control (de.toem.impulse.cells.ports.IPortProgress)
// console     : Console output (de.toem.impulse.scripting.IScriptConsole)
 
// Init the record
generator.initRecord("Example Record",TimeBase.ns);

 
// Create a record with scopes and some signals
var signals = generator.addScope(null, "Signals");

var int1 = generator.addSignal(signals, "Integer1", "An integer", ProcessType.Discrete, SignalType.Integer, SignalDescriptor.DEFAULT);
var int2 = generator.addSignal(signals, "Integer2", "An integer array", ProcessType.Discrete, SignalType.IntegerArray, new SignalDescriptor(SignalDescriptor.CONTENT_DEFAULT,2,ISample.INTEGER_ACCURACY_DEFAULT,ISample.FORMAT_DEFAULT));

var event1 = generator.addSignal(signals, "Event1", "Simple events", ProcessType.Discrete, SignalType.Event, SignalDescriptor.DEFAULT);
var event2 = generator.addSignal(signals, "Event2", "Enum events with ints",ProcessType.Discrete, SignalType.Event, SignalDescriptor.DEFAULT);
var event3 = generator.addSignal(signals, "Event3", "Enum events with strings",ProcessType.Discrete, SignalType.Event, SignalDescriptor.DEFAULT);
var event4 = generator.addSignal(signals, "Event4", "Enum array",ProcessType.Discrete, SignalType.EventArray, new SignalDescriptor(SignalDescriptor.CONTENT_DEFAULT,2,ISample.INTEGER_ACCURACY_DEFAULT,ISample.FORMAT_DEFAULT));

var struct1 = generator.addSignal(signals, "Struct1", "A struct signal", ProcessType.Discrete,SignalType.Struct, new SignalDescriptor( SignalDescriptor.CONTENT_DEFAULT, -1));
var struct2 = generator.addSignal(signals, "Struct2", "Another struct signal", ProcessType.Discrete,SignalType.Struct, new SignalDescriptor( SignalDescriptor.CONTENT_DEFAULT, -1));

// We start at 0 ns
var t = 0; // 0 ns
generator.open(t);

// get the writers
var integerWriter/*:IIntegerSamplesWriter:*/ = generator.getWriter(int1);
var integerArrayWriter/*:IIntegerSamplesWriter:*/ = generator.getWriter(int2);

// And continue until 1000 ns
for (; t < 100000; t ++) {

    // write time as integer
    integerWriter.writeInt(t, false,  (100 * Math.sin(t/1000.0)));
	integerArrayWriter.writeLongArgs(t, false, (Math.sin((t + 100) / 3000.0) * 10.0),(Math.cos((t + 100) / 3000.0) * 10.0));       
}

// simple events
var eventWriter/*:IEventSamplesWriter:*/ =  generator.getWriter(event1);
eventWriter.write(12000, false);
eventWriter.write(22000, false);

// enum events with strings
eventWriter =  generator.getWriter(event2);
eventWriter.write(13000, false,"Start");
eventWriter.write(14000, false,"Continue");
eventWriter.write(15000, false,"Stop");
eventWriter.write(25000, false,"Destroy");     
eventWriter.write(30000, false,"Start");  
eventWriter.write(44000, false,"Continue");
eventWriter.write(45000, false,"Stop");
eventWriter.write(55000, false,"Destroy");     
eventWriter.write(60000, false,"Start");  

// enum events with ints
eventWriter = generator.getWriter(event3);
eventWriter.write(13000, false,1);
eventWriter.write(14000, false,2);
eventWriter.write(15000, false,3);
eventWriter.write(25000, false,4);    

// enum arrays
eventWriter = generator.getWriter(event4);
eventWriter.writeStringArgs(13000, false,"Ja","Nein");
eventWriter.writeStringArgs(14000, false,"Ja","Nein");


// structs 
var structWriter /*:IStructSamplesWriter:*/=  generator.getWriter(struct1);

var members/*:[Lde.toem.impulse.values.StructMember;:*/ = structWriter.createMembers(3);
structWriter.createMember(members,0,"State", ISample.STRUCT_TYPE_LOCAL_ENUM,"STATE", ISample.FORMAT_DEFAULT);
structWriter.createMember(members,1,"Value", ISample.STRUCT_TYPE_ENUM,null, ISample.FORMAT_DEFAULT);
structWriter.createMember(members,2,"Other", ISample.STRUCT_TYPE_INTEGER,null, ISample.FORMAT_DEFAULT);

members[0].setValue("Off");
members[1].setValue("Inspect");
members[2].setValue(100);
structWriter.write(10000, false, members);
members[0].setValue("On");
members[1].setValue("First");
members[2].setValue(200);
structWriter.write(20000, false, members);
structWriter.attachRelation(struct2.getPath(), "Delayed//", 20000);
members[0].setValue("Running");
members[1].setValue("First");
members[2].setValue(700);
structWriter.write(30000, false, members);
members[0].setValue("Waiting");
members[1].setValue("Second");
members[2].setValue(750);
structWriter.write(40000, false, members);
members[0].setValue("Running");
members[1].setValue("Second");
members[2].setValue(750);
structWriter.write(50000, false, members);
members[0].setValue("Stopping");
members[1].setValue("Third");
members[2].setValue(950);
structWriter.write(60000, false, members);
members[0].setValue("Off");
members[1].setValue("Third");
members[2].setValue(950);
structWriter.write(70000, false, members);

structWriter =  generator.getWriter(struct2);
members[0].setValue("Off");
members[1].setValue("Inspect");
members[2].setValue(100);
structWriter.write(30000, false, members);
members[0].setValue("On");
members[1].setValue("First");
members[2].setValue(200);
structWriter.write(40000, false, members);
members[0].setValue("Running");
members[1].setValue("First");
members[2].setValue(700);
structWriter.write(50000, false, members);
members[0].setValue("Waiting");
members[1].setValue("Second");
members[2].setValue(750);
structWriter.write(60000, false, members);
members[0].setValue("Running");
members[1].setValue("Second");
members[2].setValue(750);
structWriter.write(70000, false, members);
members[0].setValue("Stopping");
members[1].setValue("Third");
members[2].setValue(950);
structWriter.write(80000, false, members);
members[0].setValue("Off");
members[1].setValue("Third");
members[2].setValue(950);
structWriter.write(90000, false, members);

// And close finally
generator.close(100000);





toem

technical software and tooling

Company

Contact Us

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