Integrating EPICS and LabVIEW
Agenda Overview Channel Access (CA) Support LabVIEW EPICS CA Server LabVIEW EPICS CA Client EPICS IOC Support CompactRIO PXI 3 rd Party Options Questions and Answers 3
Overview 4
EPICS Overview Experimental Physics and Industrial Control System (EPICS) Used to develop and implement distributed control systems to operate large experiments SCADA architecture that uses client/server and publish/subscribe Input/Output Controller (IOC) collect experiment and control data Operator Interface (OPI) display data and control experiments Channel Access (CA) is a Ethernet protocol used to distribute the data Process Variables (PVs) are unique data items on CA protocol 5
EPICS Software Architecture Distributed Clients (OPI Operator Interface) and Servers (IOC I/O Controllers) Network protocol: Channel Access (CA) with Process Variables (PVs) OPI (Operator Interface) OPI (Operator Interface) CA (Channel Access) IOC (I/O Controller) IOC (I/O Controller) IOC (I/O Controller) IOC (I/O Controller) I/O HW I/O HW I/O HW I/O HW Analog I/O, Digital I/O, Motion Control, Image Acquisition, etc. 6
IOC Software Architecture Network Traffic (Channel Access protocol) Channel Access Protocol Server Sequencer (Finite State Machine) Channel Access Protocol Server Publishes values from the database onto the network using Channel Access protocol EPICS Database Sequencer Controls timing for when to update values Database Engine EPICS Database Contains the record definition and values Hardware 7 Database Engine Writes I/O values to the database
Why Integrate EPICS and LabVIEW? EPICS Client EPICS Client LabVIEW as a Client Presentation Analysis Control IOC (I/O Controller) I/O HW LabVIEW as a Server Interface to hardware Real-time control Access to FPGA 8
LabVIEW EPICS CA Server 9
LabVIEW EPICS CA Server Network Traffic (Channel Access Protocol) EPICS Client LV EPICS Server I/O Server Channel Access Server I/O HW LabVIEW Shared Variable Engine LabVIEW Application Hardware 10
Architecture Comparison Network Traffic (Channel Access protocol) Channel Access Protocol Server Sequencer (Finite State Machine) LV EPICS Server I/O Server EPICS Database LabVIEW Shared Variable Engine Database Engine LabVIEW Application Hardware 11 Hardware
LabVIEW EPICS CA Server Runs on LabVIEW for Windows and LabVIEW Real-Time Implemented as an I/O Server Interfaced via Shared Variable Provides Channel Access functionality only 12
Example BiRa s Power Supply 16 channels of high precision bipolar DC power Mainly used for corrector magnets in particle accelerators Running LabVIEW EPICS CA Server on an embedded real-time controller 13
Concept The EPICS CA Server and EPICS CA Client are implemented as plug-ins to the I/O Server In both cases the interface in LabVIEW is implemented via the Shared Variable Process Variables (PVs) I/O Server Shared Variables 14
Distribution Windows Real-Time OS CA Server LabVIEW DSC LabVIEW RT CA Client LabVIEW DSC or Free download LabVIEW RT EPICS CA Server: available in LabVIEW 2011, via the DSC module for Windows and the RT module (PXI and crio) EPICS CA Client: available in LabVIEW 2011, via the DSC module for Windows and the RT module (PXI and crio) EPICS CA Client: also available as a free download 15
Implementation CA Server Start by creating the Shared Variables you want to publish on the EPICS network Then create an EPICS CA Server I/O Server Define the PV names and associate them with the Shared Variables Read or write to the Shared Variables in LabVIEW to access the associated PVs 16
Example 17
Demo 1 - CA Server Create an empty project Create a new library containing the Shared Variables 19
Demo 1 - CA Server Create a new I/O Server and select EPICS Server as the I/O Server type 20
Demo 1 - CA Server Click on Add/Remove Variables 21
Demo 1 - CA Server Select the Shared Variables library and click Add All >> 22
Demo 1 - CA Server Click OK to see the PV configuration (with default names) 23
Demo 1 - CA Server Click twice on the PV name to enter a new PV name 24
Demo 1 - CA Server Deploy both libraries Create a new VI and drag and drop the 2 Shared Variables to the front panel Run the VI continuously 25
Demo 1 - CA Server You can use EPICS commands to verify that the PVs are properly published 26
Demo 1 - CA Server From there you can use the Shared Variables as the LabVIEW representation of the PVs 27
Programmatic Access to LabVIEW EPICS CA Server 28
Programmatic Access Simple implementation is configuration-based New feature since LabVIEW 2010 allows to programmatically: Create an EPICS CA Server Create the Process Variables Bind Process Variables to Shared Variables Benefits Easily handles large number of PVs Greatly facilitates deployment 29 29
Duplicating Systems 30
Possible Implementation Create PVs programmatically and use an ini file to modify the names of the PVs Each unique system can use the same application where the only difference is a text file 31
Writing Application to Run on Multiple Targets Implement the following steps more information on each step in the coming slides Use an ini file to modify the names of the PVs Use relative paths for ini file, server, and library Make the shared variables Target Relative 32
Use relative paths for ini file, server, and library Use path to local root directory for ini file path Use localhost for the computer name in the server path Build the shared variable library path Pvnames.ini is the name of the file Variables is the name of the shared variable library to be published on EPICS EPICS_Server is the name of the EPICS Server 33
Make the shared variables Target Relative Right click and select Reference Mode >> Target Relative 34
Details Simple Example 35
Details SubVI Auto Name PVs 36 36
Details SubVI Rename With Prefix 37
LabVIEW EPICS CA Client 38
LabVIEW EPICS CA Client Network Traffic (Channel Access Protocol) EPICS Client LV EPICS Client I/O Server IOC (I/O Controller) I/O HW LabVIEW Shared Variable Engine LabVIEW Application 39
LabVIEW EPICS CA Client Runs on LabVIEW for Windows and LabVIEW RT Implemented as an I/O Server Interfaced via Shared Variable 40
Implementation CA Client Create an EPICS CA Client I/O Server Define the PVs you want to monitor, either manually or by importing a.db file Create the associated Shared Variables and bind them to each PV Read or write to the Shared Variables in LabVIEW to access the associated PVs 41
Example 42
Demo 2 CA Client Using a simple data base PV cycles from 0 to 10 43
Demo 2 - CA Client Create an empty project Create a new I/O Server and select EPICS Client as the I/O Server type 45
Demo 2 - CA Client Click on Add Record to add a record manually 46
Demo 2 - CA Client Enter the desired PV name in the Name text box (under Attributes) Click OK and rename the library 47
Demo 2 - CA Client Another option is to import PVs directly from a.db file by clicking Import File Select the desired.db file If the file contains substitutions you will be asked to enter a name for each one 48
Demo 2 - CA Client Create a new library containing the Shared Variable(s) Enter the desired name for the Shared Variable(s) 49
Demo 2 - CA Client Check Enable Aliasing, click Browse, and point to the value field (VAL) for the desired PV 50
Demo 2 - CA Client Click OK twice and rename the library 51
Demo 2 - CA Client Create a new VI and drag and drop the Shared Variable to the front panel Run the VI continuously 52
Demo 2 - CA Client From there you can use the Shared Variables as the LabVIEW representation of the PVs 53
Client Programmatic Access New Feature in LabVIEW 2011 Allows user to programmatically Create an EPICS CA Client Connect to existing Process Variables Bind Process Variables to Shared Variables Benefits Easily handle large numbers of variables 54
Additional Information 55
Additional Information Supported data types Available fields Deployment Tips and tricks 56
Supported Data Types Shared Variable Data Type PV Type Data Type Description PV Category Single DBF_FLOAT Single-precision floating-point number Double DBF_DOUBLE Double-precision floating-point number Int8 DBF_CHAR 8-bit integer UInt8 DBF_UCHAR Unsigned 8-bit integer Numeric Int16 DBF_SHORT 16-bit integer UInt16 DBF_USHORT Unsigned 16-bit integer Int32 DBF_LONG 32-bit integer UInt32 DBF_ULONG Unsigned 32-bit integer Boolean DBF_ENUM True or False logical value Logical String DBF_String A sequence of characters representing readable text String Array of Single DBF_FLOAT Array of single-precision floating-point numbers Array of Double Array of double-precision floating-point DBF_DOUBLE numbers Array of Boolean DBF_ENUM Array of True or False logical values Array of Int8 DBF_CHAR Array of 8-bit integers Array of UInt8 DBF_UCHAR Array of unsigned 8-bit integers Array of Int16 DBF_SHORT Array of 16-bit integers Array of UInt16 DBF_USHORT Array of unsigned 16-bit integers Array of Int32 DBF_LONG Array of 32-bit integers Array of UInt32 DBF_ULONG Array of unsigned 32-bit integers 57 Array
Available Fields EPICS CA Server On Windows, when using alarming with LabVIEW DSC, the corresponding fields (HIHI, HHSV, SEVR, etc.) are supported On RT targets, the EPICS CA Server only allows you to set the VAL field EPICS CA Client Any field can be accessed, but a Shared Variable will have to be created per field 58
Deployment To a Windows target Requires the LabVIEW DSC run-time engine, or Requires a full copy of LabVIEW DSC To a Real-Time target (PXI, crio, sbrio) Requires that the EPICS CA Server support is included 59
Tips and Tricks When you import Process Variables from a.db file, LabVIEW imports only the VAL field Use EPICS commands (caget, caput, cainfo, etc.) to dissociate EPICS issues from LabVIEW issues Use the Distributed System Manager to monitor the status of any LabVIEW EPICS I/O Server (you can even create one from DSM) 60
EPICS CA Server Benchmarks Maximum Update Rate(ms) 9024 9014 1000 PVs 220 900 500 PVs 115 100 PVs 22 90 10 PVs 3 5 2 PVs 1 5 61
Distribution Windows Real-Time OS CA Server LabVIEW DSC LabVIEW RT CA Client LabVIEW DSC or Free download LabVIEW RT EPICS CA Server: available in LabVIEW 2011, via the DSC module for Windows and the RT module (PXI and crio) EPICS CA Client: available in LabVIEW 2011, via the DSC module for Windows and the RT module (PXI and crio) EPICS CA Client: also available as a free download 62
EPICS IOC on CompactRIO 63
Embedding EPICS IOC on CompactRIO EPICS IOC and LabVIEW Real-Time running simultaneously Take advantage of FPGA platform with CompactRIO CA EPICS IOC I/O Card I/O Card LabVIEW Real-Time VxWorks PCI LabVIEW FPGA Xilinx FPGA CompactRIO Architecture 64 I/O Card I/O Slots
IOC Server on CompactRIO Network Traffic (Channel Access Protocol) Channel Access Protocol Server Publishes values from the database onto the network using Channel Access protocol. Sequencer (Finite State Machine) Reads values from the database to drive state changes in the IOC control application. EPICS Database Shared Memory Database Engine LabVIEW Application Hardware 65
IOC Server on CompactRIO CompactRIO controller runs VxWorks Implemented via shared memory Interface to hardware via LabVIEW RT and FPGA Can be used with Scan Mode Requires a custom VxWorks kernel (LV 2010 SP1 and earlier) Requires special.out files (LV 2011) Limited EPICS Device Support # Read a double from shared memory record(ai,"$(name):ai0") { # field("read a double from SM") field(dtyp,"sm Device") field(inp,"@0") field(scan,".1 second") } 66
Shared Memory Benchmarks LV 8.5 9014 Arrays Maximum transfer of 1 to 5 MB/s Integers Maximum transfer of about 10 to 12 kb/s 67
Example Los Alamos LANSCE Migration to a crio with embedded EPICS 12 binary outputs 36 binary inputs 12 analog inputs 5 stepper motor channels Full IOC functionality allows access to all record fields and EPICS utilities Maximum flexibility for partitioning the problem LabVIEW for beam diagnostic EPICS for industrial control 68
EPICS IOC on PXI 69
IOC Server on PXI Network Traffic (Channel Access Protocol) Channel Access Protocol Server Publishes values from the database onto the network using Channel Access protocol. Sequencer (Finite State Machine) Reads values from the database to drive state changes in the IOC control application. EPICS Database Shared Memory Database Engine LabVIEW Application Hardware 70
IOC Server on PXI Shared Memory PXI controller runs Linux, hypervisor, and LV RT Implemented via hypervisor shared memory Interface to hardware via LabVIEW RT and FPGA (FlexRIO) EPICS Device Support needs to be developed by customer or integrator 71
EPICS IOC on PXI (no LabVIEW) Support driven by ITER requirements EPICS and Linux (RHEL) EPICS device driver Multifunction DAQ cards (M Series and X Series) Timing and Synchronization (PXI-6682) Ongoing efforts to support FPGA-based devices (R Series and FlexRIO) through device support and C API 72 72
Standard Embedded RIO Architecture Processor FPGA I/O Modules 73
Standard Embedded RIO Architecture Processor FPGA I/O Modules NI Custom 74
EPICS and FPGA-based Devices LabVIEW FPGA strategy is to empower domain experts to leverage FPGA technology No VHDL / Digital Design training For VHDL experts CLIP / IP Integration nodes to integrate IP (minimal LV FPGA required during development) EPICS device driver support implemented in C Generic FPGA interface, to be customized based on the application and FlexRIO adapter module 75
FPGA Interface C API and Linux Use RIO devices (e.g. R Series or FlexRIO) from C/C++ applications running on Linux Generate C header file from Windows development machine, then use C compiler of choice on Linux Development System Requirements for LabVIEW FPGA: Windows XP (or later) NI-RIO 3.5.0 (or later) FPGA Interface C API 1.2 (or later) LabVIEW FPGA 2009 (or later) Deployment System Requirements: 32-bit Red Hat Enterprise Linux 5.x or 32-bit Scientific Linux 5.x NI-RIO 3.5.0 for Linux (or later) 76
FPGA Interface C API on Linux Generated Header and Source Files C API LabVIEW FPGA Development (Windows) Linux Deployment Development RIO Device 1. Develop LabVIEW FPGA VI, compile bitfile, and generate C API. 2. Develop and build C application with generated C API. 3. Deploy built application and bitfile to Linux target and run. 77
Current Support EPICS Record types supported Binary in Binary out Analog in Analog out Waveforms Linux 32bit RHEL 5.5 EPICS 3.14.11 78
Options for EPICS and NI Hardware 1 2a LabVIEW I/O Server EPICS CA Client or Server 2b LabVIEW RT on crio Shared Memory EPICS IOC on VxWorks 3 LabVIEW RT on PXI Hypervisor Shared Memory EPICS IOC on Linux PXI (No LabVIEW) Linux Driver Device Support EPICS IOC on Linux 79
3 rd Party Options 81
Other Options for Integrating EPICS and LV SNS Shared memory interface SNS Native CA support in LabVIEW Observatory Sciences 82
SNS - EPICS Shared Memory Interface LabVIEW Application (Wire scanner, BPM, etc) ReadData() WaitForInterrupt() GetIndexByName() WriteData() SetInterrupt() Shared Memory DLL CreateDBEntry() EPICS Channel Access EPICS Database EPICS IOC 83
Shared Memory IOC Integration with the control system The Shared Memory IOC allows us: Support additional processes Use records as placeholder of data but no function Not worry about buffering data Respond to events Be compatible with other IOCs Functions: Create, find and destroy variables Read from and write to variables Set and receive events Retrieve information about variables Create IOC database 84
Pros and Cons Advantages You have full IOC and everything that comes with it (including record processing) All EPICS tools will work by default Challenges Linux and RTOS support would require considerable efforts Need to support 2 infrastructures for EPICS IOC and for LabVIEW program deployment is complicated. 85
Example SNS Facility Instrumentation Measure beam parameters such as position, transverse profile, current, etc Off-line Data Analysis Statistics, performance Testing Equipment Calibration Prototyping Test electronics Simulation Electron scanner Ion profiles 86
SNS - Native CA Support In LabVIEW When using EPICS IOC only for Channel Access communication Record processing can be done in LabVIEW To be compatible with all platforms LabVIEW runs on Windows, Linux, Mac, VxWorks, Pharlap To connect to EPICS clients 87
LabVIEW CA Server Structure Launch UDP listener (for search requests) Launch TCP listener (for new VC connections) Launch several threads for communication Launch one (or several) threads for message processing Three queues responsible for data transfer and data locking VC can be in either processing state or in communication state Records are guarded differently 88
Observatory Sciences Programmatic Channel Access Client Functionality equivalent to caget, caput, and camonitor Built on top of TCP and UDP support in LabVIEW Supported data types: double, int32, and string 89
Questions? 90