ChimeraTK-DeviceAccess  03.18.00
basic.cpp

Example how to read and write a single register.

// SPDX-FileCopyrightText: Deutsches Elektronen-Synchrotron DESY, MSK, ChimeraTK Project <chimeratk-support@desy.de>
// SPDX-License-Identifier: LGPL-3.0-or-later
#include <ChimeraTK/Device.h>
#include <ChimeraTK/Utilities.h>
#include <iostream>
/*
* All information needed to access the device is
* the device alias and the register names
* (plus a .dmap file)
*/
int main() {
/*
* Before you use a device you have to tell DeviceAccess
* which dmap file to use.
*/
ChimeraTK::setDMapFilePath("example.dmap");
/*
* Create a device. Make sure a device alias is present
* in the dmap file.
*/
ChimeraTK::Device myDevice("MY_DEVICE");
myDevice.open();
/*
* Registers are defined by a path, which consists of a hierarchy of
* names separated by '/'. In this is example it is Module/Register.
* In this basic example we use a register which contains a single value
* (a scalar).
*
* The example device has a temperature controller with a set value.
*/
myDevice.getScalarRegisterAccessor<float>("TEMPERATURE_CONTROLLER/SET_POINT");
/*
* To get the value from the device call read.
*/
temperatureSetPoint.read();
/*
* Now you can treat the accessor as if it was a regular float variable.
*/
std::cout << "Current temperature set point is " << temperatureSetPoint << std::endl;
temperatureSetPoint += 1.5;
std::cout << "Temperature set point changed to " << temperatureSetPoint << std::endl;
/*
* After you are done manipulating the accessor write it to the hardware.
*/
temperatureSetPoint.write();
/*
* It is good style to close the device when you are done, although
* this would happen automatically once the device goes out of scope.
*/
myDevice.close();
return 0;
}
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 &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::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