Moved CA client examples into their own caClientApp
Added caServerApp - copied from src/cas/example/simple Made simpleApp significantly more useful Made exampleApp use the _APPNAME_ macro instead of example in various places
This commit is contained in:
@@ -5,55 +5,37 @@ include $(TOP)/configure/CONFIG
|
||||
# ADD MACRO DEFINITIONS AFTER THIS LINE
|
||||
#=============================
|
||||
|
||||
#USR_CFLAGS +=
|
||||
|
||||
PROD_HOST += caExample
|
||||
caExample_SRCS += caExample.c
|
||||
caExample_LIBS += ca
|
||||
caExample_LIBS += Com
|
||||
|
||||
PROD_HOST += caMonitor
|
||||
caMonitor_SRCS += caMonitor.c
|
||||
caMonitor_LIBS += ca
|
||||
caMonitor_LIBS += Com
|
||||
|
||||
ca_DIR = $(EPICS_BASE_LIB)
|
||||
Com_DIR = $(EPICS_BASE_LIB)
|
||||
|
||||
|
||||
#=============================
|
||||
|
||||
# xxxRecord.h will be created from xxxRecord.dbd
|
||||
DBDINC += xxxRecord
|
||||
|
||||
# <name>.dbd will be created from <name>Include.dbd
|
||||
DBD += example.dbd
|
||||
DBD += _APPNAME_.dbd
|
||||
|
||||
#=============================
|
||||
|
||||
PROD_IOC = example
|
||||
PROD_IOC = _APPNAME_
|
||||
|
||||
example_SRCS += xxxRecord.c
|
||||
example_SRCS += devXxxSoft.c
|
||||
example_SRCS += dbSubExample.c
|
||||
_APPNAME__SRCS += xxxRecord.c
|
||||
_APPNAME__SRCS += devXxxSoft.c
|
||||
_APPNAME__SRCS += dbSubExample.c
|
||||
|
||||
# <name>_registerRecordDeviceDriver.cpp will be created from <name>.dbd
|
||||
example_SRCS += example_registerRecordDeviceDriver.cpp
|
||||
example_SRCS_DEFAULT += exampleMain.cpp
|
||||
example_SRCS_vxWorks += -nil-
|
||||
_APPNAME__SRCS += _APPNAME__registerRecordDeviceDriver.cpp
|
||||
_APPNAME__SRCS_DEFAULT += _APPNAME_Main.cpp
|
||||
_APPNAME__SRCS_vxWorks += -nil-
|
||||
|
||||
#The following adds support from base/src/vxWorks
|
||||
example_OBJS_vxWorks += $(EPICS_BASE_BIN)/vxComLibrary
|
||||
_APPNAME__OBJS_vxWorks += $(EPICS_BASE_BIN)/vxComLibrary
|
||||
|
||||
#NOTES:
|
||||
# 1)It is not possible to build sncExample both as a component of example
|
||||
# 1)It is not possible to build sncExample both as a component of _APPNAME_
|
||||
# and standalone. You must choose only one.
|
||||
# 2)To build sncExample SNCSEQ must be defined in <top>/configure/RELEASE
|
||||
|
||||
#The following builds sncExample as a component of example
|
||||
#example_SRCS += sncExample.stt
|
||||
#example_LIBS += seq
|
||||
#example_LIBS += pv
|
||||
#The following builds sncExample as a component of _APPNAME_
|
||||
#_APPNAME__SRCS += sncExample.stt
|
||||
#_APPNAME__LIBS += seq
|
||||
#_APPNAME__LIBS += pv
|
||||
#seq_DIR = $(SNCSEQ_LIB)
|
||||
#pv_DIR = $(SNCSEQ_LIB)
|
||||
|
||||
@@ -77,23 +59,23 @@ example_OBJS_vxWorks += $(EPICS_BASE_BIN)/vxComLibrary
|
||||
#sncExample_LIBS += Com
|
||||
|
||||
# Use win32 object libs for registered support
|
||||
example_LIBS_win32 += recIocObj
|
||||
example_LIBS_win32 += softDevIocObj
|
||||
example_LIBS_win32 += testDevIocObj
|
||||
example_LIBS_DEFAULT += recIoc
|
||||
example_LIBS_DEFAULT += softDevIoc
|
||||
example_LIBS_DEFAULT += testDevIoc
|
||||
_APPNAME__LIBS_win32 += recIocObj
|
||||
_APPNAME__LIBS_win32 += softDevIocObj
|
||||
_APPNAME__LIBS_win32 += testDevIocObj
|
||||
_APPNAME__LIBS_DEFAULT += recIoc
|
||||
_APPNAME__LIBS_DEFAULT += softDevIoc
|
||||
_APPNAME__LIBS_DEFAULT += testDevIoc
|
||||
|
||||
example_LIBS += iocsh
|
||||
example_LIBS += miscIoc
|
||||
example_LIBS += rsrvIoc
|
||||
example_LIBS += dbtoolsIoc
|
||||
example_LIBS += asIoc
|
||||
example_LIBS += dbIoc
|
||||
example_LIBS += registryIoc
|
||||
example_LIBS += dbStaticIoc
|
||||
example_LIBS += ca
|
||||
example_LIBS += Com
|
||||
_APPNAME__LIBS += iocsh
|
||||
_APPNAME__LIBS += miscIoc
|
||||
_APPNAME__LIBS += rsrvIoc
|
||||
_APPNAME__LIBS += dbtoolsIoc
|
||||
_APPNAME__LIBS += asIoc
|
||||
_APPNAME__LIBS += dbIoc
|
||||
_APPNAME__LIBS += registryIoc
|
||||
_APPNAME__LIBS += dbStaticIoc
|
||||
_APPNAME__LIBS += ca
|
||||
_APPNAME__LIBS += Com
|
||||
|
||||
#===========================
|
||||
|
||||
|
||||
@@ -1,25 +0,0 @@
|
||||
/*caExample.c*/
|
||||
#include <stddef.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "cadef.h"
|
||||
|
||||
int main(int argc,char **argv)
|
||||
{
|
||||
double data;
|
||||
chid mychid;
|
||||
|
||||
if(argc != 2) {
|
||||
fprintf(stderr,"usage: caExample pvname\n");
|
||||
exit(1);
|
||||
}
|
||||
SEVCHK(ca_context_create(ca_disable_preemptive_callback),"ca_context_create");
|
||||
SEVCHK(ca_create_channel(argv[1],NULL,NULL,10,&mychid),"ca_create_channel failure");
|
||||
SEVCHK(ca_pend_io(5.0),"ca_pend_io failure");
|
||||
SEVCHK(ca_get(DBR_DOUBLE,mychid,(void *)&data),"ca_get failure");
|
||||
SEVCHK(ca_pend_io(5.0),"ca_pend_io failure");
|
||||
printf("%s %f\n",argv[1],data);
|
||||
return(0);
|
||||
}
|
||||
@@ -1,122 +0,0 @@
|
||||
/*caMonitor.c*/
|
||||
/* This example accepts a file containing a list of pvs to monitor
|
||||
* It prints a message for all ca evemts: connection, access rights, data
|
||||
*/
|
||||
#include <stddef.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "cadef.h"
|
||||
#include "dbDefs.h"
|
||||
|
||||
#define MAX_PV 1000
|
||||
#define MAX_PV_NAME_LEN 40
|
||||
|
||||
typedef struct{
|
||||
char value[20];
|
||||
chid mychid;
|
||||
evid myevid;
|
||||
} MYNODE;
|
||||
|
||||
|
||||
static void printChidInfo(chid chid, char *message)
|
||||
{
|
||||
printf("\n%s\n",message);
|
||||
printf("pv: %s type(%d) nelements(%ld) host(%s)",
|
||||
ca_name(chid),ca_field_type(chid),ca_element_count(chid),
|
||||
ca_host_name(chid));
|
||||
printf(" read(%d) write(%d) state(%d)\n",
|
||||
ca_read_access(chid),ca_write_access(chid),ca_state(chid));
|
||||
}
|
||||
|
||||
static void exceptionCallback(struct exception_handler_args args)
|
||||
{
|
||||
chid chid = args.chid;
|
||||
long stat = args.stat; /* Channel access status code*/
|
||||
const char *channel;
|
||||
static char *noname = "unknown";
|
||||
|
||||
channel = (chid ? ca_name(chid) : noname);
|
||||
|
||||
|
||||
if(chid) printChidInfo(chid,"exceptionCallback");
|
||||
printf("exceptionCallback stat %s channel %s\n",
|
||||
ca_message(stat),channel);
|
||||
}
|
||||
|
||||
static void connectionCallback(struct connection_handler_args args)
|
||||
{
|
||||
chid chid = args.chid;
|
||||
|
||||
printChidInfo(chid,"connectionCallback");
|
||||
}
|
||||
|
||||
static void accessRightsCallback(struct access_rights_handler_args args)
|
||||
{
|
||||
chid chid = args.chid;
|
||||
|
||||
printChidInfo(chid,"accessRightsCallback");
|
||||
}
|
||||
static void eventCallback(struct event_handler_args eha)
|
||||
{
|
||||
chid chid = eha.chid;
|
||||
|
||||
if(eha.status!=ECA_NORMAL) {
|
||||
printChidInfo(chid,"eventCallback");
|
||||
} else {
|
||||
char *pdata = (char *)eha.dbr;
|
||||
printf("Event Callback: %s = %s\n",ca_name(eha.chid),pdata);
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc,char **argv)
|
||||
{
|
||||
char *filename;
|
||||
int npv = 0;
|
||||
MYNODE *pmynode[MAX_PV];
|
||||
char *pname[MAX_PV];
|
||||
int i;
|
||||
char tempStr[MAX_PV_NAME_LEN];
|
||||
char *pstr;
|
||||
FILE *fp;
|
||||
|
||||
if(argc != 2) {
|
||||
fprintf(stderr,"usage: caMonitor filename\n");
|
||||
exit(1);
|
||||
}
|
||||
filename = argv[1];
|
||||
fp = fopen(filename,"r");
|
||||
if(!fp) {
|
||||
perror("fopen failed");
|
||||
return(1);
|
||||
}
|
||||
while(1) {
|
||||
if(npv >= MAX_PV ) break;
|
||||
pstr = fgets(tempStr,MAX_PV_NAME_LEN,fp);
|
||||
if(!pstr) break;
|
||||
if(strlen(pstr) <=1) continue;
|
||||
pstr[strlen(pstr)-1] = '\0'; /*strip off newline*/
|
||||
pname[npv] = calloc(1,strlen(pstr) + 1);
|
||||
strcpy(pname[npv],pstr);
|
||||
pmynode[npv] = (MYNODE *)calloc(1,sizeof(MYNODE));
|
||||
npv++;
|
||||
}
|
||||
SEVCHK(ca_context_create(ca_disable_preemptive_callback),"ca_context_create");
|
||||
SEVCHK(ca_add_exception_event(exceptionCallback,NULL),
|
||||
"ca_add_exception_event");
|
||||
for(i=0; i<npv; i++) {
|
||||
SEVCHK(ca_create_channel(pname[i],connectionCallback,
|
||||
&pmynode[i],20,&pmynode[i]->mychid),
|
||||
"ca_create_channel");
|
||||
SEVCHK(ca_replace_access_rights_event(pmynode[i]->mychid,
|
||||
accessRightsCallback),
|
||||
"ca_replace_access_rights_event");
|
||||
SEVCHK(ca_add_event(DBR_STRING,pmynode[i]->mychid,eventCallback,
|
||||
pmynode[i],&pmynode[i]->myevid),
|
||||
"ca_add_event");
|
||||
}
|
||||
/*Should never return from following call*/
|
||||
SEVCHK(ca_pend_event(0.0),"ca_pend_event");
|
||||
return(0);
|
||||
}
|
||||
@@ -5,12 +5,14 @@ typedef long (*processMethod)(subRecord *precord);
|
||||
|
||||
long mySubInit(subRecord *precord,processMethod process)
|
||||
{
|
||||
printf("%s mySubInit process %p\n",precord->name, (void*) process);
|
||||
printf("Record %s called mySubInit(%#p, %#p)\n",
|
||||
precord->name, precord, (void*) process);
|
||||
return(0);
|
||||
}
|
||||
|
||||
long mySubProcess(subRecord *precord)
|
||||
{
|
||||
printf("%s mySubProcess\n",precord->name);
|
||||
printf("Record %s called mySubProcess(%#p)\n",
|
||||
precord->name, precord);
|
||||
return(0);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user