2026-11-06 14:49:27 +01:00
2024-06-14 13:39:28 +02: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

p201d

P201 counting card reader daemon.

p201d provides a TCP server for reading live counts and zap-mode data from a P201 / CT2 counting card used at synchrotron beamlines. The daemon opens the card device, configures counters and input channels, and serves multiple clients with periodic count values and high-speed trigger captures.

Overview

The card is accessed via /dev/ct2_0 by default. Channel10 is used as a free-running periodic timer that gates the input channels. On each timer match an interrupt is generated, latch values are read and broadcast to all connected clients. The daemon also implements a zap mode where counters run cumulatively and a hardware trigger latches a buffer of values for later retrieval.

The command line interface configures input channels 1-9 with level and 50 ohm termination and selects the TCP port. Logging is controlled with -v and -m.

Components

  • src/main.rs - entry point, argument parsing, device acquisition, actix system bootstrap.
  • src/card.rs - hardware abstraction for the P201 / CT2 card: register I/O, ioctl, channel status, counter configuration, interrupts.
  • src/reader.rs - card reader loop, live counting mode and zap mode arming/disarming, interrupt handling via tokio::io::unix::AsyncFd.
  • src/server.rs - TcpServer actix actor, client connection acceptance and broadcast of responses.
  • src/session.rs - per-client ClientSession actor, request parsing and response encoding, v1/v2 protocol negotiation.
  • src/codec.rs - binary codec for client requests and responses, legacy SetCt and v2 opcodes for arm/disarm/status/read.
  • src/params.rs - clap definitions for device file, port, debug level and channel configuration [50ohm][:ttl|nim|auto].

Build

Requires a recent Rust toolchain and Cargo.

Dependencies from crates.io: actix, actix_derive, async-stream, tokio, tokio-util, bytes, clap, derive_more, libc, num-derive, num-traits, seq-macro, strum, strum_macros. Internal dependency:

  • besy - logging and signal handling used across Pylatus.

Build:

cargo build --release

The binary is placed in target/release/p201d. build.rs emits build timestamp and git information via vergen-gitcl.

Usage

Show help:

p201d --help

Channel configuration format is [50ohm][:ttl|nim|auto], default auto with no 50 ohm termination.

Example:

p201d -1 50ohm:ttl -2 -3 ttl -p 8123
  • -1 50ohm:ttl - channel 1, TTL level, 50 ohm termination
  • -2 - channel 2, auto level, no 50 ohm
  • -3 ttl - channel 3, TTL level, no 50 ohm
  • -p 8123 - TCP port, default 8123

Clients connect to the TCP port. Legacy protocol sends a 4-byte channel number followed by a 4-byte exposure time in microseconds. v2 protocol uses opcodes 0x100-0x104 for hello, arm, disarm, status and read-from with binary frames for live values, zap points and zap status.

License

GPL-3.0+

S
Description
ESRF P201 daemon
Readme
248 KiB
0 Stars 1 Watchers 0 Forks
Languages
Rust 100%