e8e4babbae0e4e9a40aa91cf348c0e9a.ppt
- Количество слайдов: 18
EPICS Portable Channel Access Server Marty Kraimer 1999/Ph 514: Portable CA Server 1
Overview u EPICS What is the Portable Channel Access Server? The Portable Server consists of a C++ library with a simple class interface. u Purpose of the Server library Using the simple interface to the library, a developer can create a Channel Access server tool that can interact with the EPICS database as well as other applications. u Example ca servers u u u u Channel access gateway Directory server Fault logger APT HPRF KECK instruments KEKB gateway to LINAC control system SLAC gateway to SLAC control system Gateways to other control systems at DESY 1999/Ph 514: Portable CA Server 2
Overview (cont. ) u Advantages of a Server Tool u u EPICS Your application becomes an EPICS server tool Your data become EPICS process variables MEDM and other EPICS tools can interact with your application Talk purpose u u Describe the server interface Show simple C++ example server 1999/Ph 514: Portable CA Server 3
Basic Concepts u Server Tool u u u Developer creates a channel access server tool Provides interface classes and methods required by the server library Server Tool Functions u u EPICS Creates/deletes server instance Responds to client requests u PV search u Attach/detach request u Read/write requests Posts change of state events Server Library u u u C++ library with simple class interface Calls the C++ server interface functions Developer only needs to know server interface Hides complexity of channel access Available in EPICS base Runs on Unix, WIN 32, and VMS 1999/Ph 514: Portable CA Server 4
Basic Concepts (cont. ) u Process Variable (PV) u u u EPICS Variable which server tool keeps track of Server tool provides clients with current value when requested (read request) Server tool changes current value upon client request (write request) Server tool can inform client when the current value changes (monitoring) Has attributes (e. g. alarm limits, operating range) which server tool keeps track of Channel u u A connection between a client and a PV Each client establishes a separate connection to the PV 1999/Ph 514: Portable CA Server 5
C++ Server Interface u 9 classes comprise the Portable Server API u u u EPICS Server class, ca. Server Process variable class , cas. PV pv. Exist. Return pv. Attach. Return Channel class, cas. Channel cas. Async. PVExist. IO cas. Async. Create. PVIO cas. Async. Read. IO cas. Async. Write. IO. The first four classes are required to implement the server tool The channel class and the asynchronous IO classes can be used to add more functionality Each class has several member functions which server tool must define 1999/Ph 514: Portable CA Server 6
ca. Server Class u u u u EPICS Every server tool must include a class derived from the ca. Server class Defines maximum length of a PV name Defines debug level determining amount of output printed Determines maximum number of simultaneous IO operations allowed Informs the server library if a PV is associated with the server tool Attaches a PV when a client wishes to establish a connection Server tool must provide implementations of the virtual functions u u pv. Exist. Test() pv. Attach() 1999/Ph 514: Portable CA Server 7
Example Server u EPICS Server definition class my. Server : public ca. Server { public: my. Server(unsigned pv. Count. In, char *name. In); virtual ~my. Server(void); virtual pv. Exist. Return pv. Exist. Test (const cas. Ctx& c, const char* pvname); virtual pv. Attach. Return pv. Attach(const cas. Ctx& c, const char* pvname); private: friend class my. PV; my. PV *mypv; char *pv. Name; int pv. Name. Length; gdd* value; }; u Server creation int main(int argc, char* argv[]){ my. Server* server; int forever=1; if(argc<2) { fprintf(stderr, "Usage: %s pv. Namen", argv[0]); return -1; } server = new my. Server(1, argv[1]); osi. Time delay(1000 u, 0 u); while(forever) { file. Descriptor. Manager. process(delay); } return 0; } 1999/Ph 514: Portable CA Server 8
pv. Exist. Test EPICS pv. Exist. Return pv. Exist. Test(const cas. Ctx &ctx, const char *p. PVAlias. Name) u u u Response to a client CA search The server tool may accept multiple PV name aliases for the same PV. The request is allowed to complete asynchronously (server tool uses asynchronous IO classes). Server tool passes ctx to asynchronous completion constructors Return values (class pv. Exist. Return) u return pver. Exists. Here; Server has PV u return pver. Does. Not. Exist. Here; Server does not know of this PV u return pver. Asynch. Completion; Deferred result 1999/Ph 514: Portable CA Server 9
pv. Attach EPICS pv. Attach. Return pv. Attach (const cas. Ctx &ctx, const char *p. PVAlias. Name) u u Called when client wishes to attach to PV Allowed to complete asynchronously Server tool must detect attempts to create a 2 nd PV with the same name Return values (class pv. Attach. Return) u return p. PV; Success (pass by pointer) u return PV; Success (pass by ref) u return S_cas. App_pv. Not. Found; No PV by that name here u return S_cas. App_no. Memory; No resources to create pv u return S_cas. App_async. Completion; Deferred completion u return S_cas. App_postpone. Async. IO; Too many simultaneous IO operations 1999/Ph 514: Portable CA Server 10
Example Server Methods EPICS my. Server: : my. Server(unsigned pv. Count. In, char *name. In) { pv. Name. Length = strlen(name. In); pv. Name = new char [pv. Name. Length+1]; strcpy(pv. Name, name. In); value = new gdd. Scalar(appvalue, ait. Enum. Float 64); value->reference(); value->put(0); value->set. Stat. Sevr(0, 0); mypv = new my. PV(*this, pv. Name); } pv. Exist. Return my. Server: : pv. Exist. Test(const cas. Ctx&, const char* name) { if(strncmp(name, pv. Name. Length)==0) return pver. Exists. Here; return pver. Does. Not. Exist. Here; } pv. Attach. Return my. Server: : pv. Attach(const cas. Ctx&, const char* name) { if(strncmp(name, pv. Name. Length)==0) return *mypv; return NULL; } myserver: : ~myserver(void) { delete [] pv. Name; value->unreference(); delete mypv; } 1999/Ph 514: Portable CA Server 11
cas. PV Class u Responds to read/write PV requests u Server must implement the virtual functions u u u Server implements the virtual functions u u u Other important functions u u interest. Register() interest. Delete() Calls post. Event() u u read() write() Responds to a request for a PV monitor u u EPICS get. Name() best. External. Type() begin. Transaction(), end. Transaction() destroy() Do nothing default implementations exist. Server tool need not implement those functions it does not want. 1999/Ph 514: Portable CA Server 12
Example cas. PV Class Definition EPICS class my. PV : public cas. PV { public: my. PV(my. Server& server. In, char* name. In); virtual ~my. PV(void); virtual void destroy(void); virtual ca. Status read(const cas. Ctx &, gdd &prototype); virtual ca. Status write(const cas. Ctx &, gdd &dd); virtual ait. Enum best. External. Type (void) const; virtual ca. Status interest. Register (void); virtual void interest. Delete(void); virtual const char *get. Name() const; private: my. Server& server; char *pv. Name; interest; }; 1999/Ph 514: Portable CA Server 13
Example cas. PV Methods EPICS my. PV: : my. PV (my. Server& svr. IN, char * name. In): server(svr. IN), interest(0) { pv. Name = new char [strlen(name. In)+1]; strcpy(pv. Name, name. In); } ca. Status my. PV: : read(const cas. Ctx&, gdd &dd) { dd. put(server. value); return S_cas. App_success; } ca. Status my. PV: : write(const cas. Ctx&, gdd &dd) { ait. Float 64 new. Value; dd. get(&new. Value, ait. Enum. Float 64); server. value->put(new. Value); if (interest) post. Event(server. value. Event. Mask, *value); return S_cas. App_success; } 1999/Ph 514: Portable CA Server 14
Example cas. PV Methods (cont. ) EPICS ait. Enum my. PV: : interest. Register(void) { interest =1; return S_cas. App_success; } void my. PV: : interest. Delete(void) { interest = 0; } const char *my. PV: : get. Name() const { return pv. Name; } ait. Enum my. PV: : best. External. Type() const { return ait. Enum. Float 64; } my. PV: : ~my. PV(void){delete [] pv. Name; } void my. PV: : destroy(void) { } 1999/Ph 514: Portable CA Server 15
Data Types u EPICS Channel Access client request types DBR types defined in db_access. h e. g. DBR_STS_CHAR, DBR_GR_DOUBLE u EPICS database native types DBF types defined in db_access. h e. g. DBF_DOUBLE, DBF_STRING, . . . u Server has two types which describe data u Architecture Independent Type (AIT) defined in ait. Types. h u u u ait. Uint 8 ait. Float 32 ait. Index ait. Int 16 ait. Float 64 ait. Pointer Application type defined in gdd. App. Table. h u u ait. Int 8 ait. Uint 16 ait. Enum 16 ait. Status e. g. precision, limits, status GDD library converts data from one type to another 1999/Ph 514: Portable CA Server 16
Writing Your Own Server Tool u EPICS Next steps u u Try existing samples Study sample code Study casdef. h Read documentation 1999/Ph 514: Portable CA Server 17
Documentation EPICS On-line documents at LANL u u Portable Server Tutorial Portable Server Reference A Server-Level API for EPICS (paper) Channel Access Server Update (slides) 1999/Ph 514: Portable CA Server 18
e8e4babbae0e4e9a40aa91cf348c0e9a.ppt