common/output

Output buffer utilities for the Total Control scripting environment.

This module provides a small, transient output pipeline that scripts can use to
collect and retrieve messages between operations. It complements device APIs by
giving you a consistent place to aggregate ad-hoc results (e.g., logs, IDs,
intermediate calculation outputs) without managing your own arrays.

Features

  • initOutput(): Clear the buffer explicitly.
  • addOutput(message: string|number|Object): Append one message (validated).
  • lastOutput(): string|Array: Return "" if empty, the single value if one item, or an array if multiple.
  • getOutputFunc(output: any): () => any: Wrap a snapshot into a callable (used by Java bridge).
  • getOutputLength(): number: Current number of buffered entries.

Usage Example

var { addOutput, lastOutput } = require("sigma/common/output");

// Collect simple strings
addOutput("hello");
addOutput("world");
print("1:" + lastOutput()); // �� "1:hello,world"

// Interact with device (host will clear the buffer)
var device = Device.getMain();
print("2:" + lastOutput()); // �� "2:" (cleared)

// Collect JSON + numbers
addOutput({ a: 1, b: 2 });
addOutput({ x: 1, y: 2 });
addOutput(3);
var out = lastOutput();     // �� [ {a:1,b:2}, {x:1,y:2}, 3 ]

Multi-device Example

function mycollectSN(d) { addOutput(d.SN); }
addDeviceFunction("collectSN", mycollectSN, { mode: "sync", multiple: true });

var devices = Device.searchObject(sigmaConst.DevAll);
devices.collectSN();
print("SNs:" + lastOutput()); // e.g. "SNs:SN1,SN2"

devices.click(100, 200); // buffer cleared by host
print(lastOutput());     // �� ""

Integration

  • The buffer is process-local; it is not persisted and not shared across processes.
  • Device/host APIs may clear the buffer between steps to ensure fresh state.