Esempio n. 1
0
/** Downloads all of the current EPICS settings to the electrometer.  
  * Typically used after the electrometer is power-cycled.
  */
asynStatus drvQuadEM::reset() 
{
    epicsInt32 iValue;
    epicsFloat64 dValue;

    getIntegerParam(P_Range, &iValue);
    setRange(iValue);

    getIntegerParam(P_ValuesPerRead, &iValue);
    setValuesPerRead(iValue);

    getDoubleParam(P_AveragingTime, &dValue);
    setAveragingTime(dValue);

    getIntegerParam(P_TriggerMode, &iValue);
    setTriggerMode(iValue);
    
    getIntegerParam(P_NumChannels, &iValue);
    setNumChannels(iValue);
    
    getIntegerParam(P_BiasState, &iValue);
    setBiasState(iValue);
    
    getIntegerParam(P_BiasInterlock, &iValue);
    setBiasInterlock(iValue);
    
    getDoubleParam(P_BiasVoltage, &dValue);
    setBiasVoltage(dValue);
    
    getIntegerParam(P_Resolution, &iValue);
    setResolution(iValue);

    getIntegerParam(P_ReadFormat, &iValue);
    setReadFormat(iValue);
    
    getDoubleParam(P_IntegrationTime, &dValue);
    setIntegrationTime(dValue);
    
    readStatus();
    
    getIntegerParam(P_Acquire, &iValue);
    setAcquire(iValue);

    return asynSuccess;
}
Esempio n. 2
0
void drvQuadEM::callbackTask()
{
    lock();
    int numAcquire;
    int acquireMode;
    
    while (1) {
        unlock();
        (void)epicsEventWait(ringEvent_);
        lock();
        getIntegerParam(P_AcquireMode, &acquireMode);
        getIntegerParam(P_NumAcquire, &numAcquire);
        doDataCallbacks();
        numAcquired_++;
        setIntegerParam(P_NumAcquired, numAcquired_);
        if ( (acquireMode == QEAcquireModeSingle) ||
            ((acquireMode == QEAcquireModeMultiple) && (numAcquired_ >= numAcquire))) {
            setAcquire(0);
            setIntegerParam(P_Acquire, 0);
        }
        callParamCallbacks();
    }
}
Esempio n. 3
0
/** Called when asyn clients call pasynInt32->write().
  * \param[in] pasynUser pasynUser structure that encodes the reason and address.
  * \param[in] value Value to write. */
asynStatus drvQuadEM::writeInt32(asynUser *pasynUser, epicsInt32 value)
{
    int function = pasynUser->reason;
    int status = asynSuccess;
    int channel;
    const char *paramName;
    const char* functionName = "writeInt32";

    getAddress(pasynUser, &channel);
    
    /* Set the parameter in the parameter library. */
    status |= setIntegerParam(channel, function, value);
    
    /* Fetch the parameter string name for possible use in debugging */
    getParamName(function, &paramName);

    if (function == P_Acquire) {
        if (value) {
            epicsRingBytesFlush(ringBuffer_);
            ringCount_ = 0;
        }
        status |= setAcquire(value);
    } 
    else if (function == P_AcquireMode) {
        if (value != QEAcquireModeContinuous) {
            status |= setAcquire(0);
            setIntegerParam(P_Acquire, 0);
        } 
        status |= setAcquireMode(value);
        status |= readStatus();
    }
    else if (function == P_BiasState) {
        status |= setBiasState(value);
        status |= readStatus();
    }
    else if (function == P_BiasInterlock) {
        status |= setBiasInterlock(value);
        status |= readStatus();
    }
    else if (function == P_NumChannels) {
        status |= setNumChannels(value);
        status |= readStatus();
    }
    else if (function == P_NumAcquire) {
        status |= setNumAcquire(value);
        status |= readStatus();
    }
    else if (function == P_PingPong) {
        status |= setPingPong(value);
        status |= readStatus();
    }
    else if (function == P_Range) {
        status |= setRange(value);
        status |= readStatus();
    }
    else if (function == P_ReadData) {
        status |= doDataCallbacks();
    }
    else if (function == P_Resolution) {
        status |= setResolution(value);
        status |= readStatus();
    }
    else if (function == P_TriggerMode) {
        status |= setTriggerMode(value);
        status |= readStatus();
    }
    else if (function == P_ValuesPerRead) {
        valuesPerRead_ = value;
        status |= setValuesPerRead(value);
        status |= readStatus();
    }
    else if (function == P_ReadFormat) {
        status |= setReadFormat(value);
        status |= readStatus();
    }
    else if (function == P_ReadStatus) {
        // We don't do this if we are acquiring, too disruptive
        if (!acquiring_) {
            status |= readStatus();
        }
    }
    else if (function == P_Reset) {
        status |= reset();
        status |= readStatus();
    }
    else {
        /* All other parameters just get set in parameter list, no need to
         * act on them here */
    }
    
    /* Do callbacks so higher layers see any changes */
    status |= (asynStatus) callParamCallbacks();
    
    if (status) 
        epicsSnprintf(pasynUser->errorMessage, pasynUser->errorMessageSize, 
                  "%s:%s: status=%d, function=%d, name=%s, value=%d", 
                  driverName, functionName, status, function, paramName, value);
    else        
        asynPrint(pasynUser, ASYN_TRACEIO_DRIVER, 
              "%s:%s: function=%d, name=%s, value=%d\n", 
              driverName, functionName, function, paramName, value);
    return (asynStatus)status;
}
Esempio n. 4
0
void mythen::acquisitionTask()
{
    size_t nread, nread_expect;
    size_t nwrite;
    int eventStatus;
    int imageMode;
    epicsInt32 acquire, eomReason;
    double acquireTime;
    asynStatus status = asynSuccess;
    int dataOK;

    static const char *functionName = "acquisitionTask";
    this->lock(); 

    while (1) {
        /* Is acquisition active? */
        getIntegerParam(ADAcquire, &acquire);
        
        /* If we are not acquiring then wait for a semaphore that is given when acquisition is started */
        if (!acquire || !acquiring_)  {
            setIntegerParam(ADStatus, ADStatusIdle);
            callParamCallbacks();
            /* Release the lock while we wait for an event that says acquire has started, then lock again */
            asynPrint(this->pasynUserSelf, ASYN_TRACE_FLOW, 
                "%s:%s: waiting for acquire to start\n", driverName, functionName);
            this->unlock();
            eventStatus = epicsEventWait(this->startEventId_);
            // setStringParam(ADStatusMessage, "Acquiring data");
            // setIntegerParam(ADNumImagesCounter, 0);
              // getIntegerParam(ADAcquire, &acquire);
              
                  
              //printf("Read Mode: %d\tnModules: %d\t chanperline: %d\n", readmode_,this->nmodules,chanperline_);
            if (readmode_==0)       //Raw Mode
                nread_expect = sizeof(epicsInt32)*this->nmodules*(1280/chanperline_);
            else
                nread_expect = sizeof(epicsInt32)*this->nmodules*(1280);
                
            dataOK = 1;

            eventStatus = getStatus();
            setIntegerParam(ADStatus, eventStatus);

            if (eventStatus!=ADStatusError) {

              getDoubleParam(ADAcquireTime,&acquireTime);
              // printf("Acquisition start - expect %d\n",nread_expect);
              // Work on the cases of what are you getting from getstatus
              do {
                nread=0;
                if (readmode_==0)
                  strcpy(outString_, "-readoutraw");
                else
                  strcpy(outString_, "-readout");

                status = pasynOctetSyncIO->writeRead(pasynUserMeter_, outString_, strlen(outString_), (char *)detArray_,
                                        nread_expect, M1K_TIMEOUT+acquireTime, &nwrite, &nread, &eomReason);  //Timeout is M1K_TIMEOUT + AcquireTime

                //printf("nread_expected = %d\tnread = %d\n", nread_expect,nread);

                if(nread == nread_expect) {
                    this->lock();
                    dataOK = dataCallback(detArray_);
                    this->unlock();
                    if (!dataOK) {
                        eventStatus = getStatus();
                        setIntegerParam(ADStatus, eventStatus);
                    }

                }
                else {
                    eventStatus = getStatus();
                    setIntegerParam(ADStatus, eventStatus);
                  //printf("Data not size expected ADStatus: %d\n",eventStatus);
                }
                if(status != asynSuccess) {
                    asynPrint(pasynUserSelf, ASYN_TRACE_ERROR,
                          "%s:%s: error using readout command status=%d, nRead=%d, eomReason=%d\n",
                          driverName, functionName, status, (int)nread, eomReason);
                }
              } 
              while (status == asynSuccess && (eventStatus==ADStatusAcquire||eventStatus==ADStatusReadout) && acquiring_);
             
           }
           this->lock();
            
        }
        if (eventStatus!=ADStatusError ) {
          printf("Acquisition finish\n");
          getIntegerParam(ADImageMode, &imageMode);
          if (imageMode == ADImageSingle || imageMode == ADImageMultiple) {
            printf("ADAcquire Callback\n");
            acquiring_ = 0;
            setIntegerParam(ADAcquire,  0); 
            callParamCallbacks(); 
          }
        }
        else {
          //Abort read 
          asynPrint(pasynUserSelf, ASYN_TRACE_ERROR,
                "%s:%s: error timed out waiting for data\n",
                driverName, functionName);
          acquiring_ = 0;
            setAcquire(0);
          setIntegerParam(ADAcquire,  0); 
          callParamCallbacks(); 
        }
    }
}
Esempio n. 5
0
/** Called when asyn clients call pasynInt32->write().
  * This function performs actions for some parameters, including ADAcquire, ADBinX, etc.
  * For all parameters it sets the value in the parameter library and calls any registered callbacks..
  * \param[in] pasynUser pasynUser structure that encodes the reason and address.
  * \param[in] value Value to write. */
asynStatus mythen::writeInt32(asynUser *pasynUser, epicsInt32 value)
{
    int function = pasynUser->reason;
    int status = asynSuccess;
    static const char *functionName = "writeInt32";

    /* Reject any call to the detector if it is running */
    if ((function != ADAcquire) && acquiring_) {
        asynPrint(this->pasynUserSelf, ASYN_TRACE_ERROR, 
        "%s:%s: detector is busy\n", driverName, functionName);
        return asynError;
    }

    /* Set the parameter and readback in the parameter library.
     * This may be overwritten when we read back the
     * status at the end, but that's OK */
    status |= setIntegerParam(function, value);

    if (function == ADAcquire) {
      getIntegerParam(SDReadMode, &readmode_);
      status |= setAcquire(value);
    }
    else {
      if (function == SDSetting) {
        status |= loadSettings(value);
      } else if (function == SDUseFlatField) {
        status |= setFCorrection(value);
      } else if (function == SDUseCountRate) {
        status |= setRCorrection(value);
      } else if (function == SDUseBadChanIntrpl) {
        status |= setBadChanIntrpl(value);
      } else if (function == SDBitDepth) {
        status |= setBitDepth(value);
      } else if (function == SDNumGates) {
        status = setNumGates(value);
      } else if (function == SDUseGates) {
        status = setUseGates(value);
      } else if (function == SDNumFrames) {
        status |= setFrames(value);
      } else if (function == SDTrigger) {
        status |= setTrigger(value);
      } else if (function == SDReset) {
        status |= setReset();
      } else if (function == ADImageMode) {

        //getIntegerParam(SDNumFrames, &frames_);
        status |= setFrames(frames_);
      } else {
        /* If this is not a parameter we have handled call the base class */
        if (function < FIRST_SD_PARAM) status = ADDriver::writeInt32(pasynUser, value);
      }
      status |= getSettings();
    }
 
    /* Update any changed parameters */
    status |= callParamCallbacks();

    if (status) 
        asynPrint(pasynUser, ASYN_TRACE_ERROR, 
              "%s:%s: error, status=%d function=%d, value=%d\n", 
              driverName, functionName, status, function, value);
    else        
        asynPrint(pasynUser, ASYN_TRACEIO_DRIVER, 
              "%s:%s: function=%d, value=%d\n", 
              driverName, functionName, function, value);
    return((asynStatus)status); 
}