2 #include "FPGAResonanceScanner.h"
3 #include "parameters/IO.h"
4 #include "helpers/DaqChunk.h"
5 #include "helpers/DaqChunkResonance.h"
10 :
FPGAIO5751(NiFpga_ResonanceScanner_IndicatorBool_Configured) {
11 assert(SCOPE_NAREAS == 1);
13 status = NiFpga_Initialize();
15 char*
const Bitfile =
"devices\\fpga\\" NiFpga_ResonanceScanner_Bitfile;
18 status = NiFpga_Open(Bitfile, NiFpga_ResonanceScanner_Signature,
"RIO0", 0, &
session);
19 DBOUT(L
"FPGAResonanceScanner: FPGA Session opened");
27 std::this_thread::sleep_for(std::chrono::milliseconds(500));
34 fifos[0] = NiFpga_ResonanceScanner_TargetToHostFifoU32_ToHostCh1FIFO;
35 fifos[1] = NiFpga_ResonanceScanner_TargetToHostFifoU32_ToHostCh2FIFO;
40 status = NiFpga_Finalize();
41 DBOUT(L
"FPGAResonanceScanner::~FPGAResonanceScanner session closed");
50 uint32_t chunksize = 1000000;
61 status = NiFpga_WriteU16(
session, NiFpga_ResonanceScanner_ControlU32_Samplesperpixel, samplesperpixel);
63 DBOUT(L
"FPGAResonanceScanner::SetPixeltime samples per pixel: " << samplesperpixel);
70 status = NiFpga_WriteU16(
session, NiFpga_ResonanceScanner_ControlU32_Samplesperline, samplesperline);
72 DBOUT(L
"FPGAResonanceScanner::SetPixeltime samples per line" << samplesperline);
78 status = NiFpga_WriteBool(
session, NiFpga_ResonanceScanner_ControlBool_Waitfortrigger, _waitfortrigger);
82 status = NiFpga_WriteBool(
session, NiFpga_ResonanceScanner_ControlBool_Acquirecontinuously, _cont);
86 status = NiFpga_WriteU32(
session, NiFpga_ResonanceScanner_ControlU32_Requestedpixels, _reqpixels);
92 status = NiFpga_WriteBool(
session, NiFpga_ResonanceScanner_ControlBool_Acquire,
true);
99 assert( (_chunk.NChannels() == 2) && (_chunk.Area() == 0) );
102 assert(_chunk.
data.size() >= _chunk.PerChannel() * _chunk.NChannels());
104 NiFpga_Status stat = NiFpga_Status_Success;
106 std::vector<uint32_t> u32data(_chunk.PerChannel());
107 std::vector<int32_t> bitshift(_chunk.NChannels());
112 for ( uint32_t c = 0 ; c < _chunk.NChannels() ; c++ ) {
113 stat = NiFpga_ReadFifoU32(
session
116 , _chunk.PerChannel()
117 ,
static_cast<uint32_t
>(_timeout * 1000)
120 _timedout = (stat == NiFpga_Status_FifoTimeout);
131 std::transform(std::begin(u32data), std::end(u32data), std::begin(_chunk.
data) + c*_chunk.PerChannel(), [](
const uint32_t& _u32) {
132 return static_cast<uint16_t
>(_u32 & 0x0000ffff);
139 std::transform(std::begin(u32data), std::end(u32data), std::begin(chunkres.resSync), [](
const uint32_t& _u32) {
140 return (_u32 >> 31) != 0;
144 return _chunk.PerChannel();
150 status = NiFpga_WriteBool(
session, NiFpga_ResonanceScanner_ControlBool_Acquire,
false);
154 status = NiFpga_WriteU32(
session, NiFpga_ResonanceScanner_ControlI16_Scannerdelay, _scannerdelay);
170 status = NiFpga_ReadBool(
session, NiFpga_ResonanceScanner_IndicatorBool_ToHostCh1FIFOOverflow, &b);
172 status = NiFpga_ReadBool(
session, NiFpga_ResonanceScanner_IndicatorBool_ToHostCh2FIFOOverflow, &b);
174 status = NiFpga_ReadBool(
session, NiFpga_ResonanceScanner_IndicatorBool_InterloopFIFOOverflow, &b);
176 status = NiFpga_ReadBool(
session, NiFpga_ResonanceScanner_IndicatorBool_InterloopFIFOTimeout, &b);
178 status = NiFpga_ReadBool(
session, NiFpga_ResonanceScanner_IndicatorBool_Acquiring, &b);
180 status = NiFpga_ReadBool(
session, NiFpga_ResonanceScanner_IndicatorBool_IOModuleAIOverRange, &b);
186 status = NiFpga_WriteBool(
session, NiFpga_ResonanceScanner_ControlBool_ClearInterloopFIFO,
true);
187 std::this_thread::sleep_for(std::chrono::milliseconds(50));
188 status = NiFpga_WriteBool(
session, NiFpga_ResonanceScanner_ControlBool_ClearInterloopFIFO,
false);
191 for (
auto f :
fifos )
193 std::this_thread::sleep_for(std::chrono::milliseconds(50));
196 for (
auto f : fifos )
198 std::this_thread::sleep_for(std::chrono::milliseconds(50));
parameters::InputsFPGAResonanceScanner * parameters
the parameter set
void StartAcquisition() override
Starts the acquisition on the FPGA.
A DaqChunk contains data from all channels sequentially and additionally a bool vector for the resona...
void SetContinuousAcquisition(const bool &_cont) override
Sets if the FPGA should acquire data continuously or acquire the number of pixels per channel set wit...
void SetClockSource(NiFpga_Session _session, const uint8_t &_clock_source=0)
Possible clock sources (see adapter modules help and Configure Clock.vi from NI 5751 Clock Select exa...
void StopAcquisition() override
Stops the acquisition on the FPGA.
void CheckFPGADiagnosis()
Checks the status of the FIFOs on the FPGA.
bool CheckIOModule(NiFpga_Session _session)
Necessary calls at the moment not supported by NI FPGA API 12.0, see CheckIOModule.vi for what to do.
std::vector< uint16_t > data
The data vector.
void SetRequestedPixels(const uint32_t &_area, const uint32_t &_reqpixels) override
Sets the number of pixels per channel the FPGA should acquire, set to -1 for live scanning...
Handels the NI FlexRIO adapter module IO-5751.
A DaqChunk contains data from all channels sequentially.
This is the include file for standard system include files, or project specific include files that ar...
~FPGAResonanceScanner()
Close FPGA session.
bool initialized
true if already initialized
FPGAStatusSafe status
current FPGA status.
#define DBOUT(s)
A debug output to the debug console.
int32_t ReadPixels(DaqChunk &_chunk, const double &_timeout, bool &_timedout) override
Read only pixels from the FPGA FIFO.
FPGAResonanceScanner()
Load the FPGA bitfile, set the IO module's onboard clock and initialize the acquisition.
void Initialize(parameters::InputsFPGA *_parameters) override
Set initial parameters.
void SetScannerdelay(const uint32_t &_scannerdelay) override
Sets the scanner delay on the FPGA (used currently for resonance scanners only)
void SetChannelProps()
Set channel properties as baseline and bitshift.
void SetTriggering(const bool &_waitfortrigger) override
Sets if the FPGA should wait for a trigger before starting acquisition.
virtual void Initialize(parameters::InputsFPGA *_parameters)
Set initial parameters.
double SetLinetime(const uint32_t &_area, const double &_linetime) override
Sets the time per line (in seconds) for the generation of the line clock (if implemented) ...
void ClearFIFOs()
Clears the interloop and ToHost FIFOs.
std::array< NiFpga_ResonanceScanner_TargetToHostFifoU32, 2 > fifos
both fifos for both channels
NiFpga_Session session
NI FPGA session handle.
double SetPixeltime(const uint32_t &_area, const double &_pixeltime) override
Sets the time per pixel/dwell time (in seconds)