ChimeraTK-DeviceAccess  03.18.00
numeric_address.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/NumericAddress.h>
6 
7 #include <iostream>
8 
9 /*
10  * When you are doing numerical addressing you usually don't have a map file
11  * yet. You directly open the device (pcie for instance) with the URI syntax
12  * which you usually put into the dmap file. In this example, the map file is
13  * only needed to tell the dummy what to simulate. In the code the map file
14  * information is not used since the numeric address is directly written in the
15  * code. Otherwise, the example is identical to "basic.cpp". Look there for
16  * additional documentation.
17  */
18 
19 int main() {
20  /*
21  * If you have the mtcadummy driver installed you can also use a pci device:
22  * myDevice("(pci:pcieunidummys6)");
23  *
24  * Note: The dummy always needs a map file to know the size of the address
25  * space to emulate.
26  */
27  ChimeraTK::Device myDevice("(dummy?map=my_device.map)");
28  myDevice.open();
29 
30  /*
31  * Here, the register is accessed by its numeric address through a special
32  * register path name. The first component is a constant defining that a
33  * numeric address will follow ("BAR"). The second component is the bar number
34  * (here 0), the third component is the address in bytes (here 32) and the
35  * optional register length in bytes (here 4, which is the default). This
36  * address matches the address of the register
37  * TEMPERATURE_CONTROLLER.SET_POINT in the map file.
38  *
39  * When using numeric addresses directly, no fixed point conversion is
40  * performed.
41  */
42  ChimeraTK::ScalarRegisterAccessor<int> temperatureSetPoint =
43  myDevice.getScalarRegisterAccessor<int>(ChimeraTK::numeric_address::BAR() / 0 / 32 * 4);
44 
45  temperatureSetPoint.read();
46  std::cout << "Current temperature set point is " << temperatureSetPoint << std::endl;
47  temperatureSetPoint += 15;
48  std::cout << "Temperature set point changed to " << temperatureSetPoint << std::endl;
49  temperatureSetPoint.write();
50 
51  myDevice.close();
52 
53  return 0;
54 }
ChimeraTK::Device::close
void close()
Close the device.
Definition: Device.cc:66
ChimeraTK::ScalarRegisterAccessor
Accessor class to read and write scalar registers transparently by using the accessor object like a v...
Definition: ScalarRegisterAccessor.h:24
ChimeraTK::numeric_address::BAR
RegisterPath BAR()
The numeric_address::BAR() function can be used to directly access registers by numeric addresses,...
Definition: NumericAddress.cc:7
main
int main()
Definition: numeric_address.cpp:19
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::Device::getScalarRegisterAccessor
ScalarRegisterAccessor< UserType > getScalarRegisterAccessor(const RegisterPath &registerPathName, size_t wordOffsetInRegister=0, const AccessModeFlags &flags=AccessModeFlags({})) const
Get a ScalarRegisterObject object for the given register.
Definition: Device.h:263
ChimeraTK::TransferElementAbstractor::write
bool write(ChimeraTK::VersionNumber versionNumber={})
Write the data to device.
Definition: TransferElementAbstractor.h:89
ChimeraTK::TransferElementAbstractor::read
void read()
Read the data from the device.
Definition: TransferElementAbstractor.h:57