/// XFCPort constructor XFCPort::XFCPort(const char * name) : asynPortDriver( name, 1, /* maxAddr */ 1, /* max parameters */ asynInt32Mask | asynDrvUserMask, /* interface mask*/ asynInt32Mask, /* interrupt mask */ 0, /* non-blocking, no addresses */ 1, /* autoconnect */ 0, /* default priority */ 0) /* default stack size */ { printf("Creating XFCPort \"%s\"\n", name); createParam("MISSED", asynParamInt32, &P_Missed); setIntegerParam(P_Missed, 0); }
void releaseBlockLocks(char* serviceName, int servicePort, char* fileName, int lockID) { MessageClient client = newClient(serviceName, servicePort); Message m = newMessage(); m->type = FILE_LOCK_CLIENT_SERVICE_CLIENT_MESSAGE; setStringParam(m, "functionName", "releaseblock"); setStringParam(m, "fileName", fileName); setIntegerParam(m, "lockID", lockID); Message reply = clientCall(client, m); clientDisconnect(client); destroyMessage(m); destroyMessage(reply); }
void NDFileNexus::loadTemplateFile() { bool loadStatus; int addr = 0; char fullFilename[2*MAX_FILENAME_LEN] = ""; char template_path[MAX_FILENAME_LEN] = ""; char template_file[MAX_FILENAME_LEN] = ""; static const char *functionName = "loadTemplateFile"; /* get the filename to be used for nexus template */ getStringParam(addr, NDFileNexusTemplatePath, sizeof(template_path), template_path); getStringParam(addr, NDFileNexusTemplateFile, sizeof(template_file), template_file); sprintf(fullFilename, "%s%s", template_path, template_file); if (strlen(fullFilename) == 0) return; /* Load the Nexus template file */ loadStatus = this->configDoc.LoadFile(fullFilename); if (loadStatus != true ){ asynPrint(this->pasynUserSelf, ASYN_TRACE_ERROR, "%s:%s: Parameter file %s is invalid\n", driverName, functionName, fullFilename); setIntegerParam(addr, NDFileNexusTemplateValid, 0); callParamCallbacks(addr, addr); return; } else { asynPrint(this->pasynUserSelf, ASYN_TRACE_FLOW, "%s:%s: Parameter file %s was successfully loaded\n", driverName, functionName, fullFilename); setIntegerParam(addr, NDFileNexusTemplateValid, 1); callParamCallbacks(addr, addr); } this->rootNode = this->configDoc.RootElement(); }
void asynNDArrayDriver::updateQueuedArrayCount() { while (queuedArrayUpdateRun_) { epicsEventWait(queuedArrayEvent_); // Exit early if (!queuedArrayUpdateRun_) break; lock(); setIntegerParam(NDNumQueuedArrays, getQueuedArrayCount()); callParamCallbacks(); unlock(); } epicsEventSignal(queuedArrayUpdateDone_); }
/** Called when asyn clients call pasynInt32->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 DSA2000::writeInt32(asynUser *pasynUser, epicsInt32 value) { int function = pasynUser->reason; asynStatus status = asynSuccess; struct ncp_hcmd_resethvstatus resetCommand; int sendStatus; int response; int actual; const char *paramName; const char* functionName = "writeInt32"; /* Set the parameter in the parameter library. */ setIntegerParam(function, value); /* Fetch the parameter string name for possible use in debugging */ getParamName(function, ¶mName); if (function == P_HVRangeSetting) { /* Set the range */ status = setHVStatus(); } if (function == P_HVReset) { /* Send the HV reset command */ sendStatus = nmc_sendcmd(this->module, NCP_K_HCMD_RESETHVSTATUS, &resetCommand, sizeof(resetCommand), &response, sizeof(response), &actual, 0); if (sendStatus != 9) status = asynError; } else if (function == P_ReadStatus) { status = getHVStatus(); } 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 */ 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; }
/** Callback task that runs as a separate thread. */ void testErrors::callbackTask(void) { asynStatus currentStatus; epicsInt32 iVal; epicsFloat64 dVal; int i; char octetValue[20]; /* Loop forever */ while (1) { lock(); getIntegerParam(P_StatusReturn, (int*)¤tStatus); getIntegerParam(P_Int32Value, &iVal); iVal++; if (iVal > 15) iVal=0; setIntegerParam(P_Int32Value, iVal); setParamStatus(P_Int32Value, currentStatus); getDoubleParam(P_Float64Value, &dVal); dVal += 0.1; setDoubleParam(P_Float64Value, dVal); setParamStatus(P_Float64Value, currentStatus); sprintf(octetValue, "%.1f", dVal); setParamStatus(P_UInt32DigitalValue, currentStatus); setStringParam(P_OctetValue, octetValue); setParamStatus(P_OctetValue, currentStatus); setParamStatus(P_Float64ArrayValue, currentStatus); for (i=0; i<MAX_ARRAY_POINTS; i++) { int8ArrayValue_[i] = iVal; int16ArrayValue_[i] = iVal; int32ArrayValue_[i] = iVal; float32ArrayValue_[i] = dVal; float64ArrayValue_[i] = dVal; } callParamCallbacks(); setParamStatus(P_Int8ArrayValue, currentStatus); doCallbacksInt8Array(int8ArrayValue_, MAX_ARRAY_POINTS, P_Int8ArrayValue, 0); setParamStatus(P_Int16ArrayValue, currentStatus); doCallbacksInt16Array(int16ArrayValue_, MAX_ARRAY_POINTS, P_Int16ArrayValue, 0); setParamStatus(P_Int32ArrayValue, currentStatus); doCallbacksInt32Array(int32ArrayValue_, MAX_ARRAY_POINTS, P_Int32ArrayValue, 0); setParamStatus(P_Float32ArrayValue, currentStatus); doCallbacksFloat32Array(float32ArrayValue_, MAX_ARRAY_POINTS, P_Float32ArrayValue, 0); setParamStatus(P_Float64ArrayValue, currentStatus); doCallbacksFloat64Array(float64ArrayValue_, MAX_ARRAY_POINTS, P_Float64ArrayValue, 0); unlock(); epicsThreadSleep(CALLBACK_PERIOD); } }
// Jog asynStatus SMC100Axis::moveVelocity(double minVelocity, double maxVelocity, double acceleration) { double high_limit; double low_limit; asynStatus comStatus; static const char *functionName = "SMC100Axis::moveVelocity"; asynPrint(pasynUser_, ASYN_TRACE_FLOW, "%s: minVelocity=%f, maxVelocity=%f, acceleration=%f\n", functionName, minVelocity, maxVelocity, acceleration); comStatus = sendAccelAndVelocity(acceleration, maxVelocity); if (comStatus) goto skip; /* SMC100 supports the notion of jog, but only for a remote control keypad */ // SMC100 will not allow moves outside of those set with the SL and SR commands // first we query these limits and then make the jog a move to the limit // get the high limit sprintf(pC_->outString_, "%1dSR?", axisNo_ + 1); comStatus = pC_->writeReadController(); if (comStatus) goto skip; // The response string is of the form "1SR25.0" high_limit = (atof(&pC_->inString_[3])); // get the low limit sprintf(pC_->outString_, "%1dSL?", axisNo_ + 1); comStatus = pC_->writeReadController(); if (comStatus) goto skip; // The response string is of the form "1SL-5.0" low_limit = (atof(&pC_->inString_[3])); if (maxVelocity > 0.) { /* This is a positive move in SMC100 coordinates (egus) */ sprintf(pC_->outString_, "%1dPA%f", axisNo_ + 1, high_limit); } else { /* This is a negative move in SMC100 coordinates (egus) */ sprintf(pC_->outString_, "%1dPA%f", axisNo_ + 1, low_limit); } comStatus = pC_->writeController(); if (comStatus) goto skip; skip: setIntegerParam(pC_->motorStatusProblem_, comStatus ? 1:0); callParamCallbacks(); return comStatus ? asynError : asynSuccess; }
asynStatus NDPluginFile::writeNDArray(asynUser *pasynUser, void *genericPointer) { NDArray *pArray = (NDArray *)genericPointer; asynStatus status = asynSuccess; //static const char *functionName = "writeNDArray"; this->pArrays[0] = pArray; setIntegerParam(NDFileWriteMode, NDFileModeSingle); status = writeFileBase(); /* Do callbacks so higher layers see any changes */ status = callParamCallbacks(); return status; }
//////////////////////////////////////// //! writeController() //! reference ACRMotorDriver // //! Writes a string to the IMS controller. //! Prepends deviceName to command string, if party mode not enabled, set device name to "" //! @param[in] output the string to be written. //! @param[in] timeout Timeout before returning an error. //////////////////////////////////////// asynStatus ImsMDrivePlusMotorController::writeController(const char *output, double timeout) { size_t nwrite; asynStatus status; char outbuff[MAX_BUFF_LEN]; static const char *functionName = "writeController()"; // in party-mode Line Feed must follow command string sprintf(outbuff, "%s%s", deviceName, output); asynPrint(pasynUserSelf, ASYN_TRACEIO_DRIVER, "%s:%s: deviceName=%s, command=%s\n", DRIVER_NAME, functionName, deviceName, outbuff); status = pasynOctetSyncIO->write(pAsynUserIMS, outbuff, strlen(outbuff), timeout, &nwrite); if (status) { // update comm flag setIntegerParam(this->motorStatusCommsError_, 1); } return status ; }
/** Polls the axis. * This function reads the motor position, the limit status, the home status, the moving status, * and the drive power-on status. * It calls setIntegerParam() and setDoubleParam() for each item that it polls, * and then calls callParamCallbacks() at the end. * \param[out] moving A flag that is set indicating that the axis is moving (true) or done (false). */ asynStatus MCB4BAxis::poll(bool *moving) { int done; int driveOn; int limit; double position; asynStatus comStatus; // Read the current motor position sprintf(pC_->outString_, "#%02dP", axisNo_); comStatus = pC_->writeReadController(); if (comStatus) goto skip; // The response string is of the form "#01P=+1000" position = atof(&pC_->inString_[5]); setDoubleParam(pC_->motorPosition_, position); // Read the moving status of this motor sprintf(pC_->outString_, "#%02dX", axisNo_); comStatus = pC_->writeReadController(); if (comStatus) goto skip; // The response string is of the form "#01X=1" done = (pC_->inString_[5] == '0') ? 1:0; setIntegerParam(pC_->motorStatusDone_, done); *moving = done ? false:true; // Read the limit status sprintf(pC_->outString_, "#%02dE", axisNo_); comStatus = pC_->writeReadController(); if (comStatus) goto skip; // The response string is of the form "#01E=1" limit = (pC_->inString_[5] == '1') ? 1:0; setIntegerParam(pC_->motorStatusHighLimit_, limit); limit = (pC_->inString_[6] == '1') ? 1:0; setIntegerParam(pC_->motorStatusLowLimit_, limit); limit = (pC_->inString_[7] == '1') ? 1:0; setIntegerParam(pC_->motorStatusAtHome_, limit); // Read the drive power on status sprintf(pC_->outString_, "#%02dE", axisNo_); comStatus = pC_->writeReadController(); if (comStatus) goto skip; driveOn = (pC_->inString_[5] == '1') ? 1:0; setIntegerParam(pC_->motorStatusPowerOn_, driveOn); setIntegerParam(pC_->motorStatusProblem_, 0); skip: setIntegerParam(pC_->motorStatusProblem_, comStatus ? 1:0); callParamCallbacks(); return comStatus ? asynError : asynSuccess; }
/// Constructor for the FileList class. /// Calls constructor for the asynPortDriver base class. FileList::FileList(const char *portName, const char *searchDir, const char *searchPat, int fullPath) : asynPortDriver(portName, 4, /* maxAddr */ NUM_FileList_PARAMS, asynInt32Mask | asynOctetMask | asynDrvUserMask | asynFloat64Mask, /* Interface mask */ asynInt32Mask | asynOctetMask | asynFloat64Mask, /* Interrupt mask */ 0, /* asynFlags. This driver can block but it is not multi-device */ 1, /* Autoconnect */ 0, /* Default priority */ 0) /* Default stack size*/, watchQueue_(10, sizeof(char *)), m_fullPath(fullPath != 0 ? true : false) { int status = asynSuccess; const char *functionName = "FileList"; createParam(P_DirBaseString, asynParamOctet, &P_DirBase); createParam(P_SearchString, asynParamOctet, &P_Search); createParam(P_CaseString, asynParamInt32, &P_CaseSensitive); createParam(P_JSONArrString, asynParamOctet, &P_JSONOutArr); //Allocate column data pJSONOut_ = (char *)calloc(OUT_CHAR_LIM, 1); setStringParam(P_DirBase, searchDir); setStringParam(P_Search, searchPat); setIntegerParam(P_CaseSensitive, 0); updateList(); // Start filewatcher char * str = strdup(searchDir); watchQueue_.send((void*)&str, sizeof(char*)); /* Do callbacks so higher layers see any changes */ status |= (asynStatus)callParamCallbacks(); // Create the thread that will service the file watcher // To write to the controller epicsThreadCreate("fileWatcher", epicsThreadPriorityMax, epicsThreadGetStackSize(epicsThreadStackMedium), (EPICSTHREADFUNC)fileWatcherThreadC, (void *)this); if (status) { std::cerr << status << "epicsThreadCreate failure" << std::endl; return; } }
asynStatus shamrock::getStatus() { int error; asynStatus status; int grating; float wavelength; float width; int i; static const char *functionName = "getStatus"; error = ShamrockGetGrating(shamrockId_, &grating); status = checkError(error, functionName, "ShamrockGetGrating"); if (status) return asynError; setIntegerParam(SRGrating_, grating); error = ShamrockGetWavelength(shamrockId_, &wavelength); status = checkError(error, functionName, "ShamrockGetWavelength"); if (status) return asynError; setDoubleParam(SRWavelength_, wavelength); for (i=0; i<MAX_SLITS; i++) { setDoubleParam(i, SRSlitSize_, 0.); if (slitIsPresent_[i] == 0) continue; error = ShamrockGetAutoSlitWidth(shamrockId_, i+1, &width); status = checkError(error, functionName, "ShamrockGetAutoSlitWidth"); if (status) return asynError; setDoubleParam(i, SRSlitSize_, width); } error = ShamrockGetCalibration(shamrockId_, calibration_, numPixels_); status = checkError(error, functionName, "ShamrockGetCalibration"); setDoubleParam(0, SRMinWavelength_, calibration_[0]); setDoubleParam(0, SRMaxWavelength_, calibration_[numPixels_-1]); // We need to find a C/C++ library to do 3'rd order polynomial fit // For now we do a first order fit! double slope = (calibration_[numPixels_-1] - calibration_[0]) / (numPixels_-1); for (i=0; i<MAX_ADDR; i++) { callParamCallbacks(i); } doCallbacksFloat32Array(calibration_, numPixels_, SRCalibration_, 0); return asynSuccess; }
/** This is called to write data a single NDArray to the file. It can be called multiple times * to add arrays to a single file in stream or capture mode */ asynStatus NDFileHDF5XML::writeFile(NDArray *pArray) { unsigned long int stripsize; static const char *functionName = "writeFile"; int sizex, sizey; int numToCapture; int imgc, nimg; int writeMode; sizex = pArray->dims[0].size; sizey = pArray->dims[1].size; //NDFileFormat getIntegerParam(NDFileFormat, &fileformat); getIntegerParam(NDFileWriteMode, &writeMode); // pArray->pAttributeList->report(20); getAttributes(pArray->pAttributeList); hdf_interface->pArray = pArray; //This will write the image data... //!!lock(); configDoc->Accept(hdf5Writer); //!!unlock(); this->nextRecord++; setIntegerParam(NDFileNumCaptured, this->nextRecord); getIntegerParam(NDFileNumCapture, &numToCapture); /* if ((((writeMode == NDFileModeStream) || (writeMode == NDFileModeCapture)) && this->nextRecord >= numToCapture) ) { setIntegerParam(NDFileNumCaptured, numToCapture); hdf_interface->pArray = pArray; closeFile(); } */ return (asynSuccess); }
/** Called when asyn clients call pasynInt32->write(). * This function sends a signal to the simTask thread if the value of P_Run 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 testAsynPortDriver::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_Run) { /* If run was set then wake up the simulation task */ if (value) epicsEventSignal(eventId_); } else if (function == P_VertGainSelect) { setVertGain(); } else if (function == P_VoltsPerDivSelect) { setVoltsPerDiv(); } else if (function == P_TimePerDivSelect) { setTimePerDiv(); } 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; }
/** Checks whether the directory specified NDFilePath parameter exists. * * This is a convenience function that determinesthe directory specified NDFilePath parameter exists. * It sets the value of NDFilePathExists to 0 (does not exist) or 1 (exists). * It also adds a trailing '/' character to the path if one is not present. * Returns a error status if the directory does not exist. */ asynStatus asynNDArrayDriver::checkPath() { /* Formats a complete file name from the components defined in NDStdDriverParams */ asynStatus status = asynError; char filePath[MAX_FILENAME_LEN]; char lastChar; int hasTerminator=0; struct stat buff; int istat; size_t len; int isDir=0; int pathExists=0; getStringParam(NDFilePath, sizeof(filePath), filePath); len = strlen(filePath); if (len == 0) return(asynSuccess); /* If the path contains a trailing '/' or '\' remove it, because Windows won't find * the directory if it has that trailing character */ lastChar = filePath[len-1]; #ifdef _WIN32 if ((lastChar == '/') || (lastChar == '\\')) #else if (lastChar == '/') #endif { filePath[len-1] = 0; len--; hasTerminator=1; } istat = stat(filePath, &buff); if (!istat) isDir = (S_IFDIR & buff.st_mode); if (!istat && isDir) { pathExists = 1; status = asynSuccess; } /* If the path did not have a trailing terminator then add it if there is room */ if (!hasTerminator) { if (len < MAX_FILENAME_LEN-2) strcat(filePath, delim); setStringParam(NDFilePath, filePath); } setIntegerParam(NDFilePathExists, pathExists); return status; }
/** Called when asyn clients call pasynOctet->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 Address of the string to write. * \param[in] nChars Number of characters to write. * \param[out] nActual Number of characters actually written. */ asynStatus hdf5Driver::writeOctet (asynUser *pasynUser, const char *value, size_t nChars, size_t *nActual) { int function = pasynUser->reason; asynStatus status = asynSuccess; const char *functionName = "writeOctet"; // Not interested in base class parameters if(function < FIRST_HDF5_PARAM) return ADDriver::writeOctet(pasynUser, value, nChars, nActual); if(function == HDF5FilePath) { bool exists = checkFilePath(value); setIntegerParam(HDF5FileExists, exists); setStringParam(function, value); if(exists) { int acquiring; getIntegerParam(ADStatus, &acquiring); if(acquiring != ADStatusAcquire) { openFile(value); } } } callParamCallbacks(); if (status) asynPrint(pasynUser, ASYN_TRACE_ERROR, "%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; }
/** Called when asyn clients call pasynInt32->write(). * This function sends a signal to the simTask thread if the value of P_Run 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 testErrors::writeInt32(asynUser *pasynUser, epicsInt32 value) { int function = pasynUser->reason; asynStatus status = asynSuccess; int itemp; const char *paramName; const char* functionName = "writeInt32"; /* Fetch the parameter string name for use in debugging */ getParamName(function, ¶mName); /* Set the parameter value in the parameter library. */ setIntegerParam(function, value); if (function == P_DoUpdate) { epicsEventSignal(eventId_); } else if (function == P_StatusReturn) { } else if (function == P_EnumOrder) { setEnums(); } else { /* Set the parameter status in the parameter library except for the above commands with always return OK */ /* Get the current error status */ getIntegerParam(P_StatusReturn, &itemp); status = (asynStatus)itemp; 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=%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; }
/** Base method for reading a file * Creates the file name with NDPluginBase::createFileName, then calls the pure virtual functions openFile, * readFile and closeFile in the derived class. Does callbacks with the NDArray that was read in. */ asynStatus NDPluginFile::readFileBase(void) { asynStatus status = asynSuccess; char fullFileName[MAX_FILENAME_LEN]; int dataType=0; NDArray *pArray=NULL; static const char* functionName = "readFileBase"; status = (asynStatus)createFileName(MAX_FILENAME_LEN, fullFileName); if (status) { asynPrint(this->pasynUserSelf, ASYN_TRACE_ERROR, "%s:%s error creating full file name, fullFileName=%s, status=%d\n", driverName, functionName, fullFileName, status); return(status); } /* Call the readFile method in the derived class */ /* Do this with the main lock released since it is slow */ this->unlock(); epicsMutexLock(this->fileMutexId); status = this->openFile(fullFileName, NDFileModeRead, pArray); status = this->readFile(&pArray); status = this->closeFile(); epicsMutexUnlock(this->fileMutexId); this->lock(); /* If we got an error then return */ if (status) return(status); /* Update the new values of dimensions and the array data */ setIntegerParam(NDDataType, dataType); /* Call any registered clients */ doCallbacksGenericPointer(pArray, NDArrayData, 0); /* Set the last array to be this one */ this->pArrays[0]->release(); this->pArrays[0] = pArray; return(status); }
asynStatus NDPluginAttribute::writeInt32(asynUser *pasynUser, epicsInt32 value) { int function = pasynUser->reason; asynStatus status = asynSuccess; static const char *functionName = "NDPluginAttribute::writeInt32"; /* Set the parameter in the parameter library. */ status = (asynStatus) setIntegerParam(function, value); if (function == NDPluginAttributeReset) { setDoubleParam(NDPluginAttributeVal, 0.0); setDoubleParam(NDPluginAttributeValSum, 0.0); //Clear the time series array memset(pTimeSeries_, 0, maxTimeSeries_*sizeof(epicsFloat64)); doCallbacksFloat64Array(this->pTimeSeries_, maxTimeSeries_, NDPluginAttributeArray, 0); currentPoint_ = 0; valueSum_ = 0.0; } else if (function == NDPluginAttributeUpdate) { //Update the data array by hand. doCallbacksFloat64Array(this->pTimeSeries_, maxTimeSeries_, NDPluginAttributeArray, 0); } else { /* If this parameter belongs to a base class call its method */ if (function < FIRST_NDPLUGIN_ATTR_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; }
/** Called when asyn clients call pasynInt32->write(). * This function performs actions for some parameters, including NDPluginDriverEnableCallbacks and * NDPluginDriverArrayAddr. * 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 NDPluginROI::writeInt32(asynUser *pasynUser, epicsInt32 value) { int function = pasynUser->reason; asynStatus status = asynSuccess; static const char* functionName = "writeInt32"; /* Set the parameter in the parameter library. */ status = (asynStatus) setIntegerParam(function, value); if (function == NDPluginROIDim0Min) { requestedOffset_[0] = value; } else if (function == NDPluginROIDim1Min) { requestedOffset_[1] = value; } else if (function == NDPluginROIDim2Min) { requestedOffset_[2] = value; } else if (function == NDPluginROIDim0Size) { requestedSize_[0] = value; } else if (function == NDPluginROIDim1Size) { requestedSize_[1] = value; } else if (function == NDPluginROIDim2Size) { requestedSize_[2] = value; } else { /* If this parameter belongs to a base class call its method */ if (function < FIRST_NDPLUGIN_ROI_PARAM) status = NDPluginDriver::writeInt32(pasynUser, value); } /* Do callbacks so higher layers see any changes */ callParamCallbacks(); if (status) asynPrint(pasynUser, ASYN_TRACE_ERROR, "%s:%s: function=%d, value=%d\n", driverName, functionName, function, value); else asynPrint(pasynUser, ASYN_TRACEIO_DRIVER, "%s:%s: function=%d, value=%d\n", driverName, functionName, function, value); return status; }
//------------------------------------------------------------------------------ //! @brief Called when asyn clients call pasynInt32->write(). //! //! If pasynUser->reason is equal to //! - P_FanSpeed the nominal fan speed will be changed to value //! - P_sysreset a system reset of the crate will be performed //! //! @param [in] pasynUser pasynUser structure that encodes the reason and address //! @param [in] value Value to write //! //! @return in case of no error occured asynSuccess is returned. Otherwise //! asynError or asynTimeout is returned. A error message is stored //! in pasynUser->errorMessage. //------------------------------------------------------------------------------ asynStatus drvAsynWienerVme::writeInt32( asynUser *pasynUser, epicsInt32 value ) { int function = pasynUser->reason; asynStatus status = asynSuccess; static const char *functionName = "writeInt32"; if ( ( function != P_FanSpeed ) && ( function != P_Sysreset ) ) return asynSuccess; status = (asynStatus) setIntegerParam( function, value ); status = (asynStatus) callParamCallbacks(); if( status ) epicsSnprintf( pasynUser->errorMessage, pasynUser->errorMessageSize, "\033[31;1m%s:%s:%s: status=%d, function=%d, value=%d\033[0m", driverName, _deviceName, functionName, status, function, value ); else asynPrint( pasynUser, ASYN_TRACEIO_DEVICE, "%s:%s:%s: function=%d, value=%d\n", driverName, _deviceName, functionName, function, value ); can_frame_t pframe; pframe.can_id = ( 1 << 7 ) | _crateId; if ( function == P_FanSpeed ) { pframe.can_dlc = 2; pframe.data[0] = 0xc0; pframe.data[1] = (epicsUInt8)( value & 0xff ); } else if ( function == P_Sysreset ) { pframe.can_dlc = 1; pframe.data[0] = 0x44; } status = pasynGenericPointerSyncIO->write( _pasynGenericPointer, &pframe, pasynUser->timeout ); if ( status ) { epicsSnprintf( pasynUser->errorMessage, pasynUser->errorMessageSize, "\033[31;1m%s:%s:%s: function=%d, Could not send can frame.\033[0m", driverName, _deviceName, functionName, function ); return asynError; } return status; }
/** Called when asyn clients call pasynInt32->write(). * Extracts the function and axis number from pasynUser. * Sets the value in the parameter library. * If the function is motorSetClosedLoop_ then it turns the drive power on or off. * If the function is ddriveReadBinaryIO_ then it reads the binary I/O registers on the controller. * For all other functions it calls asynMotorController::writeInt32. * Calls any registered callbacks for this pasynUser->reason and address. * \param[in] pasynUser asynUser structure that encodes the reason and address. * \param[in] value Value to write. */ asynStatus ddriveController::writeInt32(asynUser *pasynUser, epicsInt32 value) { int function = pasynUser->reason; asynStatus status = asynSuccess; ddriveAxis *pAxis = getAxis(pasynUser); const char *paramName = "(unset)"; /* Fetch the parameter string name for possible use in debugging */ getParamName(function, ¶mName); /* 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(pAxis->axisNo_, function, value); const DDParam *ddp = DDParamFromIndex(function); if (ddp && ddp->type == asynParamInt32) { if (ddp->global) { status = writeParameter(ddp, value); } else { status = pAxis->writeParameter(ddp, value); } } else { /* Call base class method */ status = asynMotorController::writeInt32(pasynUser, value); } /* Do callbacks so higher layers see any changes */ callParamCallbacks(pAxis->axisNo_); if (status) asynPrint(pasynUser, ASYN_TRACE_ERROR, "%s:%s: error, status=%d function=%s (%d), value=%d\n", driverName, __func__, status, paramName, function, value); else asynPrint(pasynUser, ASYN_TRACEIO_DRIVER, "%s:%s: function=%s (%d), value=%d\n", driverName, __func__, paramName, function, value); return status; }
asynStatus ddriveAxis::writeParameter(const DDParam *param, int value) { if (!param || param->global) return asynError; if (param->service_param) { pc_->enterServiceMode(); // Write the parameter pc_->write("wrmb,%d,%d,%d", axisNo_, param->service_param, value); asynStatus ret = queryParameter(param, value); if (ret == asynSuccess) setIntegerParam(param->idx, value); pc_->exitServiceMode(); // queryparameter() should already do this return ret; } else { asynPrint(pc_->pasynUser_, ASYN_TRACE_FLOW, "-> write param: %s,%d,%d\n", param->command, axisNo_, value); return pc_->write("%s,%d,%d", param->command, axisNo_, value); } }
void mar345::setShutter(int open) { ADShutterMode_t shutterMode; int itemp; double delay; double shutterOpenDelay, shutterCloseDelay; getIntegerParam(ADShutterMode, &itemp); shutterMode = (ADShutterMode_t)itemp; getDoubleParam(ADShutterOpenDelay, &shutterOpenDelay); getDoubleParam(ADShutterCloseDelay, &shutterCloseDelay); switch (shutterMode) { case ADShutterModeDetector: if (open) { /* Open the shutter */ writeServer("COMMAND SHUTTER OPEN"); /* This delay is to get the exposure time correct. * It is equal to the opening time of the shutter minus the * closing time. If they are equal then no delay is needed, * except use 1msec so delay is not negative and commands are * not back-to-back */ delay = shutterOpenDelay - shutterCloseDelay; if (delay < .001) delay=.001; epicsThreadSleep(delay); } else { /* Close shutter */ writeServer("COMMAND SHUTTER CLOSE"); epicsThreadSleep(shutterCloseDelay); } /* The mar345 does not provide a way to read the actual shutter status, so * set it to agree with the control value */ setIntegerParam(ADShutterStatus, open); callParamCallbacks(); break; default: ADDriver::setShutter(open); break; } }
/** Constructor for NDFileNexus; all parameters are simply passed to NDPluginFile::NDPluginFile. * \param[in] portName The name of the asyn port driver to be created. * \param[in] queueSize The number of NDArrays that the input queue for this plugin can hold when * NDPluginDriverBlockingCallbacks=0. Larger queues can decrease the number of dropped arrays, * at the expense of more NDArray buffers being allocated from the underlying driver's NDArrayPool. * \param[in] blockingCallbacks Initial setting for the NDPluginDriverBlockingCallbacks flag. * 0=callbacks are queued and executed by the callback thread; 1 callbacks execute in the thread * of the driver doing the callbacks. * \param[in] NDArrayPort Name of asyn port driver for initial source of NDArray callbacks. * \param[in] NDArrayAddr asyn port driver address for initial source of NDArray callbacks. * \param[in] priority The thread priority for the asyn port driver thread if ASYN_CANBLOCK is set in asynFlags. * \param[in] stackSize The stack size for the asyn port driver thread if ASYN_CANBLOCK is set in asynFlags. */ NDFileNexus::NDFileNexus(const char *portName, int queueSize, int blockingCallbacks, const char *NDArrayPort, int NDArrayAddr, int priority, int stackSize) /* Invoke the base class constructor. * We allocate 2 NDArray of unlimited size in the NDArray pool. * This driver can block (because writing a file can be slow), and it is not multi-device. * Set autoconnect to 1. priority and stacksize can be 0, which will use defaults. */ : NDPluginFile(portName, queueSize, blockingCallbacks, NDArrayPort, NDArrayAddr, 1, NUM_NDFILE_NEXUS_PARAMS, 2, 0, asynGenericPointerMask, asynGenericPointerMask, ASYN_CANBLOCK, 1, priority, stackSize) { //static const char *functionName = "NDFileNexus"; createParam(NDFileNexusTemplatePathString, asynParamOctet, &NDFileNexusTemplatePath); createParam(NDFileNexusTemplateFileString, asynParamOctet, &NDFileNexusTemplateFile); createParam(NDFileNexusTemplateValidString, asynParamInt32, &NDFileNexusTemplateValid); this->pFileAttributes = new NDAttributeList; this->imageNumber = 0; setIntegerParam(NDFileNexusTemplateValid, 0); this->supportsMultipleArrays = 1; }
asynStatus motorSimController::processDeferredMoves() { asynStatus status = asynError; double position = 0.0; int axis; motorSimAxis *pAxis; for (axis=0; axis<numAxes_; axis++) { pAxis = getAxis(axis); if (pAxis->deferred_move_) { position = pAxis->deferred_position_; /* Check to see if in hard limits */ if ((pAxis->nextpoint_.axis[0].p >= pAxis->hiHardLimit_ && position > pAxis->nextpoint_.axis[0].p) || (pAxis->nextpoint_.axis[0].p <= pAxis->lowHardLimit_ && position < pAxis->nextpoint_.axis[0].p)) return asynError; pAxis->endpoint_.axis[0].p = position - pAxis->enc_offset_; pAxis->endpoint_.axis[0].v = 0.0; setIntegerParam(axis, motorStatusDone_, 0); pAxis->deferred_move_ = 0; } } return status; }
/** 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. ADAcquire, ADSizeX, and many other * function codes make calls to the Firewire library from this function. */ asynStatus shamrock::writeInt32( asynUser *pasynUser, epicsInt32 value) { asynStatus status = asynSuccess; int error; int function = pasynUser->reason; int addr; static const char *functionName = "writeInt32"; pasynManager->getAddr(pasynUser, &addr); if (addr < 0) addr=0; /* Set the value in the parameter library. This may change later but that's OK */ status = setIntegerParam(addr, function, value); if (function == SRGrating_) { error = ShamrockSetGrating(shamrockId_, value); status = checkError(error, functionName, "ShamrockSetGrating"); } // Port Information else if (function == SRFlipperMirrorPort_) { if (flipperMirrorIsPresent_[addr]) { error = ShamrockSetFlipperMirror(shamrockId_, addr+1, value); status = checkError(error, functionName, "ShamrockSetFlipperMirror"); } } getStatus(); asynPrint(pasynUserSelf, ASYN_TRACEIO_DRIVER, "%s::%s function=%d, value=%d, status=%d\n", driverName, functionName, function, value, status); callParamCallbacks(addr); return status; }
/** Starts and stops the acquisition. **/ asynStatus mythen::setAcquire(epicsInt32 value) { size_t nread; size_t nwrite; asynStatus status = asynSuccess; epicsInt32 eomReason; static const char *functionName = "setAcquire"; // printf("setAcquire %d\n",value); if (value == 0) { // while (1) { // // Repeat sending STOP until we get only a 0 back // status = pasynOctetSyncIO->setInputEos(pasynUserMeter_, "", 0); // if (status) break; status = pasynOctetSyncIO->writeRead(pasynUserMeter_, "-stop", strlen(outString_), inString_, sizeof(epicsInt32), M1K_TIMEOUT, &nwrite, &nread, &eomReason); setIntegerParam(ADStatus, getStatus()); // if (status == asynSuccess || status == asynTimeout) break; // } acquiring_ = 0; } else { if(!(acquiring_)) { strcpy(outString_,"-start"); this->sendCommand(); // Notify the read thread that acquisition has started epicsEventSignal(startEventId_); acquiring_ = 1; } } if (status) { acquiring_ = 0; } if(status != asynSuccess) asynPrint(pasynUserSelf, ASYN_TRACE_ERROR, "%s:%s: error!\n", driverName, functionName); return status; }
asynStatus DSA2000::getHVStatus() { struct ncp_hcmd_rethvstatus getCommand; struct ncp_mresp_rethvstatus getResponse; epicsUInt32 HVStatus; asynStatus status = asynSuccess; int sendStatus; int range; double DACVolts, ADCVolts, fullScale; int actual; sendStatus = nmc_sendcmd(this->module, NCP_K_HCMD_RETHVSTATUS, &getCommand, sizeof(getCommand), &getResponse, sizeof(getResponse), &actual, 0); if (sendStatus != 233) status = asynError; HVStatus = getResponse.status; setUIntDigitalParam(P_HVStatus, HVStatus, 0xFFFFFFFF); if (HVStatus & HVPS_Negative) { fullScale = 5000.; range = rangeMinus5000; } else { if (HVStatus & HVPS_5000V) { fullScale = 5000; range = rangePlus5000; } else { fullScale = 1300.; range = rangePlus1300; } } setIntegerParam(P_HVRangeReadback, range); DACVolts = getResponse.DACValue * fullScale / 4095.; setDoubleParam(P_DACReadback, DACVolts); ADCVolts = getResponse.ADCValue * fullScale / 255.; setDoubleParam(P_ADCReadback, ADCVolts); callParamCallbacks(); return status; }
int acquireLocks(char* serviceName, int servicePort, char* fileName, int numLocks, int64_t offsets[], int64_t lengths[]) { int i; int lockID; printf("acquiring %d locks\n", numLocks); MessageClient client = newClient(serviceName, servicePort); Message m = newMessage(); m->type = FILE_LOCK_CLIENT_SERVICE_CLIENT_MESSAGE; setStringParam(m, "functionName", "acquire"); setStringParam(m, "fileName", fileName); setIntegerParam(m, "numLocks", numLocks); createLongArrayParam(m, "offsets", numLocks); createLongArrayParam(m, "lengths", numLocks); for (i = 0; i < numLocks; ++i) { setLongArrayParamValue(m, "offsets", i, offsets[i]); setLongArrayParamValue(m, "lengths", i, lengths[i]); } //printf("acquirelocks: Message to be sent:\n"); //printMessage(m); Message reply = clientCall(client, m); clientDisconnect(client); //printf("acquirelocks: Reply:\n"); //printMessage(reply); //printf("acquirelocks: before getIntegerParam()\n"); lockID = getIntegerParam(reply, "lockID"); destroyMessage(m); destroyMessage(reply); return lockID; }