2#include "debugtrace.hpp"
3#include "lasp_config.h"
14 assert(daq.getHandle() != 0);
18 DaqInScanFlag inscanflags = DAQINSCAN_FF_DEFAULT;
19 ScanOption scanoptions = SO_CONTINUOUS;
20 UlError err = ERR_NO_ERROR;
22 std::vector<DaqInChanDescriptor> indescs;
29 us enabled_ch_counter = 0;
30 for (
us chin = 0; chin < 4; chin++) {
31 if (eninchannels_without_mon[chin] ==
true) {
32 DaqInChanDescriptor indesc;
33 indesc.type = DAQI_ANALOG_SE;
34 indesc.channel = chin;
36 double rangeval = ranges.at(enabled_ch_counter);
38 if (fabs(rangeval - 1.0) < 1e-8) {
40 }
else if (fabs(rangeval - 10.0) < 1e-8) {
41 rangenum = BIP10VOLTS;
44 std::cerr <<
"Fatal: input range value is invalid" << endl;
47 indesc.range = rangenum;
48 indescs.push_back(indesc);
55 DaqInChanDescriptor indesc;
56 indesc.type = DAQI_DAC;
60 indesc.range = BIP10VOLTS;
61 indescs.push_back(indesc);
63 assert(indescs.size() == nchannels);
65 DEBUGTRACE_MESSAGE(
"Starting input scan");
67 err = ulDaqInScan(daq.getHandle(), indescs.data(), nchannels,
69 &samplerate, scanoptions, inscanflags, buf.data());
76 TransferStatus transferStatus;
77 UlError err = ulDaqInScanStatus(
daq.getHandle(), &status, &transferStatus);
91 auto runCallback = ([&](
us totalOffset) {
96 us monitorOffset = monitorOutput ? 1 : 0;
100 data.value<
double>(frame, 0) =
110 for (
us channel = 0; channel <
nchannels - monitorOffset; channel++) {
113 data.value<
double>(frame, channel + monitorOffset) =
121 TransferStatus transferStatus;
123 UlError err = ulDaqInScanStatus(
daq.getHandle(), &status, &transferStatus);
132 assert(status == SS_RUNNING);
152 UlError err = ulDaqInScanStop(
daq.getHandle());
153 if (err != ERR_NO_ERROR) {
159 :
BufHandler(daq, daq.nenoutchannels()), cb(cb) {
161 DEBUGTRACE_MESSAGE(
"Starting output scan");
162 DEBUGTRACE_PRINT(nchannels);
163 AOutScanFlag outscanflags = AOUTSCAN_FF_DEFAULT;
164 ScanOption scanoptions = SO_CONTINUOUS;
165 UlError err = ulAOutScan(daq.getHandle(), 0, 0, BIP10VOLTS,
167 &samplerate, scanoptions, outscanflags, buf.data());
174 TransferStatus transferStatus;
176 UlError err = ulAOutScanStatus(
daq.getHandle(), &status, &transferStatus);
177 if (err != ERR_NO_ERROR) {
179 throw rte(
"Unable to start output on DAQ");
181 if (status != SS_RUNNING) {
182 throw rte(
"Unable to start output on DAQ");
192 assert(
daq.getHandle() != 0);
194 UlError err = ERR_NO_ERROR;
197 TransferStatus transferStatus;
199 err = ulAOutScanStatus(
daq.getHandle(), &status, &transferStatus);
201 if (status != SS_RUNNING) {
208 cerr <<
"totalFramesCount: " <<
totalFramesCount <<
". Detected output underrun" << endl;
230 d.copyToRaw(0,
reinterpret_cast<byte_t *
>(&(
buf[0])));
240 UlError err = ulAOutScanStop(
daq.getHandle());
241 if (err != ERR_NO_ERROR) {
const DataTypeDescriptor dtype_descr
The type of data, in this case always double precision floats.
std::vector< double > buf
Storage capacity for the DAQ I/O.
us nchannels
The number of channels, number of frames per callback (block).
us totalFramesCount
Counter for the total number of frames acquired / sent since the start of the stream.
bool botenqueued
Whether the bottom part of the buffer is enqueued enqueued.
DT9837A & daq
Reference to underlying Daq.
bool topenqueued
Whether the top part of the buffer is enqueued.
Data translation DT9837A Daq device.
Used for internal throwing of exceptions.
bool monitorOutput
If set to true and if the device has this capability, the output channels are added as input channels...
Data coming from / going to DAQ. Non-interleaved format, which means data in buffer is ordered by cha...
boolvec eninchannels(const bool include_monitor=true) const
Create a vector of boolean values of the enabled input channels.
dvec inputRangeForEnabledChannels(const bool include_monitor=true) const
Returns the input range for each channel. Maximum allowed absolute value of the signal that can pass ...
DataType dtype
The number from the enumeration.
InBufHandler(DT9837A &daq, InDaqCallback cb)
bool operator()()
InBufHandler::operator()()
bool operator()()
OutBufHandler::operator()
OutBufHandler(DT9837A &daq, OutDaqCallback cb)
void throwOnPossibleUlException(UlError err)
Throws an appropriate stream exception based on the UlError number. The mapping is based on the error...
std::vector< double > dvec
std::function< void(DaqData &)> OutDaqCallback
std::function< void(const DaqData &)> InDaqCallback
void showErr(UlError err)
Print error message to stderr.
std::vector< bool > boolvec
size_t us
We often use boolean values.