ChimeraTK-DeviceAccess 03.25.00
Loading...
Searching...
No Matches
accessor2D.cpp

An example how to use the TwoDRegisterAccessor.

An example how to use the TwoDRegisterAccessor

// SPDX-FileCopyrightText: Deutsches Elektronen-Synchrotron DESY, MSK, ChimeraTK Project <chimeratk-support@desy.de>
// SPDX-License-Identifier: LGPL-3.0-or-later
#include <ChimeraTK/Device.h>
#include <ChimeraTK/Utilities.h>
#include <iostream>
int main() {
ChimeraTK::setDMapFilePath("example.dmap");
ChimeraTK::Device myDevice("MY_DEVICE");
myDevice.open();
/*
* In this example there is a data region called "DATA" in
* a module called "ADC".
*/
ChimeraTK::TwoDRegisterAccessor<double> twoDAccessor = myDevice.getTwoDRegisterAccessor<double>("ADC/DATA");
/*
* Read data for all channels from the hardware
*/
twoDAccessor.read();
/*
* You can access each sequence/channel individually. They are std::vectors.
* You get a reference to the vector inside the accessor. No data copying.
*/
for(size_t i = 0; i < twoDAccessor.getNChannels(); ++i) {
std::cout << "Channel " << i << ":";
std::vector<double>& channel = twoDAccessor[i];
for(double sample : channel) {
std::cout << " " << sample;
}
std::cout << std::endl;
}
/*
* You can modify the stuff at will in the accessors internal buffer.
* In this example we use two [] operators like a 2D array.
*/
for(size_t i = 0; i < twoDAccessor.getNChannels(); ++i) {
for(size_t j = 0; j < twoDAccessor.getNElementsPerChannel(); ++j) {
twoDAccessor[i][j] = i * 100 + j;
}
}
/*
* Finally write to the hardware.
*/
twoDAccessor.write();
myDevice.close();
return 0;
}
int main()
Class allows to read/write registers from device.
Definition Device.h:39
TwoDRegisterAccessor< UserType > getTwoDRegisterAccessor(const RegisterPath &registerPathName, size_t numberOfElements=0, size_t elementsOffset=0, const AccessModeFlags &flags=AccessModeFlags({})) const
Get a TwoDRegisterAccessor object for the given register.
Definition Device.h:286
void close()
Close the device.
Definition Device.cc:66
void open(std::string const &aliasName)
Open a device by the given alias name from the DMAP file.
Definition Device.cc:58
bool write(ChimeraTK::VersionNumber versionNumber={})
Write the data to device.
void read()
Read the data from the device.
Accessor class to read and write 2D registers.
size_t getNElementsPerChannel() const
Return number of elements/samples per channel.
size_t getNChannels() const
Return the number of channels (formerly called sequences)
void setDMapFilePath(std::string dmapFilePath)
Set the location of the dmap file.