DAQManager::DAQManager() { stateCount = 8; states = new uInt32[stateCount]; states[0] = 0x8; states[1] = 0xC; states[2] = 0x4; states[3] = 0x6; states[4] = 0x2; states[5] = 0x3; states[6] = 0x1; states[7] = 0x9; stateNum = 0; dataAcquired = 0; voltageData = new float64[SAMPLE_COUNT]; #ifdef _WIN32 DAQmxCreateTask("", &motorTaskHandle); DAQmxCreateTask("", &adcTaskHandle); DAQmxCreateTask("", &triggerTaskHandle); DAQmxCreateDOChan(motorTaskHandle, "Dev1/port0", "", DAQmx_Val_ChanForAllLines); DAQmxCreateDOChan(triggerTaskHandle, "Dev1/port1", "", DAQmx_Val_ChanForAllLines); DAQmxCreateAIVoltageChan(adcTaskHandle, "Dev1/ai0", "", DAQmx_Val_Cfg_Default, -10.0, 10.0, DAQmx_Val_Volts, NULL); DAQmxCfgSampClkTiming(adcTaskHandle, "", SAMPLE_FREQ, DAQmx_Val_Rising, DAQmx_Val_FiniteSamps, SAMPLE_COUNT); DAQmxCfgDigEdgeStartTrig(adcTaskHandle, "/Dev1/PFI0", DAQmx_Val_Rising); DAQmxRegisterEveryNSamplesEvent(adcTaskHandle, DAQmx_Val_Acquired_Into_Buffer, 1000, 0, EveryNCallbackWrapper, this); DAQmxStartTask(motorTaskHandle); DAQmxStartTask(triggerTaskHandle); uInt32 data; int32 written; data = states[0]; DAQmxWriteDigitalU32(motorTaskHandle, 1, 1, 10.0, DAQmx_Val_GroupByChannel, &data, &written, NULL); data=0x0; DAQmxWriteDigitalU32(triggerTaskHandle, 1, 1, 10.0, DAQmx_Val_GroupByChannel, &data, &written, NULL); #elif __APPLE__ DAQmxBaseCreateTask("motorTask", &motorTaskHandle); DAQmxBaseCreateDOChan(motorTaskHandle, "Dev1/port0", "", DAQmx_Val_ChanForAllLines); DAQmxBaseStartTask(motorTaskHandle); DAQmxBaseCreateTask("adcTask", &adcTaskHandle); DAQmxBaseCreateAIVoltageChan(adcTaskHandle, "Dev1/ai0", "", DAQmx_Val_Cfg_Default, -10.0, 10.0, DAQmx_Val_Volts, NULL); DAQmxBaseCfgSampClkTiming(adcTaskHandle,"OnboardClock", SAMPLE_FREQ, DAQmx_Val_Rising, DAQmx_Val_ContSamps, SAMPLE_COUNT); DAQmxBaseCfgInputBuffer(adcTaskHandle,0); DAQmxBaseStartTask(adcTaskHandle); uInt32 data; int32 written; data = states[0]; DAQmxBaseWriteDigitalU32(motorTaskHandle, 1, 1, 10.0, DAQmx_Val_GroupByChannel, &data, &written, NULL); #endif }
void DAQManager::motorAdvance(){ uInt32 data; int32 written; data = states[stateNum]; #ifdef _WIN32 DAQmxWriteDigitalU32(motorTaskHandle, 1, 1, 10.0, DAQmx_Val_GroupByChannel, &data, &written, NULL); stateNum++; if (stateNum == stateCount) stateNum = 0; Sleep(5); #elif __APPLE__ DAQmxBaseWriteDigitalU32(motorTaskHandle, 1, 1, 10.0, DAQmx_Val_GroupByChannel, &data, &written, NULL); stateNum++; if (stateNum == stateCount) stateNum = 0; usleep(5000); #endif }
std::size_t DigitalOutputTask::write(const std::uint32_t &firstSample, std::size_t numSamples, double timeout) { nidaqmxbase::int32_t sampsPerChanWritten; std::int32_t error = DAQmxBaseWriteDigitalU32(getHandle(), numSamples, FALSE, timeout, DAQmx_Val_GroupByChannel, reinterpret_cast<nidaqmxbase::uint32_t *>(const_cast<std::uint32_t *>(&firstSample)), &sampsPerChanWritten, NULL); Error::throwIfFailed(error); return std::size_t(sampsPerChanWritten); }