J002 Using sample writers

Content outdated

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

Sample writers help you to insert samples of various data types (integers, float, arrays, structs, text,...) into your defined signals.

Screen Cast: J02 Using sample writers

To insert samples into a defined signal you need to perform the following steps:
  • Acquire writers for the signals you want to fill   
  • Open the writers
  • Optionally add enumeration and member information
  • Write samples
  • Close the writers
See 02 Signal Basics for more about signals.

Getting the writer for a signal

Usually when defining a signal (optional "createWriter" parameter is set to true), a writer is created in background. To get the writer, just use the getWriter method. In the other case you need to create the writer explicitly with createWriter.


ISamplesWriter getWriter(Signal signal);
ISamplesWriter createWriter(Signal signal);
ISamplesWriter createWriter(Signal signal, ProcessType processType, 
	SignalType signalType, SignalDescriptor signalDescriptor, IDomainBase domainBase);


// Java (reader derived from IRecordGenerator, ISingleDomainRecordGenerator)
Scope signals = addScope(null, "External Signals");
Signal clk = addSignal(signals, "Clk", "", 
	ProcessType.Discrete, SignalType.Logic, SignalDescriptor.DEFAULT);
ILogicSamplesWriter writer = (ILogicSamplesWriter) getWriter(clk);
// JavaScript (recJs, scripted reader,..)
var signals = generator.addScope(null, "External Signals");
var clk = generator.addSignal(signals, "Clk", "",
	ProcessType.Discrete, SignalType.Logic, SignalDescriptor.DEFAULT);
var writer <:ILogicSamplesWriter:> = generator.getWriter(clk);

The writer object depends on the signal type. The writer could be of type:

  • Logic: ILogicSamplesWriter
  • Float, FloatArray: IFloatSamplesWriter
  • Integer, IntegerArray: IIntegerSamplesWriter
  • Struct: IStructSamplesWriter
  • Event, EventArray: IEventSamplesWriter
  • Text, TextArray: ITextSamplesWriter
  • Binary: IBinarySamplesWriter
Open JavaDoc Reference

Opening and closing writers

If you are using a ISingleDomainRecordGenerator, you can open and close all signals at one. In case multiple domain (IRecordGenerator) you need to open and close all used writers manually.
Signals may be discrete or continuous. Discrete means that each sample can be at any position of the given domain base with the restriction:

position(sample(idx)) <= position(sample(idx+1))

Continuous signal have a start, end and rate indicator. Therefor the position of each sample is definite. Discrete signal just have start and end indicators. Each sample contains the delta position to its predecessor.

  • start,end: Domain position as a multiple of its domain base (e.g. domain base=1ms; units = 100; -> domain value = 100ms).
  • rate: Domain distance as a multiple of its domain base.


// ISingleDomainRecordGenerator
void open(long start);
void open(long start, long rate);
void close(long end);
// ISamplesWriter
boolean open(long start);
boolean open(long start, long rate, ... ); 	// ignore the additional parameters 
    										// (set to 0 or null)
void close(long end);


// Java (reader derived from IRecordGenerator, ISingleDomainRecordGenerator)
initRecord("my record",TimeBase.ns);
// write ...
close(1000); // at 1 us
// JavaScript (recJs, scripted reader,..)
generator.initRecord("my record",TimeBase.ns);
// write ...
generator.close(1000); // at 1 us

Legend: Setting enumeration values and defining array members

The legend of a signal contains information like string representations of enumeration value and member information of arrays and struct signals.

  • enumerationGroup: Enumeration group, 0 for global enumeration.
  • label: String representation of the enumeration.
  • id: Index/Id of the member.
  • name: Name of the member
  • content Content description of the member, or null.
  • format Format specifier defining how to render the value (e.g. ISample.FORMAT_DECIMAL).


// ISamplesWriter
boolean setEnum(int enumerationGroup, String label, int value);
boolean setMember(int id, String name, String content, int format);


// Java (reader derived from IRecordGenerator, ISingleDomainRecordGenerator)
// JavaScript (recJs, scripted reader,..)

For the enumerationGroup group you may choose one of the following values. ENUM_GLOBAL is used for normal enumerations. You may choose ENUM_MEMBER_0 + member id for enumeration that are only valid for one member (array or struct member).
A member is defined by its id (index in case of arrays), a member name, an optional content information and the format descriptor (describes the textual representation of the value).

public static final int ENUM_MIN = 0; 
public static final int ENUM_GLOBAL = 0;
public static final int ENUM_ASSOC_TARGET = 1;
public static final int ENUM_ASSOC_STYLE = 2;
public static final int ENUM_LABEL_STYLE = 3;
public static final int ENUM_MEMBER_0 = 8;
public static final int ENUM_MAX = Short.MAX_VALUE;

Writing samples

The interface to write a samples depends on the signal type (see above overview of sample writer interfaces).
  • 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.


// ISamplesWriter
boolean write(long units, boolean conflict, ... value ... );


// Java (reader derived from IRecordGenerator, ISingleDomainRecordGenerator)
Signal val = addSignal(signals, "val", "", ProcessType.Discrete, SignalType.Float, 
IFloatSamplesWriter writer = (IFloatSamplesWriter) getWriter(val);
close(1000); // at 1 us
// JavaScript (recJs, scripted reader,..)
var val = generator.addSignal(signals, "val", "", ProcessType.Discrete, 
	SignalType.Float, SignalDescriptor.DEFAULT); 
var writer <:IFloatSamplesWriter:> = generator.getWriter(val);
generator.close(1000); // at 1 us
The next chapters (J03 ... ) will cover the usage of the different writer interfaces.


technical software and tooling


Contact Us

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