2026-11-02 13:37:34 +01:00
2026-11-02 13:37:34 +01:00
2026-10-22 16:08:10 +02:00
2026-10-30 13:03:07 +01:00
2026-11-02 13:37:34 +01:00
2026-11-02 13:37:34 +01:00
2026-11-02 13:37:34 +01:00
2026-11-02 13:37:34 +01:00

xiad

Acquisition daemon for the XIA FalconX pulse processor, talking its native SINC protocol over TCP. No Handel, no Windows, no TACO device server in between: xiad connects to the box directly and will serve spectra and counting statistics to Pylatus the way p201d serves a counting card.

Status

Increments 1 to 4: SINC client, the probe diagnostic, the Handel ini loader with check and apply, and the daemon itself (serve) with live spectra, fixed-time counting, gated (zap) acquisition and ini changes from the client. The hardware gate from the MUSST comes with musstd.

Running

xiad [-s SINC_PORT] [-v...] HOST probe [--list]
xiad [-s SINC_PORT] [-v...] HOST check INI
xiad [-s SINC_PORT] [-v...] HOST apply INI
xiad [-s SINC_PORT] [-v...] HOST serve [-p PORT] [--software-gate]
xiad [-s SINC_PORT] [-v...] HOST trigger [COUNT] [-i SECONDS]

probe pings the instrument, prints the instrument identity and the acquisition state of both channels and exits. --list additionally dumps every parameter the firmware knows with its type, access, units and allowed values. The FalconX listens on port 8756; through an ssh tunnel use -s with the local port.

check reads a Handel ini file and compares it with the instrument without writing anything: the detector characterization byte for byte, then every parameter the ini maps to. apply uploads the characterization when it differs, writes the parameters one by one in ini order the way Handel does, remembers the file as the current ini and ends with the same comparison. Both exit non-zero when something differs.

serve listens for Pylatus on port 8504 by default and stays in the foreground for the init system. At start, and again after every reconnection, it applies the remembered ini the way Handel re-applies its file at every start, switches the gate statistics off, subscribes to the channel and starts a continuous histogram: the instrument then pushes a spectrum every refresh period (0.1 s from the ini) and every client sees it as the live display. When the FalconX cannot be reached, at boot before the switches are up or after a power cut, the daemon keeps serving, reports the state as offline, answers requests with an error and retries every 2 seconds; only the transitions are logged.

The current ini is kept in $XDG_CONFIG_HOME/xiad/<host>.toml (name and text), written by apply and by the INI request below. Without one the daemon trusts whatever the instrument holds.

trigger toggles the software gate of the instrument COUNT times, SECONDS apart (0.1 by default), over a second SINC connection. It is the bench substitute for the MUSST: a daemon started with --software-gate arms with gate.source = software, and two toggles then make one point with the edge collection modes.

Protocol to Pylatus

Both directions send a little endian header u32 type, u32 len followed by len payload bytes. Requests:

0x100 HELLO            no payload, answered with CONFIG and STATUS
0x101 CT               f64 seconds: count for that long, then the final spectrum
0x102 ABORT            no payload, stops a ct (its last frame arrives incomplete) or a zap
0x103 STATUS           no payload
0x104 INI              u32 name length, name, ini text: apply and remember it
0x105 ARM              u32 points: one spectrum per gate edge until that many
0x106 DISARM           no payload, same as ABORT
0x107 READ_FROM        u32 first: resend the stored points with an index >= first

Every response is broadcast to all clients, the instrument being one shared device. Responses:

1 SPECTRUM   96 byte header, then u32 bins:
             u32 channel, u32 complete, u32 kind (0 live, 1 ct, 2 zap), u32 nbins,
             u64 dataset_id, f64 time_elapsed, u64 samples_detected,
             u64 samples_erased, u64 pulses_accepted, u64 pulses_rejected,
             f64 input_count_rate, f64 output_count_rate, f64 dead_time_percent,
             u32 gate_state, u32 reserved
2 STATUS     u32 version (2), u32 state (0 idle, 1 counting, 2 armed, 3 offline),
             u32 capacity, u32 points, u32 lost, u32 reserved, f64 duration
3 ERROR      utf8 text
4 CONFIG     f64 bin width in eV, u32 number of bins, u32 first bin, then the
             utf8 name of the current ini; the name is empty when none is
             remembered and the bin width is 0 when the ini does not give one

Only the accepted spectrum is sent. The Handel counters derive from the header: triggers = accepted + rejected, livetime = triggers / input_count_rate, events = accepted, realtime = time_elapsed; regions of interest are sums over bins and belong to the client.

A ct switches the instrument to its fixedTime mode for duration seconds and back to continuous afterwards. Intermediate spectra arrive every refresh period as incomplete ct frames, the last one is marked complete: the instrument, not the clock, decides which frame is the last, so each frame is held back until the next one or the end of the run. The refresh period is lowered to the duration for short counts, the firmware minimum is 10 ms.

ARM switches the instrument to its gated mode: gate.source external (or software, see trigger), the collection mode the ini implies through input_logic_polarity and gate_ignore (fallingEdge for the BM31 files), no refresh frames. Every gate edge then yields one complete zap spectrum whose dataset_id is the point index from 0; a gap in the indices is a point the instrument dropped, counted in lost of STATUS, and the client fills it in. The run ends by itself once points edges have been seen, received plus lost, or on DISARM; either way the daemon returns to the continuous live display with the gate switched off. capacity, points and lost of STATUS describe the last armed run, whose points stay in memory until the next ARM: READ_FROM resends them to every client, for one that lagged behind the broadcast or connected late. spec/falconx/xiaclient.py in the Pylatus tree talks this protocol for tests.

Handel ini

ProSpect characterizes the detector on Windows and Handel saves the result in an ini file. xiad reads that file instead of Handel: [module channel data] holds the characterization (data_chanN = base64 of a zlib stream: the 128 data bytes as hex plus the example, model and final pulse shapes), [default definitions] holds the acquisition values, and [module definitions] ties them to a channel.

The acquisition values are translated with the rules from Handel's falconxn_psl.c (BSD-3): analog_gain becomes afe.dacGain through its log formula, scale_factor splits into histogram.coarseBinScaling and pulse.scaleFactor, number_mca_channels and mca_start_channel become the bin sub region, enumerations map to the SINC option names, and instrument.digital.config is set to 8in-24out as Handel does at start-up. histogram.mode and the gate.* parameters are deliberately not touched: Handel sets those when a run starts, so they belong to the acquisition commands. input_logic_polarity and gate_ignore are only reported, as the gate collection mode a gated run will use. mca_bin_width, number_mca_channels and mca_start_channel go to the client in CONFIG as the energy axis of the spectrum: Handel never writes the bin width to the instrument, ProSpect stores it in the ini for exactly this use, scaling the axis of a display.

The comparison accepts the instrument's own rounding: integers within one unit, floats within 0.1 percent, since the box stores thresholds on its DAC grid and truncates the DAC gain to an integer.

Every SetParam makes the instrument broadcast a ParamUpdated message to all connected clients, which is what crashes the ESRF xmapds device server: do not apply while it is connected.

SINC on the wire

Every message is a 10 byte little endian header followed by a protobuf payload:

marker  uint32   0x88E7D5C6 from the client, 0x87D6C4B5 from the instrument
length  uint32   payload length + 2
code    uint8    3 = protobuf
type    uint8    MessageType from sinc.proto
payload          proto2 message of that type

Replies carry no request id and arrive in command order; xiad keeps a FIFO of waiting callers and hands each reply to the oldest one. Frames the instrument pushes on its own (histograms, parameter updates, asynchronous errors, calibration progress) bypass the FIFO and go to an event channel.

A histogram payload is not a plain protobuf: a uint16 header length (0xFFFF means a uint32 follows), the HistogramDataResponse header without intensities, then the raw little endian uint32 plots, one per plotLen entry.

proto/sinc.proto is the interface description published by XIA in Handel-FalconX-Releases; it is compiled at build time by protox and prost, no system protoc needed.

Build

cargo build --release

Dependencies from crates.io: base64, bytes, clap, confy, dirs, flate2, futures, prost, serde, tokio, tokio-util; prost-build, protox, vergen-gitcl at build time. Internal: besy.

tests/data/ holds the BM31 production ini; the unit tests decode it and check the translation against the values read from the live instrument.

License

GPL-3.0+

S
Description
XIA daemon
Readme
136 KiB
0 Stars 1 Watchers 0 Forks
Languages
Rust 100%