QXRD  0.11.16
qxrddetectorperkinelmer.cpp
Go to the documentation of this file.
1 #include "qxrddebug.h"
3 #include "qxrdapplication.h"
5 #include "qxrdacquisition.h"
6 #include "qcepallocator.h"
7 #include "qcepmutexlocker.h"
8 #include "qxrddetectorproxy.h"
9 
10 //static QxrdDetectorPerkinElmer *g_Detector = NULL;
11 static void CALLBACK OnEndFrameCallback(HACQDESC hAcqDesc);
12 static void CALLBACK OnEndAcqCallback(HACQDESC hAcqDesc);
13 
15  QxrdExperimentWPtr expt,
17  int detNum,
18  QcepObject *parent) :
19  QxrdDetector(saver, expt, acq, QxrdDetectorThread::PerkinElmerDetector, detNum, parent),
20  m_Mutex(QMutex::Recursive),
21  m_BufferSize(0),
22  m_AcqDesc(NULL),
23  m_StartupDelayed(0),
24  m_PROMID(-1),
25  m_HeaderID(-1),
26  m_CameraType(-1),
27  m_CameraModel(""),
28  m_CurrentGain(-1),
29  m_SyncMode(HIS_SYNCMODE_INTERNAL_TIMER),
30  m_Counter(0),
31  m_PerkinElmer(),
32  m_DetectorNumber (saver, this, "detectorNumber", 0, "Perkin Elmer Detector Number"),
33  m_DetectorSubType(saver, this, "detectorSubType", 0, "Perkin Elmer Detector Subtype"),
34  m_DetectorAddress(saver, this, "detectorAddress", "", "Perkin Elmer Detector Address"),
35  m_DetectorGain (saver, this, "detectorGain", 0, "Detector Gain"),
36  m_DetectorBinning(saver, this, "detectorBinning", 0, "Detector Binning Mode")
37 {
39  printf("QxrdDetectorPerkinElmer::QxrdDetectorPerkinElmer(%p)\n", this);
40  }
41 
43  printMessage("QxrdDetectorPerkinElmer::QxrdDetectorPerkinElmer()");
44  }
45 
46 // ::g_Detector = this;
47 }
48 
50 {
52  printf("QxrdDetectorPerkinElmer::~QxrdDetectorPerkinElmer(%p)\n", this);
53  }
54 
56  printMessage("QxrdDetectorPerkinElmer::~QxrdDetectorPerkinElmer()");
57  }
58 
60 
61  if (plugin && m_AcqDesc) {
62  plugin->Acquisition_SetAcqData(m_AcqDesc, NULL);
63  plugin->Acquisition_SetCallbacksAndMessages(m_AcqDesc, NULL, 0, 0, NULL, NULL);
64  plugin->Acquisition_Abort(m_AcqDesc);
65  plugin->Acquisition_CloseAll();
66  }
67 }
68 
70 {
72 
73  if (proxy) {
74  proxy->pushProperty(QxrdDetectorProxy::PEDetNumProperty, "detectorNumber", "PE Detector Number", 0);
75  proxy->pushProperty(QxrdDetectorProxy::PESubTypeProperty, "detectorSubType", "PE Detector Type", 0);
76  proxy->pushProperty(QxrdDetectorProxy::StringProperty, "detectorAddress", "PE Detector Address", "");
77  proxy->pushProperty(QxrdDetectorProxy::PEGainProperty, "detectorGain", "PE Detector Gain", 0);
78  proxy->pushProperty(QxrdDetectorProxy::PEBinningProperty, "detectorBinning", "PE Detector Binning", 0);
79  }
80 }
81 
83 {
85 
86  if (proxy) {
87  proxy->pushProperty(QxrdDetectorProxy::PEDetNumProperty, "detectorNumber", "PE Detector Number", get_DetectorNumber());
88  proxy->pushProperty(QxrdDetectorProxy::PESubTypeProperty, "detectorSubType", "PE Detector Type", get_DetectorSubType());
89  proxy->pushProperty(QxrdDetectorProxy::StringProperty, "detectorAddress", "PE Detector Address", get_DetectorAddress());
90  proxy->pushProperty(QxrdDetectorProxy::PEGainProperty, "detectorGain", "PE Detector Gain", get_DetectorGain());
91  proxy->pushProperty(QxrdDetectorProxy::PEBinningProperty, "detectorBinning", "PE Detector Binning", get_DetectorBinning());
92  }
93 }
94 
96 {
98 
99  if (proxy) {
100  set_DetectorNumber (proxy->property("detectorNumber").toInt());
101  set_DetectorSubType (proxy->property("detectorSubType").toInt());
102  set_DetectorAddress (proxy->property("detectorAddress").toString());
103  set_DetectorGain (proxy->property("detectorGain").toInt());
104  set_DetectorBinning (proxy->property("detectorBinning").toInt());
105  }
106 }
107 
109 {
110  return get_DetectorSubType();
111 }
112 
114 {
115  return get_DetectorAddress();
116 }
117 
119 {
120  QString res = "No Error";
121 
122  switch (n) {
123  case HIS_ALL_OK:
124  res = "HIS_ALL_OK";
125  break;
126 
127  case HIS_ERROR_MEMORY:
128  res = "HIS_ERROR_MEMORY";
129  break;
130 
131  case HIS_ERROR_BOARDINIT:
132  res = "HIS_ERROR_BOARDINIT";
133  break;
134 
135  case HIS_ERROR_NOCAMERA:
136  res = "HIS_ERROR_NOCAMERA";
137  break;
138 
139  case HIS_ERROR_CORRBUFFER_INCOMPATIBLE:
140  res = "HIS_ERROR_CORRBUFFER_INCOMPATIBLE";
141  break;
142 
143  case HIS_ERROR_ACQ_ALREADY_RUNNING:
144  res = "HIS_ERROR_ACQ_ALREADY_RUNNING";
145  break;
146 
147  case HIS_ERROR_TIMEOUT:
148  res = "HIS_ERROR_TIMEOUT";
149  break;
150 
151  case HIS_ERROR_INVALIDACQDESC:
152  res = "HIS_ERROR_INVALIDACQDESC";
153  break;
154 
155  case HIS_ERROR_VXDNOTFOUND:
156  res = "HIS_ERROR_VXDNOTFOUND";
157  break;
158 
159  case HIS_ERROR_VXDNOTOPEN:
160  res = "HIS_ERROR_VXDNOTOPEN";
161  break;
162 
163  case HIS_ERROR_VXDUNKNOWNERROR:
164  res = "HIS_ERROR_VXDUNKNOWNERROR";
165  break;
166 
167  case HIS_ERROR_VXDGETDMAADR:
168  res = "HIS_ERROR_VXDGETDMAADR";
169  break;
170 
171  case HIS_ERROR_ACQABORT:
172  res = "HIS_ERROR_ACQABORT";
173  break;
174 
175  case HIS_ERROR_ACQUISITION:
176  res = "HIS_ERROR_ACQUISITION";
177  break;
178 
179  case HIS_ERROR_VXD_REGISTER_IRQ:
180  res = "HIS_ERROR_VXD_REGISTER_IRQ";
181  break;
182 
183  case HIS_ERROR_VXD_REGISTER_STATADR:
184  res = "HIS_ERROR_MEMORY";
185  break;
186 
187  case HIS_ERROR_GETOSVERSION:
188  res = "HIS_ERROR_GETOSVERSION";
189  break;
190 
191  case HIS_ERROR_SETFRMSYNC:
192  res = "HIS_ERROR_SETFRMSYNC";
193  break;
194 
195  case HIS_ERROR_SETFRMSYNCMODE:
196  res = "HIS_ERROR_SETFRMSYNCMODE";
197  break;
198 
199  case HIS_ERROR_SETTIMERSYNC:
200  res = "HIS_ERROR_SETTIMERSYNC";
201  break;
202 
203  case HIS_ERROR_INVALID_FUNC_CALL:
204  res = "HIS_ERROR_INVALID_FUNC_CALL";
205  break;
206 
207  case HIS_ERROR_ABORTCURRFRAME:
208  res = "HIS_ERROR_ABORTCURRFRAME";
209  break;
210 
211  case HIS_ERROR_GETHWHEADERINFO:
212  res = "HIS_ERROR_GETHWHEADERINFO";
213  break;
214 
215  case HIS_ERROR_HWHEADER_INV:
216  res = "HIS_ERROR_HWHEADER_INV";
217  break;
218 
219  case HIS_ERROR_SETLINETRIG_MODE:
220  res = "HIS_ERROR_SETLINETRIG_MODE";
221  break;
222 
223  case HIS_ERROR_WRITE_DATA:
224  res = "HIS_ERROR_WRITE_DATA";
225  break;
226 
227  case HIS_ERROR_READ_DATA:
228  res = "HIS_ERROR_READ_DATA";
229  break;
230 
231  case HIS_ERROR_SETBAUDRATE:
232  res = "HIS_ERROR_SETBAUDRATE";
233  break;
234 
235  case HIS_ERROR_NODESC_AVAILABLE:
236  res = "HIS_ERROR_NODESC_AVAILABLE";
237  break;
238 
239  case HIS_ERROR_BUFFERSPACE_NOT_SUFF:
240  res = "HIS_ERROR_BUFFERSPACE_NOT_SUFF";
241  break;
242 
243  case HIS_ERROR_SETCAMERAMODE:
244  res = "HIS_ERROR_SETCAMERAMODE";
245  break;
246 
247  case HIS_ERROR_FRAME_INV:
248  res = "HIS_ERROR_FRAME_INV";
249  break;
250 
251  case HIS_ERROR_SLOW_SYSTEM:
252  res = "HIS_ERROR_SLOW_SYSTEM";
253  break;
254 
255  case HIS_ERROR_GET_NUM_BOARDS:
256  res = "HIS_ERROR_GET_NUM_BOARDS";
257  break;
258 
259  case HIS_ERROR_HW_ALREADY_OPEN_BY_ANOTHER_PROCESS:
260  res = "HIS_ERROR_HW_ALREADY_OPEN_BY_ANOTHER_PROCESS";
261  break;
262 
263  case HIS_ERROR_CREATE_MEMORYMAPPING:
264  res = "HIS_ERROR_CREATE_MEMORYMAPPING";
265  break;
266 
267  case HIS_ERROR_VXD_REGISTER_DMA_ADDRESS:
268  res = "HIS_ERROR_VXD_REGISTER_DMA_ADDRESS";
269  break;
270 
271  case HIS_ERROR_VXD_REGISTER_STAT_ADDR:
272  res = "HIS_ERROR_VXD_REGISTER_STAT_ADDR";
273  break;
274 
275  case HIS_ERROR_VXD_UNMASK_IRQ:
276  res = "HIS_ERROR_VXD_UNMASK_IRQ";
277  break;
278 
279  case HIS_ERROR_LOADDRIVER:
280  res = "HIS_ERROR_LOADDRIVER";
281  break;
282 
283  case HIS_ERROR_FUNC_NOTIMPL:
284  res = "HIS_ERROR_FUNC_NOTIMPL";
285  break;
286 
287  case HIS_ERROR_MEMORY_MAPPING:
288  res = "HIS_ERROR_MEMORY_MAPPING";
289  break;
290 
291  case HIS_ERROR_CREATE_MUTEX:
292  res = "HIS_ERROR_CREATE_MUTEX";
293  break;
294 
295  case HIS_ERROR_ACQ:
296  res = "HIS_ERROR_ACQ";
297  break;
298 
299  case HIS_ERROR_DESC_NOT_LOCAL:
300  res = "HIS_ERROR_DESC_NOT_LOCAL";
301  break;
302 
303  case HIS_ERROR_INVALID_PARAM:
304  res = "HIS_ERROR_INVALID_PARAM";
305  break;
306 
307  case HIS_ERROR_ABORT:
308  res = "HIS_ERROR_ABORT";
309  break;
310 
311  case HIS_ERROR_WRONGBOARDSELECT:
312  res = "HIS_ERROR_WRONGBOARDSELECT";
313  break;
314 
315  case HIS_ERROR_WRONG_CAMERA_MODE:
316  res = "HIS_ERROR_WRONG_CAMERA_MODE";
317  break;
318 
319  case HIS_ERROR_AVERAGED_LOST:
320  res = "HIS_ERROR_AVERAGED_LOST";
321  break;
322 
323  case HIS_ERROR_BAD_SORTING_PARAM:
324  res = "HIS_ERROR_BAD_SORTING_PARAM";
325  break;
326 
327  case HIS_ERROR_UNKNOWN_IP_MAC_NAME:
328  res = "HIS_ERROR_UNKNOWN_IP_MAC_NAME";
329  break;
330 
331  case HIS_ERROR_NO_BOARD_IN_SUBNET:
332  res = "HIS_ERROR_NO_BOARD_IN_SUBNET";
333  break;
334 
335  case HIS_ERROR_UNABLE_TO_OPEN_BOARD:
336  res = "HIS_ERROR_UNABLE_TO_OPEN_BOARD";
337  break;
338 
339  case HIS_ERROR_UNABLE_TO_CLOSE_BOARD:
340  res = "HIS_ERROR_UNABLE_TO_CLOSE_BOARD";
341  break;
342 
343  case HIS_ERROR_UNABLE_TO_ACCESS_DETECTOR_FLASH:
344  res = "HIS_ERROR_UNABLE_TO_ACCESS_DETECTOR_FLASH";
345  break;
346 
347  case HIS_ERROR_HEADER_TIMEOUT:
348  res = "HIS_ERROR_HEADER_TIMEOUT";
349  break;
350 
351  case HIS_ERROR_NO_PING_ACK:
352  res = "HIS_ERROR_NO_PING_ACK";
353  break;
354 
355  case HIS_ERROR_NR_OF_BOARDS_CHANGED:
356  res = "HIS_ERROR_NR_OF_BOARDS_CHANGED";
357  break;
358  }
359 
360  return res;
361 }
362 
363 void QxrdDetectorPerkinElmer::acquisitionError(const char *fn, int ln, int n)
364 {
366 
367  if (acq) {
368  acq -> cancel();
369  }
370 
371  printMessage(tr("Acquisition Error %1 [%2] at line %3 in file %4")
372  .arg(n).arg(acquisitionErrorString(n)).arg(ln).arg(fn));
373 
374  criticalMessage(tr("Acquisition Error %1 [%2] at line %3 in file %4")
375  .arg(n).arg(acquisitionErrorString(n)).arg(ln).arg(fn));
376 }
377 
379 {
380  QxrdApplication *app = qobject_cast<QxrdApplication*>(g_Application);
381 
382  if (app && m_PerkinElmer == NULL) {
383  m_PerkinElmer = app->perkinElmerPlugin();
384  }
385 
386  if (m_PerkinElmer == NULL) {
387  criticalMessage("No perkin elmer plugin available");
388  }
389 
390  return m_PerkinElmer;
391 }
392 
393 /*
394  Sorting Mode Values:
395 
396  Det. S Mode Hdr ID
397  RID 128 1
398  RID 256 2
399  RID 128-400 3
400  RID 1024-100 4
401  RID 512-400 A0 5
402  XRD 512-400 A1/A2 6
403  XRD 0840 6
404  XRD 512-400 E 7
405  XRD 1640 A 8
406  XRD 0820 8
407  XRD 1620 A 8
408  XRD 1640 A 9
409  XRD 1620/21 AM/AN 11
410  XRD 1620/40 AN CS 12
411 
412  Header ID Values:
413  All except AM/AN 10
414  XRD 16x0 AM 11
415  XRD 16x0 AN 12,13
416  XRD 1621 AN 14
417  */
418 
420 {
421  if (QThread::currentThread() != thread()) {
422  QMetaObject::invokeMethod(this, "startDetector"/*, Qt::BlockingQueuedConnection*/);
423  } else {
425  printMessage(tr("QxrdAcquisitionPerkinElmer::start"));
426  }
427 
429 
431  THREAD_CHECK;
432 
433  int nRet = HIS_ALL_OK;
434  UINT nSensors;
435  BOOL bEnableIRQ = true;
436  BOOL bSelfInit = true;
437  BOOL bAlwaysOpen = true;
438  ACQDESCPOS Pos = 0;
439  UINT nChannelType;
440  int nChannelNr;
441  UINT dwSortFlags, dwDataType, dwRows, dwColumns, dwFrames;
442  DWORD dwAcqType, dwSystemID, dwSyncMode, dwHwAccess;
443  WORD binningMode;
444 
446 
447  // if (exp) {
448  // m_DetectorNumber = exp->get_DetectorNumber();
449  // m_SubType = exp->get_DetectorSubType();
450  // m_Address = exp->get_DetectorAddress();
451  // }
452 
454 
455  int subType = get_DetectorSubType();
456 
457  if (subType == QxrdDetectorThread::PCI_SubType) {
458  printMessage("Initialising PCI/PCIe Perkin Elmer Detector");
459 
460  if (plugin) {
461  nRet = plugin->Acquisition_EnumSensors(&nSensors, bEnableIRQ, FALSE);
462  }
463 
465  printMessage(tr("Acquisition_EnumSensors = %1").arg(nRet));
466  }
467 
468  if (nRet != HIS_ALL_OK) {
469  acquisitionInitError(__FILE__, __LINE__, nRet);
470  return;
471  }
472 
474  printMessage(tr("Number of sensors = %1").arg(nSensors));
475  }
476 
477  if (get_DetectorNumber() == 0 && nSensors != 1) {
478  acquisitionNSensorsError(__FILE__, __LINE__, nRet);
479  return;
480  } else if (get_DetectorNumber() < 0 || get_DetectorNumber() > nSensors) {
481  acquisitionNSensorsError(__FILE__, __LINE__, nRet);
482  return;
483  }
484 
485  for (int i=1; i<=(get_DetectorNumber() ? get_DetectorNumber() : 1); i++) {
486  if (plugin && (nRet = plugin->Acquisition_GetNextSensor(&Pos, &m_AcqDesc))!=HIS_ALL_OK) {
487  acquisitionNSensorsError(__FILE__, __LINE__, nRet);
488  return;
489  }
490  }
491  } else if (subType == QxrdDetectorThread::GBIF_IP_SubType) {
492  printMessage(tr("Attempting to connect to Perkin Elmer detector on the network at IP Address %1")
493  .arg(get_DetectorAddress()));
494 
495  if (plugin && (nRet = plugin->Acquisition_GbIF_Init(&m_AcqDesc, 0, bEnableIRQ,
496  1024, 1024, bSelfInit,
497  bAlwaysOpen, 1,
498  (GBIF_STRING_DATATYPE*) qPrintable(get_DetectorAddress()))) != HIS_ALL_OK) {
499  acquisitionInitError(__FILE__, __LINE__, nRet);
500  return;
501  }
502  } else if (subType == QxrdDetectorThread::GBIF_MAC_SubType) {
503  printMessage(tr("Attempting to connect to Perkin Elmer detector on the network at MAC address %1").arg(get_DetectorAddress()));
504 
505  if (plugin && (nRet = plugin->Acquisition_GbIF_Init(&m_AcqDesc, 0, bEnableIRQ,
506  1024, 1024, bSelfInit,
507  bAlwaysOpen, 2,
508  (GBIF_STRING_DATATYPE*) qPrintable(get_DetectorAddress()))) != HIS_ALL_OK) {
509  acquisitionInitError(__FILE__, __LINE__, nRet);
510  return;
511  }
512  } else if (subType == QxrdDetectorThread::GBIF_Name_SubType) {
513  printMessage(tr("Attempting to connect to Perkin Elmer detector on the network at device name %1").arg(get_DetectorAddress()));
514 
515  if (plugin && (nRet = plugin->Acquisition_GbIF_Init(&m_AcqDesc, 0, bEnableIRQ,
516  1024, 1024, bSelfInit,
517  bAlwaysOpen, 3,
518  (GBIF_STRING_DATATYPE*) qPrintable(get_DetectorAddress()))) != HIS_ALL_OK) {
519  acquisitionInitError(__FILE__, __LINE__, nRet);
520  return;
521  }
522  } else if (subType == QxrdDetectorThread::GBIF_Scan_SubType) {
523  printMessage("Searching for Perkin Elmer Detectors on the network");
524 
525  long nBoards=0;
526 
527  if (plugin && (nRet = plugin->Acquisition_GbIF_GetDeviceCnt(&nBoards)) != HIS_ALL_OK) {
528  acquisitionNSensorsError(__FILE__, __LINE__, nRet);
529  return;
530  }
531 
532  QVector<GBIF_DEVICE_PARAM> devs(nBoards);
533 
534  if (plugin && (nRet = plugin->Acquisition_GbIF_GetDeviceList(devs.data(), nBoards))) {
535  acquisitionNSensorsError(__FILE__, __LINE__, nRet);
536  return;
537  }
538 
539  printMessage(tr("Found %1 Detectors").arg(nBoards));
540 
541  if (nBoards == 0) {
542  criticalMessage("No detectors found");
543  return;
544  }
545 
546  for (int i=0; i<nBoards; i++) {
547  printMessage(tr("Device %1: %2 found at IP: %3, MAC: %4, Name: %5")
548  .arg(i+1)
549  .arg(devs[i].cModelName)
550  .arg((char*)(devs[i].ucIP))
551  .arg((char*)(devs[i].ucMacAddress))
552  .arg(devs[i].cDeviceName));
553  }
554 
555  if (get_DetectorNumber() >= 0 && get_DetectorNumber() <= nBoards) {
556  int n = (get_DetectorNumber() ? get_DetectorNumber() : 1);
557 
558  if (plugin && (nRet = plugin->Acquisition_GbIF_Init(&m_AcqDesc, 0, bEnableIRQ,
559  1024, 1024, bSelfInit,
560  bAlwaysOpen, 1,
561  devs[n-1].ucIP)) != HIS_ALL_OK) {
562  acquisitionInitError(__FILE__, __LINE__, nRet);
563  return;
564  }
565  }
566  } else {
567  criticalMessage(tr("Unrecognized detector type %1").arg(subType));
568  return;
569  }
570 
571  if (plugin && (nRet = plugin->Acquisition_GetCommChannel(m_AcqDesc, &nChannelType, &nChannelNr))!=HIS_ALL_OK) {
572  acquisitionError(__FILE__, __LINE__, nRet);
573  return;
574  }
575 
577  printMessage(tr("Acquisition_GetCommChannel channel type = %1, channel no = %2")
578  .arg(nChannelType).arg(nChannelNr));
579  }
580 
581  if (plugin && (nRet=plugin->Acquisition_GetConfiguration(m_AcqDesc, &dwFrames, &dwRows, &dwColumns, &dwDataType,
582  &dwSortFlags, &bEnableIRQ, &dwAcqType,
583  &dwSystemID, &dwSyncMode, &dwHwAccess))!=HIS_ALL_OK) {
584  acquisitionError(__FILE__, __LINE__, nRet);
585  return;
586  }
587 
589  printMessage(tr("Acquisition_GetConfiguration frames = %1, rows = %2, cols = %3")
590  .arg(dwFrames).arg(dwRows).arg(dwColumns));
591  printMessage(tr("Acquisition_GetConfiguration data type = %1, sort flags = %2, IRQ = %3")
592  .arg(dwDataType).arg(dwSortFlags).arg(bEnableIRQ));
593  printMessage(tr("Acquisition_GetConfiguration acq type = %1, systemID = %2, syncMode = %3, hwAccess = %4")
594  .arg(dwAcqType).arg(dwSystemID).arg(dwSyncMode).arg(dwHwAccess));
595  }
596 
598 
599  if (acq) {
600  set_NRows(dwRows);
601  set_NCols(dwColumns);
602  }
603 
604  if (plugin && (nRet=plugin->Acquisition_GetCameraBinningMode(m_AcqDesc, &binningMode)) != HIS_ALL_OK) {
605  acquisitionError(__FILE__, __LINE__, nRet);
606  return;
607  }
608 
610  printMessage(tr("Acquisition_GetCameraBinningMode mode = %1").arg(binningMode));
611  }
612 
613  CHwHeaderInfo hwHeaderInfo;
614 
615  if (plugin && (nRet=plugin->Acquisition_GetHwHeaderInfo(m_AcqDesc, &hwHeaderInfo)) != HIS_ALL_OK) {
616  acquisitionError(__FILE__, __LINE__, nRet);
617  return;
618  }
619 
621  printMessage(tr("Prom ID %1, Header ID %2").arg(hwHeaderInfo.dwPROMID).arg(hwHeaderInfo.dwHeaderID));
622  }
623 
624  m_PROMID = hwHeaderInfo.dwPROMID;
625  m_HeaderID = hwHeaderInfo.dwHeaderID;
626 
627  if (hwHeaderInfo.dwHeaderID >= 14) {
628  CHwHeaderInfoEx hdrx;
629 
630  if (plugin && (nRet = plugin->Acquisition_GetHwHeaderInfoEx(m_AcqDesc, &hwHeaderInfo, &hdrx)) != HIS_ALL_OK) {
631  acquisitionError(__FILE__, __LINE__, nRet);
632  return;
633  }
634 
636  printMessage(tr("Camera Type %1").arg(hdrx.wCameratype));
637  printMessage(tr("Binning Mode %1").arg(hdrx.wBinningMode));
638  }
639 
640  m_CameraType = hdrx.wCameratype;
641  }
642 
643  int nReadoutTimes = 8;
644  double readoutTimes[8];
645 
646  if (plugin && (nRet = plugin->Acquisition_GetIntTimes(m_AcqDesc, readoutTimes, &nReadoutTimes)) != HIS_ALL_OK) {
647  acquisitionError(__FILE__, __LINE__, nRet);
648  return;
649  }
650 
651  for (int i=0; i<nReadoutTimes; i++) {
652  m_ReadoutTimes.append(readoutTimes[i]);
653  }
654 
656  printMessage(tr("%1 predefined exposure times available").arg(m_ReadoutTimes.count()));
657 
658  for (int i=0; i<nReadoutTimes; i++) {
659  printMessage(tr("Exp %1 = %2").arg(i).arg(m_ReadoutTimes[i]));
660  }
661  }
662 
663  if (plugin && (nRet = plugin->Acquisition_SetAcqData(m_AcqDesc, (ACQDATATYPE) this)) != HIS_ALL_OK) {
664  acquisitionError(__FILE__, __LINE__, nRet);
665  return;
666  }
667 
668  if (plugin && (nRet = plugin->Acquisition_SetCallbacksAndMessages(m_AcqDesc, NULL, 0,
669  0, OnEndFrameCallback, OnEndAcqCallback))!=HIS_ALL_OK) {
670  acquisitionError(__FILE__, __LINE__, nRet);
671  return;
672  }
673 
674  m_BufferSize = 4;
675  m_BufferIndex = 0;
676 
677  if (acq) {
678  m_Buffer.resize(get_NRows()*get_NCols()*m_BufferSize);
679  m_Buffer.fill(0);
680 
682  printMessage(tr("Exposure Time = %1").arg(acq->get_ExposureTime()));
683  }
684  }
685 
687  printMessage(tr("SetFrameSyncMode HIS_SYNCMODE_INTERNAL_TIMER"));
688  }
689 
690  if (plugin && (nRet=plugin->Acquisition_SetFrameSyncMode(m_AcqDesc, HIS_SYNCMODE_INTERNAL_TIMER)) != HIS_ALL_OK) {
691  if (plugin && (nRet=plugin->Acquisition_SetFrameSyncMode(m_AcqDesc, HIS_SYNCMODE_FREE_RUNNING)) != HIS_ALL_OK) {
692  acquisitionError(__FILE__, __LINE__, nRet);
693  return;
694  } else {
695  m_SyncMode = HIS_SYNCMODE_FREE_RUNNING;
696  }
697  } else {
698  m_SyncMode = HIS_SYNCMODE_INTERNAL_TIMER;
699  }
700 
702  printMessage(tr("Sync Mode = %1").arg(m_SyncMode));
703  }
704 
705  if (acq) {
707 
709 
710  if (acq->get_ExposureTime() <= 0) {
711  acq->set_ExposureTime(0.135);
712  }
713 
715 
716  if (plugin && (nRet=plugin->Acquisition_DefineDestBuffers(m_AcqDesc, m_Buffer.data(), m_BufferSize,
717  get_NRows(), get_NCols())) != HIS_ALL_OK) {
718  acquisitionError(__FILE__, __LINE__, nRet);
719  return;
720  }
721  }
722 
724  printMessage(tr("Define Dest Buffers"));
725  }
726 
727  if (qcepDebug(DEBUG_DELAY_ACQ)) {
728  m_StartupDelayed = 1;
729  } else {
731  }
732  }
733  }
734 }
735 
737 {
738  printMessage(tr("Stopping Perkin Elmer Detector %1").arg(get_DetectorName()));
739 }
740 
742 {
743  if (isEnabled() && checkPluginAvailable()) {
746 
747  if (plugin && acq) {
748  double newTime = acq->get_ExposureTime();
749 // if (newTime*1e6 < m_ReadoutTimes.value(0)) {
750 // printMessage(tr("Attempt to set exposure time less than minimum supported (%1 < %2)")
751 // .arg(newTime).arg(m_ReadoutTimes.value(0)/1e6));
752 
753 // newTime = m_ReadoutTimes.value(0)/1e6;
754 // }
755 
756  printMessage(tr("Exposure time changed to %1").arg(newTime));
757 
758  DWORD tmp = (int)(newTime*1e6);
759 
760  printMessage(tr("SetTimerSync %1").arg(tmp));
761 
762  int nRet;
763 
764  if ((nRet=plugin->Acquisition_SetTimerSync(m_AcqDesc, &tmp)) != HIS_ALL_OK) {
765  acquisitionError(__FILE__, __LINE__, nRet);
766  return;
767  }
768 
769  printMessage(tr("TimerSync = %1").arg(tmp));
770 
771 // acq->set_ExposureTime(tmp/1.0e6);
772  }
773  }
774 }
775 
777 {
778 // return;
779 
780  if (isEnabled() && checkPluginAvailable()) {
783 
784  if (plugin && acq) {
785  if (m_HeaderID == 14) {
786  int newMode = 1;
787 
788  switch (get_DetectorBinning()) {
790  newMode = 1;
791  break;
792 
794  newMode = 2 + 256;
795  break;
796 
798  newMode = 2 + 512;
799  break;
800  }
801 
802  printMessage(tr("Change binning mode to %1").arg(newMode));
803 
804  int nRet;
805  WORD binningMode = newMode;
806  WORD originalMode;
807 
808  // if (newMode == 1) {
809  // if (m_CameraType == 1) {
810  // newMode = 2;
811  // } else {
812  // newMode = 258;
813  // }
814  // }
815  if ((nRet=plugin->Acquisition_GetCameraBinningMode(m_AcqDesc, &originalMode)) != HIS_ALL_OK) {
816  acquisitionError(__FILE__, __LINE__, nRet);
817  return;
818  }
819 
820  printMessage(tr("Initial binning mode = %1").arg(originalMode));
821 
822  printMessage(tr("Setting binning mode = %1").arg(newMode));
823 
824  if ((nRet=plugin->Acquisition_SetCameraBinningMode(m_AcqDesc, newMode)) != HIS_ALL_OK) {
825  acquisitionError(__FILE__, __LINE__, nRet);
826  return;
827  }
828 
829  if ((nRet=plugin->Acquisition_GetCameraBinningMode(m_AcqDesc, &binningMode)) != HIS_ALL_OK) {
830  acquisitionError(__FILE__, __LINE__, nRet);
831  return;
832  }
833 
834  printMessage(tr("Binning mode was set to %1").arg(binningMode));
835 
836  if (binningMode <= 1) {
837  set_HBinning(1);
838  set_VBinning(1);
839  } else {
840  set_HBinning(2);
841  set_VBinning(2);
842  }
843  }
844  }
845  }
846 }
847 
849 {
850  if (isEnabled() && checkPluginAvailable()) {
853 
854  if (acq && plugin) {
855  if (m_HeaderID >= 11) {
856  int newGain = get_DetectorGain();
857 
858  printMessage(tr("Camera Gain Changed to %1").arg(newGain));
859 
860  printMessage("Setting camera gain");
861 
862  int nRet;
863 
864  if (m_CurrentGain != get_DetectorGain()) {
865  if ((nRet=plugin->Acquisition_SetCameraGain(m_AcqDesc, get_DetectorGain())) != HIS_ALL_OK) {
866  acquisitionError(__FILE__, __LINE__, nRet);
867  return;
868  }
869  m_CurrentGain = get_DetectorGain();
870  }
871 
872  printMessage("Set camera gain");
873  }
874  }
875  }
876 }
877 
879 {
882 
883  int nRet;
884 
885  if (plugin && (nRet=plugin->Acquisition_Acquire_Image(m_AcqDesc, m_BufferSize,
886  0, HIS_SEQ_CONTINUOUS, NULL, NULL, NULL)) != HIS_ALL_OK) {
887  acquisitionError(__FILE__, __LINE__, nRet);
888  return;
889  }
890 
892  printMessage("Acquire");
893  }
894  }
895 }
896 
898 {
899  if (QThread::currentThread() != thread()) {
900  QMetaObject::invokeMethod(this, "beginAcquisition", Qt::BlockingQueuedConnection, Q_ARG(double, exposure));
901  } else {
903 
904  if (m_StartupDelayed) {
906  printMessage("Delayed Acquisition Startup");
907  }
908 
910  m_StartupDelayed = 0;
911  }
912 
913  m_Counter.fetchAndStoreOrdered(0);
914 
916 
917  if (plugin && m_AcqDesc) {
919  printMessage("Reset frame counter");
920  }
921 
922  plugin -> Acquisition_ResetFrameCnt(m_AcqDesc);
923  }
924  }
925 }
926 
928 {
929  if (QThread::currentThread() != thread()) {
930  QMetaObject::invokeMethod(this, "endAcquisition", Qt::BlockingQueuedConnection);
931  } else {
933  }
934 }
935 
937 {
938  if (QThread::currentThread() != thread()) {
939  QMetaObject::invokeMethod(this, "shutdownAcquisition", Qt::BlockingQueuedConnection);
940  } else {
942 
944 
945  if (plugin && m_AcqDesc) {
946  plugin->Acquisition_Abort(m_AcqDesc);
947  }
948  }
949 }
950 
951 void QxrdDetectorPerkinElmer::onEndFrame(int counter, unsigned int n1, unsigned int n2)
952 {
953  // QTime tic;
954  // tic.start();
955 
959 
960  if (plugin && acq) {
962  get_NCols(), get_NRows(), this);
963 
964  // printf("allocator took %d msec\n", tic.restart());
965 
967  printMessage(tr("QxrdDetectorPerkinElmer::onEndFrame(%1,%2,%3)")
968  .arg(counter).arg(n1).arg(n2));
969  }
970 
971  QcepMutexLocker lock(__FILE__, __LINE__, &m_Mutex);
972 
973  // if (get_Cancelling()) {
974  // set_Cancelling(false);
975  // return /*true*/;
976  // }
977 
978  long npixels = get_NRows()*get_NCols();
979 
980  unsigned short* frame = m_Buffer.data() + m_BufferIndex*npixels;
981 
982  DWORD /*actualFrame = n1,*/ actSecFrame = n2;
983 
984  // this->Acquisition_GetActFrame(m_AcqDesc, &actualFrame, &actSecFrame);
985  //
986  // if (n1 != actualFrame || n2 != actSecFrame) {
987  // printf("Lost frame, %d[%d], %d[%d]\n", n1, (int) actualFrame, n2, (int) actSecFrame);
988  // return;
989  // }
990 
991 #if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0))
992  int counter1 = m_Counter.load();
993 #else
994  int counter1 = m_Counter;
995 #endif
996 
997  if ((counter1 - counter) > 5) {
998  printMessage(tr("%1 frames behind [%2,%3], skipping")
999  .arg(counter1-counter).arg(counter).arg(counter1));
1000  return;
1001  }
1002 
1003  if (((actSecFrame-1)%m_BufferSize) != m_BufferIndex) {
1005  printMessage(tr("actSecFrame %1, m_BufferIndex %2")
1006  .arg(actSecFrame).arg(m_BufferIndex));
1007  }
1008  }
1009 
1010  quint16* current = (image ? image->data() : NULL);
1011  quint32 cksum = 0;
1012  double avg = 0;
1013 
1014  unsigned short *fp = frame;
1015 
1016  for (long i=0; i<npixels; i++) {
1017  unsigned short val = *fp++;
1018  cksum += val;
1019  avg += val;
1020  }
1021 
1022  if (current && frame) {
1023  ::memcpy(current, frame, npixels*sizeof(quint16));
1024  }
1025 
1026  // printf("Image copy took %d msec\n", tic.restart());
1027 
1028  // set_Average(avg/npixels);
1029 
1031  printMessage(tr("Frame checksum 0x%1, avg %2\n")
1032  .arg(cksum,8,16,QChar('0')).arg(avg/npixels));
1033 
1034  for (int f=0; f<m_BufferSize; f++) {
1035  unsigned short* fp = m_Buffer.data() + f*npixels;
1036 
1037  quint32 cksum = 0;
1038  double avg = 0;
1039 
1040  for (long i=0; i<npixels; i++) {
1041  unsigned short val = *fp++;
1042  cksum += val;
1043  avg += val;
1044  }
1045 
1046  printMessage(tr("Frame %1 checksum 0x%2, avg %3\n")
1047  .arg(f).arg(cksum,8,16,QChar('0')).arg(avg/npixels));
1048  }
1049  }
1050 
1052 
1053  // acquiredFrameAvailable(image);
1054 
1055  if (image) {
1056  image->set_ImageSequenceNumber(counter1);
1057  image->set_ImageNumber(n1);
1058  }
1059 
1060  enqueueAcquiredFrame(image);
1061  }
1062  }
1063 }
1064 
1065 void QxrdDetectorPerkinElmer::acquisitionInitError(const char *fn, int ln, int n)
1066 {
1067  acquisitionError(fn, ln, n);
1068 
1069  criticalMessage("Detector Initialization Failed");
1070 }
1071 
1072 void QxrdDetectorPerkinElmer::acquisitionNSensorsError(const char *fn, int ln, int n)
1073 {
1074  acquisitionError(fn, ln, n);
1075 
1076  criticalMessage("Detector Initialization Failed");
1077 }
1078 
1079 //void QxrdDetectorPerkinElmer::setupCameraGainMenu(QComboBox *cb, int initialGain)
1080 //{
1081 // if (qcepDebug(DEBUG_PERKINELMER)) {
1082 // printMessage(tr("QxrdAcquisitionPerkinElmer::setupCameraGainMenu m_HeaderID == %1").arg(m_HeaderID));
1083 // }
1084 
1085 // bool b = cb -> blockSignals(true);
1086 
1087 // if (m_HeaderID == 11) { /* AM type */
1088 // for (int i=0; i<16; i++) {
1089 // QString msg;
1090 
1091 // if (i==0) {
1092 // msg = "High: ";
1093 // } else if (i==15) {
1094 // msg = "Low: ";
1095 // }
1096 
1097 // double value = 0.1;
1098 // if (i & 1) {
1099 // value += 0.3;
1100 // }
1101 
1102 // if (i & 2) {
1103 // value += 0.9;
1104 // }
1105 
1106 // if (i & 4) {
1107 // value += 4.7;
1108 // }
1109 
1110 // if (i & 8) {
1111 // value += 10.0;
1112 // }
1113 
1114 // msg += tr("%1 pF").arg(value);
1115 
1116 // cb -> addItem(msg);
1117 // }
1118 // } else if (m_HeaderID >= 12) { /* AN type */
1119 // cb -> addItem(tr("High: 0.25 pF"));
1120 // cb -> addItem(tr("0.5 pF"));
1121 // cb -> addItem(tr("1 pF"));
1122 // cb -> addItem(tr("2 pF"));
1123 // cb -> addItem(tr("4 pF"));
1124 // cb -> addItem(tr("Low: 8 pF"));
1125 // } else {
1126 // cb -> addItem(tr("Gain not settable"));
1127 // }
1128 
1129 // cb -> setCurrentIndex(initialGain);
1130 
1131 // cb -> blockSignals(b);
1132 //}
1133 
1134 //void QxrdDetectorPerkinElmer::setupCameraBinningModeMenu(QComboBox *cb, int initialBinning)
1135 //{
1138 // bool b = cb -> blockSignals(true);
1139 
1140 // if (m_HeaderID == 14) {
1141 // if (m_CameraType == 1) {
1142 // cb -> addItem(tr("No binning"));
1143 // cb -> addItem(tr("2x2 binning"));
1144 // } else {
1145 // cb -> addItem(tr("No binning"));
1146 // cb -> addItem(tr("2x2 binning"));
1147 // }
1148 // } else {
1149 // cb -> addItem(tr("No binning"));
1150 // }
1151 
1152 // cb -> setCurrentIndex(initialBinning);
1153 
1154 // cb -> blockSignals(b);
1155 //}
1156 
1158 {
1159 // QTime tic;
1160  // tic.start();
1164 
1165  if (plugin && acq) {
1166  QxrdSynchronizedAcquisitionPtr sync(acq->synchronizedAcquisition());
1167 
1168  if (sync) {
1169 #if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0))
1170  sync->acquiredFrameAvailable(m_Counter.load());
1171 #else
1172  sync->acquiredFrameAvailable(m_Counter);
1173 #endif
1174  }
1175 
1176  // printf("syncAcq->acquiredFrameAvailable took %d msec\n", tic.restart());
1177 
1178  DWORD actualFrame, actSecFrame;
1179 
1180  plugin->Acquisition_GetActFrame(m_AcqDesc, &actualFrame, &actSecFrame);
1181  plugin->Acquisition_GetLatestFrameHeader(m_AcqDesc, &m_HwHeaderInfo, &m_HwHeaderInfoEx);
1182 
1183  // printf("m_PerkinElmer->Acquisition_GetActFrame took %d msec\n", tic.restart());
1184 
1185  int counter = m_Counter.fetchAndAddOrdered(1) + 1;
1186 
1187  // printf("m_Counter.fetchAndAddOrdered took %d msec\n", tic.restart());
1188 
1189  onEndFrame(counter, actualFrame, actSecFrame);
1190  }
1191  }
1192 }
1193 
1194 static void CALLBACK OnEndFrameCallback(HACQDESC hAcqDesc)
1195 {
1196  QxrdApplication *app = qobject_cast<QxrdApplication*>(g_Application);
1197 
1198  if (app) {
1199  QxrdPerkinElmerPluginInterfacePtr plugin(app->perkinElmerPlugin());
1200 
1201  if (hAcqDesc && plugin) {
1203 
1204  plugin->Acquisition_GetAcqData(hAcqDesc, &object);
1205 
1206  QxrdDetectorPerkinElmer *detector = reinterpret_cast<QxrdDetectorPerkinElmer*>(object);
1207 
1208  if (detector && detector->isEnabled()) {
1209  detector->onEndFrameCallback();
1210  }
1211  }
1212  }
1213 }
1214 
1215 static void CALLBACK OnEndAcqCallback(HACQDESC /*hAcqDesc*/)
1216 {
1217 }
1218 
1220 {
1221  printMessage(tr("Detector Header Info"));
1222  printMessage(tr("HeaderID %1 PROMID %2 Frame %3 Msec %4 Usec %5 Status %6")
1223  .arg(m_HwHeaderInfo.dwHeaderID)
1224  .arg(m_HwHeaderInfo.dwPROMID)
1225  .arg(m_HwHeaderInfoEx.wFrameCnt)
1226  .arg(m_HwHeaderInfoEx.wRealInttime_milliSec)
1227  .arg(m_HwHeaderInfoEx.wRealInttime_microSec)
1228  .arg(m_HwHeaderInfoEx.wStatus));
1229 
1230  printMessage(tr("Cmd1 %1 Cmd2 %2 Cmd3 %3 Cmd4 %4")
1231  .arg(m_HwHeaderInfoEx.wCommand1)
1232  .arg(m_HwHeaderInfoEx.wCommand2)
1233  .arg(m_HwHeaderInfoEx.wCommand3)
1234  .arg(m_HwHeaderInfoEx.wCommand4));
1235 }
1236 
1237 
QSharedPointer< QxrdExperiment > QxrdExperimentPtr
void onEndFrame(int counter, unsigned int n1, unsigned int n2)
QSharedPointer< QxrdDetectorProxy > QxrdDetectorProxyPtr
virtual void pushPropertiesToProxy(QxrdDetectorProxyPtr proxy)
QxrdExperimentWPtr m_Experiment
Definition: qxrddetector.h:93
int detectorSubType() const
qint64 qcepDebug(int cond)
Definition: qcepdebug.cpp:26
void criticalMessage(QString msg, QDateTime ts=QDateTime::currentDateTime()) const
QSharedPointer< QxrdAcquisition > QxrdAcquisitionPtr
void printMessage(QString msg, QDateTime ts=QDateTime::currentDateTime()) const
QSharedPointer< QxrdPerkinElmerPluginInterface > QxrdPerkinElmerPluginInterfacePtr
static void CALLBACK OnEndAcqCallback(HACQDESC hAcqDesc)
void pushPropertiesToProxy(QxrdDetectorProxyPtr proxy)
virtual void pullPropertiesfromProxy(QxrdDetectorProxyPtr proxy)
void acquisitionNSensorsError(const char *fn, int ln, int n)
void beginAcquisition(double exposure)
QxrdAcquisitionWPtr m_Acquisition
Definition: qxrddetector.h:94
#define FALSE
Definition: triangulate.c:3
JSON Parse a string as a JSON object
QWeakPointer< QxrdExperiment > QxrdExperimentWPtr
bool checkDetectorEnabled()
void enqueueAcquiredFrame(QcepImageDataBasePtr img)
void pullPropertiesfromProxy(QxrdDetectorProxyPtr proxy)
QSharedPointer< QxrdSynchronizedAcquisition > QxrdSynchronizedAcquisitionPtr
static void CALLBACK OnEndFrameCallback(HACQDESC hAcqDesc)
static void pushDefaultsToProxy(QxrdDetectorProxyPtr proxy)
virtual void startDetector()
void acquisitionInitError(const char *fn, int ln, int n)
void acquisitionError(const char *fn, int ln, int n)
#define THREAD_CHECK
Definition: qcepmacros.h:11
QxrdPerkinElmerPluginInterfaceWPtr m_PerkinElmer
QString detectorAddress() const
static QcepInt16ImageDataPtr newInt16Image(AllocationStrategy strat, int width, int height, QcepObject *parent)
QWeakPointer< QxrdAcquisition > QxrdAcquisitionWPtr
QcepApplication * g_Application
#define ACQDATATYPE
static void pushDefaultsToProxy(QxrdDetectorProxyPtr proxy, int detType)
QxrdDetectorPerkinElmer(QcepSettingsSaverWPtr saver, QxrdExperimentWPtr expt, QxrdAcquisitionWPtr acq, int detNum, QcepObject *parent)
virtual void shutdownAcquisition()
virtual void endAcquisition()
QSharedPointer< QcepInt16ImageData > QcepInt16ImageDataPtr
virtual void beginAcquisition(double exposure)
QWeakPointer< QcepSettingsSaver > QcepSettingsSaverWPtr