ChimeraTK-DeviceAccess  03.18.00
accessor2D.cpp

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;
}
ChimeraTK::TwoDRegisterAccessor
Accessor class to read and write 2D registers.
Definition: ForwardDeclarations.h:20
ChimeraTK::Device::close
void close()
Close the device.
Definition: Device.cc:66
main
int main()
Definition: accessor2D.cpp:9
ChimeraTK::Device
Class allows to read/write registers from device.
Definition: Device.h:39
ChimeraTK::TwoDRegisterAccessor::getNChannels
size_t getNChannels() const
Return the number of channels (formerly called sequences)
Definition: TwoDRegisterAccessor.h:41
ChimeraTK::Device::open
void open(std::string const &aliasName)
Open a device by the given alias name from the DMAP file.
Definition: Device.cc:58
ChimeraTK::Device::getTwoDRegisterAccessor
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:283
ChimeraTK::TwoDRegisterAccessor::getNElementsPerChannel
size_t getNElementsPerChannel() const
Return number of elements/samples per channel.
Definition: TwoDRegisterAccessor.h:44
ChimeraTK::setDMapFilePath
void setDMapFilePath(std::string dmapFilePath)
Set the location of the dmap file.
Definition: Utilities.cpp:327