ChimeraTK-DeviceAccess 03.25.00
Loading...
Searching...
No Matches
accessor2D.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 * In this example there is a data region called "DATA" in
17 * a module called "ADC".
18 */
19 ChimeraTK::TwoDRegisterAccessor<double> twoDAccessor = myDevice.getTwoDRegisterAccessor<double>("ADC/DATA");
20
21 /*
22 * Read data for all channels from the hardware
23 */
24 twoDAccessor.read();
25
26 /*
27 * You can access each sequence/channel individually. They are std::vectors.
28 * You get a reference to the vector inside the accessor. No data copying.
29 */
30 for(size_t i = 0; i < twoDAccessor.getNChannels(); ++i) {
31 std::cout << "Channel " << i << ":";
32 std::vector<double>& channel = twoDAccessor[i];
33 for(double sample : channel) {
34 std::cout << " " << sample;
35 }
36 std::cout << std::endl;
37 }
38
39 /*
40 * You can modify the stuff at will in the accessors internal buffer.
41 * In this example we use two [] operators like a 2D array.
42 */
43 for(size_t i = 0; i < twoDAccessor.getNChannels(); ++i) {
44 for(size_t j = 0; j < twoDAccessor.getNElementsPerChannel(); ++j) {
45 twoDAccessor[i][j] = i * 100 + j;
46 }
47 }
48
49 /*
50 * Finally write to the hardware.
51 */
52 twoDAccessor.write();
53
54 myDevice.close();
55
56 return 0;
57}
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.