#include <iop_modbus.h>

Classes

struct  IoRange
 

Public Member Functions

 mbDevice (void)
 
 mbDevice (const mbDevice &)
 
virtual ~mbDevice (void)
 
virtual void Clear (void)
 
virtual void Compile (void)
 
void AppendRemoteOutputs (int mbid, int mbaddr, int cnt, int fdaddr)
 
void AppendRemoteInputs (int mbid, int mbaddr, int cnt, int fdaddr)
 
void SlaveAddress (const std::string &rAddr)
 
virtual void Start (void)
 
virtual void Stop (void)
 
- Public Member Functions inherited from faudes::sDevice
 sDevice (void)
 
 sDevice (const sDevice &rOtherDevice)
 
virtual ~sDevice (void)
 
void InsInputEvent (const std::string &event)
 
void AppendTrigger (const std::string &event, const Trigger &trigger)
 
void InsOutputEvent (const std::string &event)
 
void AppendAction (const std::string &event, const Action &action)
 
int MaxBitAddress (void) const
 
virtual void Reset (void)
 
virtual void WriteOutput (Idx output)
 
void WriteSignal (int bitaddr, bool value)
 
bool ReadSignal (int bitaddr)
 
virtual int CycleTime () const
 
virtual void CycleTime (int cycleTime)
 
- Public Member Functions inherited from faudes::vDevice
 vDevice (void)
 
virtual ~vDevice (void)
 
void Name (const std::string &rName)
 
const std::string & Name (void) const
 
void Tolerance (Time::Type maxgap)
 
Time::Type Tolerance (void)
 
virtual void TimeScale (unsigned int scale)
 
virtual int TimeScale (void)
 
virtual void Configure (Idx event, const AttributeDeviceEvent &attr)
 
virtual void Configure (const EventSet &rPhysicalEvents)
 
virtual const EventSetOutputs (void) const
 
virtual const EventSetInputs (void) const
 
virtual bool ResetRequest (void)
 
virtual DeviceState Status (void)
 
virtual std::string StatusString (void)
 
virtual void FlushOutputs (void)
 
virtual Idx ReadInput (void)
 
virtual Idx PeekInput (void)
 
virtual bool InputReady (void)
 
virtual bool WaitInputs (Time::Type duration)
 
virtual bool WaitInputsMs (long int duration)
 
virtual Time::Type CurrentTime (void)
 
virtual long int CurrentTimeMs (void)
 
virtual void CurrentTime (Time::Type now)
 
virtual void CurrentTimeMs (long int nowms)
 
virtual faudes_systime_t FtuToSystemTime (Time::Type duration)
 
void UseCondition (faudes_mutex_t *wmutex, faudes_cond_t *wcond)
 
void UseBuffer (faudes_mutex_t *bmutex, std::deque< Idx > *bbuffer)
 
virtual std::string EStr (Idx ev)
 
SampledDensityFunction Performance (void)
 
void ResetPerformance (void)
 
void WritePerformance (void)
 
- Public Member Functions inherited from faudes::Type
 Type (void)
 
 Type (const Type &rType)
 
virtual ~Type (void)
 
virtual TypeNew (void) const
 
virtual TypeCopy (void) const
 
virtual const TypeCast (const Type *pOther) const
 
virtual TypeAssign (const Type &rSrc)
 
Typeoperator= (const Type &rSrc)
 
virtual bool Equal (const Type &rOther) const
 
bool operator== (const Type &rOther) const
 
bool operator!= (const Type &rOther) const
 
virtual const std::string & TypeName (void) const
 
void Write (const Type *pContext=0) const
 
void Write (const std::string &pFileName, const std::string &rLabel="", const Type *pContext=0, std::ios::openmode openmode=std::ios::out|std::ios::trunc) const
 
void Write (const std::string &pFileName, std::ios::openmode openmode) const
 
void Write (TokenWriter &rTw, const std::string &rLabel="", const Type *pContext=0) const
 
virtual void XWrite (const std::string &pFileName, const std::string &rLabel="", const Type *pContext=0) const
 
void XWrite (const Type *pContext=0) const
 
void XWrite (TokenWriter &rTw, const std::string &rLabel="", const Type *pContext=0) const
 
std::string ToString (const std::string &rLabel="", const Type *pContext=0) const
 
std::string ToText (const std::string &rLabel="", const Type *pContext=0) const
 
void DWrite (const Type *pContext=0) const
 
void DWrite (const std::string &pFileName, const std::string &rLabel="", const Type *pContext=0, std::ios::openmode openmode=std::ios::out|std::ios::trunc) const
 
void DWrite (TokenWriter &rTw, const std::string &rLabel="", const Type *pContext=0) const
 
void SWrite (TokenWriter &rTw) const
 
void SWrite (void) const
 
std::string ToSText (void) const
 
void Read (const std::string &rFileName, const std::string &rLabel="", const Type *pContext=0)
 
void FromString (const std::string &rString, const std::string &rLabel="", const Type *pContext=0)
 
void Read (TokenReader &rTr, const std::string &rLabel="", const Type *pContext=0)
 

Protected Member Functions

virtual bool DoReadSignalsPre (void)
 
virtual void DoReadSignalsPost (void)
 
virtual bool DoReadSignal (int bitaddr)
 
virtual bool DoWriteSignalsPre (void)
 
virtual void DoWriteSignalsPost (void)
 
virtual void DoWriteSignal (int bitaddr, bool value)
 
virtual void DoLoopCallback (void)
 
void DoReadPreface (TokenReader &rTr, const std::string &rLabel="", const Type *pContext=0)
 
void DoWritePreface (TokenWriter &rTw, const std::string &rLabel, const Type *pContext) const
 
int MbFlushBuffers (void)
 
int MbSendRequest (int id)
 
int MbReceiveResponse (void)
 
int MbReceiveRequest (int mastersock)
 
int MbSendResponse (int mastersock)
 
- Protected Member Functions inherited from faudes::sDevice
void DoWritePreface (TokenWriter &rTw, const std::string &rLabel, const Type *pContext=0) const
 
- Protected Member Functions inherited from faudes::vDevice
virtual void DoWrite (TokenWriter &rTw, const std::string &rLabel="", const Type *pContext=0) const
 
virtual void DoWriteConfiguration (TokenWriter &rTw, const std::string &rLabel="", const Type *pContext=0) const
 
virtual void DoRead (TokenReader &rTr, const std::string &rLabel="", const Type *pContext=0)
 
virtual void DoReadConfiguration (TokenReader &rTr, const std::string &rLabel="", const Type *pContext=0)
 
virtual long int FtuToMs (Time::Type faudes_time)
 
virtual Time::Type MsToFtu (long int real_time)
 
- Protected Member Functions inherited from faudes::Type
void DoAssign (const Type &rSrc)
 
bool DoEqual (const Type &rOther) const
 
virtual void DoXWrite (TokenWriter &rTw, const std::string &rLabel="", const Type *pContext=0) const
 
virtual void DoDWrite (TokenWriter &rTw, const std::string &rLabel="", const Type *pContext=0) const
 
virtual void DoSWrite (TokenWriter &rTw) const
 
virtual const TypeDefinitionTypeDefinitionp (void) const
 
virtual Token XBeginTag (const std::string &rLabel="", const std::string &rFallbackLabel="") const
 

Protected Attributes

bool mMasterRole
 
SimplenetAddress mSlaveAddress
 
std::vector< IoRangemSlaveIoRanges
 
int mImageSize
 
char * mpImage
 
char * pInputImage
 
char * pOutputImage
 
char * mpOutputMask
 
int mSlaveSocket
 
int mRequestCount
 
char * mMessage
 
int mMessageLen
 
int mRequestId
 
std::vector< int > mMasterSockets
 
- Protected Attributes inherited from faudes::sDevice
TaNameSet< AttributeSignalEvent > * pConfiguration
 
std::map< int, EventSetmInputPosEdgeIndexMap
 
std::map< int, EventSetmInputNegEdgeIndexMap
 
std::map< int, EventSetmOutputLevelIndexMap
 
int mMaxBitAddress
 
faudes_mutex_t mMutex
 
bool mSyncWrite
 
- Protected Attributes inherited from faudes::vDevice
std::string mDefaultLabel
 
std::string mName
 
EventSetmpConfiguration
 
EventSet mInputs
 
EventSet mOutputs
 
DeviceState mState
 
faudes_mutex_t mWaitMutex
 
faudes_cond_t mWaitCondition
 
faudes_mutex_t * pWaitMutex
 
faudes_cond_t * pWaitCondition
 
faudes_systime_t mTimeZero
 
int mTimeScale
 
Time::Type mMaxSyncGap
 
std::deque< IdxmInputBuffer
 
std::deque< Idx > * pInputBuffer
 
faudes_mutex_t mBufferMutex
 
faudes_mutex_t * pBufferMutex
 
bool mResetRequest
 
faudes_systime_t * mpPerformanceWaitEnter
 
faudes_systime_t * mpPerformanceWaitExit
 
int mPerformanceEndIterator
 
int mPerformanceBeginIterator
 

Additional Inherited Members

- Public Types inherited from faudes::sDevice
typedef AttributeSignalInput::Trigger Trigger
 
typedef AttributeSignalOutput::Action Action
 
typedef AttributeSignalOutput::Value Value
 
- Public Types inherited from faudes::vDevice
enum  DeviceState { Down , StartUp , Up , ShutDown }
 
- Static Public Member Functions inherited from faudes::vDevice
static vDeviceFromTokenReader (TokenReader &rTr)
 
static vDeviceFromFile (const std::string &rFileName)
 
static void StopAll (void)
 

Detailed Description

Processimage synchronisation via Modbus/TCP

This device is derived from the signal based sDevice to read and write line levels via ethernet using the Modbus/TCP protocol; see also the Modbus Organization.
When configured as master, the mbDevice initiates commucation with a specified list of slaves in order to retrieve input line levels and to set output line levels. The latter are locally buffered and are propagated to the event-based interface inherited via the base class sDevice. When configured as slave, the mbDevice accepts connections from any Modbus master, will response to their request sand update the local line-level buffer accordingly.

Further dedatils on the configuration, incl. an example, are provided by the ModbusDevice user-reference

Technical details.

  • The mbDevice slave implements reading and writing bits/coils/registers/holding registers, incl. the multi-read/write variants; regardless which commads you use, they all refer to the one process image implicitly defined by the event configuration.
  • The mbDevice matser usees the commands read multiple bits and write multiple coils for process image synchonisation.
  • All network communication come with quite relaxed timeouts. Please let us know, if you require more strict timeout behaviour.
  • Network communication is currently implemented synchronous with the edge detection background task; this is restrictive and may be changed in future revisions.
  • Communication uses an additional line-level buffer; a better solution would be to share the line buffer with the sDevice; however, this is not supported by the current sDevice interface.
  • Programatic configuration is still incomplete.
  • The mbDevice compiles with MinGW/Windows, however, it was not properly tested in this configuration; please let us know, if you plan to use mbDevice in a Windows context.

Note: This device must be explicitely enabled in Makefile.plugin.

Definition at line 72 of file iop_modbus.h.

Constructor & Destructor Documentation

◆ mbDevice() [1/2]

faudes::mbDevice::mbDevice ( void  )

Default constructor

Definition at line 43 of file iop_modbus.cpp.

◆ mbDevice() [2/2]

faudes::mbDevice::mbDevice ( const mbDevice )
inline

Copy constructor (not implemented!)

Definition at line 86 of file iop_modbus.h.

◆ ~mbDevice()

faudes::mbDevice::~mbDevice ( void  )
virtual

Explicit destructor.

Definition at line 61 of file iop_modbus.cpp.

Member Function Documentation

◆ AppendRemoteInputs()

void faudes::mbDevice::AppendRemoteInputs ( int  mbid,
int  mbaddr,
int  cnt,
int  fdaddr 
)

Append remotely implemented inputs. You must (re-)compile the mbDevice after adding remote inputs.

Parameters
mbidRemote device id
mbaddrbitaddress within the remote device
cntnumber of input bits to bw read
fdaddraddress within local process image

Definition at line 135 of file iop_modbus.cpp.

◆ AppendRemoteOutputs()

void faudes::mbDevice::AppendRemoteOutputs ( int  mbid,
int  mbaddr,
int  cnt,
int  fdaddr 
)

Append remotely implemented outputs. You must (re-)compile the mbDevice after adding remote outputs.

Parameters
mbidRemote device id
mbaddrbitaddress within the remote device
cntnumber of output bits to bw written
fdaddraddress within local process image

Definition at line 146 of file iop_modbus.cpp.

◆ Clear()

void faudes::mbDevice::Clear ( void  )
virtual

Clear all configuration (implies Stop)

Reimplemented from faudes::sDevice.

Definition at line 73 of file iop_modbus.cpp.

◆ Compile()

void faudes::mbDevice::Compile ( void  )
virtual

Compile to internal data-structures.

Exception in misconfiguration/inconsistencies

Reimplemented from faudes::sDevice.

Definition at line 84 of file iop_modbus.cpp.

◆ DoLoopCallback()

void faudes::mbDevice::DoLoopCallback ( void  )
protectedvirtual

Loop hook.

This function is called once during each cycle of the backgroud thread. It implements the actual communication via Modbus/TCP.

Reimplemented from faudes::sDevice.

Definition at line 480 of file iop_modbus.cpp.

◆ DoReadPreface()

void faudes::mbDevice::DoReadPreface ( TokenReader rTr,
const std::string &  rLabel = "",
const Type pContext = 0 
)
protectedvirtual

Read non-event-related configuration data from tokenreader

Parameters
rTrTokenReader to read from
rLabelSection to read
pContextRead context to provide contextual information

Reimplemented from faudes::sDevice.

Definition at line 202 of file iop_modbus.cpp.

◆ DoReadSignal()

bool faudes::mbDevice::DoReadSignal ( int  bitaddr)
protectedvirtual

Get input signal.

Extract bit value from image.

Parameters
bitaddrAbstract bit address
Returns
True for logic level high;

Implements faudes::sDevice.

Definition at line 926 of file iop_modbus.cpp.

◆ DoReadSignalsPost()

void faudes::mbDevice::DoReadSignalsPost ( void  )
protectedvirtual

IO Hook, inputs

Reimplemented from faudes::sDevice.

Definition at line 921 of file iop_modbus.cpp.

◆ DoReadSignalsPre()

bool faudes::mbDevice::DoReadSignalsPre ( void  )
protectedvirtual

IO Hook, inputs

Returns
True on success.

Reimplemented from faudes::sDevice.

Definition at line 915 of file iop_modbus.cpp.

◆ DoWritePreface()

void faudes::mbDevice::DoWritePreface ( TokenWriter rTw,
const std::string &  rLabel,
const Type pContext 
) const
protectedvirtual

Write non-event-related configuration data to tokenreader

Parameters
rTwTokenWriter to write
rLabelSection to write
pContextContext to provide contextual information

Reimplemented from faudes::vDevice.

Definition at line 163 of file iop_modbus.cpp.

◆ DoWriteSignal()

void faudes::mbDevice::DoWriteSignal ( int  bitaddr,
bool  value 
)
protectedvirtual

Set output signal.

Set value of bit in process image.

Parameters
bitaddrAbstract bit address
valueTrue for logic level high;

Implements faudes::sDevice.

Definition at line 942 of file iop_modbus.cpp.

◆ DoWriteSignalsPost()

void faudes::mbDevice::DoWriteSignalsPost ( void  )
protectedvirtual

IO Hook, outputs

Reimplemented from faudes::sDevice.

Definition at line 937 of file iop_modbus.cpp.

◆ DoWriteSignalsPre()

bool faudes::mbDevice::DoWriteSignalsPre ( void  )
protectedvirtual

IO Hook, outputs

Returns
True on success

Reimplemented from faudes::sDevice.

Definition at line 932 of file iop_modbus.cpp.

◆ MbFlushBuffers()

int faudes::mbDevice::MbFlushBuffers ( void  )
protected

I/O helper

Definition at line 372 of file iop_modbus.cpp.

◆ MbReceiveRequest()

int faudes::mbDevice::MbReceiveRequest ( int  mastersock)
protected

Definition at line 448 of file iop_modbus.cpp.

◆ MbReceiveResponse()

int faudes::mbDevice::MbReceiveResponse ( void  )
protected

Definition at line 419 of file iop_modbus.cpp.

◆ MbSendRequest()

int faudes::mbDevice::MbSendRequest ( int  id)
protected

Definition at line 396 of file iop_modbus.cpp.

◆ MbSendResponse()

int faudes::mbDevice::MbSendResponse ( int  mastersock)
protected

Definition at line 464 of file iop_modbus.cpp.

◆ SlaveAddress()

void faudes::mbDevice::SlaveAddress ( const std::string &  rAddr)

Set server address of this node. Note: you can only set th server address while the device is down.

Parameters
rAddrIP address of the remote Modbus device, e.g. "localhost:1502"
Exceptions
Exception
  • No valid address (id 551) (NOT IMPLEMENTED)

Definition at line 157 of file iop_modbus.cpp.

◆ Start()

void faudes::mbDevice::Start ( void  )
virtual

Activate the device. This function opens/initializes a network connection and starts the -background thread for communication and edge detection.

Exceptions
Exception
  • not yet configured (id not configured)
  • failed to network connection (id not configured)

Reimplemented from faudes::sDevice.

Definition at line 292 of file iop_modbus.cpp.

◆ Stop()

void faudes::mbDevice::Stop ( void  )
virtual

Deactivate the device. This function shuts down the network, stops the background thread and sets all output signals to 0.

Reimplemented from faudes::sDevice.

Definition at line 337 of file iop_modbus.cpp.

Member Data Documentation

◆ mImageSize

int faudes::mbDevice::mImageSize
protected

Remote process image buffer

Definition at line 286 of file iop_modbus.h.

◆ mMasterRole

bool faudes::mbDevice::mMasterRole
protected

Role: master/slave

Definition at line 270 of file iop_modbus.h.

◆ mMasterSockets

std::vector<int> faudes::mbDevice::mMasterSockets
protected

Background thread: tcp connection to remote masters

Definition at line 300 of file iop_modbus.h.

◆ mMessage

char* faudes::mbDevice::mMessage
protected

Definition at line 295 of file iop_modbus.h.

◆ mMessageLen

int faudes::mbDevice::mMessageLen
protected

Definition at line 296 of file iop_modbus.h.

◆ mpImage

char* faudes::mbDevice::mpImage
protected

Definition at line 287 of file iop_modbus.h.

◆ mpOutputMask

char* faudes::mbDevice::mpOutputMask
protected

Definition at line 290 of file iop_modbus.h.

◆ mRequestCount

int faudes::mbDevice::mRequestCount
protected

Definition at line 294 of file iop_modbus.h.

◆ mRequestId

int faudes::mbDevice::mRequestId
protected

Definition at line 297 of file iop_modbus.h.

◆ mSlaveAddress

SimplenetAddress faudes::mbDevice::mSlaveAddress
protected

IP addresses

Definition at line 273 of file iop_modbus.h.

◆ mSlaveIoRanges

std::vector< IoRange > faudes::mbDevice::mSlaveIoRanges
protected

Definition at line 283 of file iop_modbus.h.

◆ mSlaveSocket

int faudes::mbDevice::mSlaveSocket
protected

Background thread: tcp connection to remote slave

Definition at line 293 of file iop_modbus.h.

◆ pInputImage

char* faudes::mbDevice::pInputImage
protected

Definition at line 288 of file iop_modbus.h.

◆ pOutputImage

char* faudes::mbDevice::pOutputImage
protected

Definition at line 289 of file iop_modbus.h.


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

libFAUDES 2.33b --- 2025.05.07 --- c++ api documentaion by doxygen