본문 바로가기

카테고리 없음

epics asynPortDriver 정리

AO: DB 에서 ao는 channel access 를 통해 들어온 값을 ioc로 가져와서 외부로 값을 써주는 것

AI : DB에서 ai는 ioc가 외부의 값을 가져와 channel access로 값을 보내주는 것


record(ao,"$(FUNCTION_NAME):FSM-EVENT")
{
    field(DTYP, "asynInt32")
    field(OUT, "@asyn($(PORT)) FSM_EVENT")

    field(DRVH, "5")
    field(DRVL, "0")
    field(HOPR, "5")
    field(LOPR, "0")
    field(VAL, "0")

}

record(ai,"$(FUNCTION_NAME):FSM-STATE")
{
    field(DTYP, "asynInt32")
    field(SCAN, ".1 second")
    field(INP, "@asyn($(PORT)) FSM_STATE")

}


ayncPortDriver::writeInt32(asynUser *pasynUser, epicsInt32 value)

는 ao 에 대응되는 함수로 외부에서 channel access를 통해 들어오는 값이  변화가 있을 때 값을 value를 통해 가져옴.


/* Asyn read/write methods - parameter manipulation */

asynStatus RTLoopThreadPortDriver::writeInt32(asynUser *pasynUser, epicsInt32 value)
{
    int function = pasynUser->reason;
    asynStatus status = asynSuccess;
    const char *paramName;
    const char* functionName = "writeInt32";

    /* Set the parameter in the parameter library. */
    status = (asynStatus) setIntegerParam(function, value);

    /* Fetch the parameter string name for possible use in debugging */
    getParamName(function, &paramName);
    if(function == P_FSMEvent){
        if(value ==0) m_fsm_event = FSM_EVT_INIT;
        else if(value ==1) m_fsm_event = FSM_EVT_CONFIG;
        else if(value ==2) m_fsm_event = FSM_EVT_START;
        else if(value ==3) m_fsm_event = FSM_EVT_STOP;
        else if(value ==4) m_fsm_event = FSM_EVT_EXIT;
       
        }else if(function == P_FSMState){
    }
    /* 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 status;
}


asynStatus RTLoopThreadPortDriver::readInt32(asynUser *pasynUser, epicsInt32 *value)는 ai에 대응되는 함수로 ioc가 가지고 있는 내부의 값을 주기적으로 (DB에 적용된 주기 만큼) 읽어들여 channel access를 통해 값을 외부로 보내준다.



asynStatus RTLoopThreadPortDriver::readInt32(asynUser *pasynUser, epicsInt32 *value)
{
    int function = pasynUser->reason;
    const char *paramName;
    const char *functionName = "readInt32";

   asynStatus status = asynSuccess;
    /* Set the parameter in the parameter library. */
    status = (asynStatus) getIntegerParam(function, value);

    /* Fetch the parameter string name for possible use in debugging */
    getParamName(function, &paramName);
   if(function == P_FSMEvent)
        getIntegerParam(P_FSMEvent,value);
    else if(function == P_FSMState){
        int state_val = 0;
        if(m_fsm_state == FSM_STE_OFF) state_val= 0;
        else if( m_fsm_state == FSM_STE_INIT) state_val = 1;
        else if(m_fsm_state == FSM_STE_CONFIG) state_val=2;
        else if(m_fsm_state == FSM_STE_IDLE) state_val = 3;
        else if(m_fsm_state == FSM_STE_RUNNING) state_val = 4;
        else if(m_fsm_state == FSM_STE_ERROR) state_val = 5;
        // set pv value (ioc internal value)  
        setIntegerParam(P_FSMState,state_val);

// get pv value and update value that used to transfer the value

        getIntegerParam(P_FSMState,value);
    
    }
    else if(function ==P_RfmTestRun)
        getIntegerParam(P_RfmTestRun, value);
    else if(function == P_RfmWriteRun)
        getIntegerParam(P_RfmWriteRun,value);
    else if(function == P_EnableProdRfmThread)
        getIntegerParam(P_EnableProdRfmThread,value);
    else if(function == P_EnableConsSdnThread)
        getIntegerParam(P_EnableConsSdnThread,value);
    else if(function == P_EnableProdSdnThread)
        getIntegerParam(P_EnableProdSdnThread,value);
    else if(function == P_EnableConsRfmThread)
        getIntegerParam(P_EnableConsRfmThread,value);
    else if(function == P_EnableConsLogThread)
        getIntegerParam(P_EnableConsLogThread,value);




    asynPrint(pasynUser, ASYN_TRACEIO_DRIVER,
          "%s:%s: function=%d, name=%s, value=%d\n",
          driverName, functionName, function, paramName, *value);
    return asynSuccess;
}