Ejemplo n.º 1
0
/** Writes a string to the controller.
  * \param[in] output The string to be written.
  * \param[in] timeout Timeout before returning an error.*/
asynStatus AG_CONEXController::writeCONEX(const char *output, double timeout)
{
  size_t nwrite;
  asynStatus status;
  // const char *functionName="writeCONEX";
  
  status = pasynOctetSyncIO->write(pasynUserController_, output,
                                   strlen(output), timeout, &nwrite);
                                   
  // On Linux it seems to be necessary to delay a short time between writes
  #ifdef linux
  epicsThreadSleep(LINUX_WRITE_DELAY);
  #endif
                                  
  return status ;
}
Ejemplo n.º 2
0
int main(int argc,char *argv[])
{
	int i, j;
	extern short DEBUG;
	short daemon;
	char stcmd[256];

	/* Need to catch hang up signal to make sure semaphores are
	   cleaned up properly */
	SetSigShutdownHandler();

	daemon = 0;
	if(argc>=2) {    
		snprintf( stcmd, 255, "%s", argv[1]);
		/* parse command line args for crate and IP */
		j = 0;
		for( i = 2; i < argc; i++) {
		  if( strcmp( argv[i], "-D") == 0) {
		    i++;
		    DEBUG = atoi( argv[i]);
		  } else if( strcmp( argv[i], "-d") == 0) {
		    daemon = 1;
		  }
		}
	}
	else
	{
		printf( "Syntax: hvcontrol <st.cmd> [-c <name>@<hostname>[:<slotlist>]] [-d] [-D <debuglevel>]\n");
		printf( "        where <slotlist> = comma and dash separated list of slots.\n");
		printf( "              -d = run in daemon mode\n");
		printf( "              <debuglevel> = 0 no messages\n");
		printf( "              <debuglevel> = 10 all available messages\n");
	}

	if (strlen(stcmd)>0)	iocsh(stcmd);

	if (daemon)	{
		for(;;)
			epicsThreadSleep(1.0);
	} else {
		iocsh(NULL);
	}
	Shutdown();

	return(0);
}
Ejemplo n.º 3
0
static void controlThreadFunc(void *param)
{

	drvM6802_taskConfig *ptaskConfig = (drvM6802_taskConfig*) param;
	drvM6802_controlThreadConfig *pcontrolThreadConfig;
	controlThreadQueueData		queueData;

	while( !ptaskConfig->pcontrolThreadConfig ) epicsThreadSleep(.1);
	pcontrolThreadConfig = (drvM6802_controlThreadConfig*) ptaskConfig->pcontrolThreadConfig;


	epicsPrintf("task launching: %s thread for %s task\n",pcontrolThreadConfig->threadName, ptaskConfig->taskName);

	while(TRUE) {
		EXECFUNCQUEUE            pFunc;
		execParam                *pexecParam;
		struct dbCommon          *precord;
		struct rset              *prset;

		drvM6802_taskConfig    *ptaskConfig;

		epicsMessageQueueReceive(pcontrolThreadConfig->threadQueueId,
				         (void*) &queueData,
					 sizeof(controlThreadQueueData));

		pFunc      = queueData.pFunc;
	        pexecParam = &queueData.param;	
		precord    = (struct dbCommon*) pexecParam->precord;
		prset      = (struct rset*) precord->rset;
		ptaskConfig = (drvM6802_taskConfig *) pexecParam->ptaskConfig;

		if(!pFunc) continue;
		else pFunc(pexecParam);

		if(!precord) continue;


		dbScanLock(precord);
		(*prset->process)(precord); 
		dbScanUnlock(precord);
	}


	return;
}
Ejemplo n.º 4
0
/** Get Acquition Status */ 
epicsInt32 mythen::getStatus()
{
    epicsInt32 detStatus;
    int aux;

    strcpy(outString_, "-get status");
    writeReadMeter();
    aux = stringToInt32(this->inString_);
    int m_status =  aux & 1;          // Acquire running status (non-zero)
    int t_status = aux & (1<<3);      // Waiting for trigger (non-zero)        
    int d_status = aux & (1<<16);     // No Data Available when not zero
    int triggerWaitCnt=0;
    double triggerWait;
    
    //printf("Mythen Status - M:%d\tT:%d\tD:%d\n",m_status,t_status, d_status);
    
    if (m_status || !d_status ) { 
      detStatus = ADStatusAcquire;
      
      triggerWaitCnt=0;
      //Waits for Trigger for increaseing amount of time for a total of almost 1 minute
      while ((t_status ) && (triggerWaitCnt<MAX_TRIGGER_TIMEOUT_COUNT)) {
        triggerWait = 0.0001*pow(10.0,((double)(triggerWaitCnt/10)+1));
        //Wait
        epicsThreadSleep(triggerWait);
        //Check again
        strcpy(outString_, "-get status");
        writeReadMeter();
        aux = stringToInt32(this->inString_);
        t_status = aux & (1<<3);       
        d_status = aux & (1<<16);     
        triggerWaitCnt++;
        
      }
      
      if (!d_status)
        detStatus = ADStatusReadout;
      if (triggerWaitCnt==MAX_TRIGGER_TIMEOUT_COUNT)
        detStatus = ADStatusError;
    }
    else
      detStatus = ADStatusIdle;
    
    return detStatus;
}
Ejemplo n.º 5
0
asynStatus AG_CONEXAxis::home(double minVelocity, double maxVelocity, double acceleration, int forwards)
{
  asynStatus status;
  //static const char *functionName = "AG_CONEXAxis::home";

  // Must go to unreferenced state to home
  sprintf(pC_->outString_, "%dRS", pC_->controllerID_);
  status = pC_->writeCONEX();
  epicsThreadSleep(1.0);

  // The CONEX-CC supports home velocity, but only by going to Configuration state (PW1) 
  // and writing to non-volatile memory with the OH command.
  // This is time-consuming and can only be done a limited number of times so we don't do it here.

  sprintf(pC_->outString_, "%dOR", pC_->controllerID_);
  status = pC_->writeCONEX();
  return status;
}
Ejemplo n.º 6
0
void
vxStats_busyloop(unsigned busyperc)
{
    epicsTimeStamp then, now;
    double         fac = vxStats_busyloop_period/(double)100.0;

    if ( busyperc > 100 )
        busyperc = 100;

    while ( vxStats_busyloop_run ) {
        epicsTimeGetCurrent(&then);
        do {
            epicsTimeGetCurrent(&now);
        } while ( epicsTimeDiffInSeconds(&now,&then) < (double)busyperc*fac );

        epicsThreadSleep((double)(100-busyperc)*fac);
    }
}
Ejemplo n.º 7
0
static
void testcancel(void)
{
    epicsJob *job[2];
    epicsThreadPool *pool;
    testOk1((pool=epicsThreadPoolCreate(NULL))!=NULL);
    if(!pool)
        return;

    cancel[0]=epicsEventCreate(epicsEventEmpty);
    cancel[1]=epicsEventCreate(epicsEventEmpty);

    testOk1((job[0]=epicsJobCreate(pool, &neverrun, EPICSJOB_SELF))!=NULL);
    testOk1((job[1]=epicsJobCreate(pool, &toolate, EPICSJOB_SELF))!=NULL);

    /* freeze */
    epicsThreadPoolControl(pool, epicsThreadPoolQueueRun, 0);

    testOk1(epicsJobUnqueue(job[0])==S_pool_jobIdle); /* not queued yet */

    epicsJobQueue(job[0]);
    testOk1(epicsJobUnqueue(job[0])==0);
    testOk1(epicsJobUnqueue(job[0])==S_pool_jobIdle);

    epicsThreadSleep(0.01);
    epicsJobQueue(job[0]);
    testOk1(epicsJobUnqueue(job[0])==0);
    testOk1(epicsJobUnqueue(job[0])==S_pool_jobIdle);

    epicsThreadPoolControl(pool, epicsThreadPoolQueueRun, 1);

    epicsJobQueue(job[1]); /* actually let it run this time */

    epicsEventMustWait(cancel[0]);
    testOk1(epicsJobUnqueue(job[0])==S_pool_jobIdle);
    epicsEventSignal(cancel[1]);

    epicsThreadPoolDestroy(pool);
    epicsEventDestroy(cancel[0]);
    epicsEventDestroy(cancel[1]);

    testOk1(shouldneverrun==0);
    testOk1(numtoolate==1);
}
Ejemplo n.º 8
0
/** Array generation ask that runs as a separate thread.  When the P_RunStop parameter is set to 1
  * it periodically generates a burst of arrays. */
void testArrayRingBuffer::arrayGenTask(void)
{
    double loopDelay;
    int runStop; 
    int i, j;
    int burstLength;
    double burstDelay;
    int maxArrayLength;
    int arrayLength;
    
    lock();
    /* Loop forever */ 
    getIntegerParam(P_MaxArrayLength, &maxArrayLength);   
    while (1) {
        getDoubleParam(P_LoopDelay, &loopDelay);
        getDoubleParam(P_BurstDelay, &burstDelay);
        getIntegerParam(P_RunStop, &runStop);
        // Release the lock while we wait for a command to start or wait for updateTime
        unlock();
        if (runStop) epicsEventWaitWithTimeout(eventId_, loopDelay);
        else         (void)epicsEventWait(eventId_);
        // Take the lock again
        lock(); 
        /* runStop could have changed while we were waiting */
        getIntegerParam(P_RunStop, &runStop);
        if (!runStop) continue;
        getIntegerParam(P_ArrayLength, &arrayLength);
        if (arrayLength > maxArrayLength) {
            arrayLength = maxArrayLength;
            setIntegerParam(P_ArrayLength, arrayLength);
        }
        getIntegerParam(P_BurstLength, &burstLength);
        for (i=0; i<burstLength; i++) {
            for (j=0; j<arrayLength; j++) {
                pData_[j] = i;
            }
            setIntegerParam(P_ScalarData, i);
            callParamCallbacks();
            doCallbacksInt32Array(pData_, arrayLength, P_ArrayData, 0);
            if (burstDelay > 0.0) 
                epicsThreadSleep(burstDelay);
        }
    }
}
Ejemplo n.º 9
0
int drvACQ196_ARM_enable(ST_STD_device *pSTDdev)
{

	if(pSTDdev->StatusDev & TASK_ARM_ENABLED ) 
	{
		printf("\n>>> drvACQ196_ARM_enable : ADC already run \n");
		return WR_ERROR;
	}

	acq196_set_ABORT(pSTDdev);
	epicsThreadSleep(0.1);

	acq196_set_ARM(pSTDdev);
	
	pSTDdev->StatusDev &= ~TASK_SYSTEM_IDLE;
	pSTDdev->StatusDev |= TASK_ARM_ENABLED;

	return WR_OK;
}
Ejemplo n.º 10
0
static void readdjob(void *arg, epicsJobMode mode)
{
    readdPriv *priv=arg;
    testOk1(mode==epicsJobModeRun||mode==epicsJobModeCleanup);
    if(mode==epicsJobModeCleanup)
        return;
    testOk1(priv->inprogress==0);
    testDiag("count==%u", priv->count);

    if(priv->count--) {
        priv->inprogress=1;
        epicsJobQueue(priv->job);
        epicsThreadSleep(0.05);
        priv->inprogress=0;
    }else{
        epicsEventSignal(priv->done);
        epicsJobDestroy(priv->job);
    }
}
Ejemplo n.º 11
0
//==============================================================================
//
int main () {
   std::cout << "test abstract client user starting ("
             << ACAI_VERSION_STRING << ")\n\n";

   ACAI::Client::initialise ();

   ClientUser* user = new ClientUser ();

   TestClient* t1 = new TestClient ("T1");
   TestClient* t2 = new TestClient ("T2");
   TestClient* t3 = new TestClient ("T3");
   TestClient* t4 = new TestClient ("T4");

   user->registerClient (t1);
   user->registerClient (t2);
   user->registerClient (t3);
   std::cout << "\n";

   std::cout << "open registered clients\n";
   user->openRegisteredChannels();
   std::cout << "registered clients opened\n";

   std::cout << "open T4 client\n";
   t4->openChannel();
   std::cout << "T4 client opened\n";

   bool ok = user->waitAllRegisteredChannelsReady (2.0, 0.1);
   std::cout << "all channels open " << (ok ? "yes" : "no") <<  "\n";

   for (int t = 0; t < 500; t++) {
      epicsThreadSleep (0.02);   // 20mSec
      ACAI::Client::poll ();     // call back function invoked from here
   }

   std::cout << "close registered clients\n";
   user->closeRegisteredChannels();

   delete user;

   ACAI::Client::finalise();
   std::cout << "\ntest abstract client user complete\n";
   return 0;
}
Ejemplo n.º 12
0
static void devAdmin_BO_SYS_RUN(ST_execParam *pParam)
{
	ST_ADMIN *pAdminCfg = drvAdmin_get_AdminPtr();
	struct dbCommon *precord = pParam->precord;
	ST_STD_device *pSTDdev = (ST_STD_device*) ellFirst(pAdminCfg->pList_DeviceTask);

	/**********************************************
		user add here modified code. 
	***********************************************/
	if( (int)pParam->setValue == 1 ) /* command to run  */
	{
		if( admin_check_Run_condition()  == WR_ERROR) 
			return;

		/* direct call to sub-device.. for status notify immediately */
		while(pSTDdev) 
		{
			pSTDdev->StatusDev &= ~TASK_ARM_ENABLED;
			pSTDdev->StatusDev |= TASK_DAQ_STARTED;

			pSTDdev = (ST_STD_device*) ellNext(&pSTDdev->node);
		}

		epicsThreadSleep(0.3);
	}
	else 
	{
#if 0	/* do nothing... 'cause aleady done in sub devices */	
		if( admin_check_Stop_condition()  == WR_ERROR) 
			return;

		/* do something, if you need */
		while(pSTDdev) 
		{
			drvACQ196_RUN_stop(pSTDdev);

			pSTDdev = (ST_STD_device*) ellNext(&pSTDdev->node);
		}
#endif
	}
	notify_refresh_admin_status();
	epicsPrintf("%s: %s: %d \n", pAdminCfg->taskName, precord->name, (int)pParam->setValue);
}
int main(int argc,char *argv[])
{
	int i, j;
	short daemon;
	char stcmd[256];

	/* Need to catch hang up signal to make sure semaphores are
	   cleaned up properly */
	SetSigShutdownHandler();

	daemon = 0;
	if(argc>=2) {    
		snprintf( stcmd, 255, "%s", argv[1]);
		j = 0;
		for( i = 2; i < argc; i++) {
		  if( strcmp( argv[i], "-D") == 0) {
		    i++;
		    DEBUG = atoi( argv[i]);
		  } else if( strcmp( argv[i], "-d") == 0) {
		    daemon = 1;
		  }
		}
	}
	else
	{
		printf( "Syntax: hvcontrol <st.cmd> [-d] [-D <debuglevel>]\n");
		printf( "              -d = run in daemon mode\n");
		printf( "              <debuglevel> = 0 no messages\n");
		printf( "              <debuglevel> = 10 all available messages\n");
	}

	if (strlen(stcmd)>0)	iocsh(stcmd);

	if (daemon)	{
		for(;;)
			epicsThreadSleep(1.0);
	} else {
		iocsh(NULL);
	}
	Shutdown();
    epicsExit(0);
	return(0);
}
TEST_CASE test_msg_throttle()
{
    ThrottledMsgLogger throttle("Test", 2.0);
    // OK to print one message.
    throttle.LOG_MSG("Hello!\n");
    // Then, messages are discouraged...
    TEST(!throttle.isPermitted());
    throttle.LOG_MSG("Hello, too!\n");
    throttle.LOG_MSG("Hello, too!\n");
    throttle.LOG_MSG("Hello, too!\n");
    throttle.LOG_MSG("Hello, too!\n");
    throttle.LOG_MSG("Hello, too!\n");

    TEST_MSG(1, "waiting a little bit...");
    epicsThreadSleep(2.5);
    throttle.LOG_MSG("Hello again\n");

    TEST_OK;
}
Ejemplo n.º 15
0
/* Some sample loads on MVME167:
*
*	-> sp jbk_artificial_load, 100000000, 10000, 1
*		Load average: 69%
*	-> sp jbk_artificial_load, 100000000, 100000, 1
*		Load average: 95%
*	-> sp jbk_artificial_load, 100000000, 25000, 1
*		Load average: 88%
*/
int jbk_artificial_load(unsigned long iter,unsigned long often,unsigned long tick_delay)
{
    volatile unsigned long i;
    double   delay = (double)tick_delay * epicsThreadSleepQuantum();

    if(iter==0)
    {
        printf("Usage: jbk_artificial_load(num_iterations,iter_betwn_delays,tick_delay)\n");
        return 0;
    }

    for(i=0; i<iter; i++)
    {
        if(i%often==0)
            epicsThreadSleep(delay);
    }

    return 0;
}
Ejemplo n.º 16
0
void SimADC::run()
{
    const double min_sleep = epicsThreadSleepQuantum();

    sim_global_type::guard_t G(mutex);

    while(true) {
        {
            double zzz = rate.value>0.0 ? 1.0/rate.value : min_sleep;
            sim_global_type::unguard_t U(G);
            epicsThreadSleep(zzz);
        }
        if(runner_stop)
            break;

        cycle();
    }
    printf("SimADC shutdown\n");
}
bool PvaClientMultiMonitorDouble::poll()
{
    if(!isMonitorConnected){
         connect();
         epicsThreadSleep(.01);
    }
    bool result = false;
    shared_vector<epics::pvData::boolean> isConnected = pvaClientMultiChannel->getIsConnected();
    for(size_t i=0; i<nchannel; ++i)
    {
         if(isConnected[i]) {
              if(pvaClientMonitor[i]->poll()) {
                   doubleValue[i] = pvaClientMonitor[i]->getData()->getDouble();
                   pvaClientMonitor[i]->releaseEvent();
                   result = true;
              }
         }
    }
    return result;
}
Ejemplo n.º 18
0
static void interruptThread(drvPvt *pdrvPvt)
{
    while(1) {
        epicsEventMustWait(pdrvPvt->waitWork);
        while(1) {
            int addr;
            epicsUInt32 value;
            ELLLIST *pclientList;
            interruptNode *pnode;
            asynUInt32DigitalInterrupt *pinterrupt;

            if(pdrvPvt->interruptDelay <= .0001) break;
            for(addr=0; addr<NCHANNELS; addr++) {
                chanPvt *pchannel = &pdrvPvt->channel[addr];
                epicsMutexMustLock(pdrvPvt->lock);
                value = pchannel->value;
                if(value<0xf) {
                    value +=1;
                } else if(value&0x80000000) {
                    value = 0;
                } else {
                    value <<= 1;
                }
                pchannel->value = value;
                epicsMutexUnlock(pdrvPvt->lock);
            }
            pasynManager->interruptStart(
                pdrvPvt->asynUInt32DigitalPvt,&pclientList);
            pnode = (interruptNode *)ellFirst(pclientList);
            while (pnode) {
                pinterrupt = pnode->drvPvt;
                addr = pinterrupt->addr;
                pinterrupt->callback(pinterrupt->userPvt, pinterrupt->pasynUser,
                                     pdrvPvt->channel[addr].value);
                pnode = (interruptNode *)ellNext(&pnode->node);
            }
            pasynManager->interruptEnd(pdrvPvt->asynUInt32DigitalPvt);
            epicsThreadSleep(pdrvPvt->interruptDelay);
        }
    }
}
Ejemplo n.º 19
0
void mdsPlusShotID(int param)
{
    int status;
    char buf[40];
    DBADDR    *paddr;

    paddr = (DBADDR *)dbCalloc(1, sizeof(struct dbAddr));

    /* sleep */
    epicsThreadSleep(2.0);
    /*status = dbPutLink(shotIdOutLink, DBR_LONG, &shotId, 1);*/
    /* Put next pulse number */
    sprintf(buf, "icrf:pulseid.VAL");
    status = dbNameToAddr(buf, paddr);
    status = dbPutField(paddr, DBR_LONG, &shotId, 1);

    free(paddr);
    if(genSubDebug > 0)
         printf("genSub: mdsPlusShotID()  next shot number [%ld]. Status=%d\n",shotId,status);

}
Ejemplo n.º 20
0
epicsShareFunc void epicsShareAPI epicsThreadOnce(epicsThreadOnceId *id, void (*func)(void *), void *arg)
{
    static struct epicsThreadOSD threadOnceComplete;
    #define EPICS_THREAD_ONCE_DONE &threadOnceComplete
    int status;

    epicsThreadInit();
    status = mutexLock(&onceLock);
    if(status) {
        fprintf(stderr,"epicsThreadOnce: pthread_mutex_lock returned %s.\n",
            strerror(status));
        exit(-1);
    }

    if (*id != EPICS_THREAD_ONCE_DONE) {
        if (*id == EPICS_THREAD_ONCE_INIT) { /* first call */
            *id = epicsThreadGetIdSelf();    /* mark active */
            status = pthread_mutex_unlock(&onceLock);
            checkStatusQuit(status,"pthread_mutex_unlock", "epicsThreadOnce");
            func(arg);
            status = mutexLock(&onceLock);
            checkStatusQuit(status,"pthread_mutex_lock", "epicsThreadOnce");
            *id = EPICS_THREAD_ONCE_DONE;    /* mark done */
        } else if (*id == epicsThreadGetIdSelf()) {
            status = pthread_mutex_unlock(&onceLock);
            checkStatusQuit(status,"pthread_mutex_unlock", "epicsThreadOnce");
            cantProceed("Recursive epicsThreadOnce() initialization\n");
        } else
            while (*id != EPICS_THREAD_ONCE_DONE) {
                /* Another thread is in the above func(arg) call. */
                status = pthread_mutex_unlock(&onceLock);
                checkStatusQuit(status,"pthread_mutex_unlock", "epicsThreadOnce");
                epicsThreadSleep(epicsThreadSleepQuantum());
                status = mutexLock(&onceLock);
                checkStatusQuit(status,"pthread_mutex_lock", "epicsThreadOnce");
            }
    }
    status = pthread_mutex_unlock(&onceLock);
    checkStatusQuit(status,"pthread_mutex_unlock","epicsThreadOnce");
}
Ejemplo n.º 21
0
/*
 * This function spawns additional thread that emulate PPS input. Function is used for
 * testing of timestamping functionality... DO NOT USE IN PRODUCTION!!!!!
 *
 * Change by: tslejko
 * Reason: testing utilities
 */
void mrmEvgSoftTime(void* pvt) {
    evgMrm* evg = static_cast<evgMrm*>(pvt);

    if (!evg) {
        errlogPrintf("mrmEvgSoftTimestamp: Could not find EVG!\n");
    }

    while (1) {
        epicsUInt32 data = evg->sendTimestamp();
        if (!data){
            errlogPrintf("mrmEvgSoftTimestamp: Could not retrive timestamp...\n");
            epicsThreadSleep(1);
            continue;
        }

        //Send out event reset
        evg->getSoftEvt()->setEvtCode(MRF_EVENT_TS_COUNTER_RST);

        //Clock out data...
        for (int i = 0; i < 32; data <<= 1, i++) {
            if (data & 0x80000000)
                evg->getSoftEvt()->setEvtCode(MRF_EVENT_TS_SHIFT_1);
            else
                evg->getSoftEvt()->setEvtCode(MRF_EVENT_TS_SHIFT_0);
        }

        struct timespec sleep_until_t;

        clock_gettime(CLOCK_REALTIME,&sleep_until_t); //Get current time
        /* Sleep until next full second */
        sleep_until_t.tv_nsec=0;
        sleep_until_t.tv_sec++;

        clock_nanosleep(CLOCK_REALTIME,TIMER_ABSTIME,&sleep_until_t,0);


//		sleep(1);
    }
}
 void pvConnected(ProcessVariable &pv, const epicsTime &when)
 {
     {
         Guard guard(__FILE__, __LINE__, mutex);
         connected = true;
         puts("\nConnected");
     }
     if (stop_in_connect)
     {
         puts("Stop in connect");
         hack.signal();
     }
     {
         Guard pv_guard(__FILE__, __LINE__, pv);
         pv.subscribe(pv_guard);
     }
     {
         Guard ctx_guard(__FILE__, __LINE__, ctx);
         ctx.flush(ctx_guard);
     }
     epicsThreadSleep(linger);
 }
void ReadASCII::readFilePoll(void)
{
	//Thread to poll the file used in the PID lookup and update the array of values when the file is modified
	char localDir[DIR_LENGTH], dirBase[DIR_LENGTH];
	asynStatus status;

	while (1) {
		
		//wait for a file change
		epicsThreadSleep(2.0);
		
		if (true == fileBad)
			continue;

		lock();

		//get directory in this thread
		getStringParam(P_DirBase, DIR_LENGTH, dirBase);
		getStringParam(P_Dir, DIR_LENGTH, localDir);

		//release lock
		unlock();

		strcat(dirBase, "/");
		strcat(dirBase, localDir);

		if (false == isModified(dirBase))
		{
			continue;
		}

		lock();

		status = readFile(dirBase);

		unlock();
	}
}
Ejemplo n.º 24
0
void Scaler974::eventThread()
{
    int done, presetCount;
    char response[100], statusString[20];
    size_t responseLen, statusLen;
    int counts[MAX_CHANNELS];
    int i;
    asynStatus status;
    static const char *functionName="eventThread";
    
    while(1)
    {
        epicsEventWait(this->eventId);
        while(1)
        {
            status = this->sendCommand("SHOW_COUNTS", statusString, sizeof(statusString), &statusLen,
                                       response, sizeof(response), &responseLen);
            sscanf(response, "%d;%d;%d;%d;", 
                   &counts[0], &counts[1], &counts[2], &counts[3]);
            asynPrint(this->pasynUserSelf, ASYN_TRACEIO_DRIVER,
                "%s:%s status=%d, counts=%d %d %d %d\n",
                driverName, functionName, status, counts[0], counts[1], counts[2], counts[3]);
            this->lock();
            /* Get value of done in case scaler was stopped by scalerArm(0) */
            getIntegerParam(scalerDone, &done);
            getIntegerParam(scalerPreset, &presetCount);
            if (!done && (counts[0] >= presetCount)) done = 1;
            setIntegerParam(scalerDone, done);
            for (i=0; i<MAX_CHANNELS; i++) {
                setIntegerParam(i, scalerReadSingle, counts[i]);
                callParamCallbacks(i, i);
            }
            this->unlock();
            if (done) break; 
            epicsThreadSleep(this->polltime);
        }
    }
}
Ejemplo n.º 25
0
void func_acq196_SYS_RUN(void *pArg, double arg1, double arg2)
{
	ST_STD_device* pSTDdev = (ST_STD_device *)pArg;
	
	if( (int)arg1 == 1 ) /* command to run  */
	{
		if( check_dev_run_condition(pSTDdev)  == WR_ERROR) 
			return;

		/* direct call to sub-device.. for status notify immediately */
//		while(pSTDdev) 
//		{
			if( drvACQ196_RUN_start(pSTDdev) == WR_ERROR ) 
				return;

//			pSTDdev = (ST_STD_device*) ellNext(&pSTDdev->node);
//		}

		epicsThreadSleep(0.3);
	}
	else 
	{
#if 0	/* do nothing... 'cause aleady done in sub devices */	
		if( check_dev_stop_condition(pSTDdev)  == WR_ERROR) 
			return;

		/* do something, if you need */
		while(pSTDdev) 
		{
			

			pSTDdev = (ST_STD_device*) ellNext(&pSTDdev->node);
		}
#endif
	}
	

}
Ejemplo n.º 26
0
/* Action function for state "get" in state set "read_anon_sync" */
static void seqg_action_read_anon_sync_3_get(SS_ID seqg_env, int seqg_trn, int *seqg_pnst)
{
	switch(seqg_trn)
	{
	case 0:
		{
# line 155 "../pvGet.st"
			seq_efSet(seqg_env, ef_read_anon_sync);
		}
		return;
	case 1:
		{
# line 158 "../pvGet.st"
			epicsMutexMustLock(mutex);
# line 159 "../pvGet.st"
			seqg_var->seqg_vars_read_anon_sync.expected = shared;
# line 160 "../pvGet.st"
			seq_pvGetTmo(seqg_env, 0/*anon*/, SYNC, DEFAULT_TIMEOUT);
# line 161 "../pvGet.st"
			epicsMutexUnlock(mutex);
# line 163 "../pvGet.st"
			testOk(seqg_var->seqg_vars_read_anon_sync.expected == seqg_var->anon, "synchronous get:           expected=%d==%d=anon", seqg_var->seqg_vars_read_anon_sync.expected, seqg_var->anon);
# line 164 "../pvGet.st"
			epicsThreadSleep(0.1);
# line 165 "../pvGet.st"
			epicsMutexMustLock(mutex);
# line 166 "../pvGet.st"
			seqg_var->seqg_vars_read_anon_sync.expected = shared;
# line 167 "../pvGet.st"
			seq_pvGetTmo(seqg_env, 0/*anon*/, SYNC, DEFAULT_TIMEOUT);
# line 168 "../pvGet.st"
			epicsMutexUnlock(mutex);
# line 170 "../pvGet.st"
			testOk(seqg_var->seqg_vars_read_anon_sync.expected == seqg_var->anon, "repeat get after delay:    expected=%d==%d=anon", seqg_var->seqg_vars_read_anon_sync.expected, seqg_var->anon);
		}
		return;
	}
}
Ejemplo n.º 27
0
/* Action function for state "get" in state set "read_named_sync" */
static void seqg_action_read_named_sync_2_get(SS_ID seqg_env, int seqg_trn, int *seqg_pnst)
{
	switch(seqg_trn)
	{
	case 0:
		{
# line 119 "../pvGet.st"
			seq_efSet(seqg_env, ef_read_named_sync);
		}
		return;
	case 1:
		{
# line 122 "../pvGet.st"
			epicsMutexMustLock(mutex);
# line 123 "../pvGet.st"
			seqg_var->seqg_vars_read_named_sync.expected = shared;
# line 124 "../pvGet.st"
			seq_pvGetTmo(seqg_env, 2/*named*/, SYNC, DEFAULT_TIMEOUT);
# line 125 "../pvGet.st"
			epicsMutexUnlock(mutex);
# line 127 "../pvGet.st"
			testOk(seqg_var->seqg_vars_read_named_sync.expected == seqg_var->seqg_vars_read_named_sync.named, "synchronous get:           expected=%d==%d=named", seqg_var->seqg_vars_read_named_sync.expected, seqg_var->seqg_vars_read_named_sync.named);
# line 128 "../pvGet.st"
			epicsThreadSleep(0.1);
# line 129 "../pvGet.st"
			epicsMutexMustLock(mutex);
# line 130 "../pvGet.st"
			seqg_var->seqg_vars_read_named_sync.expected = shared;
# line 131 "../pvGet.st"
			seq_pvGetTmo(seqg_env, 2/*named*/, SYNC, DEFAULT_TIMEOUT);
# line 132 "../pvGet.st"
			epicsMutexUnlock(mutex);
# line 134 "../pvGet.st"
			testOk(seqg_var->seqg_vars_read_named_sync.expected == seqg_var->seqg_vars_read_named_sync.named, "repeat get after delay:    expected=%d==%d=named", seqg_var->seqg_vars_read_named_sync.expected, seqg_var->seqg_vars_read_named_sync.named);
		}
		return;
	}
}
Ejemplo n.º 28
0
static void myThreadFunction( void *pvt ) {
    int board = (int)pvt;

    /* prepare */
    if (myBoard_prepare( board )) {
        fprintf( stderr, "prepare failed for board=%d\n", board );
        return;
    }

    if (myBoard_start( board )) {
        fprintf( stderr, "start failed for board=%d\n", board );
        return;
    }

    fprintf( stderr, "enter loop\n" );
    fflush( stderr );
    while (1) {
        epicsThreadSleep(0.1);
        if (myBoard_distributeData( board )) {
            myBoard_wakeupQueue( board );
        }
    }
}
Ejemplo n.º 29
0
/*
 * Clean up a socket on exit
 * This helps reduce problems with vxWorks when the IOC restarts
 */
static void
cleanup (void *arg)
{
    asynStatus status;
    ttyController_t *tty = (ttyController_t *)arg;

    if (!tty) return;
    status=pasynManager->lockPort(tty->pasynUser);
    if(status!=asynSuccess)
        asynPrint(tty->pasynUser, ASYN_TRACE_ERROR, "%s: cleanup locking error\n", tty->portName);

    if (tty->fd != INVALID_SOCKET) {
        asynPrint(tty->pasynUser, ASYN_TRACE_FLOW, "%s: shutdown socket\n", tty->portName);
        tty->flags |= FLAG_SHUTDOWN; /* prevent reconnect */
        epicsSocketDestroy(tty->fd);
        tty->fd = INVALID_SOCKET;
        /* If this delay is not present then the sockets are not always really closed cleanly */
        epicsThreadSleep(CLOSE_SOCKET_DELAY);
    }

    if(status==asynSuccess)
        pasynManager->unlockPort(tty->pasynUser);
}
Ejemplo n.º 30
0
int Eiger::trigger (int timeout, double exposure)
{
    // Trigger for INTS mode
    if(!exposure)
        return put(SSCommand, "trigger", "", 0, NULL, timeout);

    // Tigger for INTE mode
    // putDouble should block for the whole exposure duration, but it doesn't
    // (Eiger's fault)

    epicsTimeStamp start, end;

    epicsTimeGetCurrent(&start);
    if(putDouble(SSCommand, "trigger", exposure, NULL, timeout))
        return EXIT_FAILURE;
    epicsTimeGetCurrent(&end);

    double diff = epicsTimeDiffInSeconds(&end, &start);
    if(diff < exposure)
        epicsThreadSleep(exposure - diff);

    return EXIT_SUCCESS;
}