How blueforsoy/control_software_gen2_api_examples works
Purpose and execution model
This is a Python 3.10+ example repository for integrating with Bluefors Control Software 2 (CS2). It is not a single deployable application: scripts are intended to be run or adapted by users to monitor CS2 state and issue device commands through CS2 APIs.
Primary example families are:
• HTTP command/API examples: api_examples/
• WebSocket monitoring: websocket_example/monitoring.py
• Automated cooldown/warm-up orchestration: cooldown_scripts/
CS2 API boundary
All functional scripts act as clients of a CS2 installation, typically addressed through its HTTPS API and documented by the instance’s Swagger UI. CS2 is the system of record and device-control authority; this repository supplies client-side polling, command sequencing, and monitoring examples.
Transport security is a material boundary: HTTPS clients must trust the CS2 certificate, either through the host trust store or an explicitly supplied certificate path. WebSocket connections likewise carry authenticated CS2 traffic.
Paths: api_examples/README.md, websocket_example/README.md, cooldown_scripts/configuration.py
Authentication and token lifecycle
CS2 authentication is delegated to Keycloak. The shared authentication layer obtains access tokens, refreshes them when needed, and attaches them to subsequent HTTP or WebSocket requests.
There are two authentication implementations: a reusable package-level Keycloak client and a cooldown-specific adapter used by the orchestration scripts.
Paths: auth/keycloak.py, auth/__init__.py, cooldown_scripts/keycloak_auth.py
HTTP API command examples
The HTTP examples establish the basic control-plane pattern: authenticate, call CS2 REST endpoints over HTTPS, inspect returned values, and submit device commands. They are a starting point for bespoke integrations rather than a generalized SDK, so callers own production concerns such as retries and robust error handling.
Paths: api_examples/, api_examples/README.md
WebSocket monitoring pipeline
The monitoring example represents the event/streaming path. It authenticates to CS2, opens a WebSocket connection, and consumes monitoring values as they arrive, avoiding a polling-only integration model. Downstream user code can use this pattern for live dashboards, alarms, or process supervision.
Paths: websocket_example/monitoring.py, websocket_example/__init__.py
Cooldown and warm-up orchestration
cooldown_scripts/ is the repository’s highest-level workflow layer. It encodes staged cryogenic-system procedures: condensing, pulse-tube cooling, pump/vacuum control, full PPC handling, and warm-system operations. These scripts coordinate multiple CS2 commands and observed conditions rather than exposing isolated endpoint calls.
Paths: cooldown_scripts/cooldown.py, cooldown_scripts/warm_system.py, cooldown_scripts/condensing.py
Procedure stages and subsystem boundaries
The orchestration is decomposed by physical subsystem and operational stage:
• configuration and shared operational parameters;
• common API/process functions;
• pulse-tube cooling;
• vacuum-can pump control;
• PPC full procedure;
• condensing and overall cooldown sequencing.
This separation allows an engineer to reuse stage-specific operations while cooldown.py composes broader procedures.
Paths: cooldown_scripts/configuration.py, cooldown_scripts/functions.py, cooldown_scripts/pt_cooling.py, cooldown_scripts/pump_vc_full.py, cooldown_scripts/ppc_full.py
Operational constraints
Examples intentionally omit much production hardening, including comprehensive error handling and retry behavior. Any production automation built from the cooldown scripts should add command idempotency, state validation, timeout/retry policies, token-refresh failure handling, audit logging, and safe abort/interlock behavior around CS2 device-control calls.
Main entry points: functions.py Common API functions · cooldown.py Cooldown sequencer · keycloak.py Shared Keycloak client · monitoring.py WebSocket monitor
Components 14
Client examples
- HTTP API examples · Authenticate, inspect state, and submit REST commands.
- WebSocket monitor · Consumes live CS2 monitoring values.
websocket_example/monitoring.py
Authentication
- Shared Keycloak client · Manages reusable access-token acquisition and refresh.
auth/keycloak.py - Cooldown auth adapter · Authentication implementation for procedure scripts.
cooldown_scripts/keycloak_auth.py
Cooldown orchestration
- Operational configuration
cooldown_scripts/configuration.py - Common API functions
cooldown_scripts/functions.py - Pulse-tube cooling
cooldown_scripts/pt_cooling.py - Vacuum-can pumping
cooldown_scripts/pump_vc_full.py - Full PPC procedure
cooldown_scripts/ppc_full.py - Condensing stage
cooldown_scripts/condensing.py - Cooldown sequencer · Composes staged cryogenic cooldown operations.
cooldown_scripts/cooldown.py - Warm-system procedure
cooldown_scripts/warm_system.py
CS2 services
- Keycloak · Delegated CS2 authentication authority.
- CS2 installation · System of record and device-control authority, reached through authenticated HTTPS and WebSocket APIs.
Connections 19
- HTTP API examples → Shared Keycloak client: obtains tokens
- HTTP API examples → CS2 installation: HTTPS REST commands · Clients must trust the CS2 certificate.
- WebSocket monitor → Shared Keycloak client: obtains tokens
- WebSocket monitor → CS2 installation: authenticated WebSocket
- Shared Keycloak client → Keycloak: authenticate / refresh
- Cooldown auth adapter → Keycloak: authenticate / refresh
- Common API functions → Cooldown auth adapter: uses auth
- Common API functions → CS2 installation: HTTPS device calls
- Pulse-tube cooling → Common API functions: uses common operations
- Vacuum-can pumping → Common API functions: uses common operations
- Full PPC procedure → Common API functions: uses common operations
- Condensing stage → Common API functions: uses common operations
- Cooldown sequencer → Operational configuration: reads parameters
- Cooldown sequencer → Condensing stage: coordinates
- Cooldown sequencer → Pulse-tube cooling: coordinates
- Cooldown sequencer → Vacuum-can pumping: coordinates
- Cooldown sequencer → Full PPC procedure: coordinates
- Warm-system procedure → Operational configuration: reads parameters
- Warm-system procedure → Common API functions: issues operations