// Set full path file name in buffer object, // and determinate its language by its extension. // If the ext is not in the list, the defaultLang passed as argument will be set. void Buffer::setFileName(const TCHAR *fn, LangType defaultLang) { NppParameters *pNppParamInst = NppParameters::getInstance(); if (_fullPathName == fn) { updateTimeStamp(); doNotify(BufferChangeTimestamp); return; } _fullPathName = fn; _fileName = PathFindFileName(_fullPathName.c_str()); // for _lang LangType newLang = defaultLang; TCHAR *ext = PathFindExtension(_fullPathName.c_str()); if (*ext == '.') // extension found { ext += 1; // Define User Lang firstly const TCHAR* langName = pNppParamInst->getUserDefinedLangNameFromExt(ext, _fileName); if (langName) { newLang = L_USER; _userLangExt = langName; } else // if it's not user lang, then check if it's supported lang { _userLangExt.clear(); newLang = pNppParamInst->getLangFromExt(ext); } } if (newLang == defaultLang || newLang == L_TEXT) //language can probably be refined { if ((!generic_stricmp(_fileName, TEXT("makefile"))) || (!generic_stricmp(_fileName, TEXT("GNUmakefile")))) newLang = L_MAKEFILE; else if (!generic_stricmp(_fileName, TEXT("CmakeLists.txt"))) newLang = L_CMAKE; else if ((!generic_stricmp(_fileName, TEXT("SConstruct"))) || (!generic_stricmp(_fileName, TEXT("SConscript"))) || (!generic_stricmp(_fileName, TEXT("wscript")))) newLang = L_PYTHON; else if (!generic_stricmp(_fileName, TEXT("Rakefile"))) newLang = L_RUBY; } updateTimeStamp(); if (newLang != _lang || _lang == L_USER) { _lang = newLang; doNotify(BufferChangeFilename | BufferChangeLanguage | BufferChangeTimestamp); return; } doNotify(BufferChangeFilename | BufferChangeTimestamp); }
// Set full path file name in buffer object, // and determinate its language by its extension. // If the ext is not in the list, the defaultLang passed as argument will be set. void Buffer::setFileName(const char *fn, LangType defaultLang) { NppParameters *pNppParamInst = NppParameters::getInstance(); if (!strcmpi(fn, _fullPathName)) { updateTimeStamp(); doNotify(BufferChangeTimestamp); return; } strcpy(_fullPathName, fn); _fileName = PathFindFileName(_fullPathName); // for _lang LangType newLang = defaultLang; char *ext = PathFindExtension(_fullPathName); if (*ext == '.') { //extension found ext += 1; // Define User Lang firstly const char *langName = NULL; if ((langName = pNppParamInst->getUserDefinedLangNameFromExt(ext))) { newLang = L_USER; strcpy(_userLangExt, langName); } else // if it's not user lang, then check if it's supported lang { _userLangExt[0] = '\0'; newLang = getLangFromExt(ext); } } if (newLang == defaultLang || newLang == L_TXT) //language can probably be refined { if ((!_stricmp(_fileName, "makefile")) || (!_stricmp(_fileName, "GNUmakefile"))) newLang = L_MAKEFILE; else if (!_stricmp(_fileName, "CmakeLists.txt")) newLang = L_CMAKE; } updateTimeStamp(); if (newLang != _lang || _lang == L_USER) { _lang = newLang; doNotify(BufferChangeFilename | BufferChangeLanguage | BufferChangeTimestamp); return; } doNotify(BufferChangeFilename | BufferChangeTimestamp); }
Buffer::Buffer(FileManager * pManager, BufferID id, Document doc, DocFileStatus type, const TCHAR *fileName) // type must be either DOC_REGULAR or DOC_UNNAMED : _pManager(pManager) , _id(id) , _doc(doc) , _lang(L_TEXT) { NppParameters* pNppParamInst = NppParameters::getInstance(); const NewDocDefaultSettings& ndds = (pNppParamInst->getNppGUI()).getNewDocDefaultSettings(); _format = ndds._format; _unicodeMode = ndds._unicodeMode; _encoding = ndds._codepage; if (_encoding != -1) _unicodeMode = uniCookie; _currentStatus = type; setFileName(fileName, ndds._lang); updateTimeStamp(); checkFileState(); // reset after initialization _isDirty = false; _canNotify = true; _needLexer = false; // new buffers do not need lexing, Scintilla takes care of that }
void ViewProperties::setViewMode(DolphinView::Mode mode) { if (m_node.localProperties().m_viewMode != mode) { m_node.setViewMode(mode); updateTimeStamp(); } }
void ViewProperties::setShowHiddenFilesEnabled(bool show) { if (m_node.localProperties().m_showHiddenFiles != show) { m_node.setShowHiddenFilesEnabled(show); updateTimeStamp(); } }
void ViewProperties::setSorting(DolphinView::Sorting sorting) { if (m_node.localProperties().m_sorting != sorting) { m_node.setSorting(sorting); updateTimeStamp(); } }
void ViewProperties::setSortOrder(Qt::SortOrder sortOrder) { if (m_node.localProperties().m_sortOrder != sortOrder) { m_node.setSortOrder(sortOrder); updateTimeStamp(); } }
void ViewProperties::setValidForSubDirs(bool valid) { if (m_node.isValidForSubDirs() != valid) { m_node.setValidForSubDirs(valid); updateTimeStamp(); } }
/** Simulation task that runs as a separate thread. When the P_Run parameter is set to 1 * to rub the simulation it computes a 1 kHz sine wave with 1V amplitude and user-controllable * noise, and displays it on * a simulated scope. It computes waveforms for the X (time) and Y (volt) axes, and computes * statistics about the waveform. */ void testAsynPortDriver::simTask(void) { /* This thread computes the waveform and does callbacks with it */ double timePerDiv, voltsPerDiv, voltOffset, triggerDelay, noiseAmplitude; double updateTime, minValue, maxValue, meanValue; double time, timeStep; double noise, yScale; int run, i, maxPoints; double pi=4.0*atan(1.0); lock(); /* Loop forever */ while (1) { getDoubleParam(P_UpdateTime, &updateTime); getIntegerParam(P_Run, &run); // Release the lock while we wait for a command to start or wait for updateTime unlock(); if (run) epicsEventWaitWithTimeout(eventId_, updateTime); else (void) epicsEventWait(eventId_); // Take the lock again lock(); /* run could have changed while we were waiting */ getIntegerParam(P_Run, &run); if (!run) continue; getIntegerParam(P_MaxPoints, &maxPoints); getDoubleParam (P_TimePerDiv, &timePerDiv); getDoubleParam (P_VoltsPerDiv, &voltsPerDiv); getDoubleParam (P_VoltOffset, &voltOffset); getDoubleParam (P_TriggerDelay, &triggerDelay); getDoubleParam (P_NoiseAmplitude, &noiseAmplitude); time = triggerDelay; timeStep = timePerDiv * NUM_DIVISIONS / maxPoints; minValue = 1e6; maxValue = -1e6; meanValue = 0.; yScale = 1.0 / voltsPerDiv; for (i=0; i<maxPoints; i++) { noise = noiseAmplitude * (rand()/(double)RAND_MAX - 0.5); pData_[i] = AMPLITUDE * (sin(time*FREQUENCY*2*pi)) + noise; /* Compute statistics before doing the yOffset and yScale */ if (pData_[i] < minValue) minValue = pData_[i]; if (pData_[i] > maxValue) maxValue = pData_[i]; meanValue += pData_[i]; pData_[i] = NUM_DIVISIONS/2 + yScale * (voltOffset + pData_[i]); time += timeStep; } updateTimeStamp(); meanValue = meanValue/maxPoints; setDoubleParam(P_MinValue, minValue); setDoubleParam(P_MaxValue, maxValue); setDoubleParam(P_MeanValue, meanValue); callParamCallbacks(); doCallbacksFloat64Array(pData_, maxPoints, P_Waveform, 0); } }
Buffer::Buffer(FileManager * pManager, BufferID id, Document doc, DocFileStatus type, const TCHAR *fileName) // type must be either DOC_REGULAR or DOC_UNNAMED : _pManager(pManager), _id(id), _isDirty(false), _doc(doc), _isFileReadOnly(false), _isUserReadOnly(false), _recentTag(-1), _references(0), _canNotify(false), _timeStamp(0), _needReloading(false), _encoding(-1) { NppParameters *pNppParamInst = NppParameters::getInstance(); const NewDocDefaultSettings & ndds = (pNppParamInst->getNppGUI()).getNewDocDefaultSettings(); _format = ndds._format; _unicodeMode = ndds._encoding; _encoding = ndds._codepage; if (_encoding != -1) _unicodeMode = uniCookie; _userLangExt = TEXT(""); _fullPathName = TEXT(""); _fileName = NULL; setFileName(fileName, ndds._lang); updateTimeStamp(); checkFileState(); _currentStatus = type; _isDirty = false; _needLexer = false; //new buffers do not need lexing, Scintilla takes care of that _canNotify = true; }
/** Callback task that runs as a separate thread. */ void testErrors::callbackTask(void) { asynStatus currentStatus; int itemp; epicsInt32 iVal; epicsUInt32 uiVal; epicsFloat64 dVal; int i; char octetValue[20]; /* Loop forever */ while (1) { lock(); updateTimeStamp(); getIntegerParam(P_StatusReturn, &itemp); currentStatus = (asynStatus)itemp; getIntegerParam(P_Int32Value, &iVal); iVal++; if (iVal > 64) iVal=0; setIntegerParam(P_Int32Value, iVal); setParamStatus( P_Int32Value, currentStatus); getIntegerParam(P_BinaryInt32Value, &iVal); iVal++; if (iVal > 1) iVal=0; setIntegerParam(P_BinaryInt32Value, iVal); setParamStatus( P_BinaryInt32Value, currentStatus); getIntegerParam(P_MultibitInt32Value, &iVal); iVal++; if (iVal > MAX_INT32_ENUMS-1) iVal=0; setIntegerParam(P_MultibitInt32Value, iVal); setParamStatus( P_MultibitInt32Value, currentStatus); getUIntDigitalParam(P_UInt32DigitalValue, &uiVal, UINT32_DIGITAL_MASK); uiVal++; if (uiVal > 64) uiVal=0; setUIntDigitalParam(P_UInt32DigitalValue, uiVal, UINT32_DIGITAL_MASK); setParamStatus( P_UInt32DigitalValue, currentStatus); getUIntDigitalParam(P_BinaryUInt32DigitalValue, &uiVal, UINT32_DIGITAL_MASK); uiVal++; if (uiVal > 1) uiVal=0; setUIntDigitalParam(P_BinaryUInt32DigitalValue, uiVal, UINT32_DIGITAL_MASK); setParamStatus( P_BinaryUInt32DigitalValue, currentStatus); getUIntDigitalParam(P_MultibitUInt32DigitalValue, &uiVal, UINT32_DIGITAL_MASK); uiVal++; if (uiVal > MAX_UINT32_ENUMS-1) uiVal=0; setUIntDigitalParam(P_MultibitUInt32DigitalValue, uiVal, UINT32_DIGITAL_MASK); setParamStatus( P_MultibitUInt32DigitalValue, currentStatus); getDoubleParam(P_Float64Value, &dVal); dVal += 0.1; setDoubleParam(P_Float64Value, dVal); setParamStatus(P_Float64Value, currentStatus); sprintf(octetValue, "%.1f", dVal); setStringParam(P_OctetValue, octetValue); setParamStatus(P_OctetValue, currentStatus); for (i=0; i<MAX_ARRAY_POINTS; i++) { int8ArrayValue_[i] = iVal; int16ArrayValue_[i] = iVal; int32ArrayValue_[i] = iVal; float32ArrayValue_[i] = (epicsFloat32)dVal; float64ArrayValue_[i] = dVal; } callParamCallbacks(); setParamStatus(P_Int8ArrayValue, currentStatus); setParamStatus(P_Int16ArrayValue, currentStatus); setParamStatus(P_Int32ArrayValue, currentStatus); setParamStatus(P_Float32ArrayValue, currentStatus); setParamStatus(P_Float64ArrayValue, currentStatus); doCallbacksInt8Array(int8ArrayValue_, MAX_ARRAY_POINTS, P_Int8ArrayValue, 0); doCallbacksInt16Array(int16ArrayValue_, MAX_ARRAY_POINTS, P_Int16ArrayValue, 0); doCallbacksInt32Array(int32ArrayValue_, MAX_ARRAY_POINTS, P_Int32ArrayValue, 0); doCallbacksFloat32Array(float32ArrayValue_, MAX_ARRAY_POINTS, P_Float32ArrayValue, 0); doCallbacksFloat64Array(float64ArrayValue_, MAX_ARRAY_POINTS, P_Float64ArrayValue, 0); unlock(); epicsEventWait(eventId_); } }
// update fi params with data from fi.input file void updateFIParams(){ #ifdef MPI_ENABLED MPI_Comm_rank(MPI_COMM_WORLD, ¤tRank); #endif char * line = NULL; char *name,*value; size_t len = 0; ssize_t read; FILE* fp; // initialize rand seed once srand(time(NULL)); // init execution key //execKey = time(NULL); updateTimeStamp(); fp = fopen(fiParams,"r"); if (fp == NULL){ printf("\nError:Coudn't find fi param file \"fi.in\"\n"); exit(-1); } // read fault injection params while ((read = getline(&line, &len, fp)) != -1) { name = getStrFieldByIndex(line,":\n",0); value = getStrFieldByIndex(line,":\n",1); processParams(name,value); } // select dyn instr only in fi mode if(pfs==0){ // update interval size if(tf>0){ intvsz = tf; } // update interval count if(dynFSCount>0 && intvsz>0){ if(dynFSCount%intvsz==0){ intvCount = dynFSCount/intvsz; } else { intvCount = floor(dynFSCount/intvsz)+1; } } // update target dynamic FS indices only once at runtime if(!fidatardflag){ updateFSIdx(); } if(dynFSIdx==NULL){ printf("\nError:memory allocation failed for dynFSIdx!!\n"); exit(-1); } } // write FI headers const char* instrfield = "Instr_Name"; const char* originalVal = "Original_Value"; const char* corruptedVal = "Corrupted_Value"; const char* bitPosVal = "Bit_Position"; if(!file_exists(fiStat) && pfs==0){ writeFIData(instrfield,(void*)originalVal,(void*)corruptedVal,(void*)bitPosVal,StringTy,"w"); } #ifndef MPI_ENABLED printParams(); #endif checkParams(); fidatardflag=1; fclose(fp); return; }
/** This thread controls acquisition, reads image files to get the image data, * and does the callbacks to send it to higher layers */ void hdf5Driver::hdf5Task (void) { const char *functionName = "hdf5Task"; int status = asynSuccess; epicsTimeStamp startTime, endTime; int imageMode, currentFrame, colorMode; double acquirePeriod, elapsedTime, delay; this->lock(); for(;;) { int acquire; getIntegerParam(ADAcquire, &acquire); if (!acquire) { this->unlock(); // Wait for semaphore unlocked asynPrint(this->pasynUserSelf, ASYN_TRACE_FLOW, "%s:%s: waiting for acquire to start\n", driverName, functionName); status = epicsEventWait(this->mStartEventId); this->lock(); acquire = 1; setStringParam(ADStatusMessage, "Acquiring data"); setIntegerParam(ADNumImagesCounter, 0); } // Are there datasets loaded? if(!mDatasetsCount) { setStringParam(ADStatusMessage, "No datasets loaded"); goto error; } // Get acquisition parameters epicsTimeGetCurrent(&startTime); getIntegerParam(ADImageMode, &imageMode); getDoubleParam(ADAcquirePeriod, &acquirePeriod); getIntegerParam(HDF5CurrentFrame, ¤tFrame); setIntegerParam(ADStatus, ADStatusAcquire); callParamCallbacks(); // Get information to allocate NDArray size_t dims[2]; NDDataType_t dataType; if(getFrameInfo(currentFrame, dims, &dataType)) { setStringParam(ADStatusMessage, "Failed to get frame info"); goto error; } // Allocate NDArray NDArray *pImage; if(!(pImage = pNDArrayPool->alloc(2, dims, dataType, 0, NULL))) { setStringParam(ADStatusMessage, "Failed to allocate frame"); goto error; } // Copy data into NDArray if(getFrameData(currentFrame, pImage->pData)) { setStringParam(ADStatusMessage, "Failed to read frame data"); goto error; } // Set ColorMode colorMode = NDColorModeMono; pImage->pAttributeList->add("ColorMode", "Color mode", NDAttrInt32, &colorMode); // Call plugins callbacks int arrayCallbacks; getIntegerParam(NDArrayCallbacks, &arrayCallbacks); if (arrayCallbacks) { this->unlock(); asynPrint(this->pasynUserSelf, ASYN_TRACE_FLOW, "%s:%s: calling imageData callback\n", driverName, functionName); doCallbacksGenericPointer(pImage, NDArrayData, 0); this->lock(); } pImage->release(); // Get the current parameters int lastFrame, imageCounter, numImages, numImagesCounter; getIntegerParam(HDF5LastFrame, &lastFrame); getIntegerParam(NDArrayCounter, &imageCounter); getIntegerParam(ADNumImages, &numImages); getIntegerParam(ADNumImagesCounter, &numImagesCounter); setIntegerParam(NDArrayCounter, ++imageCounter); setIntegerParam(ADNumImagesCounter, ++numImagesCounter); setIntegerParam(HDF5CurrentFrame, ++currentFrame); // Put the frame number and time stamp into the buffer pImage->uniqueId = imageCounter; pImage->timeStamp = startTime.secPastEpoch + startTime.nsec / 1.e9; updateTimeStamp(&pImage->epicsTS); // Prepare loop if necessary int loop; getIntegerParam(HDF5Loop, &loop); if (loop && currentFrame > lastFrame) { getIntegerParam(HDF5FirstFrame, ¤tFrame); setIntegerParam(HDF5CurrentFrame, currentFrame); } // See if acquisition is done if (imageMode == ADImageSingle || currentFrame > lastFrame || (imageMode == ADImageMultiple && numImagesCounter >= numImages)) { // First do callback on ADStatus setStringParam(ADStatusMessage, "Waiting for acquisition"); setIntegerParam(ADStatus, ADStatusIdle); acquire = 0; setIntegerParam(ADAcquire, acquire); asynPrint(this->pasynUserSelf, ASYN_TRACE_FLOW, "%s:%s: acquisition completed\n", driverName, functionName); } callParamCallbacks(); // Delay next acquisition and check if received STOP signal if(acquire) { epicsTimeGetCurrent(&endTime); elapsedTime = epicsTimeDiffInSeconds(&endTime, &startTime); delay = acquirePeriod - elapsedTime; asynPrint(this->pasynUserSelf, ASYN_TRACE_FLOW, "%s:%s: delay=%f\n", driverName, functionName, delay); if(delay > 0.0) { // Set the status to waiting to indicate we are in the delay setIntegerParam(ADStatus, ADStatusWaiting); callParamCallbacks(); this->unlock(); status = epicsEventWaitWithTimeout(mStopEventId, delay); this->lock(); if (status == epicsEventWaitOK) { acquire = 0; if (imageMode == ADImageContinuous) setIntegerParam(ADStatus, ADStatusIdle); else setIntegerParam(ADStatus, ADStatusAborted); callParamCallbacks(); } } } continue; error: setIntegerParam(ADAcquire, 0); setIntegerParam(ADStatus, ADStatusError); callParamCallbacks(); continue; } }
connect(this,SIGNAL(boardClosed()), ui->wheelsPanel, SLOT(onBoardClosed())); connect(ui->layerSelector, SIGNAL(activated(int)), SLOT(setDisplayMode(int))); connect(&m_pollTimer, SIGNAL(timeout()), SLOT(motorsTask())); connect(this, SIGNAL(faceDetected(QPointF)), m_sound, SLOT(click())); buildStateMachine(); // the last thing to do: open the board and be ready ui->openControllerButton->setChecked(true); // setup video input connect(&m_videoTimer, SIGNAL(timeout()), SLOT(videoTask())); connect(&m_videoTimer, SIGNAL(timeout()), SLOT(updateTimeStamp())); connect(ui->camSelector, SIGNAL(activated(int)), SLOT(openCamera())); connect(ui->resolution, SIGNAL(currentIndexChanged(int)), SLOT(openCamera())); connect(ui->camSettings, SIGNAL(clicked()), SLOT(openCamSettings())); int nCams = m_cams->listDevices(); ui->camSelector->setEnabled(nCams); ui->camSettings->setEnabled(nCams); ui->resolution->setEnabled(nCams); ui->camSelector->clear(); if (nCams) { for(int i=0; i<nCams; ++i) { ui->camSelector->addItem( m_cams->getDeviceName(i) ); openCamera(); } } else {
/** * Readout thread function */ void ADSBIG::readoutTask(void) { epicsEventWaitStatus eventStatus; epicsFloat64 timeout = 0.001; bool error = false; size_t dims[2]; int nDims = 2; epicsInt32 sizeX = 0; epicsInt32 sizeY = 0; epicsInt32 minX = 0; epicsInt32 minY = 0; NDDataType_t dataType; epicsInt32 iDataType = 0; epicsUInt32 dataSize = 0; epicsTimeStamp nowTime; NDArray *pArray = NULL; epicsInt32 numImagesCounter = 0; epicsInt32 imageCounter = 0; PAR_ERROR cam_err = CE_NO_ERROR; const char* functionName = "ADSBIG::readoutTask"; asynPrint(this->pasynUserSelf, ASYN_TRACE_FLOW, "%s Started Readout Thread.\n", functionName); while (1) { //Wait for a stop event, with a short timeout, to catch any that were done after last one. eventStatus = epicsEventWaitWithTimeout(m_stopEvent, timeout); if (eventStatus == epicsEventWaitOK) { asynPrint(this->pasynUserSelf, ASYN_TRACE_FLOW, "%s Got Stop Event Before Start Event.\n", functionName); } lock(); if (!error) { setStringParam(ADStatusMessage, "Idle"); } callParamCallbacks(); unlock(); eventStatus = epicsEventWait(m_startEvent); if (eventStatus == epicsEventWaitOK) { asynPrint(this->pasynUserSelf, ASYN_TRACE_FLOW, "%s Got Start Event.\n", functionName); error = false; setStringParam(ADStatusMessage, " "); lock(); setIntegerParam(ADNumImagesCounter, 0); setIntegerParam(ADNumExposuresCounter, 0); //Sanity checks if ((p_Cam == NULL) || (p_Img == NULL)) { asynPrint(this->pasynUserSelf, ASYN_TRACE_ERROR, "%s NULL pointer.\n", functionName); break; } //printf("%s Time before acqusition: ", functionName); //epicsTime::getCurrent().show(0); //Read the frame sizes getIntegerParam(ADMinX, &minX); getIntegerParam(ADMinY, &minY); getIntegerParam(ADSizeX, &sizeX); getIntegerParam(ADSizeY, &sizeY); p_Cam->SetSubFrame(minX, minY, sizeX, sizeY); //Read what type of image we want - light field or dark field? int darkField = 0; getIntegerParam(ADSBIGDarkFieldParam, &darkField); if (darkField > 0) { cam_err = p_Cam->GrabSetup(p_Img, SBDF_DARK_ONLY); } else { cam_err = p_Cam->GrabSetup(p_Img, SBDF_LIGHT_ONLY); } if (cam_err != CE_NO_ERROR) { asynPrint(this->pasynUserSelf, ASYN_TRACE_ERROR, "%s. CSBIGCam::GrabSetup returned an error. %s\n", functionName, p_Cam->GetErrorString(cam_err).c_str()); error = true; setStringParam(ADStatusMessage, p_Cam->GetErrorString(cam_err).c_str()); } unsigned short binX = 0; unsigned short binY = 0; p_Img->GetBinning(binX, binY); asynPrint(this->pasynUserSelf, ASYN_TRACE_FLOW, " binX: %d\n", binY); asynPrint(this->pasynUserSelf, ASYN_TRACE_FLOW, " binY: %d\n", binX); asynPrint(this->pasynUserSelf, ASYN_TRACE_FLOW, " PixelHeight: %f\n", p_Img->GetPixelHeight()); asynPrint(this->pasynUserSelf, ASYN_TRACE_FLOW, " PixelWidth: %f\n", p_Img->GetPixelWidth()); asynPrint(this->pasynUserSelf, ASYN_TRACE_FLOW, " Height: %d\n", p_Img->GetHeight()); asynPrint(this->pasynUserSelf, ASYN_TRACE_FLOW, " Width: %d\n", p_Img->GetWidth()); asynPrint(this->pasynUserSelf, ASYN_TRACE_FLOW, " Readout Mode: %d\n", p_Cam->GetReadoutMode()); asynPrint(this->pasynUserSelf, ASYN_TRACE_FLOW, " Dark Field: %d\n", darkField); if (!error) { //Do exposure callParamCallbacks(); unlock(); if (darkField > 0) { cam_err = p_Cam->GrabMain(p_Img, SBDF_DARK_ONLY); } else { cam_err = p_Cam->GrabMain(p_Img, SBDF_LIGHT_ONLY); } lock(); if (cam_err != CE_NO_ERROR) { asynPrint(this->pasynUserSelf, ASYN_TRACE_ERROR, "%s. CSBIGCam::GrabMain returned an error. %s\n", functionName, p_Cam->GetErrorString(cam_err).c_str()); error = true; setStringParam(ADStatusMessage, p_Cam->GetErrorString(cam_err).c_str()); } setDoubleParam(ADSBIGPercentCompleteParam, 100.0); if (!m_aborted) { unsigned short *pData = p_Img->GetImagePointer(); //printf("%s Time after acqusition: ", functionName); //epicsTime::getCurrent().show(0); //Update counters getIntegerParam(NDArrayCounter, &imageCounter); imageCounter++; setIntegerParam(NDArrayCounter, imageCounter); getIntegerParam(ADNumImagesCounter, &numImagesCounter); numImagesCounter++; setIntegerParam(ADNumImagesCounter, numImagesCounter); //NDArray callbacks int arrayCallbacks = 0; getIntegerParam(NDArrayCallbacks, &arrayCallbacks); getIntegerParam(NDDataType, &iDataType); dataType = static_cast<NDDataType_t>(iDataType); if (dataType == NDUInt8) { dataSize = sizeX*sizeY*sizeof(epicsUInt8); } else if (dataType == NDUInt16) { dataSize = sizeX*sizeY*sizeof(epicsUInt16); } else if (dataType == NDUInt32) { dataSize = sizeX*sizeY*sizeof(epicsUInt32); } else { asynPrint(this->pasynUserSelf, ASYN_TRACE_ERROR, "%s. ERROR: We can't handle this data type. dataType: %d\n", functionName, dataType); error = true; dataSize = 0; } setIntegerParam(NDArraySize, dataSize); if (!error) { if (arrayCallbacks) { //Allocate an NDArray dims[0] = sizeX; dims[1] = sizeY; if ((pArray = this->pNDArrayPool->alloc(nDims, dims, dataType, 0, NULL)) == NULL) { asynPrint(this->pasynUserSelf, ASYN_TRACE_ERROR, "%s. ERROR: pArray is NULL.\n", functionName); } else { epicsTimeGetCurrent(&nowTime); pArray->uniqueId = imageCounter; pArray->timeStamp = nowTime.secPastEpoch + nowTime.nsec / 1.e9; updateTimeStamp(&pArray->epicsTS); //Get any attributes that have been defined for this driver this->getAttributes(pArray->pAttributeList); //We copy data because the SBIG class library holds onto the original buffer until the next acqusition asynPrint(this->pasynUserSelf, ASYN_TRACE_FLOW, "%s: Copying data. dataSize: %d\n", functionName, dataSize); memcpy(pArray->pData, pData, dataSize); unlock(); asynPrint(this->pasynUserSelf, ASYN_TRACE_FLOW, "%s: Calling NDArray callback\n", functionName); doCallbacksGenericPointer(pArray, NDArrayData, 0); lock(); pArray->release(); } } setIntegerParam(ADStatus, ADStatusIdle); } else { setIntegerParam(ADStatus, ADStatusError); } } else { //end if (!m_aborted) setIntegerParam(ADStatus, ADStatusAborted); m_aborted = false; } } callParamCallbacks(); //Complete Acquire callback setIntegerParam(ADAcquire, 0); callParamCallbacks(); unlock(); asynPrint(this->pasynUserSelf, ASYN_TRACE_FLOW, "%s Completed acqusition.\n", functionName); } //end of start event } //end of while(1) asynPrint(this->pasynUserSelf, ASYN_TRACE_ERROR, "%s: ERROR: Exiting ADSBIGReadoutTask main loop.\n", functionName); }
void FastCCD::processImage(cin_data_frame_t *frame) { const char* functionName = "processImage"; this->lock(); // Set the unique ID pImage->uniqueId = frame->number; pImage->dims[0].size = frame->size_x; pImage->dims[0].offset = 0; pImage->dims[0].binning = 1; pImage->dims[1].size = frame->size_y; pImage->dims[1].offset = 0; pImage->dims[1].binning = 1; // Process Timestamps. // Frame timestamp is a timespec always trust driver becuase it is correct! pImage->timeStamp = frame->timestamp.tv_sec + 1e-9 * frame->timestamp.tv_nsec; pImage->epicsTS.secPastEpoch = frame->timestamp.tv_sec; pImage->epicsTS.nsec = frame->timestamp.tv_nsec; updateTimeStamp(&pImage->epicsTS); // Get any attributes for the driver this->getAttributes(pImage->pAttributeList); int arrayCallbacks; getIntegerParam(NDArrayCallbacks, &arrayCallbacks); if (arrayCallbacks) { /* Call the NDArray callback */ /* Must release the lock here, or we can get into a deadlock, because we can * block on the plugin lock, and the plugin can be calling us */ this->unlock(); doCallbacksGenericPointer(pImage, NDArrayData, 0); this->lock(); } if (this->framesRemaining > 0) this->framesRemaining--; if (this->framesRemaining == 0) { cin_ctl_int_trigger_stop(&cin_ctl_port); cin_ctl_ext_trigger_stop(&cin_ctl_port); setIntegerParam(ADAcquire, 0); setIntegerParam(ADStatus, ADStatusIdle); } /* Update the frame counter */ int imageCounter; getIntegerParam(NDArrayCounter, &imageCounter); imageCounter++; setIntegerParam(NDArrayCounter, imageCounter); asynPrint(this->pasynUserSelf, ASYN_TRACEIO_DRIVER, "%s:%s: frameId=%d\n", driverName, functionName, frame->number); // Release the frame as we are done with it! pImage->release(); /* Update any changed parameters */ callParamCallbacks(); this->unlock(); return; }
/** This thread controls acquisition, reads SFRM files to get the image data, and * does the callbacks to send it to higher layers */ void BISDetector::BISTask() { int status = asynSuccess; int imageCounter; int numImages, numImagesCounter; int imageMode; int acquire; NDArray *pImage; double acquireTime, timeRemaining; ADShutterMode_t shutterMode; int frameType; int numDarks; double readSFRMTimeout; epicsTimeStamp startTime, currentTime; const char *functionName = "BISTask"; char fullFileName[MAX_FILENAME_LEN]; char statusMessage[MAX_MESSAGE_SIZE]; size_t dims[2]; int itemp; int arrayCallbacks; this->lock(); /* Loop forever */ while (1) { /* Is acquisition active? */ getIntegerParam(ADAcquire, &acquire); /* If we are not acquiring then wait for a semaphore that is given when acquisition is started */ if (!acquire) { setStringParam(ADStatusMessage, "Waiting for acquire command"); setIntegerParam(ADStatus, ADStatusIdle); callParamCallbacks(); /* Release the lock while we wait for an event that says acquire has started, then lock again */ this->unlock(); asynPrint(this->pasynUserSelf, ASYN_TRACE_FLOW, "%s:%s: waiting for acquire to start\n", driverName, functionName); status = epicsEventWait(this->startEventId); this->lock(); setIntegerParam(ADNumImagesCounter, 0); } /* Get current values of some parameters */ getIntegerParam(ADFrameType, &frameType); /* Get the exposure parameters */ getDoubleParam(ADAcquireTime, &acquireTime); getIntegerParam(ADShutterMode, &itemp); shutterMode = (ADShutterMode_t)itemp; getDoubleParam(BISSFRMTimeout, &readSFRMTimeout); setIntegerParam(ADStatus, ADStatusAcquire); /* Create the full filename */ createFileName(sizeof(fullFileName), fullFileName); setStringParam(ADStatusMessage, "Starting exposure"); /* Call the callbacks to update any changes */ setStringParam(NDFullFileName, fullFileName); callParamCallbacks(); switch (frameType) { case BISFrameNormal: epicsSnprintf(this->toBIS, sizeof(this->toBIS), "[Scan /Filename=%s /scantime=%f /Rescan=0]", fullFileName, acquireTime); break; case BISFrameDark: getIntegerParam(BISNumDarks, &numDarks); epicsSnprintf(this->toBIS, sizeof(this->toBIS), "[Dark /AddTime=%f /Repetitions=%d]", acquireTime, numDarks); break; case BISFrameRaw: epicsSnprintf(this->toBIS, sizeof(this->toBIS), "[Scan /Filename=%s /scantime=%f /Rescan=0 /DarkFlood=0]", fullFileName, acquireTime); break; case BISFrameDoubleCorrelation: epicsSnprintf(this->toBIS, sizeof(this->toBIS), "[Scan /Filename=%s /scantime=%f /Rescan=1]", fullFileName, acquireTime); break; } /* Send the acquire command to BIS */ writeBIS(2.0); setStringParam(ADStatusMessage, "Waiting for Acquisition"); callParamCallbacks(); /* Set the the start time for the TimeRemaining counter */ epicsTimeGetCurrent(&startTime); timeRemaining = acquireTime; /* BIS will control the shutter if we are using the hardware shutter signal. * If we are using the EPICS shutter then tell it to open */ if (shutterMode == ADShutterModeEPICS) ADDriver::setShutter(1); /* Wait for the exposure time using epicsEventWaitWithTimeout, * so we can abort. */ epicsTimerStartDelay(this->timerId, acquireTime); while(1) { this->unlock(); status = epicsEventWaitWithTimeout(this->stopEventId, BIS_POLL_DELAY); this->lock(); if (status == epicsEventWaitOK) { /* The acquisition was stopped before the time was complete */ epicsTimerCancel(this->timerId); break; } epicsTimeGetCurrent(¤tTime); timeRemaining = acquireTime - epicsTimeDiffInSeconds(¤tTime, &startTime); if (timeRemaining < 0.) timeRemaining = 0.; setDoubleParam(ADTimeRemaining, timeRemaining); callParamCallbacks(); } if (shutterMode == ADShutterModeEPICS) ADDriver::setShutter(0); setDoubleParam(ADTimeRemaining, 0.0); callParamCallbacks(); this->unlock(); status = epicsEventWaitWithTimeout(this->readoutEventId, 5.0); this->lock(); /* If there was an error jump to bottom of loop */ if (status != epicsEventWaitOK) { setIntegerParam(ADAcquire, 0); asynPrint(pasynUserSelf, ASYN_TRACE_ERROR, "%s:%s: error waiting for readout to complete\n", driverName, functionName); goto done; } getIntegerParam(NDArrayCallbacks, &arrayCallbacks); getIntegerParam(NDArrayCounter, &imageCounter); imageCounter++; setIntegerParam(NDArrayCounter, imageCounter); getIntegerParam(ADNumImagesCounter, &numImagesCounter); numImagesCounter++; setIntegerParam(ADNumImagesCounter, numImagesCounter); callParamCallbacks(); if (arrayCallbacks && frameType != BISFrameDark) { /* Get an image buffer from the pool */ getIntegerParam(ADSizeX, &itemp); dims[0] = itemp; getIntegerParam(ADSizeY, &itemp); dims[1] = itemp; pImage = this->pNDArrayPool->alloc(2, dims, NDInt32, 0, NULL); epicsSnprintf(statusMessage, sizeof(statusMessage), "Reading from File %s", fullFileName); setStringParam(ADStatusMessage, statusMessage); callParamCallbacks(); status = readSFRM(fullFileName, &startTime, acquireTime + readSFRMTimeout, pImage); /* If there was an error jump to bottom of loop */ if (status) { setIntegerParam(ADAcquire, 0); pImage->release(); goto done; } /* Put the frame number and time stamp into the buffer */ pImage->uniqueId = imageCounter; pImage->timeStamp = startTime.secPastEpoch + startTime.nsec / 1.e9; updateTimeStamp(&pImage->epicsTS); /* Get any attributes that have been defined for this driver */ this->getAttributes(pImage->pAttributeList); /* Call the NDArray callback */ /* Must release the lock here, or we can get into a deadlock, because we can * block on the plugin lock, and the plugin can be calling us */ this->unlock(); asynPrint(this->pasynUserSelf, ASYN_TRACE_FLOW, "%s:%s: calling NDArray callback\n", driverName, functionName); doCallbacksGenericPointer(pImage, NDArrayData, 0); this->lock(); /* Free the image buffer */ pImage->release(); } getIntegerParam(ADImageMode, &imageMode); if (imageMode == ADImageMultiple) { getIntegerParam(ADNumImages, &numImages); if (numImagesCounter >= numImages) setIntegerParam(ADAcquire, 0); } if (imageMode == ADImageSingle) setIntegerParam(ADAcquire, 0); done: callParamCallbacks(); } }