ChimeraTK-DeviceAccess 03.25.00
Loading...
Searching...
No Matches
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
9int 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}
int main()
Class allows to read/write registers from device.
Definition Device.h:39
void close()
Close the device.
Definition Device.cc:66
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:276
void open(std::string const &aliasName)
Open a device by the given alias name from the DMAP file.
Definition Device.cc:58
Accessor class to read and write registers transparently by using the accessor object like a vector o...
unsigned int getNElements()
Return number of elements/samples in the register.
bool write(ChimeraTK::VersionNumber versionNumber={})
Write the data to device.
void read()
Read the data from the device.
void setDMapFilePath(std::string dmapFilePath)
Set the location of the dmap file.