EPICS

Portable Channel Access Server
Kazuro Furukawa, KEK(Marty Kraimer, APS, USPAS1999)

Portable CA Server – EPICS Training – K.F – Jul.2003.

1EPICS

Pre-Overviewu

Why Channel Access Server? Example: KEK Linac
X-Window Interface for Commissioning

EPICSGatewaytoKEKB-Ring
Touch Panel for Operation

MS-Windows Interface for Operation

Main Network (FDDI, Ethernet)
Device Manager

Main Computer System (Unix)
Equipment Level Network (Optical Ethernet)

VME's (~25)(and Loop-3)

PLC's (~140)

CAMAC's (~15)

VXI's (~30)

PC / GPIB / RS232C

Beam Monitor
MagnetTrigger

Klystron
MagnetVacuumTriggerRF Monitor

GunBeam Monitor
othersPortable CA Server – EPICS Training – K.F – Jul.2003.

2

Pre-Overview 2u

EPICS

Why Channel Access Server?
You may want to provide your information to the EPICS worldfrom Platforms other than EPICS IOC’su You want to save/restore intermediate results on the machineother than EPICS IOC’su

There are Several Possibilities
u [1] Simple IOC Gateway - SimplestuPortable CA Server – EPICS Training – K.F – Jul.2003.

3

Pre-Overview 3u

EPICS[2] Another Possibility on Win32 Environment
LANL ActiveX example
u For Small Number of Variablesuu[3] More Platforms will be Supported as IOC’s(with or without Realtime Processing)u With 3.14 or Lateru Not only with CA service but also with Database Processingu[4] Portable Channel Access Server
Current Standard way in EPICS Baseu Definition of Server-side APIuuIOC’s will use the same common library software

C++ templates are provided to develop application softwareu “Channel Access Portable Server – API Tutorial” (LANL)u

Portable CA Server – EPICS Training – K.F – Jul.2003.

4Overview
uEPICS

What is the Portable Channel Access Server?
The Portable Server consists of a C++ library with a simple classinterface.

u

Purpose of the Server library
Using the simple interface to the library, a developer can create aChannel Access server tool that can interact with the EPICS
database as well as other applications.

uExample ca servers
Channel access gatewayu Directory serveru Fault logger APT HPRF
u KECK instruments
u KEKB gateway to LINAC control system
u SLAC gateway to SLAC control systemu Gateways to other control systems at DESYuPortable CA Server – EPICS Training – K.F – Jul.2003.

5

Overview (cont.)
uEPICS

Advantages of a Server ToolYour application becomes an EPICS server toolu Your data become EPICS process variables
u MEDM and other EPICS tools can interact with your application
uuTalk purpose
Describe the server interface
u Show simple C++ example server
uPortable CA Server – EPICS Training – K.F – Jul.2003.

6

Basic Concepts
uEPICS

Server Tool
Developer creates a channel access server toolu Provides interface classes and methods required by the server libraryu Server Tool FunctionsuuuuuCreates/deletes server instance
Responds to client requests
u PV searchu Attach/detach request
u Read/write requests
Posts change of state events

Server Library
C++ library with simple class interface
u Calls the C++ server interface functions
u Developer only needs to know server interface
u Hides complexity of channel accessu Available in EPICS baseu Runs on Unix, WIN32, and VMS
uPortable CA Server – EPICS Training – K.F – Jul.2003.

7

Basic Concepts(cont.)uEPICS

Process Variable (PV)
Variable which server tool keeps track ofu Server tool provides clients with current value when requested(read request)
u Server tool changes current value upon client request (writerequest)
u Server tool can inform client when the current value changes(monitoring)u Has attributes (e.g. alarm limits, operating range) which server
tool keeps track ofu

uChannel
A connection between a client and a PV
u Each client establishes a separate connection to the PVuPortable CA Server – EPICS Training – K.F – Jul.2003.

8C++ Server Interface
u

EPICS

9 classes comprise the Portable Server API
Server class, caServeru Process variable class , casPV
u pvExistReturnu pvAttachReturnu Channel class, casChannelu casAsyncPVExistIO
u casAsyncCreatePVIOu casAsyncReadIOu casAsyncWriteIO.
uuuu

The first four classes are required to implement the server tool
The channel class and the asynchronous IO classes can be used toadd more functionality
Each class has several member functions which server tool must
definePortable CA Server – EPICS Training – K.F – Jul.2003.

9caServer Classuuuuuuu

EPICS

Every server tool must include a class derived from the caServer
class
Defines maximum length of a PV nameDefines debug level determining amount of output printed
Determines maximum number of simultaneous IO operations allowedInforms the server library if a PV is associated with the server toolAttaches a PV when a client wishes to establish a connection
Server tool must provide implementations of the virtual functionspvExistTest()
u pvAttach()uPortable CA Server – EPICS Training – K.F – Jul.2003.

10

Example ServeruServer definitionuServer creation

EPICS

class myServer : public caServer{
public:myServer(unsigned pvCountIn,char *nameIn);virtual ~myServer(void);
virtual pvExistReturn pvExistTest(const casCtx& c,const char* pvname);
virtual pvAttachReturn pvAttach(const casCtx& c,const char* pvname);
private:friend class myPV;
myPV *mypv;
char *pvName;int pvNameLength;
gdd* value;};
int main(int argc, char* argv[]){
myServer* server;
int forever=1;
if(argc<2) {fprintf(stderr,"Usage: %s pvName\n",argv[0]);return -1;}
server = new myServer(1,argv[1]);osiTime delay(1000u,0u);
while(forever) {fileDescriptorManager.process(delay);}
return 0;}
Portable CA Server – EPICS Training – K.F – Jul.2003.

11

pvExistTestEPICSpvExistReturn pvExistTest(const casCtx &ctx, const char
*pPVAliasName)

Response to a client CA searchu The server tool may accept multiple PV name aliases forthe same PV.
u The request is allowed to complete asynchronously(server tool uses asynchronous IO classes).
u Server tool passes ctx to asynchronous completion
constructors
u Return values (class pvExistReturn)uu

return pverExistsHere;

Server has PVureturn pverDoesNotExistHere;

Server does not know of this PVu

return pverAsynchCompletion;

Deferred result
Portable CA Server – EPICS Training – K.F – Jul.2003.

12

pvAttach

EPICS

pvAttachReturn pvAttach (const casCtx &ctx,
const char *pPVAliasName)uuuu

Called when client wishes to attach to PV
Allowed to complete asynchronously
Server tool must detect attempts to create a 2nd PV with the same
nameReturn values (class pvAttachReturn)u

return pPV;

Success (pass by pointer)ureturn PV;

Success (pass by ref)u

return S_casApp_pvNotFound;

No PV by that name hereureturn S_casApp_noMemory;

No resources to create pv
ureturn S_casApp_asyncCompletion;

Deferred completionureturn S_casApp_postponeAsyncIO;

Too many simultaneous IO operations
Portable CA Server – EPICS Training – K.F – Jul.2003.

13

Example Server Methods

EPICS

myServer::myServer(unsigned pvCountIn,char *nameIn){
pvNameLength = strlen(nameIn);pvName = new char [pvNameLength+1];
strcpy(pvName,nameIn);value = new gddScalar(appvalue,aitEnumFloat64);
value->reference();value->put(0);value->setStatSevr(0,0);
mypv = new myPV(*this,pvName);}
pvExistReturn myServer::pvExistTest(const casCtx&,
const char* name){if(strncmp(name,pvName,pvNameLength)==0)
return pverExistsHere;return pverDoesNotExistHere;}
pvAttachReturn myServer::pvAttach(const casCtx&,const char* name){if(strncmp(name,pvName,pvNameLength)==0) return *mypv;
return NULL;}
myserver::~myserver(void){
delete [] pvName;value->unreference();delete mypv;}
Portable CA Server – EPICS Training – K.F – Jul.2003.

14

casPV Classu

EPICS

Responds to read/write PV requestsu

Server must implement the virtual functionsread()u write()uuResponds to a request for a PV monitoruServer implements the virtual functions
interestRegister()u interestDelete()uuuCalls postEvent()

Other important functions
getName()u bestExternalType()u beginTransaction(),endTransaction()u destroy()uuuDo nothing default implementations exist.
Server tool need not implement those functions it does not want.

Portable CA Server – EPICS Training – K.F – Jul.2003.

15

Example casPV ClassDefinition

EPICS

class myPV : public casPV{public:myPV(myServer& serverIn,char* nameIn);virtual ~myPV(void);
virtual void destroy(void);
virtual caStatus read(const casCtx &, gdd &prototype);
virtual caStatus write(const casCtx &, gdd &dd);
virtual aitEnum bestExternalType(void) const;
virtual caStatus interestRegister(void);
virtual void interestDelete(void);
virtual const char *getName() const;
private:myServer& server;
char *pvName;
int interest;};Portable CA Server – EPICS Training – K.F – Jul.2003.

16

Example casPV Methods

EPICS

myPV::myPV (myServer& svrIN,char * nameIn):server(svrIN),interest(0){pvName = new char [strlen(nameIn)+1];
strcpy(pvName,nameIn);}caStatus myPV::read(const casCtx&, gdd &dd)
{dd.put(server.value);
return S_casApp_success;}caStatus myPV::write(const casCtx&, gdd &dd){
aitFloat64 newValue;
dd.get(&newValue, aitEnumFloat64);
server.value->put(newValue);if (interest) postEvent(server.valueEventMask,*value);
return S_casApp_success;}Portable CA Server – EPICS Training – K.F – Jul.2003.

17

Example casPV Methods(cont.)

EPICS

aitEnum myPV::interestRegister(void){interest =1;
return S_casApp_success;}void myPV::interestDelete(void) { interest = 0; }const char *myPV::getName() const { return pvName; }aitEnum myPV::bestExternalType() const{
return aitEnumFloat64;}
myPV::~myPV(void){delete [] pvName;}
void myPV::destroy(void) { }Portable CA Server – EPICS Training – K.F – Jul.2003.

18

Data Typesu

EPICS

Channel Access client request types
DBR types defined in db_access.he.g. DBR_STS_CHAR, DBR_GR_DOUBLEu

EPICS database native types
DBF types defined in db_access.he.g. DBF_DOUBLE, DBF_STRING,...

uServer has two types which describe datau

Architecture Independent Type (AIT) defined in aitTypes.h
aitInt8u aitUint16
u aitEnum16
u aitStatusuuaitInt16
aitFloat64
aitPointerApplication type defined in gddAppTable.huu

aitUint8
aitFloat32
aitIndexe.g. precision, limits, status

GDD library converts data from one type to another

Portable CA Server – EPICS Training – K.F – Jul.2003.

19Writing Your Own Server Toolu

EPICS

Next stepsTry existing samples
u Study sample codeu Study casdef.hu Read documentationuPortable CA Server – EPICS Training – K.F – Jul.2003.

20

Documentation

EPICS

On-line documents at LANL
Portable Server Tutorialu Portable Server Referenceu A Server-Level API for EPICS (paper)u Channel Access Server Update (slides)uPortable CA Server – EPICS Training – K.F – Jul.2003.

21