Digital events data
Digital events data
Digital XSPICE nodes produce string values rather than numeric vectors. Their data is collected separately
from analog voltages/currents, regardless of the handle’s -output setting. The raw event API must be present
in the loaded ngspice library, and the circuit’s XSPICE code models must be loaded.
Load the circuit, select the nodes and publication mode, then run the simulation:
set sim [::ngspicetclbridge::new $ngspiceLibrary]
$sim circuit -string $netlist
$sim eventnodes -all -mode changes
::ngspicetclbridge::run $sim
set data [$sim eventdata]
Use -nodes {clk out} instead of -all to record particular nodes. Calling eventnodes without options
returns supported, available, selected and mode. Discovery and configuration require an idle simulator. An
empty -nodes {} selection disables recording. Configuration changes clear the stored history and known states.
eventdata returns the currently retained history, not just records added since the previous read. Every
result has four top-level keys: mode, analysis, nodes and batches. It is an independent Tcl value; subsequent runs,
callbacks and clears do not change a result already returned to your script. No Tcl event-loop turn is
required to read the published data. Event output does not use RBC vectors or vector naming options.
analysis is none before a plot starts, then tran, op or dc. Starting another analysis replaces the current event result. AC/noise and other unsupported plots cause eventdata to report an error; their operating-point preparation is not presented as a frequency-dependent digital response.
Choosing a transient mode
changes: record native event reports grouped into complete sampling batches. Use it for transition logs.snapshot: record all selected node states at each accepted transient output point. Use it for aligned state tables; unchanged values are carried forward.pernode: record each node’s native event reports as soon as they arrive. Use it for individual waveforms or monitoring that must not wait for a complete batch across nodes.
The following outputs are illustrative, formatted across lines for readability. Times are in seconds for
transient analysis. Value strings are supplied by ngspice’s event-type decoder: for example, digital values can
contain logic state and drive strength, such as 0s, 1s or Uz. Preserve the complete string; other event
types may use different representations. The type field names the native event type, such as digital.
changes: complete batches of event reports
mode changes
analysis tran
nodes {clk {type digital} out {type digital}}
batches {
{time 1e-9 events {{clk 1e-9 1s 1} {out 1e-9 0s 1}}}
{time 2e-9 events {{out 1.5e-9 1s 1}}}
}
nodes maps each selected node name to its metadata dictionary. batches is an ordered list of dictionaries:
time: the transient output point associated with this batch.events: records in the form{node eventTime value last}.nodeis the original ngspice node name;eventTimeis the time of that native event, which may differ from the batch time;valueis its string.last: 1 marks the last report in that particular node’s native callback group; 0 means more reports for that node follow. It does not indicate that all nodes have been delivered, or that simulation has ended.
Empty batches are omitted. Native predecessor records, repeated timestamps and repeated values are
preserved, so changes does not mean every row has a value different from the previous row. Records retain
callback order; events from different nodes are not necessarily globally sorted by eventTime.
foreach batch [dict get $data batches] {
foreach event [dict get $batch events] {
lassign $event node eventTime value last
puts "$node at $eventTime: $value"
}
}
snapshot: all selected states at each output point
mode snapshot
analysis tran
nodes {clk {type digital} out {type digital}}
batches {
{time 1e-9 values {clk 1s out {}} known {clk}}
{time 2e-9 values {clk 1s out 0s} known {clk out}}
}
Each batch contains time, values and known:
time: the accepted transient output time for this snapshot.values: a dictionary containing every selected node and its latest received value. Nodes without a new report retain their previous value; a node with no report yet has an empty string.known: the names of nodes whose values have actually been received. Consult this list to distinguish a missing initial value from an explicit unknown/high-impedance state reported by ngspice.
Registering a node does not force ngspice to report an initial value. In the first example snapshot, out has
not reported yet; in the second it has reported 0s, while clk is carried forward as 1s. Snapshots record
one batch per accepted output point, even if nothing changes. This can require much more memory than changes or
pernode. The snapshot is a carried-forward state, not an interpolation of the digital history.
foreach batch [dict get $data batches] {
set time [dict get $batch time]
if {{out} in [dict get $batch known]} {
puts "$time: [dict get $batch values out]"
}
}
pernode: immediately available node histories
mode pernode
analysis tran
nodes {
clk {type digital events {{0.0 0s 0} {1e-9 1s 1}}}
out {type digital events {{1.5e-9 0s 1}}}
}
batches {}
Each node dictionary adds events, a list of {eventTime value last} records. The node name is already the
dictionary key, so it is omitted from each record. These fields have the same meanings as in changes.
batches is always empty. A selected node with no reports has events {}. Histories for different nodes
can be at different stages of delivery during a run; this mode provides no all-nodes completion boundary.
foreach event [dict get $data nodes clk events] {
lassign $event eventTime value last
puts "$eventTime: $value"
}
Operating point and DC sweep
The same eventnodes and eventdata commands support OP and DC. Selection, clear, ownership and circuit
replacement rules are unchanged. The bridge samples settled node histories at each numeric output point,
including internal subcircuit nodes. OP/DC points are available immediately after that callback, without
the one-output-point publication delay used for transient batches.
$sim eventnodes -all -mode snapshot
$sim command op
set operatingPoint [$sim eventdata]
$sim command {dc vin 0 2 1}
set sweep [$sim eventdata]
For an ADC bridge with thresholds 0.5 V and 1.5 V, a DC snapshot result can look like this:
mode snapshot
analysis dc
nodes {xlogic.d {type d}}
batches {
{point 0 coordinates {vin 0.0} values {xlogic.d 0s} known {xlogic.d}}
{point 1 coordinates {vin 1.0} values {xlogic.d Us} known {xlogic.d}}
{point 2 coordinates {vin 2.0} values {xlogic.d 1s} known {xlogic.d}}
}
pointis the zero-based numeric output index in this plot. It continues across nested sweep branches and is not reset by eventdata -clear. It is not a simulation timestamp.coordinatesmaps sweep names to values in native units: volts, amperes, ohms or degrees Celsius. An OP result has analysis op and one point with coordinates{}. It has no time coordinate.valuesmaps every selected node to its settled string state. known lists the nodes successfully read; a nativeUstate is a known reported value, not missing data.
For a nested sweep such as dc vin 0 0.4 0.2 vbias 0 0.2 0.2, the last snapshot has point 5 and coordinates
{vin 0.4 vbias 0.2}. The primary coordinate comes from ngspice’s output scale. The outer coordinate starts at
the declared outer limit and advances when the primary scale wraps to its next branch. Repeated primary values
therefore remain distinguishable. Nested sweep limits must be literal numbers, optionally with SPICE suffixes;
parameter expressions, altered sweep definitions and compressed/filtered output are not supported. Use one
.dc directive in circuit input, or a direct dc command; includes, aliases and multiple .dc directives
cannot reliably provide coordinate metadata and are outside this interface. A retrieval failure is reported by
eventdata rather than returning a partly filled point.
OP/DC changes mode records the first known state and subsequent value changes. Empty points are omitted:
mode changes
analysis dc
nodes {xlogic.d {type d}}
batches {
{point 0 coordinates {vin 0.0} events {{xlogic.d 0s}}}
{point 1 coordinates {vin 1.0} events {{xlogic.d Us}}}
{point 2 coordinates {vin 2.0} events {{xlogic.d 1s}}}
}
OP/DC pernode mode stores those changes under each node. Each record is a dictionary:
mode pernode
analysis dc
nodes {xlogic.d {type d events {
{point 0 coordinates {vin 0.0} value 0s}
{point 1 coordinates {vin 1.0} value Us}
{point 2 coordinates {vin 2.0} value 1s}
}}}
batches {}
OP uses the same mode-dependent layouts, with only the initial state and an empty coordinates dictionary. There is no last flag in OP/DC records: these are settled states, not native transient callback groups. No transient delay, pulse width or glitch history can be inferred from a DC sweep.
foreach batch [dict get $sweep batches] {
puts "[dict get $batch coordinates vin] V: [dict get $batch values xlogic.d]"
}
OP/DC collection uses ngGet_Evt_NodeInfo. Queries copy native event history, so their cost
grows with stored history; this initial implementation favors correctness over large-sweep performance.
Publication, clearing and repeated runs
All transient modes receive data through the same raw callback. In changes and snapshot, the next analog sample callback publishes the preceding batch; completion or halt publishes the final batch. The raw callback’s last flag alone cannot complete a batch across all nodes. Reading eventdata or calling flush does not publish a partial batch. Purely digital transient circuits use ngspice’s time-only output for this boundary. Transient collection requires normal output from time zero; there is no wall-clock sampling interval.
eventdata -clear discards committed and pending history, retaining node selection and latest known states.
It returns the cleared result, not the discarded records. Later callbacks continue recording; snapshot can
carry forward retained states. To consume history, read it before clearing it. Reads and clears are separate
calls: pause the simulation first if records arriving between those calls must not be discarded.
A new plot clears history and known states. Halt/resume of the same plot preserves them. Numeric vectors
-clear and command -clear do not clear digital history. Replacing a circuit through the circuit subcommand
while idle clears history and explicit -nodes selection, retains the mode, and re-registers -all against the
new nodes. Direct circuit-changing commands and scripts are unsupported once event collection is configured.
eventcounts exposes send_raw_evt (native callback invocations), event_init (bridge initialization) and
event_batch (complete transient batch boundaries or accepted OP/DC output points). All support waitevent
-since. event_batch includes boundaries with no changes, so it need not equal the number of stored changes
batches. Disabled node registrations remain until circuit destruction and can still contribute to
send_raw_evt. Clearing history does not reset these counters. Decoder errors are reported by eventdata
until configuration or a new plot resets them.
Copyright (c) George Yashin