14 #ifndef NIDAQMXDRIVER_H_
15 #define NIDAQMXDRIVER_H_
17 #include "interface.h"
19 #include "atomic_queue.h"
23 #define CHECK_DAQMX_ERROR(ret) XNIDAQmxInterface::checkDAQmxError(ret, __FILE__, __LINE__)
28 #define CHECK_DAQMX_RET(ret) {int code__ = ret; \
29 if(CHECK_DAQMX_ERROR(code__) > 0) {gWarnPrint(XNIDAQmxInterface::getNIDAQmxErrMessage(code__)); } }
31 #define CHECK_DAQMX_ERROR(ret) (0)
32 #define CHECK_DAQMX_RET(ret)
33 typedef unsigned int TaskHandle;
34 typedef int64_t int64;
35 typedef uint64_t uInt64;
36 typedef int32_t int32;
37 typedef uint32_t uInt32;
38 typedef int16_t int16;
39 typedef uint16_t uInt16;
41 typedef uint8_t uInt8;
42 typedef double float64;
43 #endif //HAVE_NI_DAQMX
49 XNIDAQmxInterface(
const char *name,
bool runtime,
const shared_ptr<XDriver> &driver);
52 static XString getNIDAQmxErrMessage();
53 static XString getNIDAQmxErrMessage(
int status);
54 static int checkDAQmxError(
int ret,
const char*file,
int line);
56 virtual bool isOpened()
const {
return m_devname.length();}
59 const char*
devName()
const {
return m_devname.c_str();}
61 static void parseList(
const char *list, std::deque<XString> &buf);
63 void synchronizeClock(TaskHandle task);
67 XNIDAQmxRoute(
const char*src,
const char*dst,
int *ret = NULL);
76 return p ? p->type : 0L;
81 return p ? p->series : 0L;
87 FLAG_BUGGY_DMA_AO = 0x10u, FLAG_BUGGY_DMA_AI = 0x20u,
88 FLAG_BUGGY_DMA_DI = 0x40u, FLAG_BUGGY_DMA_DO = 0x80u,
89 FLAG_BUGGY_XFER_COND_AO = 0x100u, FLAG_BUGGY_XFER_COND_AI = 0x200u,
90 FLAG_BUGGY_XFER_COND_DI = 0x400u, FLAG_BUGGY_XFER_COND_DO = 0x800u};
95 double maxAORate(
unsigned int )
const {
return m_productInfo->
ao_max_rate;}
96 double maxDIRate(
unsigned int )
const {
return m_productInfo->
di_max_rate;}
97 double maxDORate(
unsigned int )
const {
return m_productInfo->
do_max_rate;}
104 static shared_ptr<SoftwareTrigger> create(
const char *label,
unsigned int bits);
105 static void unregister(
const shared_ptr<SoftwareTrigger> &);
106 const char *label()
const {
return m_label.c_str();}
107 void setArmTerm(
const char *arm_term) {m_armTerm = arm_term;}
108 const char *armTerm()
const {
return m_armTerm.c_str();}
109 bool isPersistentCoherentMode()
const {
return m_isPersistentCoherent;}
110 void setPersistentCoherentMode(
bool x) {m_isPersistentCoherent = x;}
111 void start(float64
freq);
113 unsigned int bits()
const {
return m_bits;}
115 void forceStamp(uint64_t now, float64 freq);
116 void stamp(uint64_t cnt);
118 template <
typename T>
120 if(((m_risingEdgeMask & val) & (m_risingEdgeMask & ~oldval))
121 || ((m_fallingEdgeMask & ~val) & (m_fallingEdgeMask & oldval))) {
127 void connect(uint32_t rising_edge_mask,
132 m_blankTerm = llrint(blankterm *
freq());
143 void clear(uint64_t now, float64 freq);
147 uint64_t
tryPopFront(uint64_t threshold, float64 freq);
149 typedef std::deque<shared_ptr<XNIDAQmxInterface::SoftwareTrigger> > SoftwareTriggerList;
150 typedef SoftwareTriggerList::iterator SoftwareTriggerList_it;
152 return s_virtualTrigList;
159 uint32_t m_risingEdgeMask, m_fallingEdgeMask;
160 uint64_t m_blankTerm;
163 enum {QUEUE_SIZE = 8192};
166 typedef std::deque<uint64_t> SlowQueue;
173 bool m_isPersistentCoherent;
178 virtual
void close() throw (XInterfaceError &);
198 template<
class tDriver>
202 Transaction &tr_meas,
const shared_ptr<XMeasure> &meas);
205 const shared_ptr<XNIDAQmxInterface> &interface()
const {
return m_interface;}
215 shared_ptr<XListener> m_lsnOnOpen, m_lsnOnClose;
217 const shared_ptr<XNIDAQmxInterface> m_interface;
219 template<
class tDriver>
221 Transaction &tr_meas,
const shared_ptr<XMeasure> &meas) :
222 tDriver(name, runtime, ref(tr_meas), meas),
224 dynamic_pointer_cast<
XDriver>(this->shared_from_this()))) {
225 meas->interfaces()->insert(tr_meas, m_interface);
227 m_lsnOnOpen = tr[ *interface()].onOpen().connectWeakly(
229 m_lsnOnClose = tr[ *interface()].onClose().connectWeakly(
233 template<
class tDriver>
240 e.print(this->getLabel() + i18n(
": Opening driver failed, because "));
244 template<
class tDriver>
251 e.print(this->getLabel() + i18n(
": Stopping driver failed, because "));
255 template<
class tDriver>