nidaqdso.h
1 /***************************************************************************
2  Copyright (C) 2002-2015 Kentaro Kitagawa
3  kitagawa@phys.s.u-tokyo.ac.jp
4 
5  This program is free software; you can redistribute it and/or
6  modify it under the terms of the GNU Library General Public
7  License as published by the Free Software Foundation; either
8  version 2 of the License, or (at your option) any later version.
9 
10  You should have received a copy of the GNU Library General
11  Public License and a list of authors along with this program;
12  see the files COPYING and AUTHORS.
13 ***************************************************************************/
14 #ifndef nidaqdsoH
15 #define nidaqdsoH
16 
17 #include "dso.h"
18 
19 #include "nidaqmxdriver.h"
20 
21 //! Software DSO w/ NI DAQmx
22 class XNIDAQmxDSO : public XNIDAQmxDriver<XDSO> {
23 public:
24  XNIDAQmxDSO(const char *name, bool runtime,
25  Transaction &tr_meas, const shared_ptr<XMeasure> &meas);
26  virtual ~XNIDAQmxDSO();
27  //! Converts raw to record
28  virtual void convertRaw(RawDataReader &reader, Transaction &tr) throw (XRecordError&);
29 protected:
30  //! Be called just after opening interface. Call start() inside this routine appropriately.
31  virtual void open() throw (XKameError &);
32  //! Be called during stopping driver. Call interface()->stop() inside this routine.
33  virtual void close() throw (XKameError &);
34 
35  virtual void onTrace1Changed(const Snapshot &shot, XValueNodeBase *);
36  virtual void onTrace2Changed(const Snapshot &shot, XValueNodeBase *);
37  virtual void onTrace3Changed(const Snapshot &shot, XValueNodeBase *);
38  virtual void onTrace4Changed(const Snapshot &shot, XValueNodeBase *);
39  virtual void onAverageChanged(const Snapshot &shot, XValueNodeBase *);
40  virtual void onSingleChanged(const Snapshot &shot, XValueNodeBase *);
41  virtual void onTrigSourceChanged(const Snapshot &shot, XValueNodeBase *);
42  virtual void onTrigPosChanged(const Snapshot &shot, XValueNodeBase *);
43  virtual void onTrigLevelChanged(const Snapshot &shot, XValueNodeBase *);
44  virtual void onTrigFallingChanged(const Snapshot &shot, XValueNodeBase *);
45  virtual void onTimeWidthChanged(const Snapshot &shot, XValueNodeBase *);
46  virtual void onVFullScale1Changed(const Snapshot &shot, XValueNodeBase *);
47  virtual void onVFullScale2Changed(const Snapshot &shot, XValueNodeBase *);
48  virtual void onVFullScale3Changed(const Snapshot &shot, XValueNodeBase *);
49  virtual void onVFullScale4Changed(const Snapshot &shot, XValueNodeBase *);
50  virtual void onVOffset1Changed(const Snapshot &shot, XValueNodeBase *);
51  virtual void onVOffset2Changed(const Snapshot &shot, XValueNodeBase *);
52  virtual void onVOffset3Changed(const Snapshot &shot, XValueNodeBase *);
53  virtual void onVOffset4Changed(const Snapshot &shot, XValueNodeBase *);
54  virtual void onRecordLengthChanged(const Snapshot &shot, XValueNodeBase *);
55  virtual void onForceTriggerTouched(const Snapshot &shot, XTouchableNode *);
56 
57  virtual double getTimeInterval();
58  //! Clears count or start sequence measurement
59  virtual void startSequence();
60  virtual int acqCount(bool *seq_busy);
61 
62  //! Loads waveform and settings from instrument
63  virtual void getWave(shared_ptr<RawData> &writer, std::deque<XString> &channels);
64 
65  virtual bool isDRFCoherentSGSupported() const {return true;}
66 private:
67  typedef int16 tRawAI;
68  shared_ptr<XNIDAQmxInterface::SoftwareTrigger> m_softwareTrigger;
69  shared_ptr<XListener> m_lsnOnSoftTrigStarted, m_lsnOnSoftTrigChanged;
70  void onSoftTrigStarted(const shared_ptr<XNIDAQmxInterface::SoftwareTrigger> &);
71  void onSoftTrigChanged(const shared_ptr<XNIDAQmxInterface::SoftwareTrigger> &);
72  shared_ptr<XThread<XNIDAQmxDSO> > m_threadReadAI;
73  void *executeReadAI(const atomic<bool> &);
74  atomic<bool> m_suspendRead;
75  atomic<bool> m_running;
76  std::vector<tRawAI> m_recordBuf;
77  enum {CAL_POLY_ORDER = 4};
78  float64 m_coeffAI[4][CAL_POLY_ORDER];
79  inline float64 aiRawToVolt(const float64 *pcoeff, float64 raw);
80  struct DSORawRecord {
81  unsigned int numCh;
82  unsigned int accumCount;
83  unsigned int recordLength;
84  int acqCount;
85  bool isComplex; //true in the coherent SG mode.
86  std::vector<int32_t> record;
87  atomic<int> locked;
88  bool tryLock() {
89  bool ret = locked.compare_set_strong(false, true);
90  return ret;
91  }
92  void unlock() {
93  assert(locked);
94  locked = false;
95  }
96  };
97  DSORawRecord m_dsoRawRecordBanks[2];
98  int m_dsoRawRecordBankLatest;
99  //! for moving av.
100  std::deque<std::vector<tRawAI> > m_record_av;
101  TaskHandle m_task;
102  double m_interval;
103  unsigned int m_preTriggerPos;
104  void clearAcquision();
105  void setupAcquision();
106  void disableTrigger();
107  void setupTrigger();
108  void clearStoredSoftwareTrigger();
109  void setupSoftwareTrigger();
110  void setupTiming();
111  void createChannels();
112  void acquire(const atomic<bool> &terminated);
113  static int32 onTaskDone_(TaskHandle task, int32 status, void*);
114  void onTaskDone(TaskHandle task, int32 status);
115 
116  XRecursiveMutex m_readMutex;
117 
118  inline bool tryReadAISuspend(const atomic<bool> &terminated);
119 };
120 
121 #endif

Generated for KAME4 by  doxygen 1.8.3