Skip to content

Instantly share code, notes, and snippets.

@RobbieClarken
Last active June 27, 2016 06:08
Show Gist options
  • Save RobbieClarken/aa34ca49820da01e06874a37cf848755 to your computer and use it in GitHub Desktop.
Save RobbieClarken/aa34ca49820da01e06874a37cf848755 to your computer and use it in GitHub Desktop.

On the host machine:

mkdir ioc
docker run -it --name detector \
           -v "$PWD/ioc":/ioc \
           -e USER=root \
           -w /ioc \
           -p 8081:8081 \
           -p 5064:5064 \
           -p 5064:5064/udp \
           -p 5065:5065 \
           -p 5065:5065/udp \
           AustralianSynchrotron/epics:ubuntu16.04-areadetector2.4

In the docker container:

makeBaseApp.pl -t ioc cameraExample
makeBaseApp.pl -i -a linux-x86_64 -p cameraExample CameraServer

Replace cameraExampleApp/src/Makefile with:

TOP=../..
include $(TOP)/configure/CONFIG

PROD_NAME = cameraExample
PROD_IOC = $(PROD_NAME)

DBD += $(PROD_NAME).dbd

include $(ADCORE)/ADApp/commonDriverMakefile

PROD_SRCS_DEFAULT += $(PROD_NAME)_registerRecordDeviceDriver.cpp $(PROD_NAME)Main.cpp

include $(TOP)/configure/RULES

The important line to note is include $(ADCORE)/ADApp/commonDriverMakefile. This utilises a makefile in ADCore to specify which support modules and libraries are required. Since it uses the ADCORE macro, we should add that to our configure/RELEASE. Append to configure/RELEASE:

SUPPORT=/opt/epics/modules/soft/synApps/support
AREA_DETECTOR=$(SUPPORT)/areaDetector
ADCORE=$(AREA_DETECTOR)/ADCore

Try running make. Note we get the following errors:

Can't open include file "calcSupport.dbd"
Can't open include file "sscanSupport.dbd"
ErrorCan't open include file "busySupport.dbd"
ErrorCan't open include file "asyn.dbd"
ErrorCan't open include file "asSupport.dbd"

This indicates we need to include the calc, sscan, busy, asyn and autosave support modules. Append to configure/RELEASE:

ASYN=$(SUPPORT)/asyn-4-26
AUTOSAVE=$(SUPPORT)/autosave-5-6-1
BUSY=$(SUPPORT)/busy-1-6-1
CALC=$(SUPPORT)/calc-3-4-2-1
SSCAN=$(SUPPORT)/sscan-2-10-1

Try running make again. This time we may get errors like:

/usr/bin/ld: cannot find -lhdf5

To fix this, append to configure/CONFIG_SITE:

USE_GRAPHICSMAGICK = YES
HDF5_LIB = /usr/lib/x86_64-linux-gnu/hdf5/serial
HDF5_INCLUDE = -I/usr/include/hdf5/serial
SZIP = YES
SZIP_LIB = /usr/lib/x86_64-linux-gnu
SZIP_INCLUDE = -I/usr/local/include
XML2_INCLUDE = -I/usr/include/libxml2
GRAPHICS_MAGICK_LIB = /usr/lib
GRAPHICS_MAGICK_INCLUDE = -I/usr/include/GraphicsMagick

Run make and it should now compile.

We can now add a camera. For this example we will add the simulation detector. First make the detector; the source is in $(AREA_DETECTOR)/ADExample.

In cameraExampleApp/src/Makefile add:

$(PROD_NAME)_DBD += simDetectorSupport.dbd
PROD_LIBS += simDetector

Try running make. We get an error:

Can't open include file "simDetectorSupport.dbd"

This indicates we need to update configure/RELEASE with:

ADEXAMPLE=$(AREA_DETECTOR)/ADExample

Run make and it should now compile.

To instantiate the simulation detector and create PVs for it, replace iocBoot/iocCameraServer/st.cmd with:

#!../../bin/linux-x86_64/cameraExample

< envPaths
epicsEnvSet("PREFIX", "13SIM1:")
epicsEnvSet("PORT",   "SIM1")
epicsEnvSet("QSIZE",  "20")
epicsEnvSet("XSIZE",  "800")
epicsEnvSet("YSIZE",  "600")
epicsEnvSet("NCHANS", "2048")
epicsEnvSet("CBUFFS", "500")
epicsEnvSet("EPICS_DB_INCLUDE_PATH", "$(ADCORE)/db")
epicsEnvSet("EPICS_CA_MAX_ARRAY_BYTES", "10000000")

dbLoadDatabase("$(TOP)/dbd/cameraExample.dbd")
cameraExample_registerRecordDeviceDriver pdbbase

simDetectorConfig("$(PORT)", $(XSIZE), $(YSIZE), 1, 0, 0)
dbLoadRecords("$(ADEXAMPLE)/db/simDetector.template","P=$(PREFIX),R=cam1:,PORT=$(PORT),ADDR=0,TIMEOUT=1")

iocInit()

Try running st.cmd (you will need to chmod u+x it first). If you run dbl in the ioc shell you will see a number of 13SIM1:cam1: PVs. To see the camera data we need to use the NDPluginStdArrays plugin to create a waveform PV.

Before iocInit() in st.cmd add:

NDStdArraysConfigure("IMAGE1", 3, 0, "$(PORT)", 0)
dbLoadRecords("NDStdArrays.template", "P=$(PREFIX),R=image1:,PORT=IMAGE1,ADDR=0,TIMEOUT=1,NDARRAY_PORT=$(PORT),TYPE=Int8,FTVL=UCHAR,NELEMENTS=12000000")

Start st.cmd and run dbl and you will see there are now 13SIM1:image1: PVs including 13SIM1:image1:ArrayData which will recieve the detector data.

To start collecting data and enable the StdArrays plugin we need to run:

caput 13SIM1:cam1:Acquire 1
caput 13SIM1:cam1:ArrayCallbacks 1
caput 13SIM1:image1:EnableCallbacks 1

If we run caget -#10 13SIM1:image1:ArrayData we will see the first 10 elements of the data waveform.

There are number of common areaDetector plugins that are desired for most areaDetector IOCs. To enable them:

Before iocInit() add:

< $(ADCORE)/iocBoot/commonPlugins.cmd
set_requestfile_path("$(ADEXAMPLE)/exampleApp/Db")

After iocInit() add:

create_monitor_set("auto_settings.req", 10, "P=$(PREFIX)")

Create an autosave folder in the same directory as st.cmd and create auto_settings.req with:

file "simDetector_settings.req",    P=$(P),  R=cam1:
file "NDStdArrays_settings.req",    P=$(P),  R=image1:
file "commonPlugin_settings.req",   P=$(P)

Run st.cmd. dbl will show many new PVs. After 10 seconds autosave files will be created in the autosave folder.

To enable the ffmpegServer plugin, first build the source code for this plugin ($(AREA_DETECTOR)/ffmpegServer) and then edit our ioc's configure/RELEASE and add:

FFMPEGSERVER=$(AREA_DETECTOR)/ffmpegServer

In cameraExampleApp/src/Makefile add:

$(PROD_NAME)_DBD += ffmpegServer.dbd
PROD_LIBS += ffmpegServer

Run make from the top level.

In st.cmd add (before iocInit()):

ffmpegServerConfigure(8081)
ffmpegStreamConfigure("MPEG1", 2, 0, "$(PORT)", "0", -1)
dbLoadRecords("$(FFMPEGSERVER)/db/ffmpegStream.template", "P=$(PREFIX),R=mpeg1:,PORT=MPEG1,ADDR=0,TIMEOUT=1,NDARRAY_PORT=$(PORT)")

Start the IOC. Run:

caput 13SIM1:cam1:Acquire 1
caput 13SIM1:cam1:ArrayCallbacks 1
caput 13SIM1:mpeg1:EnableCallbacks 1

Go to http://172.17.0.2:8081/MPEG1.mjpg and you will see the mjpeg stream.

To make autosave restore the enable status of the ffmpegServer plugin, add to iocBoot/iocCameraServer/auto_settings.req:

$(P)mpeg1:EnableCallbacks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment