4 #if QT_VERSION >= 0x040700
5 #include <QElapsedTimer>
8 #include <QMutexLocker>
11 #define DAQmxErrChk(functionCall) do { if( DAQmxFailed(error=(functionCall)) ) { QxrdNIDAQPlugin::errorCheck(__FILE__,__LINE__,error); goto Error; } } while(0)
21 setObjectName(
"nidaq");
72 QMetaObject::invokeMethod(
m_ErrorOutput,
"printMessage", Qt::QueuedConnection, Q_ARG(QString, msg));
78 if (DAQmxFailed(err)) {
79 int sz = DAQmxGetErrorString(err, NULL, 0);
82 char *buff = (
char*) malloc(sz);
84 if (DAQmxGetErrorString(err, buff, sz) == 0) {
86 QMetaObject::invokeMethod(
m_ErrorOutput,
"printMessage", Qt::QueuedConnection,
87 Q_ARG(QString, tr(
"%1:%2 NI-DAQ Error %3 : %4").arg(file).arg(line).arg(err).arg(buff)))) {
89 printf(
"%s:%d NI-DAQ Error %d : %s\n", file, line, err, buff);
252 qPrintable(tr(
"Dev1/ai%1").arg(chan)), NULL, DAQmx_Val_Cfg_Default, -10.0, 10.0, DAQmx_Val_Volts, NULL));
278 qPrintable(tr(
"Dev1/ao%1").arg(chan)), NULL, -10.0, 10.0, DAQmx_Val_Volts, NULL));
303 qPrintable(channelName),
306 DAQmx_Val_Volts, NULL));
331 qPrintable(chan), NULL, -10.0, 10.0, DAQmx_Val_Volts, NULL));
335 DAQmxCfgSampClkTiming(
m_AOTaskHandle, NULL, rate, DAQmx_Val_Rising, DAQmx_Val_FiniteSamps, size)
339 DAQmxWriteAnalogF64(
m_AOTaskHandle, size,
false, -1, DAQmx_Val_GroupByChannel, wfm, &nsampwrt, NULL)
414 static TaskHandle counterTask = 0;
418 if (counterTask == 0) {
419 DAQmxErrChk(DAQmxCreateTask(
"counter", &counterTask));
420 DAQmxErrChk(DAQmxCreateCICountEdgesChan(counterTask,
"Dev1/ctr2",
"", DAQmx_Val_Rising, 0, DAQmx_Val_CountUp));
421 DAQmxErrChk(DAQmxSetCICountEdgesTerm(counterTask,
"/Dev1/ctr2",
"/Dev1/100MHzTimebase"));
426 DAQmxErrChk(DAQmxReadCounterScalarF64(counterTask, 0, &res, NULL));
432 DAQmxClearTask(counterTask);
452 foreach(QString chan, chans) {
453 QStringList parsed = chan.split(
",");
454 QString ch = parsed.value(0);
455 QString sig = parsed.value(1);
457 DAQmxErrChk(DAQmxCreateCICountEdgesChan(
m_CountersTask, qPrintable(parsed.value(0)),
"", DAQmx_Val_Rising, 0, DAQmx_Val_CountUp));
487 m_Counts[i] = counts[i];
494 return QVector<double>();
501 QVector<double> minVals,
502 QVector<double> maxVals)
513 QRegExp re_ai(
"^(.*)/ai\\d+$");
514 QRegExp re_ci(
"^(.*)/ctr\\d+$");
521 for(
int i=0; i<chans.count(); i++) {
522 QString chan = chans.value(i);
524 if (re_ai.exactMatch(chan)) {
527 DAQmx_Val_Cfg_Default,
530 DAQmx_Val_Volts, NULL ));
535 if (re_ai.capturedTexts().count() >= 2) {
536 if (aiDevice.count() == 0) {
537 aiDevice = re_ai.capturedTexts().value(1);
541 printMessage(tr(
"Analog input channel : %1").arg(chan));
542 }
else if (re_ci.exactMatch(chan)) {
549 DAQmxErrChk(DAQmxCreateCICountEdgesChan(thdl, qPrintable(chan),
"", DAQmx_Val_Rising, 0, DAQmx_Val_CountUp));
554 if (re_ci.capturedTexts().count() >= 2) {
555 if (aiDevice.count() == 0) {
556 aiDevice = re_ci.capturedTexts().value(1);
560 printMessage(tr(
"Counter input channel : %1").arg(chan));
571 qPrintable(tr(
"%1/ai0").arg(aiDevice)),
"",
572 DAQmx_Val_Cfg_Default, -10.0, 10.0, DAQmx_Val_Volts, NULL ));
584 sampleRate, DAQmx_Val_Rising, DAQmx_Val_ContSamps, bufferSize));
590 DAQmxErrChk(DAQmxCfgSampClkTiming(tsk, qPrintable(tr(
"/%1/ai/SampleClock").arg(aiDevice)),
591 sampleRate, DAQmx_Val_Rising, DAQmx_Val_ContSamps, bufferSize));
592 DAQmxErrChk(DAQmxSetBufInputBufSize(tsk, bufferSize));
593 DAQmxErrChk(DAQmxSetReadOverWrite(tsk, DAQmx_Val_OverwriteUnreadSamps));
633 ciBuff[i].resize(m_NContinuousSamples + 1);
639 if (avail < m_NContinuousSamples) {
653 uInt64 lastSample[30];
657 DAQmx_Val_GroupByChannel, aiBuff.data(), aiBuff.count(),
658 &actuallyRead, NULL));
669 DAQmxErrChk(DAQmxGetReadCurrReadPos(tsk, ¤tPos));
670 DAQmxErrChk(DAQmxSetReadRelativeTo(tsk, DAQmx_Val_CurrReadPos));
671 int32 offset = ((int64)lastSample[0]) - ((int64)currentPos) - (m_NContinuousSamples+1);
673 DAQmxErrChk(DAQmxReadCounterF64(tsk, m_NContinuousSamples+1, -1,
674 ciBuff[i].data(), ciBuff[i].
count(),
675 &actuallyRead, NULL));
678 DAQmxErrChk(DAQmxGetReadCurrReadPos(tsk, &lastSample[i+1]));
680 if (lastSample[i+1] != lastSample[i]) {
681 printf(
"Sync error %ld:%ld\n", lastSample[i+1], lastSample[i]);
689 ciBuff[i][j] = ciBuff[i][j+1] - ciBuff[i][j];
692 ciBuff[i].resize(m_NContinuousSamples);
736 char buffer[5120]=
"";
739 DAQmxErrChk(DAQmxGetSysDevNames(buffer,
sizeof(buffer)));
743 QStringList result = QString(buffer).split(
", ");
750 char buffer[5120]=
"";
753 DAQmxErrChk(DAQmxGetDevProductType(qPrintable(device), buffer,
sizeof(buffer)));
756 QString result = QString(buffer);
767 DAQmxErrChk(DAQmxGetDevIsSimulated(qPrintable(device), &res));
775 char buffer[5120]=
"";
778 DAQmxErrChk(DAQmxGetDevAIPhysicalChans(qPrintable(device), buffer,
sizeof(buffer)));
782 QStringList result = QString(buffer).split(
", ");
789 char buffer[5120]=
"";
792 DAQmxErrChk(DAQmxGetDevAOPhysicalChans(qPrintable(device), buffer,
sizeof(buffer)));
795 QStringList result = QString(buffer).split(
", ");
802 char buffer[5120]=
"";
805 DAQmxErrChk(DAQmxGetDevDIPorts(qPrintable(device), buffer,
sizeof(buffer)));
808 QStringList result = QString(buffer).split(
", ");
815 char buffer[5120]=
"";
818 DAQmxErrChk(DAQmxGetDevDILines(qPrintable(port), buffer,
sizeof(buffer)));
821 QStringList result = QString(buffer).split(
", ");
828 char buffer[5120]=
"";
831 DAQmxErrChk(DAQmxGetDevDOPorts(qPrintable(device), buffer,
sizeof(buffer)));
834 QStringList result = QString(buffer).split(
", ");
841 char buffer[5120]=
"";
844 DAQmxErrChk(DAQmxGetDevDOLines(qPrintable(port), buffer,
sizeof(buffer)));
847 QStringList result = QString(buffer).split(
", ");
854 char buffer[5120]=
"";
857 DAQmxErrChk(DAQmxGetDevCIPhysicalChans(qPrintable(device), buffer,
sizeof(buffer)));
860 QStringList result = QString(buffer).split(
", ");
867 char buffer[5120]=
"";
870 DAQmxErrChk(DAQmxGetDevCOPhysicalChans(qPrintable(device), buffer,
sizeof(buffer)));
873 QStringList result = QString(buffer).split(
", ");
884 DAQmxErrChk(DAQmxCreateTask(
"qxrd-analog-in", &task));
886 qPrintable(channelName),
888 DAQmx_Val_Cfg_Default, -10.0, 10.0,
889 DAQmx_Val_Volts, NULL));
891 DAQmxErrChk(DAQmxReadAnalogScalarF64(task, 10.0, &res, NULL));
894 DAQmxClearTask(task);
899 #if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0))
int configCounters(QStringList chans)
void setAnalogOutput(int chan, double val)
void triggerAnalogWaveform()
double count(int chan, double time)
double getAnalogInput(int chan)
QStringList deviceDOPorts(QString device)
QVector< double > m_Counts
QVector< double > readCounters()
TaskHandle m_ContinuousAITask
virtual void finishContinuousInput()
virtual int countContinuousInput()
QStringList deviceDIPorts(QString device)
virtual int readContinuousInput()
TaskHandle m_AITaskHandle
void errorCheck(const char *file, int line, int err)
virtual ~QxrdNIDAQPlugin()
QVector< QVector< double > > m_ContinuousInputData
QStringList deviceCOChannels(QString device)
QVector< TaskHandle > m_ContinuousCITasks
TaskHandle m_AOTaskHandle
#define DAQmxErrChk(functionCall)
virtual void setErrorOutput(QObject *errors)
QStringList deviceAOChannels(QString device)
TaskHandle m_CountersTask
QString deviceType(QString device)
virtual int prepareContinuousInput(double sampleRate, double acquireDelay, double exposureTime, QStringList chans, QVector< double > minVals, QVector< double > maxVals)
QStringList deviceDILines(QString port)
QStringList deviceAIChannels(QString device)
QVector< int > m_ContinuousChans
void setAnalogWaveform(QString chan, double rate, double wfm[], int size)
QStringList deviceDOLines(QString port)
int deviceIsSimulated(QString device)
QVector< int > m_ContinuousFlags
virtual QVector< double > readContinuousInputChannel(int ch)
QStringList deviceCIChannels(QString device)
void printMessage(QString msg)
QStringList deviceNames()