ChimeraTK-DeviceAccess  03.18.00
accessor1D.cpp

Example how to read a one-dimensional array.

// 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();
/*
* The device contains a register called CLOCKS in the BOARD section.
* It contains 4 values for 4 different clocks.
*/
ChimeraTK::OneDRegisterAccessor<double> clocks = myDevice.getOneDRegisterAccessor<double>("BOARD/CLOCKS");
std::cout << "The clocks register has " << clocks.getNElements() << " elements." << std::endl;
/*
* Read data for the whole register from the hardware
*/
clocks.read();
/*
* The OneDRegisterAccessor behaves like a std::vector, incl. [] operator
* and iterators.
*/
for(size_t i = 0; i < clocks.getNElements(); ++i) {
clocks[i] = 42 + i;
}
std::cout << "Clocks are";
for(auto clockValue : clocks) {
std::cout << " " << clockValue;
}
std::cout << std::endl;
/*
* Write all values of the CLOCKS register to the hardware.
*/
clocks.write();
myDevice.close();
return 0;
}
ChimeraTK::Device::close
void close()
Close the device.
Definition: Device.cc:66
ChimeraTK::Device::getOneDRegisterAccessor
OneDRegisterAccessor< UserType > getOneDRegisterAccessor(const RegisterPath &registerPathName, size_t numberOfWords=0, size_t wordOffsetInRegister=0, const AccessModeFlags &flags=AccessModeFlags({})) const
Get a OneDRegisterAccessor object for the given register.
Definition: Device.h:273
ChimeraTK::OneDRegisterAccessor::getNElements
unsigned int getNElements()
Return number of elements/samples in the register.
Definition: OneDRegisterAccessor.h:51
ChimeraTK::OneDRegisterAccessor
Accessor class to read and write registers transparently by using the accessor object like a vector o...
Definition: OneDRegisterAccessor.h:20
main
int main()
Definition: accessor1D.cpp:9
ChimeraTK::Device
Class allows to read/write registers from device.
Definition: Device.h:39
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::TransferElementAbstractor::write
bool write(ChimeraTK::VersionNumber versionNumber={})
Write the data to device.
Definition: TransferElementAbstractor.h:89
ChimeraTK::setDMapFilePath
void setDMapFilePath(std::string dmapFilePath)
Set the location of the dmap file.
Definition: Utilities.cpp:327
ChimeraTK::TransferElementAbstractor::read
void read()
Read the data from the device.
Definition: TransferElementAbstractor.h:57