ChimeraTK-DeviceAccess
03.18.00
basic.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
/*
10
* All information needed to access the device is
11
* the device alias and the register names
12
* (plus a .dmap file)
13
*/
14
15
int
main
() {
16
/*
17
* Before you use a device you have to tell DeviceAccess
18
* which dmap file to use.
19
*/
20
ChimeraTK::setDMapFilePath
(
"example.dmap"
);
21
22
/*
23
* Create a device. Make sure a device alias is present
24
* in the dmap file.
25
*/
26
ChimeraTK::Device
myDevice(
"MY_DEVICE"
);
27
myDevice.
open
();
28
29
/*
30
* Registers are defined by a path, which consists of a hierarchy of
31
* names separated by '/'. In this is example it is Module/Register.
32
* In this basic example we use a register which contains a single value
33
* (a scalar).
34
*
35
* The example device has a temperature controller with a set value.
36
*/
37
ChimeraTK::ScalarRegisterAccessor<float>
temperatureSetPoint =
38
myDevice.
getScalarRegisterAccessor
<
float
>(
"TEMPERATURE_CONTROLLER/SET_POINT"
);
39
40
/*
41
* To get the value from the device call read.
42
*/
43
temperatureSetPoint.
read
();
44
45
/*
46
* Now you can treat the accessor as if it was a regular float variable.
47
*/
48
std::cout <<
"Current temperature set point is "
<< temperatureSetPoint << std::endl;
49
temperatureSetPoint += 1.5;
50
std::cout <<
"Temperature set point changed to "
<< temperatureSetPoint << std::endl;
51
52
/*
53
* After you are done manipulating the accessor write it to the hardware.
54
*/
55
temperatureSetPoint.
write
();
56
57
/*
58
* It is good style to close the device when you are done, although
59
* this would happen automatically once the device goes out of scope.
60
*/
61
myDevice.
close
();
62
63
return
0;
64
}
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
main
int main()
Definition:
basic.cpp:15
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 ®isterPathName, 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::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
sources
ChimeraTK-DeviceAccess
examples
basic.cpp
Generated by
1.8.17