J04 Writing event samples

Event signals may contains no data (the may just represent a position in its domain) or can be made up from integer values, string representations or both.

Looking into the binary representation of an event signal you either find integer values or no data.  The link to strings is made by the legend table of the signal. So instead of writing strings you may add enum strings to the legend (setEnum) and write the integer representation.

Interface

The interface contains write functions for all supported data types. Additionally you find renamed wrapper functions for scripting purpose.

units
Domain position as a multiple of its domain base (e.g. domain base=1ms; units = 100; -> domain value = 100ms). Consecutive calls need to pass a value greater or equal.
conflict
If set to true, impulse will use conflict color (usually red) to paint the sample. Meaning of "conflict is use-case depended.
value
The given valuein different formats (integer/String/Enumeration)
public interface IEventSamplesWriter extends ISamplesWriter {

    boolean write(long units, boolean conflict);
    boolean write(long units, boolean conflict, int value);
    boolean write(long units, boolean conflict, String value);
    boolean write(long units, boolean conflict, Enumeration value);
    boolean write(long units, boolean conflict, int[] value);
    boolean write(long units, boolean conflict, String[] value);
    boolean write(long units, boolean conflict, Enumeration[] value);
    
    boolean writeInt(long units, boolean conflict, int value);
    boolean writeString(long units, boolean conflict, String value);
    boolean writeEnum(long units, boolean conflict, Enumeration value);
    boolean writeIntArray(long units, boolean conflict, int[] value);
    boolean writeIntArgs(long units, boolean conflict, int... value);
    boolean writeStringArray(long units, boolean conflict, String[] value);
    boolean writeStringArgs(long units, boolean conflict, String... value);
    boolean writeEnumArray(long units, boolean conflict, Enumeration[] value);
    boolean writeEnumArgs(long units, boolean conflict, Enumeration... value);
}		
Open JavaDoc Reference

Signal definition

Below you find an example of how to create an integer and an integer array signal. The integer array definition requires a signal descriptor with the required array size (2).
// Java (reader derived from IRecordGenerator, ISingleDomainRecordGenerator)
Signal signal1 = addSignal(signals, "Event1", "An event", 
	ProcessType.Discrete, SignalType.Event, SignalDescriptor.DEFAULT);

Signal signal2 = addSignal(signals, "Event2", "XY", 
	ProcessType.Discrete, SignalType.EventArray, 
    new SignalDescriptor(SignalDescriptor.CONTENT_DEFAULT,2,
    ISample.ACCURACY_DEFAULT,ISample.FORMAT_DEFAULT));

// JavaScript (recJs, scripted reader,..)
var signal1 = generator.addSignal(signals, "Event1", "An integer",
	ProcessType.Discrete, SignalType.Integer, SignalDescriptor.DEFAULT);
    
var signal2 = generator.addSignal(signals, "Event2", "An event array", 
	ProcessType.Discrete, SignalType.EventArray, 
    new SignalDescriptor(SignalDescriptor.CONTENT_DEFAULT,2,ISample.
    	ACCURACY_DEFAULT,ISample.FORMAT_DEFAULT));

Writing samples

Below some examples of using the writer methods for Java and JavaScript. The JavaDoc reference contains additional examples.
// Java (reader derived from IRecordGenerator, ISingleDomainRecordGenerator)
writer1.write(1000L,false);

int value = 4; // an integer value of an enumeration
writer1.write(1000L,false,value);  

String value = "Running"; // a string value of an enumeration
writer1.write(1000L,false,value);  

Enumeration value = new Enumeration(Enumeration.ENUM_GLOBAL,4,"Running");
writer1.write(1000L,false,value);    

String[] value = new String[]{"Running","Started"};  // a string array value of enumerations
writer2.write(1000L,false,value); 
     
// JavaScript (recJs, scripted reader,..)
var value = 4; // an integer value of an enumeration
writer1.writeInt(1000,false,value); 

var value = "Running"; // a string value of an enumeration
writer1.writeString(1000,false,value);  

writer2.writeIntArgs(1000,false,2,4);     

Print

User Rating: 0 / 5

Star InactiveStar InactiveStar InactiveStar InactiveStar Inactive