Adding a new device to EPICS¶
- Table of contents
- Adding a new device to EPICS
Adding a new device to EPICS could mean one of the following:
- Adding channels for a new unit of hardware of a type already supported by an IOC you have -- this just means changes to "db" files, see the standard EPICS tutorials on db files. 
- Compiling a new IOC with support enabled for a type of device for which someone has already written a device driver -- this just means following appropriate compile instructions. [2,3]
- Creating a new device driver for a new kind of device EPICS has never supported before, and compiling an IOC with that support. For this case, see the text below.
Adding support for a new kind of device¶
0) Install EPICS base.
1) Initialize the new app. (In the following you should change "RunControl" to name of your IOC.)
mkdir (directory anywhere);
cd (to the directory)
makeBaseApp.pl -t ioc RunControl
makeBaseApp.pl -i -t ioc RunControl
[this is a good point to commit to a repository for reference]
2) Add definition and code for the new device. For a simple single-value input channel, you want to make it an "ai" type channel. (In the following, change "devRunControlSHM.dbd" and "aiRunControlSHM.c" to whatever you want to name your files.)
Files to add:
RunControlApp/src/aiRunControlSHM.dbd -- define device in db
RunControlApp/src/devRunControlSHM.c -- the code for the device
(see $EPICS_BASE/src/std/dev/devAiSoft.c for a working ai device and modify to suit)
Files to modify:
RunControlApp/src/Makefile -- tell it what to put in your IOC support library and database definition file
Here is an example of what needs to be modified in the App/src/Makefile directory:
@@@ #---------------------------------------- # ADD MACRO DEFINITIONS AFTER THIS LINE #============================= + + # Build an IOC support library + LIBRARY_IOC += aiRunControlSHM + + DBD += aiRunControlSHM.dbd + aiRunControlSHM_SRCS += devRunControlSHM.c + aiRunControlSHM_LIBS += $(EPICS_BASE_IOC_LIBS) @@@ # RunControl.dbd will be made up from these files: RunControl_DBD += base.dbd # Include dbd files from all support applications: - #RunControl_DBD += xxx.dbd + RunControl_DBD += aiRunControlSHM.dbd # Add all the support libraries needed by this IOC - #RunControl_LIBS += xxx + RunControl_LIBS += aiRunControlSHM
3) Compile (make)
4) You will either have to add definition for new channels to .db file (which should be in <top>/RunControlApp/Db), or create a .db file for your channels. This file should be loaded in st.cmd (in <top>/iocBoot/iocRunControl/st.cmd).
6) Test with caget or caput as appropriate
Any questions with these steps are best answered by installing the simple example in referece .
- source:apps/rackmonbox -- ARM-based rack monitor and general purpose IOC-in-a-box. (Targeted somewhat to BeagleBone Black, but so far fairly general to any ARM-based single board computer.)
- devBiRackProt.c is a pretty simple example of reading from a single GPIO input using Linux's /sys/class/gpio support
- devDS1621.c is a more complicated example that reads from and writes to multiple DS1621 thermometer chips. The code illustrates that you can define both analog input (ai) and analog output (ao) support in the same file if you want. It also illustrates the technique of using the INP field of EPICS to specify what you want a given ai or ao channel to do, e.g., which of 8 possible thermometers on the i2c bus you want to contact, and whether you want to read/write the temperature, high limit, low limit, etc.
- devADT7410.c is like devDS1621.c, but for the ADT7410 chip. (Code not tested as of 2016/02/15, caveat emptor.)
- MicroBooNE slowmon box -- MicroBooNE's equivalent to the rack monitor box. (Targeted to a Glomation GESBC-9G20, somewhat specifically in some cases.)
 "What is an EPICS Database?" and "Record Types and Examples" at http://www.aps.anl.gov/epics/docs/GSWE.php
 "Read Me (Installation Instructions)" at http://www.aps.anl.gov/epics/base/R3-14/12.php
 Chapter 2 (note especially section 2.5) in "EPICS Application Developer's Guide" at http://www.aps.anl.gov/epics/base/R3-14/12.php
 K. Furukawa, "Very Simple Example of EPICS Device Support", http://www-linac.kek.jp/cont/epics/second/
 "EPICS Application Developer's Guide" at http://www.aps.anl.gov/epics/base/R3-14/12.php