ChimeraTK-DeviceAccess  03.18.00
accessor1D.cpp
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: Deutsches Elektronen-Synchrotron DESY, MSK, ChimeraTK Project <chimeratk-support@desy.de>
2 // SPDX-License-Identifier: LGPL-3.0-or-later
3 
4 #include <ChimeraTK/Device.h>
5 #include <ChimeraTK/Utilities.h>
6 
7 #include <iostream>
8 
9 int main() {
10  ChimeraTK::setDMapFilePath("example.dmap");
11 
12  ChimeraTK::Device myDevice("MY_DEVICE");
13  myDevice.open();
14 
15  /*
16  * The device contains a register called CLOCKS in the BOARD section.
17  * It contains 4 values for 4 different clocks.
18  */
19  ChimeraTK::OneDRegisterAccessor<double> clocks = myDevice.getOneDRegisterAccessor<double>("BOARD/CLOCKS");
20  std::cout << "The clocks register has " << clocks.getNElements() << " elements." << std::endl;
21 
22  /*
23  * Read data for the whole register from the hardware
24  */
25  clocks.read();
26 
27  /*
28  * The OneDRegisterAccessor behaves like a std::vector, incl. [] operator
29  * and iterators.
30  */
31  for(size_t i = 0; i < clocks.getNElements(); ++i) {
32  clocks[i] = 42 + i;
33  }
34  std::cout << "Clocks are";
35  for(auto clockValue : clocks) {
36  std::cout << " " << clockValue;
37  }
38  std::cout << std::endl;
39 
40  /*
41  * Write all values of the CLOCKS register to the hardware.
42  */
43  clocks.write();
44 
45  myDevice.close();
46 
47  return 0;
48 }
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::async
Definition: design_AsyncNDRegisterAcessor_and_NumericAddressedBackend.dox:1
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
Definition: DummyBackend.h:16
ChimeraTK::TransferElementAbstractor::read
void read()
Read the data from the device.
Definition: TransferElementAbstractor.h:57