areaDetector  3-5-0
EPICS areaDetector framework
QImaging.h
Go to the documentation of this file.
1 // * QImage.h
2 // *
3 // * Header file for QImage.cpp
4 // *
5 // * Author: Arthur Glowacki
6 // * APS-ANL
7 // *
8 // * Created: June 13, 2014
9 
10 
11 #ifndef QIMAGE_H
12 #define QIMAGE_H
13 
14 #include <stddef.h>
15 #include <stdlib.h>
16 #include <stdarg.h>
17 #include <math.h>
18 #include <stdio.h>
19 #include <errno.h>
20 #include <string.h>
21 #include <comdef.h>
22 #include <epicsTime.h>
23 #include <epicsThread.h>
24 #include <epicsEvent.h>
25 #include <epicsMutex.h>
26 #include <epicsString.h>
27 #include <epicsStdio.h>
28 #include <cantProceed.h>
29 #include <iocsh.h>
30 #include <epicsExit.h>
31 #include <queue>
32 #include <unordered_map>
33 
34 #include "QCamApi.h"
35 #include "ADDriver.h"
36 
37 #include <epicsExport.h>
38 
39 static const char *driverName = "QImage";
40 #define RETIGA_POLL_TIME .010
41 #define MAX_FILENAME_LEN 256
42 #define MAX_ARRAY_LEN 40
43 
44 
45 class QImage : public ADDriver {
46 public:
47  QImage(const char *portName, const char *model, NDDataType_t dataType, int numbuffs, int debug, int maxBuffers, size_t maxMemory, int priority, int stackSize);
48 
49  friend void QCAMAPI QImageCallback(void* usrPtr, unsigned long frameId, QCam_Err errorcode, unsigned long flags);
50 
51  // These are the methods that we override from ADDriver
52  virtual asynStatus writeInt32(asynUser *pasynUser, epicsInt32 value);
53  virtual asynStatus writeFloat64(asynUser *pasynUser, epicsFloat64 value);
54  virtual void report(FILE *fp, int details);
55  virtual asynStatus readEnum(asynUser *pasynUser, char *strings[], int values[], int severities[],
56  size_t nElements, size_t *nIn);
57  // These are new methods
58  //void exposureTask();
59  void consumerTask();
60  void frameTask();
61  void shutdown(); // This is called by epicsAtExit
62 
63  void pushCollectedFrame(int id);
64  void setExposureDone();
65 
66  protected:
68  #define FIRST_QIMAGE_PARAM qMaxBitDepthRBV
80  int qOffset;
83  int qMinXRBV;
84  int qMinYRBV;
85  int qSizeXRBV;
86  int qSizeYRBV;
88  int qGainRBV;
97  int qTrgCnt;
98  int qExpCnt;
99  int qFrmCnt;
104  int qGainMax;
105  int qGainMin;
106  int qBinning;
110  #define LAST_QIMAGE_PARAM qInitialize
111 
112 #define NUM_QIMAGE_PARAMS (&LAST_QIMAGE_PARAM - &FIRST_QIMAGE_PARAM + 1)
113 
114  private:
115  // These are the methods that are new to this class
116 
117  asynStatus resultCode(const char *funcName, const char *cmdName, QCam_Err errorcode);
118  asynStatus connectQImage();
119  asynStatus disconnectQImage();
120  //asynStatus queueFrame(unsigned long frame);
121  //asynStatus initializeBuffers();
122  asynStatus initializeQImage();
123  asynStatus queryQImageSettings();
124 
125  asynStatus initializeFrames();
126 
128  void resetFrameQueues();
130  asynStatus getCameraInfo();
132  asynStatus q_acquire(epicsInt32 value);
133  asynStatus q_setTriggerMode(epicsInt32 value);
134  asynStatus q_autoExposure(epicsInt32 value);
135  asynStatus q_whiteBalance(epicsInt32 value);
136  asynStatus q_setDataTypeAndColorMode(epicsInt32 function, epicsInt32 value);
137  asynStatus q_setImageSize(epicsInt32 function, epicsInt32 value);
138  asynStatus q_setBinning(epicsInt32 function, epicsInt32 value);
139  asynStatus q_setMinXY(epicsInt32 function, epicsInt32 value);
140  asynStatus q_resetCamera(epicsInt32 value);
141  asynStatus q_setTemperature(epicsFloat64 value);
142  asynStatus q_setCoolerActive(epicsInt32 value);
143  asynStatus q_setReadoutSpeed(epicsInt32 value);
145 
146 
147  epicsEvent captureEvent;
148  epicsEvent captureEvent2;
149 
150  //frame structure
151  struct QNDFrame
152  {
153  QCam_Frame *qFrame;
154  NDArray *ndArray;
155  QCam_Err errorcode;
156  unsigned long flags;
157  unsigned long frameId;
158  };
159 
160  // Our data
161  epicsTimeStamp startTime;
162  epicsEventId stopEventId;
163  epicsEventId m_acquireEventId;
164  epicsMutex freeFrameMutex;
165  epicsMutex capFrameMutex;
166  epicsMutex aquireMutex;
167 
168  //epicsMutex detectorMutex;
169 
170  double camPushSleepAmt;
171  double m_exposureTime;
172 
173  //std::vector<NDArray*> pImage;
174  //NDArray* pNDArr;
175  QCam_Handle qHandle;
176  int adStatus;
177  int num_buffs;
178  int trgCnt;
179  int expCnt;
180  int frmCnt;
181  int expSntl;
182  bool stopEvent;
183  double expMax;
184  double expMin;
185  double gainMax;
186  double gainMin;
187  signed long offsetMax;
188  signed long offsetMin;
189  signed long tempMax;
190  signed long tempMin;
191  unsigned long coolerReg;
192  unsigned long rawDataSize;
193  NDDataType_t m_dataType;
194  double m_acquirePeriod;
195  double m_acquireTime;
196  int _numImages;
197  int _capturedFrames;
198 
199  unsigned long maxWidth;
200  unsigned long maxHeight;
201 
202  unsigned long binningTable[32];
203  int binningTableSize = 32;
204 
205  unsigned long imageFormatTable[32];
206  int imageFormatTableSize = 32;
207 
208  unsigned long triggerType;
209 
210  volatile bool _adAcquire;
211  std::queue<int> freeFrames;
212  std::queue<int> collectedFrames;
213  std::unordered_map<unsigned long, QNDFrame*> pFrames;
214  unsigned long m_frameCntr;
215  size_t m_dims[2];
216 
217  asynStatus allocFrame(unsigned long &frameId);
218  asynStatus releaseFrame(unsigned long frameId);
219 
220  bool exiting_;
221  bool isSettingsInit;
222 
223  QCam_SettingsEx qSettings;
224 
225 };
226 
227 #define qMaxBitDepthRBVString "MAX_BIT_DEPTH_RBV"
228 #define qSerialNumberRBVString "SERIAL_NUMBER_RBV"
229 #define qUniqueIdRBVString "UNIQUE_ID_RBV"
230 #define qCcdTypeRBVString "CCD_TYPE_RBV"
231 #define qCooledRBVString "COOLED_RBV"
232 #define qRegulatedCoolingRBVString "REGULATED_COOLING_RBV"
233 #define qFanControlRBVString "FAN_CONTROL_RBV"
234 #define qHighSensitivityModeRBVString "HIGH_SENSITIVITY_MODE_RBV"
235 #define qBlackoutModeRBVString "BLACK_OUT_MODE_RBV"
236 #define qAsymmetricalBinningRBVString "ASYMMETRICAL_BINNING_RBV"
237 #define qCoolerActiveString "COOLER_ACTIVE"
238 #define qReadoutSpeedString "READOUT_SPEED"
239 #define qOffsetString "OFFSET"
240 #define qImageFormatString "IMAGE_FORMAT"
241 #define qAcquireTimeRBVString "ACQUIRE_TIME_RBV"
242 #define qMinXRBVString "MIN_X_RBV"
243 #define qMinYRBVString "MIN_Y_RBV"
244 #define qSizeXRBVString "SIZE_X_RBV"
245 #define qSizeYRBVString "SIZE_Y_RBV"
246 #define qTriggerModeRBVString "TRIGGER_MODE_RBV"
247 #define qGainRBVString "GAIN_RBV"
248 #define qTemperatureRBVString "TEMPERATURE_RBV"
249 #define qReadoutSpeedRBVString "READOUT_SPEED_RBV"
250 #define qOffsetRBVString "OFFSET_RBV"
251 #define qImageFormatRBVString "IMAGE_FORMAT_RBV"
252 #define qCoolerActiveRBVString "COOLER_ACTIVE_RBV"
253 #define qRegulatedCoolingLockRBVString "REGULATED_COOLING_LOCK_RBV"
254 #define qExposureStatusMessageRBVString "EXPOSURE_STATUS_MESSAGE"
255 #define qFrameStatusMessageRBVString "FRAME_STATUS_MESSAGE"
256 #define qTrgCntString "TRIGGER_COUNT"
257 #define qExpCntString "EXPOSURE_COUNT_RBV"
258 #define qFrmCntString "FRAME_COUNT_RBV"
259 #define qShowDiagsString "SHOW_DIAGS"
260 #define qResetCamString "RESET_DETECTOR"
261 #define qExposureMaxString "EXPOSURE_MAX_RBV"
262 #define qExposureMinString "EXPOSURE_MIN_RBV"
263 #define qGainMaxString "GAIN_MAX_RBV"
264 #define qGainMinString "GAIN_MIN_RBV"
265 #define qBinningString "QBINNING"
266 #define qAutoExposureString "AUTO_EXPOSURE"
267 #define qWhiteBalanceString "WHITE_BALANCE"
268 #define qInitializeString "INITIALIZE_DETECTOR"
269 
270 static void QImageShutdown(void* arg) {
271  QImage *p = (QImage*)arg;
272  p->shutdown();
273 }
274 
275 #endif
QImage(const char *portName, const char *model, NDDataType_t dataType, int numbuffs, int debug, int maxBuffers, size_t maxMemory, int priority, int stackSize)
QImage::QImage Class constructor.
Definition: QImaging.cpp:83
Class from which areaDetector drivers are directly derived.
Definition: ADDriver.h:141
int qUniqueIdRBV
Definition: QImaging.h:70
int qHighSensitivityModeRBV
Definition: QImaging.h:75
int qRegulatedCoolingRBV
Definition: QImaging.h:73
NDDataType_t
Enumeration of NDArray data types.
Definition: NDAttribute.h:27
virtual asynStatus writeInt32(asynUser *pasynUser, epicsInt32 value)
QImage::writeInt32: Called when asyn clients call pasynInt32->write().
Definition: QImaging.cpp:2228
int qImageFormat
Definition: QImaging.h:81
int qExposureMin
Definition: QImaging.h:103
int qGainRBV
Definition: QImaging.h:88
int qAutoExposure
Definition: QImaging.h:107
void setExposureDone()
QImage::setExposureDone: Call signal when exposure happened on the detector.
Definition: QImaging.cpp:1032
int qShowDiags
Definition: QImaging.h:100
int qTriggerModeRBV
Definition: QImaging.h:87
list value
Definition: makeDbAndEdl.py:234
virtual void report(FILE *fp, int details)
QImage::report.
Definition: QImaging.cpp:2140
void consumerTask()
QImage::consumerTask: Thread function to accept new frames from the detector and push them down the p...
Definition: QImaging.cpp:410
int qAsymmetricalBinningRBV
Definition: QImaging.h:77
int qBlackoutModeRBV
Definition: QImaging.h:76
int qRegulatedCoolingLockRBV
Definition: QImaging.h:94
char * portName
The name of this asyn port.
Definition: asynPortDriver.h:179
int qCooledRBV
Definition: QImaging.h:72
void shutdown()
QImage::shutdown: Function called at IOC exit.
Definition: QImaging.cpp:945
int qInitialize
Definition: QImaging.h:109
int qGainMax
Definition: QImaging.h:104
int qAcquireTimeRBV
Definition: QImaging.h:82
int qTrgCnt
Definition: QImaging.h:97
Definition: QImaging.h:45
int qMaxBitDepthRBV
Definition: QImaging.h:67
int qGainMin
Definition: QImaging.h:105
int qSizeYRBV
Definition: QImaging.h:86
int qSizeXRBV
Definition: QImaging.h:85
int qExposureStatusMessageRBV
Definition: QImaging.h:95
void pushCollectedFrame(int id)
QImage::pushCollectedFrame: Pushes an aquired frame to a queue to be proecssed by consumer thread.
Definition: QImaging.cpp:1020
int qExpCnt
Definition: QImaging.h:98
friend void QCAMAPI QImageCallback(void *usrPtr, unsigned long frameId, QCam_Err errorcode, unsigned long flags)
Callback function from the detector when a frame or exposure occur.
Definition: QImaging.cpp:42
void frameTask()
QImage::frameTask: Thread function for generating software triggers for the detector.
Definition: QImaging.cpp:521
int qFanControlRBV
Definition: QImaging.h:74
int qExposureMax
Definition: QImaging.h:102
virtual asynStatus readEnum(asynUser *pasynUser, char *strings[], int values[], int severities[], size_t nElements, size_t *nIn)
QImage::readEnum: Adds frame data type and color mode to enums.
Definition: QImaging.cpp:1958
int qTemperatureRBV
Definition: QImaging.h:89
int qOffsetRBV
Definition: QImaging.h:91
int qImageFormatRBV
Definition: QImaging.h:92
int qReadoutSpeedRBV
Definition: QImaging.h:90
int qCcdTypeRBV
Definition: QImaging.h:71
int qOffset
Definition: QImaging.h:80
int qBinning
Definition: QImaging.h:106
int qSerialNumberRBV
Definition: QImaging.h:69
int qCoolerActive
Definition: QImaging.h:78
int qMinYRBV
Definition: QImaging.h:84
virtual asynStatus writeFloat64(asynUser *pasynUser, epicsFloat64 value)
QImage::writeFloat64: Called when asyn clients call pasynFloat64->write().
Definition: QImaging.cpp:2341
N-dimensional array class; each array has a set of dimensions, a data type, pointer to data,...
Definition: NDArray.h:92
int qFrmCnt
Definition: QImaging.h:99
int qMinXRBV
Definition: QImaging.h:83
int qFrameStatusMessageRBV
Definition: QImaging.h:96
int qResetCam
Definition: QImaging.h:101
int qWhiteBalance
Definition: QImaging.h:108
int qReadoutSpeed
Definition: QImaging.h:79
int qCoolerActiveRBV
Definition: QImaging.h:93