EPICS Channel Access and Python Integration

Jun 25, 2024

Lecture Notes: EPICS Channel Access and Python Integration

Introduction

  • Presenter: [Name not provided]
  • Topic: Usage of EPICS Channel Access and Python
  • Content Scope: Basics of libraries, developed applications, ongoing projects related to data collection

Why Use Python?

  • Widely recognized at APS (Advanced Photon Source) for scripting, control, and data analysis
  • Key Features:
    • Elegance and readability
    • Cross-platform compatibility
    • Free and open-source with many scientific libraries (e.g., NumPy, SciPy)

pyEPICS Channel Access Library

Three Layers:

  1. Low-Level: Direct mapping to C-based Channel Access shared object library
    • Close to C code but in Python
    • Uses EPICS base DLL
  2. PV Object Layer: Process variable (PV) with methods and attributes
    • More Pythonic and object-oriented
    • Ideal for significant programming involving Channel Access
  3. Procedural Layer: Functions like caget, caput, camonitor, cainfo
    • Simplest interface
    • Uses a global cache of process variables

Procedural Interface

  • Easy to use (e.g., CA put, CA get)
  • Options for put (waiting for processing completion) and get (raw or string formatted values)
  • CA info displays control fields and CA monitor for value change monitoring

PV Object

  • Creation: PV(name)
  • Methods/Attributes: Get, put, value
  • Handles connection management using events/callbacks
  • Event Callbacks: Functions run on PV value changes

Handling Waveforms and Strings

  • Waveforms: Use NumPy arrays for dense data storage and efficiency
  • Long Strings: Character waveforms for strings longer than 40 characters
  • Methods provided for getting/setting these values as strings or arrays

Implementation with C Types Library

  • C Types: Python interface to C/Fortran DLLs
  • Benefits:
    • Simplified implementation (no additional C code required)
    • Easy installation across platforms (Windows, Mac, Linux)
    • Supported threading
  • Channel Access Calls: (e.g., create_channel, create_subscription)
  • Preemptive Callbacks: Default option for handling epics callbacks in a separate thread

High-Level Devices with pyEPICS

  • Analog Input Device Example: Managed using fields and initializing attributes
  • Motor Device: Complex handling of motor fields; supports movement, checking limits, tweaks, etc.

GUI Controls with WXPython

  • Python GUIs using WX Python (a common toolkit)
  • Widgets: Text widgets, choices, numeric controls, etc.
  • Example Application: Displaying and controlling an area detector image

Advanced Applications

  • Motor GUI Controls: Enhanced MEDM-like screens
  • Instrument Management Application: Organizes PVS into instruments with savable states

Alarms and Event Management

  • Simple Alarms: Scripts for monitoring PV values and triggering callbacks for events
  • Useful for sending alerts or changing system states

Data Collection Tools

  • Scanning Software (in-progress): Collects data using step scanning methods
  • Positioners & Detectors: Capable of handling complex scan patterns

Moving to Scriptable and Network-Based Scanning

  • GUI for Scans: Interface for configuring and running scans
  • Database Integration: Using SQL databases for managing scan parameters and results in real-time

Future Goals and Challenges

  • Standardizing HDF5 Data Storage: Ensuring robust data conversion and storage
  • Improving Interactivity: Incorporating live plots and more responsive interfaces

Conclusion

  • Summary: Comprehensive exposure to pyEPICS, its capabilities, and ongoing developments
  • Acknowledgments: Special mention to contributors including Angus Gratton from ANU