本文整理汇总了C++中epicsSnprintf函数的典型用法代码示例。如果您正苦于以下问题:C++ epicsSnprintf函数的具体用法?C++ epicsSnprintf怎么用?C++ epicsSnprintf使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了epicsSnprintf函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: getParamName
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, ¶mName);
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;
}
}
示例2: getIntegerParam
/** 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, ¶mName);
/* 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;
}
示例3: gpibPortAddressedCmd
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;
}
示例4: getIntegerParam
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);
}
示例5: dbLoadRecordsLoop
/// 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);
}
示例6: getStringParam
/** 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);
}
示例7: getParamName
/// 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, ¶mName);
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;
}
示例8: getIntegerParam
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;
}
示例9: getAddress
/** 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;
}
示例10: getIntegerParam
/** 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;
}
示例11: writeIt
/*
* 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;
}
示例12: switch
/**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;
}
示例13: writeString
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;
}
示例14: setIntegerParam
/** 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, ¶mName);
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;
}
示例15: testEpicsSnprintf
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);
}
}