Motion Master
Loading...
Searching...
No Matches
Public Member Functions | List of all members
common::Device Class Referenceabstract

Abstract interface representing a generic device. More...

#include <common.h>

Inheritance diagram for common::Device:
Inheritance graph
[legend]

Public Member Functions

virtual ~Device ()=default
 Virtual destructor for Device interface. More...
 
virtual uint8_t getState (const std::chrono::steady_clock::duration expiryTime=std::chrono::milliseconds(3000))=0
 Reads and returns the current state of the device. More...
 
virtual bool setState (uint8_t state, const std::chrono::steady_clock::duration expiryTime=std::chrono::milliseconds(3000))=0
 Sets the device to a specified state. More...
 
virtual std::vector< uint8_t > readFile (const std::string &filename, const std::chrono::steady_clock::duration expiryTime=std::chrono::milliseconds(5000))=0
 Reads the contents of a file from the device. More...
 
virtual bool writeFile (const std::string &filename, const std::vector< uint8_t > &data, const std::chrono::steady_clock::duration expiryTime=std::chrono::milliseconds(5000))=0
 Sends a file to the device. More...
 
virtual void loadParameters (bool readValues, const std::chrono::steady_clock::duration expiryTime=std::chrono::milliseconds(9000))=0
 Loads parameters from the device and stores them locally. More...
 
virtual void clearParameters ()=0
 Clears all loaded object dictionary parameters. More...
 
virtual ParameterfindParameter (uint16_t index, uint8_t subindex)=0
 Finds and returns a reference to a parameter by its index and subindex. More...
 
virtual Parameterupload (uint16_t index, uint8_t subindex, const std::chrono::steady_clock::duration expiryTime=std::chrono::milliseconds(5000))=0
 Uploads a parameter from the device via SDO and updates the local parameter store. More...
 
virtual void download (uint16_t index, uint8_t subindex, const std::chrono::steady_clock::duration expiryTime=std::chrono::milliseconds(5000))=0
 Downloads a parameter to the device using SDO communication. More...
 
virtual void download (uint16_t index, uint8_t subindex, const ParameterValue &value, const std::chrono::steady_clock::duration expiryTime=std::chrono::milliseconds(5000))=0
 Sets a parameter value in the local store and downloads it to the device. More...
 
virtual void exchangeProcessDataAndUpdateParameters ()=0
 Exchanges process data with the remote device and updates local parameters accordingly. More...
 

Detailed Description

Abstract interface representing a generic device.

This class defines the virtual interface for device operations such as state management, parameter handling, and file transfer. All methods are pure virtual and must be implemented by derived classes.

Constructor & Destructor Documentation

◆ ~Device()

virtual common::Device::~Device ( )
virtualdefault

Virtual destructor for Device interface.

Ensures derived class destructors are called properly when deleting through a pointer to Device.

The default destructor implementation is used.

Member Function Documentation

◆ clearParameters()

virtual void common::Device::clearParameters ( )
pure virtual

Clears all loaded object dictionary parameters.

This function removes all entries from the internal parameter map, effectively resetting the parameter list of the slave device.

Implemented in EthernetDevice.

◆ download() [1/2]

virtual void common::Device::download ( uint16_t  index,
uint8_t  subindex,
const ParameterValue value,
const std::chrono::steady_clock::duration  expiryTime = std::chrono::milliseconds(5000) 
)
pure virtual

Sets a parameter value in the local store and downloads it to the device.

This function updates the specified parameter in the local store with the provided value, serializes it, and then performs an SDO download to transfer the data to the device.

Parameters
indexThe 16-bit index of the parameter in the object dictionary.
subindexThe 8-bit subindex of the parameter.
valueThe new parameter value to set and download.
expiryTimeThe maximum duration to wait for the SDO download operation to complete.
Exceptions
std::runtime_errorIf the parameter data is empty after setting the value, or if the SDO download operation fails.

Implemented in EthernetDevice.

◆ download() [2/2]

virtual void common::Device::download ( uint16_t  index,
uint8_t  subindex,
const std::chrono::steady_clock::duration  expiryTime = std::chrono::milliseconds(5000) 
)
pure virtual

Downloads a parameter to the device using SDO communication.

This function sends the binary data of the specified parameter (retrieved from the local store) to the device. The operation fails if the parameter's data is empty.

Parameters
indexThe 16-bit index of the parameter in the object dictionary.
subindexThe 8-bit subindex of the parameter.
expiryTimeThe maximum duration to wait for the SDO download operation to complete.
Exceptions
std::runtime_errorIf the parameter data is empty or the SDO download fails.

Implemented in EthernetDevice.

◆ exchangeProcessDataAndUpdateParameters()

virtual void common::Device::exchangeProcessDataAndUpdateParameters ( )
pure virtual

Exchanges process data with the remote device and updates local parameters accordingly.

This function prepares the process data to send by collecting the current data from parameters mapped as RxPDOs. It then sends this data and receives updated process data from the remote device. The received data is used to update local parameters mapped as TxPDOs.

Exceptions
std::runtime_errorif findParameter throws (e.g., if parameter not found).

Implemented in EthernetDevice.

◆ findParameter()

virtual Parameter & common::Device::findParameter ( uint16_t  index,
uint8_t  subindex 
)
pure virtual

Finds and returns a reference to a parameter by its index and subindex.

This function looks up a parameter in the internal parameter map using the specified index and subindex. If the parameter is found, a reference to it is returned. If not, a runtime exception is thrown.

Parameters
indexThe index of the parameter to find.
subindexThe subindex of the parameter to find.
Returns
Reference to the found parameter.
Exceptions
std::runtime_errorIf the parameter with the specified index and subindex is not found in the map.

Implemented in EthernetDevice.

◆ getState()

virtual uint8_t common::Device::getState ( const std::chrono::steady_clock::duration  expiryTime = std::chrono::milliseconds(3000))
pure virtual

Reads and returns the current state of the device.

This function sends a request to retrieve the device’s state, which follows the EtherCAT state machine. The returned state is represented as a uint8_t with the following possible values:

  • INIT: 1
  • PREOP: 2
  • SAFEOP: 4
  • OP: 8
  • BOOT: 3
Parameters
expiryTimeThe maximum time to wait for the operation to complete.
Returns
The current device state as a uint8_t.

Implemented in EthernetDevice.

◆ loadParameters()

virtual void common::Device::loadParameters ( bool  readValues,
const std::chrono::steady_clock::duration  expiryTime = std::chrono::milliseconds(9000) 
)
pure virtual

Loads parameters from the device and stores them locally.

Parameters
readValuesIf true, the values of the parameters are read from the device; otherwise, only the parameter metadata is retrieved.
expiryTimeThe maximum duration to wait for the operation to complete.

Implemented in EthernetDevice.

◆ readFile()

virtual std::vector< uint8_t > common::Device::readFile ( const std::string &  filename,
const std::chrono::steady_clock::duration  expiryTime = std::chrono::milliseconds(5000) 
)
pure virtual

Reads the contents of a file from the device.

Parameters
filenameThe name of the file to be read.
expiryTimeThe maximum duration to wait for the operation to complete.
Returns
A std::vector<uint8_t> containing the file data received from the device.

Implemented in EthernetDevice.

◆ setState()

virtual bool common::Device::setState ( uint8_t  state,
const std::chrono::steady_clock::duration  expiryTime = std::chrono::milliseconds(3000) 
)
pure virtual

Sets the device to a specified state.

Attempts to change the remote device's state to the given value, waiting up to the specified expiry time for the operation to complete.

Parameters
stateThe new state to set on the remote device.
expiryTimeThe maximum duration to wait for the operation to complete.
Returns
true if the state was successfully set; false otherwise.

Implemented in EthernetDevice.

◆ upload()

virtual Parameter & common::Device::upload ( uint16_t  index,
uint8_t  subindex,
const std::chrono::steady_clock::duration  expiryTime = std::chrono::milliseconds(5000) 
)
pure virtual

Uploads a parameter from the device via SDO and updates the local parameter store.

This function reads a parameter value from the device using SDO communication, updates the corresponding local Parameter object with the received value, and returns a reference to it.

Parameters
indexThe 16-bit parameter index in the object dictionary.
subindexThe 8-bit subindex of the parameter.
expiryTimeThe maximum duration to wait for the SDO upload operation to complete.
Returns
Reference to the updated local common::Parameter object.
Exceptions
std::runtime_errorIf the upload fails or returns an empty payload.

Implemented in EthernetDevice, and EthernetDevice.

◆ writeFile()

virtual bool common::Device::writeFile ( const std::string &  filename,
const std::vector< uint8_t > &  data,
const std::chrono::steady_clock::duration  expiryTime = std::chrono::milliseconds(5000) 
)
pure virtual

Sends a file to the device.

Parameters
filenameThe name of the file to be written.
dataThe data to be written to the file.
expiryTimeThe maximum duration to wait for the operation to complete.
Returns
Returns true if the file was successfully written; otherwise, false.

Implemented in EthernetDevice.


The documentation for this class was generated from the following file: