//______________________________________________________________________________
void beamPositionMonitorInterface::addChannel( const std::string & pvRoot, beamPositionMonitorStructs::pvStruct & pv )
{
    std::stringstream s1;
    s1 << pvRoot << ":" << pv.pvSuffix;
    ca_create_channel( s1.str().c_str(), 0, 0, 0, &pv.CHID );
    debugMessage( "Create channel to ", s1.str() );
}
示例#2
0
static int  CACommand(string strcmd)
{
#if 0
	//In event callback function, It' dosen't work ca_get() function. I don't understand the reason.
	struct dbr_time_long shotdata;
	chid shot_id;
	ca_create_channel("CCS_SHOT_NUMBER",NULL, NULL,20,&shot_id);
	ca_pend_io(1.0);
	int state = ca_state(shot_id);
	printf("State:%d\n", state);
	ca_get(DBR_TIME_LONG, shot_id, (void *)&shotdata);
	int status = ca_pend_io(1.0);
	if(status != ECA_NORMAL)
	{
		fprintf(stdout, "SHOT number: %s denied access\n",ca_name(shot_id));
		return;
	};
	fprintf(stdout, "%s:%d\n",ca_name(shot_id),shotdata.value);
#else
	FILE *fp= popen (strcmd.c_str(), "r");
	char buf[20];
	while (fgets (buf, sizeof(buf), fp) ) {};
	pclose(fp);
	return ((strcmd.compare("ShotNum")== 0)?atoi(buf):0);
#endif
}
示例#3
0
void
SessionSummaryThr::run()
{
	if ( mysqlpp::get_library_version() != MYSQLPP_HEADER_VERSION )
	{
		cerr<< "Library/header version number mismatch" << endl;
		return;
	};
	MyNode  mynode(mpSession);
	//mynode.prevshotnum = startshot;
	SEVCHK(ca_context_create(ca_disable_preemptive_callback),"ca_context_create");
	SEVCHK(ca_add_exception_event(exceptionCallback,NULL), "ca_add_exception_event");
	//string pvnames[]={"CCS_SHOT_NUMBER","CCS_PERFORM_SHOT_SUMMARY"};
	//Test..
	//SEVCHK(ca_create_channel("DDS2_getState",connectionCallback,
	//			&mynode,10,(oldChannelNotify**)&mynode.summary_chid), "ca_create_channel");
	SEVCHK(ca_create_channel("CCS_PERFORM_SHOT_SUMMARY",connectionCallback,
				&mynode,10,(oldChannelNotify**)&mynode.summary_chid), "ca_create_channel");
	SEVCHK(ca_replace_access_rights_event(mynode.summary_chid,
				accessRightsCallback), "ca_replace_access_rights_event");
	ca_create_subscription (DBR_TIME_LONG, 0, mynode.summary_chid, DBE_VALUE|DBE_ALARM, eventCallback, (void*)&mynode, NULL);

	/*Should never return from following call*/
	SEVCHK(ca_pend_event(0.0),"ca_pend_event");
}
示例#4
0
文件: caCmd.c 项目: auriocus/AsynCA
static int newpvInfo (Tcl_Interp *interp, const char *name, Tcl_Obj *prefix) {
	pvInfo *result=ckalloc(sizeof(pvInfo));
	
	result->interp=interp;
	result->name=ckstrdup(name);
	if (prefix) Tcl_IncrRefCount(prefix);
	result->connectprefix = prefix;
	result->id = 0;
	result->connected = 0;
	result->thrid = Tcl_GetCurrentThread();
	result->monitorid = 0;
	result->monitorprefix = NULL;
	result->nElem = 1;
	result->type = -1;

	/* connect PV */
	int code = ca_create_channel(name, stateHandler, result, 0, &(result->id));
	if (code != ECA_NORMAL) {
		/* raise error */
		freepvInfo(result);
		Tcl_SetObjResult(interp, Tcl_NewStringObj(ca_message(code), -1));
		return TCL_ERROR;
	}	
	
	/* Create handle */
	static int pvcounter = 0;
	char objName[50 + TCL_INTEGER_SPACE];
	sprintf(objName, "::AsynCA::PV%d", ++pvcounter);
	result->cmd = Tcl_CreateObjCommand(interp, objName, InstanceCmd, (ClientData) result, DeleteCmd);
	
	Tcl_SetObjResult(interp, Tcl_NewStringObj(objName, -1));

	return TCL_OK;
}
示例#5
0
文件: access.cpp 项目: ukaea/epics
// extern "C"
int epicsShareAPI ca_search_and_connect (
    const char * name_str, chid * chanptr,
    caCh * conn_func, void * puser )
{
    return ca_create_channel ( name_str, conn_func, 
        puser, CA_PRIORITY_DEFAULT, chanptr );
}
示例#6
0
void ChannelAccessThr::run()
{
	//printchannel();	//for Debug
    CHNODE	mynode[register_chacc.size()];
	unsigned int i = 0;
	//const char  SHM_KEY[]  = "0x50000000";
	//const key_t  SHM_KEY  = 0x50000000;
	//char *shmPtr = m_pattach->mCachedData.open (SHM_KEY, register_chacc.size()*sizeof(CachedData), CachedChannelAccess::RT_SHM_CREAT | CachedChannelAccess::RT_SHM_RDWR);
	mutex.lock();
	for ( reg_chacciter = register_chacc.begin(); reg_chacciter != register_chacc.end(); ++reg_chacciter, i++)
	{
		mynode[i].objname	= QString(reg_chacciter->objname.c_str());
		mynode[i].acacc		= m_pattach;
		mynode[i].pvname	= QString(reg_chacciter->pvname.c_str());
		mynode[i].dbrequest	= reg_chacciter->dbrequest;
		mynode[i].chindex	= reg_chacciter->chindex;
		ca_create_channel(reg_chacciter->pvname.c_str(), connectionCallback, &mynode[i], 10, (oldChannelNotify**)&mynode[i].ch_id);
	};
	ca_pend_event(1.0);
	for ( reg_chacciter = register_chacc.begin(), i=0; reg_chacciter != register_chacc.end(); ++reg_chacciter, i++)
	{
		if (mynode[i].onceConnected)
		{
			//qDebug("Conn PV:%s", mynode[i].pvname.toStdString().c_str() );
		}
		else if (mynode[i].onceConnected == 0)
		{
			//qDebug("NotConn PV:%s", mynode[i].pvname.toStdString().c_str() );
			m_pattach->ConnectionStatusObj(mynode[i].objname, -1);
		};
	}
	mutex.unlock();
#if 1
	//in vm image, ca_pend_event(0.0001) stop processing on running;
	while(true)
	{
		if(getStop() == true) break;
		ca_pend_event(0.0001);
	};
    ca_context_destroy();
	exit();
#else
	//in vm image, this code no problem why?? U know?
	ca_pend_event(0.0);
#endif
}
void ProcessVariable::start(Guard &guard)
{
    guard.check(__FILE__, __LINE__, mutex);
#   ifdef DEBUG_PV
    printf("start ProcessVariable(%s)\n", getName().c_str());
#   endif
    LOG_ASSERT(! isRunning(guard));
    LOG_ASSERT(state == INIT);
    state = DISCONNECTED;
    // Unlock around CA lib. calls to prevent deadlocks in callbacks.
    int status;
    chid _id;
    {
        GuardRelease release(__FILE__, __LINE__, guard);
        {
            try
            {
       	        status = ca_create_channel(getName().c_str(),
                                           connection_handler,
                                           this, CA_PRIORITY_ARCHIVE, &_id);
            }
            catch (std::exception &e)
            {
                LOG_MSG("ProcessVariable::start(%s): %s\n",
                        getName().c_str(), e.what());
            }
            catch (...)
            {
                LOG_MSG("ProcessVariable::start(%s): Unknown Exception\n",
                        getName().c_str());
            }                          
            Guard ctx_guard(__FILE__, __LINE__, ctx);
            ctx.requestFlush(ctx_guard);
        }
    }
    id = _id;
    if (status != ECA_NORMAL)
        LOG_MSG("'%s': ca_create_channel failed, status %s\n",
                getName().c_str(), ca_message(status));
}
示例#8
0
int create_pvs (pv* pvs, int nPvs, caCh *pCB)
{
    int n;
    int result;
    int returncode = 0;
                                 /* Issue channel connections */
    for (n = 0; n < nPvs; n++) {
        result = ca_create_channel (pvs[n].name,
                                    pCB,
                                    &pvs[n],
                                    caPriority,
                                    &pvs[n].ch_id);
        if (result != ECA_NORMAL) {
            fprintf(stderr, "CA error %s occurred while trying "
                    "to create channel '%s'.\n", ca_message(result), pvs[n].name);
            pvs[n].status = result;
            returncode = 1;
        }
    }

    return returncode;
}
示例#9
0
void ChannelAccessThr::run()
{
	unsigned int i = 0;
	vecnode.reserve(register_chacc.size());
	mutex.lock();
	for ( reg_chacciter = register_chacc.begin(); reg_chacciter != register_chacc.end(); ++reg_chacciter, i++)
	{
		CHNODE node;
		node.objname   = QString(reg_chacciter->objname.c_str());
		node.acacc     = m_pattach;
		node.pvname    = QString(reg_chacciter->pvname.c_str());
		node.dbrequest = reg_chacciter->dbrequest;
		node.chindex   = reg_chacciter->chindex;
		node.pItem   = reg_chacciter->pItem;
		vecnode.push_back(node);
		ca_create_channel(reg_chacciter->pvname.c_str(), connectionCallback, (void*)&(vecnode.at(i)), 10, (oldChannelNotify**)&((vecnode.at(i)).ch_id));
	};
	ca_pend_event(1.0);
	for ( reg_chacciter = register_chacc.begin(), i=0; reg_chacciter != register_chacc.end(); ++reg_chacciter, i++)
	{
		CHNODE *pNode  = &vecnode.at(i); 
		if (pNode->onceConnected)
		{
		}
		else if (pNode->onceConnected == 0)
		{
			m_pattach->ConnectionStatusObj(pNode->objname, -1);
		};
	}
	mutex.unlock();

	while(true)
	{
		if(getStop() == true) break;
		ca_pend_event(0.0001);
	};
    ca_context_destroy();
	exit();
}
//______________________________________________________________________________
void shutterInterface::addChannel( const std::string & pvRoot, shutterStructs::pvStruct & pv )
{
    std::string s1 = pvRoot + pv.pvSuffix;
    ca_create_channel( s1.c_str(), 0, 0, 0, &pv.CHID );
    debugMessage( "Create channel to ", s1 );
}
示例#11
0
void SinglePlotThread::run()
{
#if 0
	// event gathering
	//printchannel();	//for Debug
	mutex.lock();
	mynode.plot	= m_plot;
	chid unit_chid;
	dbr_string_t units;
	QString unitch = m_pvname + ".EGU";
	ca_create_channel(unitch.toStdString().c_str(), 0, 0, 0, &unit_chid);
	ca_pend_io(0.1);
	ca_get(DBR_STRING, unit_chid, (void *)&units);
	ca_pend_io(0.1);
	m_plot->SetUnit(units);

	ca_create_channel(m_pvname.toStdString().c_str(), connectionCallback, &mynode, 0, (oldChannelNotify**)&mynode.mychid);
	ca_replace_access_rights_event(mynode.mychid, accessRightsCallback);
	ca_create_subscription (DBR_TIME_DOUBLE, 0, mynode.mychid, DBE_VALUE|DBE_ALARM, eventCallback, &mynode, &mynode.myevid);
	//ca_add_event(DBR_GR_DOUBLE, mynode.mychid, eventCallback, &mynode, &mynode.myevid);
	mutex.unlock();
	ca_pend_event(0.0);
#else
	//periodic gathering
	mutex.lock();
	chid unit_chid, val_chid;
	dbr_string_t units;

	QString unitch = m_pvname + ".EGU";
	ca_create_channel(unitch.toStdString().c_str(), 0, 0, 0, &unit_chid); ca_pend_io(0.2);
	ca_get(DBR_STRING, unit_chid, (void *)&units); ca_pend_io(0.2);
	m_plot->SetUnit(units);

	struct dbr_time_double data;
	ca_create_channel(m_pvname.toStdString().c_str(), 0, 0, 0, &val_chid);
	ca_pend_io(0.2);

	epicsTime  stamp;

	struct local_tm_nano_sec tm;
	int totsec = 0;
	//for periodic single plot local time
	int year, month, day, hour, min, sec;
	int factor = 1;
	switch(mperiodic)
	{
		case PointOne:
			factor *= 0.1;
			break;
		case PointFive:
			factor *= 0.5;
			break;
		case FiveSec:
			factor *= 5;
			break;
		case TenSec:
			factor *= 10;
			break;
		case OneSec:
		default:
			break;
	};
	while(getStop()==false)
	{
		ca_get(DBR_TIME_DOUBLE, val_chid, (void *)&data);
		ca_pend_io(0.2);
		//qDebug("%s : %f\n",ca_name(val_chid), data.value);
		Epoch2Datetime(year, month, day, hour, min, sec);
#if 0
		stamp = data.stamp;
		tm = (local_tm_nano_sec) stamp;
		totsec = tm.ansi_tm.tm_hour*3600+tm.ansi_tm.tm_min*60+tm.ansi_tm.tm_sec;
		m_plot->GetValue(data.value, totsec,tm.ansi_tm.tm_year,tm.ansi_tm.tm_mon, tm.ansi_tm.tm_mday );
#else
		totsec = hour*3600+min*60+sec;
		m_plot->GetValue(data.value, totsec, year, month, day);
#endif
		usleep(1000000*factor);
	};
	//ca_clear_channel(unit_chid);
	//ca_clear_channel(val_chid);
	ca_context_destroy();
	mutex.unlock();
	exit();
	qDebug("SinglePlot Exit");
#endif
}
示例#12
0
static void dbCaTask(void *arg)
{
    taskwdInsert(0, NULL, NULL);
    SEVCHK(ca_context_create(ca_enable_preemptive_callback),
        "dbCaTask calling ca_context_create");
    dbCaClientContext = ca_current_context ();
    SEVCHK(ca_add_exception_event(exceptionCallback,NULL),
        "ca_add_exception_event");
    epicsEventSignal(startStopEvent);

    /* channel access event loop */
    while (TRUE){
        do {
            epicsEventMustWait(workListEvent);
        } while (dbCaCtl == ctlPause);
        while (TRUE) { /* process all requests in workList*/
            caLink *pca;
            short  link_action;
            int    status;

            epicsMutexMustLock(workListLock);
            if (!(pca = (caLink *)ellGet(&workList))){  /* Take off list head */
                epicsMutexUnlock(workListLock);
                if (dbCaCtl == ctlExit) goto shutdown;
                break; /* workList is empty */
            }
            link_action = pca->link_action;
            pca->link_action = 0;
            if (link_action & CA_CLEAR_CHANNEL) --removesOutstanding;
            epicsMutexUnlock(workListLock);         /* Give back immediately */
            if (link_action & CA_CLEAR_CHANNEL) {   /* This must be first */
                dbCaLinkFree(pca);
                /* No alarm is raised. Since link is changing so what? */
                continue; /* No other link_action makes sense */
            }
            if (link_action & CA_CONNECT) {
                status = ca_create_channel(
                      pca->pvname,connectionCallback,(void *)pca,
                      CA_PRIORITY_DB_LINKS, &(pca->chid));
                if (status != ECA_NORMAL) {
                    errlogPrintf("dbCaTask ca_create_channel %s\n",
                        ca_message(status));
                    printLinks(pca);
                    continue;
                }
                dbca_chan_count++;
                status = ca_replace_access_rights_event(pca->chid,
                    accessRightsCallback);
                if (status != ECA_NORMAL) {
                    errlogPrintf("dbCaTask replace_access_rights_event %s\n",
                        ca_message(status));
                    printLinks(pca);
                }
                continue; /*Other options must wait until connect*/
            }
            if (ca_state(pca->chid) != cs_conn) continue;
            if (link_action & CA_WRITE_NATIVE) {
                assert(pca->pputNative);
                if (pca->putType == CA_PUT) {
                    status = ca_array_put(
                        pca->dbrType, pca->nelements,
                        pca->chid, pca->pputNative);
                } else if (pca->putType==CA_PUT_CALLBACK) {
                    status = ca_array_put_callback(
                        pca->dbrType, pca->nelements,
                        pca->chid, pca->pputNative,
                        putCallback, pca);
                } else {
                    status = ECA_PUTFAIL;
                }
                if (status != ECA_NORMAL) {
                    errlogPrintf("dbCaTask ca_array_put %s\n",
                        ca_message(status));
                    printLinks(pca);
                }
                epicsMutexMustLock(pca->lock);
                if (status == ECA_NORMAL) pca->newOutNative = FALSE;
                epicsMutexUnlock(pca->lock);
            }
            if (link_action & CA_WRITE_STRING) {
                assert(pca->pputString);
                if (pca->putType == CA_PUT) {
                    status = ca_array_put(
                        DBR_STRING, 1,
                        pca->chid, pca->pputString);
                } else if (pca->putType==CA_PUT_CALLBACK) {
                    status = ca_array_put_callback(
                        DBR_STRING, 1,
                        pca->chid, pca->pputString,
                        putCallback, pca);
                } else {
                    status = ECA_PUTFAIL;
                }
                if (status != ECA_NORMAL) {
                    errlogPrintf("dbCaTask ca_array_put %s\n",
                        ca_message(status));
                    printLinks(pca);
                }
                epicsMutexMustLock(pca->lock);
                if (status == ECA_NORMAL) pca->newOutString = FALSE;
                epicsMutexUnlock(pca->lock);
            }
            /*CA_GET_ATTRIBUTES before CA_MONITOR so that attributes available
             * before the first monitor callback                              */
            if (link_action & CA_GET_ATTRIBUTES) {
                status = ca_get_callback(DBR_CTRL_DOUBLE,
                    pca->chid, getAttribEventCallback, pca);
                if (status != ECA_NORMAL) {
                    errlogPrintf("dbCaTask ca_get_callback %s\n",
                        ca_message(status));
                    printLinks(pca);
                }
            }
            if (link_action & CA_MONITOR_NATIVE) {
                size_t element_size;
    
                element_size = dbr_value_size[ca_field_type(pca->chid)];
                epicsMutexMustLock(pca->lock);
                pca->pgetNative = dbCalloc(pca->nelements, element_size);
                epicsMutexUnlock(pca->lock);
                status = ca_add_array_event(
                    ca_field_type(pca->chid)+DBR_TIME_STRING,
                    ca_element_count(pca->chid),
                    pca->chid, eventCallback, pca, 0.0, 0.0, 0.0, 0);
                if (status != ECA_NORMAL) {
                    errlogPrintf("dbCaTask ca_add_array_event %s\n",
                        ca_message(status));
                    printLinks(pca);
                }
            }
            if (link_action & CA_MONITOR_STRING) {
                epicsMutexMustLock(pca->lock);
                pca->pgetString = dbCalloc(1, MAX_STRING_SIZE);
                epicsMutexUnlock(pca->lock);
                status = ca_add_array_event(DBR_TIME_STRING, 1,
                    pca->chid, eventCallback, pca, 0.0, 0.0, 0.0, 0);
                if (status != ECA_NORMAL) {
                    errlogPrintf("dbCaTask ca_add_array_event %s\n",
                        ca_message(status));
                    printLinks(pca);
                }
            }
        }
        SEVCHK(ca_flush_io(), "dbCaTask");
    }
shutdown:
    taskwdRemove(0);
    if (dbca_chan_count == 0)
        ca_context_destroy();
    else
        fprintf(stderr, "dbCa: chan_count = %d at shutdown\n", dbca_chan_count);
    epicsEventSignal(startStopEvent);
}