asynStatus isisdaeDriver::readArray(asynUser *pasynUser, const char* functionName, T *value, size_t nElements, size_t *nIn)
{
  int function = pasynUser->reason;
  asynStatus status = asynSuccess;
  const char *paramName = NULL;
	getParamName(function, &paramName);
	m_iface->resetMessages();
	try
	{
        asynPrint(pasynUser, ASYN_TRACEIO_DRIVER, 
              "%s:%s: function=%d, name=%s\n", 
              driverName, functionName, function, paramName);
		reportMessages();
		return status;
	}
	catch(const std::exception& ex)
	{
		*nIn = 0;
        epicsSnprintf(pasynUser->errorMessage, pasynUser->errorMessageSize, 
                  "%s:%s: status=%d, function=%d, name=%s, error=%s", 
                  driverName, functionName, status, function, paramName, ex.what());
		reportErrors(ex.what());
		return asynError;
	}
}
Exemplo n.º 2
0
/** Called when asyn clients call pasynFloat64->write().
  * \param[in] pasynUser pasynUser structure that encodes the reason and address.
  * \param[in] value Value to write. */
asynStatus testErrors::writeFloat64(asynUser *pasynUser, epicsFloat64 value)
{
    int function = pasynUser->reason;
    asynStatus status = asynSuccess;
    int itemp;
    const char *paramName;
    const char* functionName = "writeFloat64";

    /* Get the current error status */
    getIntegerParam(P_StatusReturn, &itemp);  status = (asynStatus)itemp;

    /* Fetch the parameter string name for use in debugging */
    getParamName(function, &paramName);

    /* Set the parameter in the parameter library. */
    setDoubleParam(function, value);
    /* Set the parameter status in the parameter library. */
    setParamStatus(function, status);

    /* Do callbacks so higher layers see any changes */
    callParamCallbacks();
    
    if (status) 
        epicsSnprintf(pasynUser->errorMessage, pasynUser->errorMessageSize, 
                  "%s:%s: status=%d, function=%d, name=%s, value=%f", 
                  driverName, functionName, status, function, paramName, value);
    else        
        asynPrint(pasynUser, ASYN_TRACEIO_DRIVER, 
              "%s:%s: function=%d, name=%s, value=%f\n", 
              driverName, functionName, function, paramName, value);
    return status;
}
Exemplo n.º 3
0
static asynStatus gpibPortAddressedCmd(void *pdrvPvt,asynUser *pasynUser,
    const char *data, int length)
{
    niport *pniport = (niport *)pdrvPvt;
    double     timeout = pasynUser->timeout;
    int        addr = 0;
    int        actual;
    asynStatus status;
    char cmdbuf[2] = {IBUNT,IBUNL};

    status = pasynManager->getAddr(pasynUser,&addr);
    if(status!=asynSuccess) return status;
    asynPrint(pasynUser,ASYN_TRACE_FLOW,
       "%s addr %d gpibPortAddressedCmd nchar %d\n",
        pniport->portName,addr,length);
    pniport->errorMessage[0] = 0;
    status = writeAddr(pniport,0,addr,timeout,transferStateIdle);
    if(status==asynSuccess) {
        status=writeCmd(pniport,data,length,timeout,transferStateIdle);
    }
    if(status!=asynSuccess) {
        epicsSnprintf(pasynUser->errorMessage,pasynUser->errorMessageSize,
            "%s writeGpib failed %s",pniport->portName,pniport->errorMessage);
    }
    actual = length - pniport->bytesRemainingCmd;
    asynPrintIO(pasynUser,ASYN_TRACEIO_DRIVER,
        data,actual,"%s gpibPortAddressedCmd\n",pniport->portName);
    if(status!=asynSuccess) return status;
    writeCmd(pniport,cmdbuf,2,timeout,transferStateIdle);
    return status;
}
Exemplo n.º 4
0
asynStatus mar345::erase()
{
    int numErase;
    int i;
    asynStatus status=asynSuccess;
    //const char *functionName = "erase";

    getIntegerParam(mar345NumErase, &numErase);
    if (numErase < 1) numErase=1;
    setIntegerParam(ADStatus, mar345StatusErase);
    setIntegerParam(mar345NumErased, 0);
    callParamCallbacks();
    for (i=0; i<numErase; i++) {
        if (epicsEventTryWait(this->abortEventId) == epicsEventWaitOK) {
            status = asynError;
            break;
        }
        epicsSnprintf(this->toServer, sizeof(this->toServer), "COMMAND ERASE");
        writeServer(this->toServer);
        status = waitForCompletion("SCAN_DATA    Ended o.k.", MAR345_COMMAND_TIMEOUT);
        if (status) break;
        setIntegerParam(mar345NumErased, i+1);
        callParamCallbacks();
    }
    setIntegerParam(ADStatus, mar345StatusIdle);
    setIntegerParam(mar345Erase, 0);
    callParamCallbacks();
    return(status);
}
/// Load a db file multiple times substituting a specified macro according to a number range.
///
/// The \a dbFile and \a macros arguments are like the normal dbLoadRecords() however
/// it is possible to embed a macro within these whose value follows the range \a start to \a stop.
/// You can either load the same \a dbFile multiple times with different macros, or even load
/// different database files by using \a loopVar as part of the filename. If you want to use a list
/// of (non-numeric) substitutions rather than an integer range see dbLoadRecordsList()
///
/// The name of the macro to be used for substitution is contained in \a loopVar and needs to be
/// reference in an \\ escaped way to make sure EPICS does not try to substitute it too soon.
/// as well as the \a macros the \a dbFile is also passed the \a loopVar macro value
/// @code
///     dbLoadRecordsLoop("file\$(I).db", "P=1,Q=Hello\$(I)", "I", 1, 4)
/// @endcode 
///
/// @param[in] dbFile @copydoc dbLoadRecordsLoopInitArg0
/// @param[in] macros @copydoc dbLoadRecordsLoopInitArg1
/// @param[in] loopVar @copydoc dbLoadRecordsLoopInitArg2
/// @param[in] start @copydoc dbLoadRecordsLoopInitArg3
/// @param[in] stop @copydoc dbLoadRecordsLoopInitArg4
/// @param[in] step @copydoc dbLoadRecordsLoopInitArg5
epicsShareFunc void dbLoadRecordsLoop(const char* dbFile, const char* macros, const char* loopVar, int start, int stop, int step)
{
    char loopVal[32];
    if (loopVar == NULL)
    {
        dbLoadRecords(dbFile, macros);
        return;
    }
    if (step <= 0)
    {
        step = 1;
    }
    std::string macros_s, dbFile_s;
    subMacros(macros_s, macros, loopVar);
    subMacros(dbFile_s, dbFile, loopVar);
    MAC_HANDLE* mh = NULL;
	char macros_exp[1024], dbFile_exp[1024];
    macCreateHandle(&mh, NULL);
	loadMacEnviron(mh);
    for(int i = start; i <= stop; i += step)
    {
		macPushScope(mh);
        epicsSnprintf(loopVal, sizeof(loopVal), "%d", i);
        macPutValue(mh, loopVar, loopVal);   
        macExpandString(mh, macros_s.c_str(), macros_exp, sizeof(macros_exp));
        macExpandString(mh, dbFile_s.c_str(), dbFile_exp, sizeof(dbFile_exp));
        std::ostringstream new_macros;
        new_macros << macros_exp << (strlen(macros_exp) > 0 ? "," : "") << loopVar << "=" << i;
        std::cout << "--> (" << i << ") dbLoadRecords(\"" << dbFile_exp << "\",\"" << new_macros.str() << "\")" << std::endl;
        dbLoadRecords(dbFile_exp, new_macros.str().c_str());
		macPopScope(mh);
    }
	macDeleteHandle(mh);		
}
/** Build a file name from component parts.
  * \param[in] maxChars  The size of the fullFileName string.
  * \param[out] fullFileName The constructed file name including the file path.
  * 
  * This is a convenience function that constructs a complete file name
  * from the NDFilePath, NDFileName, NDFileNumber, and
  * NDFileTemplate parameters. If NDAutoIncrement is true then it increments the
  * NDFileNumber after creating the file name.
  */
int asynNDArrayDriver::createFileName(int maxChars, char *fullFileName)
{
    /* Formats a complete file name from the components defined in NDStdDriverParams */
    int status = asynSuccess;
    char filePath[MAX_FILENAME_LEN];
    char fileName[MAX_FILENAME_LEN];
    char fileTemplate[MAX_FILENAME_LEN];
    int fileNumber;
    int autoIncrement;
    int len;
    
    this->checkPath();
    status |= getStringParam(NDFilePath, sizeof(filePath), filePath);
    status |= getStringParam(NDFileName, sizeof(fileName), fileName); 
    status |= getStringParam(NDFileTemplate, sizeof(fileTemplate), fileTemplate); 
    status |= getIntegerParam(NDFileNumber, &fileNumber);
    status |= getIntegerParam(NDAutoIncrement, &autoIncrement);
    if (status) return(status);
    len = epicsSnprintf(fullFileName, maxChars, fileTemplate, 
                        filePath, fileName, fileNumber);
    if (len < 0) {
        status |= asynError;
        return(status);
    }
    if (autoIncrement) {
        fileNumber++;
        status |= setIntegerParam(NDFileNumber, fileNumber);
    }
    return(status);   
}
/// Read Values as Octet
asynStatus ReadASCII::readOctet(asynUser *pasynUser, char *value, size_t maxChars, size_t *nActual, int *eomReason)
{
	//Checks if directory has changed, reads file again if it has
	int function = pasynUser->reason;
	asynStatus status = asynSuccess;
	const char *paramName;
	const char* functionName = "readOctet";

	/* Fetch the parameter string name for possible use in debugging */
	getParamName(function, &paramName);

	if (function == P_DirBase) {
		char dirBase[DIR_LENGTH];
		getStringParam(P_DirBase, DIR_LENGTH, dirBase);

		strncpy(value, dirBase, maxChars);
		*nActual = strlen(dirBase);
		std::cerr << status << "new dir base " << dirBase << std::endl;
	} else {
		status = asynError;
		epicsSnprintf(pasynUser->errorMessage, pasynUser->errorMessageSize,
				"%s:%s: status=%d, function=%d, name=%s function does not have read.",
				driverName, functionName, status, function, paramName);
	}

	return status;

}
Exemplo n.º 8
0
asynStatus testErrors::doReadArray(asynUser *pasynUser, epicsType *value, 
                                   size_t nElements, size_t *nIn, int paramIndex, epicsType *pValue)
{
    int function = pasynUser->reason;
    size_t ncopy = MAX_ARRAY_POINTS;
    asynStatus status = asynSuccess;
    const char *functionName = "doReadArray";

    /* Get the current error status */
    getIntegerParam(P_StatusReturn, (int*)&status);

    if (nElements < ncopy) ncopy = nElements;
    if (function == paramIndex) {
        memcpy(value, pValue, ncopy*sizeof(epicsType));
        *nIn = ncopy;
    }

    if (status) 
        epicsSnprintf(pasynUser->errorMessage, pasynUser->errorMessageSize, 
                  "%s:%s: status=%d, function=%d", 
                  driverName, functionName, status, function);
    else        
        asynPrint(pasynUser, ASYN_TRACEIO_DRIVER, 
              "%s:%s: function=%d\n", 
              driverName, functionName, function);
    return status;
}
/** Called when asyn clients call pasynOctet->write().
  * This function performs actions for some parameters, including NDAttributesFile.
  * 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 Address of the string to write.
  * \param[in] nChars Number of characters to write.
  * \param[out] nActual Number of characters actually written. */
asynStatus asynNDArrayDriver::writeOctet(asynUser *pasynUser, const char *value, 
                                    size_t nChars, size_t *nActual)
{
    int addr=0;
    int function = pasynUser->reason;
    asynStatus status = asynSuccess;
    const char *functionName = "writeOctet";

    status = getAddress(pasynUser, &addr); if (status != asynSuccess) return(status);
    /* Set the parameter in the parameter library. */
    status = (asynStatus)setStringParam(addr, function, (char *)value);

    if (function == NDAttributesFile) {
        this->readNDAttributesFile(value);
    } else if (function == NDFilePath) {
        this->checkPath();
    }
     /* Do callbacks so higher layers see any changes */
    status = (asynStatus)callParamCallbacks(addr, addr);

    if (status) 
        epicsSnprintf(pasynUser->errorMessage, pasynUser->errorMessageSize, 
                  "%s:%s: status=%d, function=%d, value=%s", 
                  driverName, functionName, status, function, value);
    else        
        asynPrint(pasynUser, ASYN_TRACEIO_DRIVER, 
              "%s:%s: function=%d, value=%s\n", 
              driverName, functionName, function, value);
    *nActual = nChars;
    return status;
}
Exemplo n.º 10
0
/** Called when asyn clients call pasynFloat64Array->read().
  * Returns the value of the P_Waveform or P_TimeBase arrays.  
  * \param[in] pasynUser pasynUser structure that encodes the reason and address.
  * \param[in] value Pointer to the array to read.
  * \param[in] nElements Number of elements to read.
  * \param[out] nIn Number of elements actually read. */
asynStatus testAsynPortDriver::readFloat64Array(asynUser *pasynUser, epicsFloat64 *value, 
                                         size_t nElements, size_t *nIn)
{
    int function = pasynUser->reason;
    size_t ncopy;
    int itemp;
    asynStatus status = asynSuccess;
    const char *functionName = "readFloat64Array";

    getIntegerParam(P_MaxPoints, &itemp); ncopy = itemp;
    if (nElements < ncopy) ncopy = nElements;
    if (function == P_Waveform) {
        memcpy(value, pData_, ncopy*sizeof(epicsFloat64));
        *nIn = ncopy;
    }
    else if (function == P_TimeBase) {
        memcpy(value, pTimeBase_, ncopy*sizeof(epicsFloat64));
        *nIn = ncopy;
    }
    if (status) 
        epicsSnprintf(pasynUser->errorMessage, pasynUser->errorMessageSize, 
                  "%s:%s: status=%d, function=%d", 
                  driverName, functionName, status, function);
    else        
        asynPrint(pasynUser, ASYN_TRACEIO_DRIVER, 
              "%s:%s: function=%d\n", 
              driverName, functionName, function);
    return status;
}
Exemplo n.º 11
0
/*
 * asynOctet methods
 */
static asynStatus
writeIt(void *drvPvt, asynUser *pasynUser, const char *data,
        size_t numchars,size_t *nbytesTransfered)
{
    usbController_t *usb = (usbController_t *)drvPvt;
    double          cmdstr[3];
    unsigned char   cmd[3];

    assert(usb);
    asynPrint(pasynUser, ASYN_TRACE_FLOW,
              "%s write.\n", usb->usbDeviceName);
    asynPrintIO(pasynUser, ASYN_TRACEIO_DRIVER, data, numchars,
                "%s write %d\n", usb->usbDeviceName, numchars);
    if (usb->dev == NULL) {
        epicsSnprintf(pasynUser->errorMessage,pasynUser->errorMessageSize,
                      "%s disconnected:", usb->usbDeviceName);
        return asynError;
    }
    if (sscanf(data, "%lf %lf %lf", &cmdstr[0], &cmdstr[1], &cmdstr[2])!=3) return asynError;
    cmd[0] = cmdstr[0];
    cmd[1] = cmdstr[1];
    cmd[2] = cmdstr[2];
    if (numchars!=3) numchars = 3;
    *nbytesTransfered = 0;
    *nbytesTransfered = libusb_control_transfer(usb->handle, 0x40, 6, 0x100, 0,
                                                cmd, (uint16_t)numchars, 0);
    if (*nbytesTransfered>=numchars)
        return asynSuccess;
    else
        return asynError;
    return asynSuccess;
}
Exemplo n.º 12
0
/**Enables or disables the flipping of the channel numbering. **/
asynStatus mythen::setBitDepth(epicsInt32 value)
{
    asynStatus status;
    epicsInt32 nbits;
    switch (value) {
      case 0: 
        nbits = 24;
        break;
      case 1: 
        nbits = 16;
        break;
      case 2:
        nbits = 8;
        break;
      case 3:
        nbits = 4;
        break;
      default:
        nbits = 24;
        break;
    }

    epicsSnprintf(outString_, sizeof(outString_), "-nbits %d", nbits);
    status = sendCommand();
    return status;
}
Exemplo n.º 13
0
static int writeString(gpibDpvt *pgpibDpvt,int P1, int P2, char **P3)
{
    asynUser *pasynUser = pgpibDpvt->pasynUser;
    stringoutRecord *precord = (stringoutRecord*)pgpibDpvt->precord;
    int            nchars;
    gpibCmd *pgpibCmd = gpibCmdGet(pgpibDpvt);
    char *format = (pgpibCmd->format) ? pgpibCmd->format : "%s";

    if(!pgpibDpvt->msg) {
        asynPrint(pasynUser,ASYN_TRACE_ERROR,
            "%s no msg buffer. Must define gpibCmd.msgLen > 0.\n",
            precord->name);
        recGblSetSevr(precord,WRITE_ALARM, INVALID_ALARM);
        return -1;
    }
    nchars = epicsSnprintf(pgpibDpvt->msg,pgpibCmd->msgLen,format,precord->val);
    if(nchars>pgpibCmd->msgLen) { 
        asynPrint(pasynUser,ASYN_TRACE_ERROR, 
            "%s msg buffer too small. msgLen %d message length %d\n", 
            precord->name,pgpibCmd->msgLen,nchars); 
        recGblSetSevr(precord,WRITE_ALARM, INVALID_ALARM); 
        return -1; 
    } 
    asynPrint(pasynUser,ASYN_TRACE_FLOW,"%s writeMsgString\n",precord->name);
    return nchars;
}
Exemplo n.º 14
0
/** Called when asyn clients call pasynInt32->write().
  * This function sends a signal to the arrayGenTask thread if the value of P_RunStop has changed.
  * 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 testArrayRingBuffer::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_RunStop) {
        if (value) epicsEventSignal(eventId_);
    } 
    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 status;
}
Exemplo n.º 15
0
static void testEpicsSnprintf(void) {
    char exbuffer[80], buffer[80];
    const int ivalue = 1234;
    const float fvalue = 1.23e4f;
    const char *svalue = "OneTwoThreeFour";
    const char *format = "int %d float %8.2e string %s";
    const char *expected = exbuffer;
    int size;
    int rtn, rlen;
    
    sprintf(exbuffer, format, ivalue, fvalue, svalue);
    rlen = strlen(expected)+1;
    
    strcpy(buffer, "AAAA");
    
    for (size = 1; size < strlen(expected) + 5; ++size) {
        rtn = epicsSnprintf(buffer, size, format, ivalue, fvalue, svalue);
        testOk(rtn <= rlen-1, "epicsSnprintf(size=%d) = %d", size, rtn);
        if (rtn != rlen-1)
            testDiag("Return value does not indicate buffer size needed");
        testOk(strncmp(buffer, expected, size - 1) == 0,
            "buffer = '%s'", buffer);
        rtn = strlen(buffer);
        testOk(rtn == (size < rlen ? size : rlen) - 1,
            "length = %d", rtn);
    }
}
Exemplo n.º 16
0
/*
 * Double up IAC characters.
 * We assume that memchr and memcpy are  nicely optimized so we're better of
 * using them than looking at and copying the characters one at a time ourself.
 */
static asynStatus
writeIt(void *ppvt, asynUser *pasynUser,
    const char *data, size_t numchars, size_t *nbytesTransfered)
{
    interposePvt *pinterposePvt = (interposePvt *)ppvt;
    const char *iac;
    char *dst = pinterposePvt->xBuf;
    size_t nIAC = 0;
    asynStatus status;

    if ((iac = memchr(data, C_IAC, numchars)) != NULL) {
        size_t nLeft = numchars;
        size_t nCopy = iac - data + 1;
        for (;;) {
            size_t nNew = nCopy + 1;
            char *np;
            if (nNew > pinterposePvt->xBufCapacity) {
                /*
                 * Try to strike a balance between too many
                 * realloc calls and too much wasted space.
                 */
                size_t newSize = pinterposePvt->xBufCapacity + 1024;
                if (newSize < numchars)
                    newSize = numchars + 1024;
                if (newSize < nNew)
                    newSize = nNew + 1024;
                np = realloc(pinterposePvt->xBuf, newSize);
                if (np == NULL) {
                    epicsSnprintf(pasynUser->errorMessage,
                                  pasynUser->errorMessageSize, "Out of memory");
                    return asynError;
                }
                dst = np + (dst - pinterposePvt->xBuf);
                pinterposePvt->xBuf = np;
                pinterposePvt->xBufCapacity = newSize;
            }
            memcpy(dst, data, nCopy);
            dst += nCopy;
            if (iac != NULL) {
                *dst++ = C_IAC;
                nIAC++;
            }
            nLeft -= nCopy;
            if (nLeft == 0)
                break;
            data += nCopy;
            if ((iac = memchr(data, C_IAC, nLeft)) != NULL)
                nCopy = iac - data + 1;
            else
                nCopy = nLeft;
        }
        numchars += nIAC;
        data = pinterposePvt->xBuf;
    }
    status =  pinterposePvt->pasynOctetDrv->write(pinterposePvt->drvPvt,
                                pasynUser, data, numchars, nbytesTransfered);
    if (*nbytesTransfered == numchars)
        *nbytesTransfered -= nIAC;
    return status;
}
Exemplo n.º 17
0
/** Called when asyn clients call pasynUInt32D->write().
  * 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 testErrors::writeUInt32Digital(asynUser *pasynUser, epicsUInt32 value, epicsUInt32 mask)
{
    int function = pasynUser->reason;
    asynStatus status = asynSuccess;
    const char *paramName;
    const char* functionName = "writeUInt32D";

    /* Get the current error status */
    getIntegerParam(P_StatusReturn, (int*)&status);

    /* Fetch the parameter string name for use in debugging */
    getParamName(function, &paramName);

    /* Set the parameter value in the parameter library. */
    setUIntDigitalParam(function, value, mask);
    /* Set the parameter status in the parameter library. */
    setParamStatus(function, status);
    
    /* Do callbacks so higher layers see any changes */
    callParamCallbacks();
    
    if (status) 
        epicsSnprintf(pasynUser->errorMessage, pasynUser->errorMessageSize, 
                  "%s:%s: status=%d, function=%d, name=%s, value=0x%X", 
                  driverName, functionName, status, function, paramName, value);
    else        
        asynPrint(pasynUser, ASYN_TRACEIO_DRIVER, 
              "%s:%s: function=%d, name=%s, value=0x%X\n", 
              driverName, functionName, function, paramName, value);
    return status;
}
Exemplo n.º 18
0
static asynStatus uint32Read(void *pvt,asynUser *pasynUser,
                             epicsUInt32 *value,epicsUInt32 mask)
{
    drvPvt *pdrvPvt = (drvPvt *)pvt;
    int        addr;
    asynStatus status;

    status = getAddr(pdrvPvt,pasynUser,&addr,0);
    if(status!=asynSuccess) return status;
    asynPrint(pasynUser, ASYN_TRACE_FLOW,
              "%s %d uint32DigitalDriver:readInt32\n",pdrvPvt->portName,addr);
    if(!pdrvPvt->connected) {
        asynPrint(pasynUser,ASYN_TRACE_ERROR,
                  "%s uint32DigitalDriver:read  not connected\n",pdrvPvt->portName);
        epicsSnprintf(pasynUser->errorMessage,pasynUser->errorMessageSize,
                      "%s uint32DigitalDriver:read not connected",pdrvPvt->portName);
        return asynError;
    }
    epicsMutexMustLock(pdrvPvt->lock);
    *value = mask & pdrvPvt->channel[addr].value;
    epicsMutexUnlock(pdrvPvt->lock);
    asynPrint(pasynUser,ASYN_TRACEIO_DRIVER,
              "%s read %d\n",pdrvPvt->portName,*value);
    return asynSuccess;
}
Exemplo n.º 19
0
/** Called when asyn clients call pasynOctet->write().
  * Simply sets the value in the parameter library and 
  * calls any registered callbacks for this pasynUser->reason and address.  
  * \param[in] pasynUser pasynUser structure that encodes the reason and address.
  * \param[in] value Address of the string to write.
  * \param[in] nChars Number of characters to write.
  * \param[out] nActual Number of characters actually written. */
asynStatus testErrors::writeOctet(asynUser *pasynUser, const char *value, 
                                  size_t nChars, size_t *nActual)
{
    int function = pasynUser->reason;
    asynStatus status = asynSuccess;
    const char *functionName = "writeOctet";

    /* Get the current error status */
    getIntegerParam(P_StatusReturn, (int*)&status);

    /* Set the parameter in the parameter library. */
    setStringParam(function, (char *)value);
    /* Set the parameter status in the parameter library. */
    setParamStatus(function, status);

     /* Do callbacks so higher layers see any changes */
    callParamCallbacks();

    if (status) 
        epicsSnprintf(pasynUser->errorMessage, pasynUser->errorMessageSize, 
                  "%s:%s: status=%d, function=%d, value=%s", 
                  driverName, functionName, status, function, value);
    else        
        asynPrint(pasynUser, ASYN_TRACEIO_DRIVER, 
              "%s:%s: function=%d, value=%s\n", 
              driverName, functionName, function, value);
    *nActual = nChars;
    return status;
}
Exemplo n.º 20
0
static asynStatus float64Read(void *pvt,asynUser *pasynUser,
                              epicsFloat64 *value)
{
    drvPvt *pdrvPvt = (drvPvt *)pvt;
    int        addr;
    asynStatus status;

    status = getAddr(pdrvPvt,pasynUser,&addr,0);
    if(status!=asynSuccess) return status;
    asynPrint(pasynUser, ASYN_TRACE_FLOW,
              "%s %d uint32DigitalDriver:float64Read\n",pdrvPvt->portName,addr);
    if(!pdrvPvt->connected) {
        asynPrint(pasynUser,ASYN_TRACE_ERROR,
                  "%s uint32DigitalDriver:read  not connected\n",pdrvPvt->portName);
        epicsSnprintf(pasynUser->errorMessage,pasynUser->errorMessageSize,
                      "%s uint32DigitalDriver:read not connected",pdrvPvt->portName);
        return asynError;
    }
    epicsMutexMustLock(pdrvPvt->lock);
    *value = pdrvPvt->interruptDelay;
    epicsMutexUnlock(pdrvPvt->lock);
    asynPrint(pasynUser,ASYN_TRACEIO_DRIVER,
              "%s read %f\n",pdrvPvt->portName,*value);
    return asynSuccess;
}
Exemplo n.º 21
0
/** Sets an int32 parameter.
  * \param[in] pasynUser asynUser structure that contains the function code in pasynUser->reason. 
  * \param[in] value The value for this parameter 
  *
  * Takes action if the function code requires it.
  */
asynStatus NDPosPlugin::writeInt32(asynUser *pasynUser, epicsInt32 value)
{
  int function = pasynUser->reason;
  int oldvalue;
  int addr;
  asynStatus status = asynSuccess;
  static const char *functionName = "NDPosPlugin::writeInt32";

  // Set the parameter in the parameter library.
  status = getAddress(pasynUser, &addr);
  if (status == asynSuccess){
    getIntegerParam(function, &oldvalue);

    // By default we set the value in the parameter library. If problems occur we set the old value back.
    setIntegerParam(function, value);

    if (function == NDPos_Running){
      // Reset the expected ID to the starting value
      int expected = 0;
      getIntegerParam(NDPos_IDStart, &expected);
      setIntegerParam(NDPos_ExpectedID, expected);
    } else if (function == NDPos_Mode){
      // Reset the position index to 0 if the mode is changed
      setIntegerParam(NDPos_CurrentIndex, 0);
    } else if (function == NDPos_Restart){
      // Reset the position index to 0
      setIntegerParam(NDPos_CurrentIndex, 0);
      // Reset the last sent position
      setStringParam(NDPos_CurrentPos, "");
    } else if (function == NDPos_Delete){
      // Reset the position index to 0
      setIntegerParam(NDPos_CurrentIndex, 0);
      // Reset the last sent position
      setStringParam(NDPos_CurrentPos, "");
      // Clear out the position array
      positionArray.clear();
      setIntegerParam(NDPos_CurrentQty, positionArray.size());
    } else {
      // If this parameter belongs to a base class call its method
      if (function < FIRST_NDPOS_PARAM){
        status = NDPluginDriver::writeInt32(pasynUser, value);
      }
    }
  }

  // Do callbacks so higher layers see any changes
  status = (asynStatus)callParamCallbacks();

  if (status){
    epicsSnprintf(pasynUser->errorMessage, pasynUser->errorMessageSize,
                  "%s: status=%d, function=%d, value=%d",
                  functionName, status, function, value);
  } else {
    asynPrint(pasynUser, ASYN_TRACEIO_DRIVER,
              "%s: function=%d, value=%d\n",
              functionName, function, value);
  }

  return status;
}
Exemplo n.º 22
0
/** Base method for closing a file
  * Calls the pure virtual function closeFile in the derived class. */
asynStatus NDPluginFile::closeFileBase()
{
    /* Closes a file */
    asynStatus status = asynSuccess;
    char errorMessage[256];
    const char* functionName = "closeFileBase";

    setIntegerParam(NDFileWriteStatus, NDFileWriteOK);
    setStringParam(NDFileWriteMessage, "");
     /* Call the closeFile method in the derived class */
    epicsMutexLock(this->fileMutexId);
    status = this->closeFile();
    if (status) {
        epicsSnprintf(errorMessage, sizeof(errorMessage)-1, 
            "Error closing file, status=%d", status);
        asynPrint(this->pasynUserSelf, ASYN_TRACE_ERROR, 
              "%s:%s %s\n", 
              driverName, functionName, errorMessage);
        setIntegerParam(NDFileWriteStatus, NDFileWriteError);
        setStringParam(NDFileWriteMessage, errorMessage);
    }
    epicsMutexUnlock(this->fileMutexId);
    
    return(status);
}
Exemplo n.º 23
0
/** This method copies an NDArray object from the asynNDArrayDriver to an NDArray pointer passed in by the caller.
  * The destination NDArray address is passed by the caller in the genericPointer argument. The caller
  * must allocate the memory for the array, and pass the size in NDArray->dataSize.
  * The method will limit the amount of data copied to the actual array size or the
  * input dataSize, whichever is smaller.
  * \param[in] pasynUser Used to obtain the addr for the NDArray to be copied from, and for asynTrace output.
  * \param[out] genericPointer Pointer to an NDArray. The NDArray must have been previously allocated by the caller.
  * The NDArray from the asynNDArrayDriver will be copied into the NDArray pointed to by genericPointer.
  */
asynStatus asynNDArrayDriver::readGenericPointer(asynUser *pasynUser, void *genericPointer)
{
    NDArray *pArray = (NDArray *)genericPointer;
    NDArray *myArray;
    NDArrayInfo_t arrayInfo;
    int addr;
    asynStatus status = asynSuccess;
    const char* functionName = "readNDArray";

    status = getAddress(pasynUser, &addr); if (status != asynSuccess) return(status);
    this->lock();
    myArray = this->pArrays[addr];
    if (!myArray) {
        epicsSnprintf(pasynUser->errorMessage, pasynUser->errorMessageSize,
                    "%s:%s: error, no valid array available, pData=%p",
                    driverName, functionName, pArray->pData);
        status = asynError;
    } else {
        this->pNDArrayPool->copy(myArray, pArray, 0);
        myArray->getInfo(&arrayInfo);
        if (arrayInfo.totalBytes > pArray->dataSize) arrayInfo.totalBytes = pArray->dataSize;
        memcpy(pArray->pData, myArray->pData, arrayInfo.totalBytes);
    }
    if (!status)
        asynPrint(pasynUser, ASYN_TRACEIO_DRIVER,
              "%s:%s: error, maxBytes=%lu, data=%p\n",
              driverName, functionName, (unsigned long)arrayInfo.totalBytes, pArray->pData);
    this->unlock();
    return status;
}
asynStatus isisdaeDriver::readValue(asynUser *pasynUser, const char* functionName, T* value)
{
	int function = pasynUser->reason;
    asynStatus status = asynSuccess;
    const char *paramName = NULL;
	getParamName(function, &paramName);
	m_iface->resetMessages();
	try
	{
		status = asynPortDriver::readValue(pasynUser, functionName, &value);
        asynPrint(pasynUser, ASYN_TRACEIO_DRIVER, 
              "%s:%s: function=%d, name=%s, value=%s\n", 
              driverName, functionName, function, paramName, convertToString(*value).c_str());
		reportMessages();
		return status;
	}
	catch(const std::exception& ex)
	{
        epicsSnprintf(pasynUser->errorMessage, pasynUser->errorMessageSize, 
                  "%s:%s: status=%d, function=%d, name=%s, value=%s, error=%s", 
                  driverName, functionName, status, function, paramName, convertToString(*value).c_str(), ex.what());
		reportErrors(ex.what());
		return asynError;
	}
}
asynStatus ReadASCII::writeOctet(asynUser *pasynUser, const char *value, size_t maxChars, size_t *nActual)
{
	//Checks if directory has changed, reads file again if it has
	int function = pasynUser->reason;
	int status = asynSuccess;
	const char *paramName;
	const char* functionName = "writeOctet";

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

	/* Fetch the parameter string name for possible use in debugging */
	getParamName(function, &paramName);

	if (function == P_Dir | function == P_DirBase) {
		// Directory has changed so update
		status |= readFileBasedOnParameters();
	}

	/* 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);

	*nActual = maxChars;
	return (asynStatus)status;
}
asynStatus NetShrVarDriver::writeArrayValue(asynUser *pasynUser, const char* functionName, T* value, size_t nElements)
{
	int function = pasynUser->reason;
	asynStatus status = asynSuccess;
	const char *paramName = NULL;
	getParamName(function, &paramName);
	try
	{
		if (m_netvarint == NULL)
		{
			throw std::runtime_error("m_netvarint is NULL");
		}
		m_netvarint->setArrayValue(paramName, value, nElements);
		asynPrint(pasynUser, ASYN_TRACEIO_DRIVER, 
			"%s:%s: function=%d, name=%s, nElements=%d\n", 
			driverName, functionName, function, paramName, (int)nElements);
		return asynSuccess;
	}
	catch(const std::exception& ex)
	{
		epicsSnprintf(pasynUser->errorMessage, pasynUser->errorMessageSize, 
			"%s:%s: status=%d, function=%d, name=%s, nElements=%d, error=%s", 
			driverName, functionName, status, function, paramName, (int)nElements, ex.what());
		return asynError;
	}
}
asynStatus ReadASCII::writeInt32(asynUser *pasynUser, epicsInt32 value)
{
	//Checks for updates to the index and on/off of PID lookup
	int function = pasynUser->reason;
	asynStatus status = asynSuccess;
	const char *paramName;
	const char* functionName = "writeInt32";
	int LUTOn;

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

	if (function == P_Index) {
		//check lookup on
		getIntegerParam(P_LookUpOn, &LUTOn);

		if (LUTOn)
		{
			//update all column floats
			setDoubleParam(P_SPOut, pSP_[value]);
			setDoubleParam(P_P, pP_[value]);
			setDoubleParam(P_I, pI_[value]);
			setDoubleParam(P_D, pD_[value]);
			setDoubleParam(P_MaxHeat, pMaxHeat_[value]);
		}
	}else if (function == P_LookUpOn) {
		//reload file if bad
		if (true == fileBad)
		{
			status = readFileBasedOnParameters();
		}

		//file may now be good - retry
		if (false == fileBad)
		{
			//uses the current temperature to find PID values
			if (value)
			{
				double curTemp;

				getDoubleParam(P_CurTemp, &curTemp);
				updatePID(getSPInd(curTemp));
			}
		}
	}

	/* 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;

}
Exemplo n.º 28
0
/****************************************************************************
 * Define private interface asynDrvUser methods
 ****************************************************************************/
static asynStatus create(void* ppvt,asynUser* pasynUser,const char* drvInfo, const char** pptypeName,size_t* psize)
{
    int i,addr;
    asynStatus sts;
    Inst* pinst;
    Port* pport = (Port*)ppvt;

    asynPrint(pasynUser,ASYN_TRACE_FLOW,"drvLove::create\n");

    sts = pasynManager->getAddr(pasynUser,&addr);
    if( ISNOTOK(sts) )
        return( sts );

    for( i = 0; i < cmdCount; ++i )
    {
        if( epicsStrCaseCmp(CmdTable[i].pname,drvInfo) == 0 )
        {
            pinst = callocMustSucceed(sizeof(Inst),sizeof(char),"drvLove::create");
            pinst->pport = pport;
            pinst->pinfo = &pport->instr[addr-1];
            pinst->read = CmdTable[i].read;
            pinst->write = CmdTable[i].write;
            pinst->pcmd = &CmdTable[i].strings[pinst->pinfo->modidx];

            pasynUser->drvUser = (void*)pinst;

            return( asynSuccess );
        }
    }

    epicsSnprintf(pasynUser->errorMessage,pasynUser->errorMessageSize,"failure to find command %s",drvInfo);
    return( asynError );
}
asynStatus NetShrVarDriver::writeOctet(asynUser *pasynUser, const char *value, size_t maxChars, size_t *nActual)
{
	int function = pasynUser->reason;
	asynStatus status = asynSuccess;
	const char *paramName = NULL;
	getParamName(function, &paramName);
	const char* functionName = "writeOctet";
	std::string value_s(value, maxChars);
	try
	{
		if (m_netvarint == NULL)
		{
			throw std::runtime_error("m_netvarint is NULL");
		}
		m_netvarint->setValue(paramName, value_s);
		asynPrint(pasynUser, ASYN_TRACEIO_DRIVER, 
			"%s:%s: function=%d, name=%s, value=%s\n", 
			driverName, functionName, function, paramName, value_s.c_str());
		*nActual = value_s.size();
		return asynPortDriver::writeOctet(pasynUser, value_s.c_str(), maxChars, nActual);
	}
	catch(const std::exception& ex)
	{
		epicsSnprintf(pasynUser->errorMessage, pasynUser->errorMessageSize, 
			"%s:%s: status=%d, function=%d, name=%s, value=%s, error=%s", 
			driverName, functionName, status, function, paramName, value_s.c_str(), ex.what());
		*nActual = 0;
		return asynError;
	}
}
Exemplo n.º 30
0
static int
Up550_convertPVReplyAI(struct gpibDpvt *pdpvt, int P1, int P2, char **P3)
{
	struct aiRecord *pai = ((struct aiRecord *)(pdpvt->precord));

	asynOctet *pasynOctet =pdpvt->pasynOctet;
	void *asynOctetPvt = pdpvt->asynOctetPvt;

	int	len;
	int	rval;
	char cmd[64] = {0,};
	char cbuf[64] = {0,};

	int addr;
	addr = pai->inp.value.gpibio.addr;
	if(addr == 1)
		make_Up550_commandString(3, "WRD0003,01", cmd);	/* PV.1 value	*/
	else if(addr == 2)
		make_Up550_commandString(3, "WRD0019,01", cmd);	/* PV.2 value	*/

	if((pasynOctet->setInputEos(asynOctetPvt,pdpvt->pasynUser,NULL,0) != asynSuccess))
		return -1;
	if((pasynOctet->setOutputEos(asynOctetPvt,pdpvt->pasynUser,NULL,0) != asynSuccess))
		return -1;
	if(pasynOctet->write(asynOctetPvt,pdpvt->pasynUser,cmd,strlen(cmd),&len) != asynSuccess)
		return -1;

	pasynOctet->read(asynOctetPvt,pdpvt->pasynUser,cbuf, sizeof(cbuf),&len, NULL);

	if (len < 15){	/* invalid length	*/
			epicsSnprintf(pdpvt->pasynUser->errorMessage, pdpvt->pasynUser->errorMessageSize, "Invalid reply %d", pdpvt->msgInputLen);
			return -1;	
	}
	if (check_validReply(cbuf, len) < 0) { /* invalid reply data	*/
			epicsSnprintf(pdpvt->pasynUser->errorMessage, pdpvt->pasynUser->errorMessageSize, "Invalid reply %d", pdpvt->msgInputLen);
			return -1;
	}

	float val;

	sscanf(cbuf+7, "%4X", &rval);
	val = rval / 10.0;
	
	pai->val = val;
	pai->udf = 0;
	return 0;
}