Home

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: 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.


Interface

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

Examples

// 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:

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.


Interface

// 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);

Examples

// Java (reader derived from IRecordGenerator, ISingleDomainRecordGenerator)
initRecord("my record",TimeBase.ns);
open(0);
// write ...
close(1000); // at 1 us
// JavaScript (recJs, scripted reader,..)
generator.initRecord("my record",TimeBase.ns);
generator.open(0);
// 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.


Interface

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

Examples

// Java (reader derived from IRecordGenerator, ISingleDomainRecordGenerator)
writer.setEnum(Enumeration.ENUM_GLOBAL,"yes",1);
writer.setMember(0,"x",null,ISample.FORMAT_DEFAULT);
// JavaScript (recJs, scripted reader,..)
writer.setEnum(Enumeration.ENUM_GLOBAL,"yes",1);
writer.setMember(0,"x",null,ISample.FORMAT_DEFAULT);

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).

Interface

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

Examples

// Java (reader derived from IRecordGenerator, ISingleDomainRecordGenerator)
Signal val = addSignal(signals, "val", "", ProcessType.Discrete, SignalType.Float, 
	SignalDescriptor.DEFAULT);
IFloatSamplesWriter writer = (IFloatSamplesWriter) getWriter(val);
generator.open(0);
writer.write(500,false,4.5);
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.open(0);
writer.write(1000,false,4.5);
generator.close(1000); // at 1 us
The next chapters (J03 ... ) will cover the usage of the different writer interfaces.