ifw-core 7.0.0
 
Loading...
Searching...
No Matches
ifw::core::protocol::opcua::Open62541 Class Reference

The Open62541 class. More...

#include <open62541.hpp>

Inheritance diagram for ifw::core::protocol::opcua::Open62541:
ifw::core::protocol::base::IComm ifw::core::protocol::opcua::IDataChangeHandler MockOpen62541

Public Member Functions

 Open62541 (const std::optional< std::string > opcua_config_file=std::nullopt)
 Constructor.
 
virtual ~Open62541 ()
 
virtual void Connect (const std::string &device, const std::string &address)
 Establish the connection to the OPCUA server.
 
virtual void Read (protocol::base::VectorVariant &params) override
 Performs a Read operation.
 
virtual void Write (const protocol::base::VectorVariant &params) override
 Performs a Write operation.
 
virtual void Rpc (const std::string &obj, const std::string &proc, const protocol::base::VectorVariant &params, protocol::base::Variant &result) override
 Executes a RPC.
 
UA_StatusCode ResumeSubscriptions ()
 Resume subscriptions for all connections.
 
virtual void StartMonitorItem (const std::string &item) override
 Start monitoring an attribute.
 
virtual void StartMonitorItems (const std::vector< std::string > &item_vector) override
 Start monitoring a vector of attributes.
 
virtual void StopMonitorItem (const std::string &item) override
 Stop monitoring an attribute.
 
virtual void Disconnect ()
 Disconnects from the server.
 
virtual void RegisterCB (protocol::base::Dispatcher< protocol::base::VectorVariant & > &dispatcher, protocol::base::Dispatcher<> &failure, protocol::base::Dispatcher<> &normal)
 Registers internal and external callbacks.
 
void SetEndpoint (const std::string &endpoint)
 Set endpoint to the connection.
 
std::string GetEndpoint () const
 Get endpoint of the connection.
 
virtual void HandleDataChange (const std::shared_ptr< MonitoredItem > monitor_item, UA_DataValue *value)
 Handle data changes.
 
virtual void HandleSessionChanges (bool status)
 Handle changes in the OPCUA session.
 
void UpdateState (UA_SecureChannelState channel_state, UA_SessionState session_state, UA_StatusCode recovery_status)
 Update connection state.
 
bool IsServerReady (UA_Client *client)
 Check if server reports ready/running state.
 
- Public Member Functions inherited from ifw::core::protocol::base::IComm
virtual ~IComm ()
 
- Public Member Functions inherited from ifw::core::protocol::opcua::IDataChangeHandler
virtual ~IDataChangeHandler ()
 ~IDataChangeHandler
 

Static Public Attributes

static std::map< std::string, std::shared_ptr< OpcuaConnection > > m_connection_map
 

Detailed Description

The Open62541 class.

This class encapsulates the Open62541 OPCUA functions used by ICS FW devices. Each device shall create one instance of this class. If a device is running in the same server as another existing device, then this connection will be reused avoiding creating multiple connections for the same server.

Constructor & Destructor Documentation

◆ Open62541()

ifw::core::protocol::opcua::Open62541::Open62541 ( const std::optional< std::string > opcua_config_file = std::nullopt)

Constructor.

Parameters
opcua_config_fileYAML file containing OPC UA properties

The OPCUA configuration file will be loaded and parsed invoking the Connect() method.

◆ ~Open62541()

ifw::core::protocol::opcua::Open62541::~Open62541 ( )
virtual

Member Function Documentation

◆ Connect()

void ifw::core::protocol::opcua::Open62541::Connect ( const std::string & device,
const std::string & address )
virtual

Establish the connection to the OPCUA server.

Parameters
deviceName of the device
addressAddress of the OPCUA Server
configConfig struct providing specific parameter settings (if needed)

Implements ifw::core::protocol::base::IComm.

◆ Disconnect()

void ifw::core::protocol::opcua::Open62541::Disconnect ( )
virtual

Disconnects from the server.

Returns
Exceptions
exceptionsfor error cases.

Implements ifw::core::protocol::base::IComm.

◆ GetEndpoint()

std::string ifw::core::protocol::opcua::Open62541::GetEndpoint ( ) const

Get endpoint of the connection.

◆ HandleDataChange()

void ifw::core::protocol::opcua::Open62541::HandleDataChange ( const std::shared_ptr< MonitoredItem > monitor_item,
UA_DataValue * value )
virtual

Handle data changes.

Parameters
monitored_itemPointer to the monitored item generating the change.
valueVector containing the values of the data changes.

Implements ifw::core::protocol::opcua::IDataChangeHandler.

◆ HandleSessionChanges()

void ifw::core::protocol::opcua::Open62541::HandleSessionChanges ( bool status)
virtual

Handle changes in the OPCUA session.

Parameters
statusStatus of the session.

◆ IsServerReady()

bool ifw::core::protocol::opcua::Open62541::IsServerReady ( UA_Client * client)

Check if server reports ready/running state.

◆ Read()

void ifw::core::protocol::opcua::Open62541::Read ( protocol::base::VectorVariant & params)
overridevirtual

Performs a Read operation.

Parameters
paramsVector of attributes to be read.
Returns
Exceptions
exceptionsfor error cases.

Implements ifw::core::protocol::base::IComm.

◆ RegisterCB()

void ifw::core::protocol::opcua::Open62541::RegisterCB ( protocol::base::Dispatcher< protocol::base::VectorVariant & > & dispatcher,
protocol::base::Dispatcher<> & failure,
protocol::base::Dispatcher<> & normal )
virtual

Registers internal and external callbacks.

Parameters
dispatcherVector of device callbacks.
failureCallback for session problems.
normalCallback for session recovery.
Exceptions
exceptionsfor error cases.

Implements ifw::core::protocol::base::IComm.

◆ ResumeSubscriptions()

UA_StatusCode ifw::core::protocol::opcua::Open62541::ResumeSubscriptions ( )

Resume subscriptions for all connections.

This method shall be called only to recover subscriptions after loosing the session, e.g. for a connection lost.

◆ Rpc()

void ifw::core::protocol::opcua::Open62541::Rpc ( const std::string & obj,
const std::string & proc,
const protocol::base::VectorVariant & params,
protocol::base::Variant & result )
overridevirtual

Executes a RPC.

Parameters
objof attributes to write.
procVector of attributes to write.
paramsVector of pameters to the RPC to be executed.
resultresulting value given by the RPC.
Returns
Exceptions
exceptionsfor error cases.

Implements ifw::core::protocol::base::IComm.

◆ SetEndpoint()

void ifw::core::protocol::opcua::Open62541::SetEndpoint ( const std::string & endpoint)

Set endpoint to the connection.

◆ StartMonitorItem()

void ifw::core::protocol::opcua::Open62541::StartMonitorItem ( const std::string & item)
overridevirtual

Start monitoring an attribute.

Parameters
itemAttribute to be monitored.
Returns

The format expected is <namespace, name> e.g. 4, PLC1.Lamp1.stat.nState

The above means, the library only supports string based names.

Exceptions
exceptionsfor error cases.

Implements ifw::core::protocol::base::IComm.

◆ StartMonitorItems()

void ifw::core::protocol::opcua::Open62541::StartMonitorItems ( const std::vector< std::string > & item_vector)
overridevirtual

Start monitoring a vector of attributes.

Parameters
item_vectorVector of attributes to be monitored.
Returns

Each attribute in the vector is expected to have the format <namespace, name> e.g. 4, PLC1.Lamp1.stat.nState

The above means, the library only supports string based names.

Exceptions
exceptionsfor error cases.

Implements ifw::core::protocol::base::IComm.

◆ StopMonitorItem()

void ifw::core::protocol::opcua::Open62541::StopMonitorItem ( const std::string & item)
overridevirtual

Stop monitoring an attribute.

Parameters
itemAttribute to be removed.
Returns
Exceptions
exceptionsfor error cases.

Implements ifw::core::protocol::base::IComm.

◆ UpdateState()

void ifw::core::protocol::opcua::Open62541::UpdateState ( UA_SecureChannelState channel_state,
UA_SessionState session_state,
UA_StatusCode recovery_status )

Update connection state.

◆ Write()

void ifw::core::protocol::opcua::Open62541::Write ( const protocol::base::VectorVariant & params)
overridevirtual

Performs a Write operation.

Parameters
paramsVector of attributes to write.
Returns
Exceptions
exceptionsfor error cases.

Implements ifw::core::protocol::base::IComm.

Member Data Documentation

◆ m_connection_map

std::map<std::string, std::shared_ptr<OpcuaConnection> > ifw::core::protocol::opcua::Open62541::m_connection_map
inlinestatic

static map of connections. Multiples objects of this class may share the same connection. This is a typical case when several controllers are handled by one PLC.


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