Skip to content

Commit 4421741

Browse files
committed
updated the plugin to ADCore
1 parent 00557cf commit 4421741

File tree

14 files changed

+70
-36
lines changed

14 files changed

+70
-36
lines changed

adPythonApp/Db/adPythonPlugin.template

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
# % macro, PORT, Asyn Port name
44
# % macro, TIMEOUT, Timeout
55

6+
include "NDPluginBase.template"
7+
68
record(ai, "$(P)$(R)Time_RBV")
79
{
810
field(DTYP, "asynFloat64")

adPythonApp/src/adPythonPlugin.cpp

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,13 @@ adPythonPlugin::adPythonPlugin(const char *portNameArg, const char *filename,
7474
createParam("ADPYTHON_LOAD", asynParamInt32, &adPythonLoad);
7575
createParam("ADPYTHON_TIME", asynParamFloat64, &adPythonTime);
7676
createParam("ADPYTHON_STATE", asynParamInt32, &adPythonState);
77+
}
7778

79+
/** Init function called once immediately after class instantiation. Starts the
80+
* plugin threads.
81+
*/
82+
void adPythonPlugin::initThreads()
83+
{
7884
// First we tell python where to find adPythonPlugin.py and other scripts
7985
char buffer[BIGBUFFER];
8086
snprintf(buffer, sizeof(buffer), "PYTHONPATH=%s", DATADIRS);
@@ -722,9 +728,9 @@ asynStatus adPythonPlugin::updateAttrDict(NDArray *pArray) {
722728
if (pObject == NULL) {
723729
asynPrint(this->pasynUserSelf, ASYN_TRACE_ERROR,
724730
"%s:%s: attribute %s could not be put in attribute dict\n",
725-
driverName, __func__, pAttr->pName);
731+
driverName, __func__, pAttr->getName());
726732
} else {
727-
PyDict_SetItemString(this->pAttrs, pAttr->pName, pObject);
733+
PyDict_SetItemString(this->pAttrs, pAttr->getName(), pObject);
728734
Py_DECREF(pObject);
729735
}
730736
pAttr = this->pFileAttributes->next(pAttr);
@@ -836,10 +842,12 @@ static int adPythonPluginConfigure(const char *portNameArg, const char *filename
836842
int priority, int stackSize) {
837843
// Stack Size must be a minimum of 2MB
838844
if (stackSize < 2097152) stackSize = 2097152;
839-
new adPythonPlugin(portNameArg, filename,
845+
adPythonPlugin* adp;
846+
adp = new adPythonPlugin(portNameArg, filename,
840847
classname, queueSize, blockingCallbacks,
841848
NDArrayPort, NDArrayAddr, maxBuffers, maxMemory,
842849
priority, stackSize);
850+
adp->initThreads();
843851
return(asynSuccess);
844852
}
845853

adPythonApp/src/adPythonPlugin.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ class adPythonPlugin : public NDPluginDriver {
1919
const char *NDArrayPort, int NDArrayAddr, int maxBuffers, size_t maxMemory,
2020
int priority, int stackSize);
2121
~adPythonPlugin() {}
22+
/** This called once immediately after class instantiation */
23+
virtual void initThreads();
2224
/** This is called when the plugin gets a new array callback */
2325
virtual void processCallbacks(NDArray *pArray);
2426
/** This is when we get a new int value */

configure/RELEASE

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ SUPPORT=/dls_sw/prod/R3.14.12.3/support
2424
WORK=/dls_sw/work/R3.14.12.3/support
2525
TOOLS_BASE=/dls_sw/prod/tools/RHEL6-x86_64
2626

27-
ASYN=$(SUPPORT)/asyn/4-21
28-
AREADETECTOR=$(SUPPORT)/areaDetector/1-9dls19
27+
ASYN=$(SUPPORT)/asyn/4-26
28+
ADCORE=$(SUPPORT)/ADCore/2-4dls2
2929
PYTHON_PREFIX=$(TOOLS_BASE)/Python/2-7-3/prefix
3030

3131
# EPICS_BASE usually appears last so other apps can override stuff:

etc/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
TOP = ..
22
include $(TOP)/configure/CONFIG
33
DIRS := $(DIRS) $(filter-out $(DIRS), $(wildcard makeIocs))
4-
DIRS := $(DIRS) $(filter-out $(DIRS), $(wildcard makeDocumentation))
4+
#DIRS := $(DIRS) $(filter-out $(DIRS), $(wildcard makeDocumentation))
55
DIRS := $(DIRS) $(filter-out $(DIRS), $(wildcard simulations))
66
include $(TOP)/configure/RULES_DIRS

etc/builder.py

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,50 @@
1+
import copy
2+
13
from iocbuilder import Device, AutoSubstitution
24
from iocbuilder.arginfo import *
35

4-
from iocbuilder.modules.areaDetector import AreaDetector, _NDPluginBase
6+
from iocbuilder.modules.asyn import Asyn, AsynPort
7+
from iocbuilder.modules.ADCore import ADCore, NDPluginBaseTemplate, includesTemplates, makeTemplateInstance
58

69
class AdPython(Device):
710
'''Library dependencies for adPython'''
8-
Dependencies = (AreaDetector,)
11+
Dependencies = (ADCore,)
912
# Device attributes
1013
LibFileList = ['adPython']
1114
DbdFileList = ['adPythonPlugin']
1215
AutoInstantiate = True
1316

17+
@includesTemplates(NDPluginBaseTemplate)
1418
class _adPythonBase(AutoSubstitution):
1519
'''This plugin Works out the area and tip of a sample'''
1620
TemplateFile = "adPythonPlugin.template"
17-
18-
class adPythonPlugin(_NDPluginBase):
21+
22+
class adPythonPlugin(AsynPort):
1923
"""This plugin creates an adPython object"""
24+
# This tells xmlbuilder to use PORT instead of name as the row ID
25+
UniqueName = "PORT"
26+
2027
_SpecificTemplate = _adPythonBase
2128
Dependencies = (AdPython,)
2229

23-
def __init__(self, classname, BUFFERS = 50, MEMORY = 0, **args):
24-
# Init the superclass (_NDPluginBase)
25-
self.__super.__init__(**args)
30+
def __init__(self, classname, PORT, NDARRAY_PORT, QUEUE = 5, BLOCK = 0, NDARRAY_ADDR = 0, BUFFERS = 50, MEMORY = 0, **args):
31+
# Init the superclass (AsynPort)
32+
self.__super.__init__(PORT)
33+
# Update the attributes of self from the commandline args
34+
self.__dict__.update(locals())
35+
# Make an instance of our template
36+
makeTemplateInstance(self._SpecificTemplate, locals(), args)
2637
# Init the python classname specific class
2738
class _tmp(AutoSubstitution):
2839
ModuleName = adPythonPlugin.ModuleName
2940
TrueName = "_adPython%s" % classname
3041
TemplateFile = "adPython%s.template" % classname
31-
_tmp(**filter_dict(args, _tmp.ArgInfo.Names()))
42+
_tmpargs = copy.deepcopy(args)
43+
_tmpargs['PORT'] = PORT
44+
_tmp(**filter_dict(_tmpargs, _tmp.ArgInfo.Names()))
3245
# Store the args
3346
self.filename = "$(ADPYTHON)/adPythonApp/scripts/adPython%s.py" % classname
34-
self.__dict__.update(locals())
47+
self.Configure = 'adPythonPluginConfigure'
3548

3649
def Initialise(self):
3750
print '# %(Configure)s(portName, filename, classname, queueSize, '\
@@ -42,11 +55,16 @@ def Initialise(self):
4255
'%(MEMORY)d)' % self.__dict__
4356

4457
# __init__ arguments
45-
ArgInfo = _NDPluginBase.ArgInfo + makeArgInfo(__init__,
58+
ArgInfo = _SpecificTemplate.ArgInfo + makeArgInfo(__init__,
4659
classname = Choice('Predefined python class to use', [
4760
"Morph", "Focus", "Template", "BarCode", "Transfer", "Mitegen",
4861
"Circle", "DataMatrix", "Gaussian2DFitter", "PowerMean",
4962
"MxSampleDetect"]),
63+
PORT = Simple('Port name for the plugin', str),
64+
QUEUE = Simple('Input array queue size', int),
65+
BLOCK = Simple('Blocking callbacks?', int),
66+
NDARRAY_PORT = Ident('Input array port', AsynPort),
67+
NDARRAY_ADDR = Simple('Input array port address', int),
5068
BUFFERS = Simple('Maximum number of NDArray buffers to be created for '
5169
'plugin callbacks', int),
5270
MEMORY = Simple('Max memory to allocate, should be maxw*maxh*nbuffer '

etc/makeIocs/Makefile.iocs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
# as an xml or py file in etc/makeIocs, or be suffixed with _sim to create a
33
# simulation from that same file
44
IOCS := example
5+
IOCS += example_demo
6+
IOCS += realcam
57

68
# These are the dirs that each IOC lives in
79
IOC_DIRS := $(patsubst %, $(TOP)/iocs/%, $(IOCS))

etc/makeIocs/example.xml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
<?xml version="1.0" ?>
2-
<components arch="linux-x86">
3-
<areaDetector.URLDriver ADDR="0" P="ADPYTHONTEST" PORT="CAM.URL" R=":URL:" TIMEOUT="1"/>
4-
<adPython.adPythonPlugin ADDR="0" Enabled="1" NDARRAY_ADDR="0" NDARRAY_PORT="CAM.URL" P="ADPYTHONTEST" PORT="CAM.PY1" R=":PY1:" TIMEOUT="1" classname="Gaussian2DFitter"/>
5-
<areaDetector.NDStdArrays ADDR="0" Enabled="1" FTVL="UCHAR" NDARRAY_ADDR="0" NDARRAY_PORT="CAM.PY1" NELEMENTS="786432" P="ADPYTHONTEST" PORT="CAM.ARR1" R=":ARR1:" TIMEOUT="1" TYPE="Int8"/>
6-
<areaDetector.NDFileHDF5 ADDR="0" Enabled="1" NDARRAY_ADDR="0" NDARRAY_PORT="CAM.PY1" P="ADPYTHONTEST" PORT="CAM.HDF" R=":HDF:" TIMEOUT="1"/>
2+
<components arch="linux-x86_64">
3+
<ADURL.URLDriver ADDR="0" P="ADPYTHONTEST" PORT="CAM.URL" R=":URL:" TIMEOUT="1"/>
4+
<adPython.adPythonPlugin ADDR="0" NDARRAY_ADDR="0" NDARRAY_PORT="CAM.URL" P="ADPYTHONTEST" PORT="CAM.PY1" R=":PY1:" TIMEOUT="1" classname="Gaussian2DFitter"/>
5+
<ADCore.NDStdArrays ADDR="0" FTVL="UCHAR" NDARRAY_ADDR="0" NDARRAY_PORT="CAM.PY1" NELEMENTS="786432" P="ADPYTHONTEST" PORT="CAM.ARR1" R=":ARR1:" TIMEOUT="1" TYPE="Int8"/>
6+
<ADCore.NDFileHDF5 ADDR="0" NDARRAY_ADDR="0" NDARRAY_PORT="CAM.PY1" P="ADPYTHONTEST" PORT="CAM.HDF" R=":HDF:" TIMEOUT="1"/>
77
<EPICS_BASE.StartupCommand command="dbpf(&quot;ADPYTHONTEST:URL:URL1&quot;, &quot;$(ADPYTHON)/greyscale_beam_corner.png&quot;)" post_init="True"/>
88
<EPICS_BASE.StartupCommand command="dbpf(&quot;ADPYTHONTEST:URL:AcquirePeriod&quot;, &quot;1&quot;)" post_init="True"/>
99
<EPICS_BASE.StartupCommand command="dbpf(&quot;ADPYTHONTEST:URL:Acquire&quot;, &quot;1&quot;)" post_init="True"/>

etc/makeIocs/example_RELEASE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
# Place any example specific dependencies here
2-
2+
ADURL=$(SUPPORT)/ADURL/2-1dls1

etc/makeIocs/example_demo.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" ?>
2-
<components arch="linux-x86">
3-
<areaDetector.URLDriver ADDR="0" P="ADPYTHONTEST" PORT="CAM.URL" R=":URL:" TIMEOUT="1"/>
4-
<adPython.adPythonPlugin ADDR="0" Enabled="1" NDARRAY_ADDR="0" NDARRAY_PORT="CAM.URL" P="ADPYTHONTEST" PORT="CAM.PY1" R=":PY1:" TIMEOUT="1" classname="Mitegen"/>
2+
<components arch="linux-x86_64">
3+
<ADURL.URLDriver ADDR="0" P="ADPYTHONTEST" PORT="CAM.URL" R=":URL:" TIMEOUT="1"/>
4+
<adPython.adPythonPlugin ADDR="0" NDARRAY_ADDR="0" NDARRAY_PORT="CAM.URL" P="ADPYTHONTEST" PORT="CAM.PY1" R=":PY1:" TIMEOUT="1" classname="Mitegen"/>
55
<ffmpegServer.ffmpegStream ADDR="0" NDARRAY_ADDR="0" NDARRAY_PORT="CAM.PY1" P="ADPYTHONTEST" PORT="CAM.MJPG" R=":MJPG:" TIMEOUT="1"/>
66
<EPICS_BASE.StartupCommand command="dbpf(&quot;ADPYTHONTEST:URL:URL1&quot;, &quot;/home/tmc43/test/mitegen/mitegen_1.png&quot;)" post_init="True"/>
77
<EPICS_BASE.StartupCommand command="dbpf(&quot;ADPYTHONTEST:URL:AcquirePeriod&quot;, &quot;1&quot;)" post_init="True"/>

0 commit comments

Comments
 (0)