| 
 | 
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. 
 
#include <iop_modbus.h> 
 |  
|   | 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) |  
|   |  
|   | 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) |  
|   |  
|   | 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 EventSet &  | Outputs (void) const |  
|   |  
| virtual const EventSet &  | Inputs (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) |  
|   |  
|   | Type (void) |  
|   |  
|   | Type (const Type &rType) |  
|   |  
| virtual  | ~Type (void) |  
|   |  
| virtual Type *  | New (void) const |  
|   |  
| virtual Type *  | Copy (void) const |  
|   |  
| virtual const Type *  | Cast (const Type *pOther) const |  
|   |  
| virtual bool  | IsDefault (void) const |  
|   |  
| virtual Type &  | Assign (const Type &rSrc) |  
|   |  
| Type &  | operator= (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) |  
|   |  
 
 |  
| 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) |  
|   |  
| void  | DoWritePreface (TokenWriter &rTw, const std::string &rLabel, const Type *pContext=0) const |  
|   |  
| 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) |  
|   |  
| 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 TypeDefinition *  | TypeDefinitionp (void) const |  
|   |  
| virtual Token  | XBeginTag (const std::string &rLabel="", const std::string &rFallbackLabel="") const |  
|   |  
 
◆ mbDevice() [1/2]
      
        
          | faudes::mbDevice::mbDevice  | 
          ( | 
          void  | 
           | ) | 
           | 
         
       
 
 
◆ 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   | 
   
 
 
 
◆ 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
 - 
  
    | mbid | Remote device id  |  
    | mbaddr | bitaddress within the remote device  |  
    | cnt | number of input bits to bw read  |  
    | fdaddr | address 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
 - 
  
    | mbid | Remote device id  |  
    | mbaddr | bitaddress within the remote device  |  
    | cnt | number of output bits to bw written  |  
    | fdaddr | address within local process image  |  
   
   
 
Definition at line 146 of file iop_modbus.cpp. 
 
 
◆ Clear()
  
  
      
        
          | void faudes::mbDevice::Clear  | 
          ( | 
          void  | 
           | ) | 
           | 
         
       
   | 
  
virtual   | 
   
 
 
 
◆ Compile()
  
  
      
        
          | void faudes::mbDevice::Compile  | 
          ( | 
          void  | 
           | ) | 
           | 
         
       
   | 
  
virtual   | 
   
 
 
 
◆ 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
 - 
  
    | rTr | TokenReader to read from  |  
    | rLabel | Section to read  |  
    | pContext | Read 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
 - 
  
    | bitaddr | Abstract 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   | 
   
 
 
 
◆ DoReadSignalsPre()
  
  
      
        
          | bool faudes::mbDevice::DoReadSignalsPre  | 
          ( | 
          void  | 
           | ) | 
           | 
         
       
   | 
  
protectedvirtual   | 
   
 
 
 
◆ 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
 - 
  
    | rTw | TokenWriter to write  |  
    | rLabel | Section to write  |  
    | pContext | Context 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
 - 
  
    | bitaddr | Abstract bit address  |  
    | value | True for logic level high;  |  
   
   
 
Implements faudes::sDevice. 
Definition at line 942 of file iop_modbus.cpp. 
 
 
◆ DoWriteSignalsPost()
  
  
      
        
          | void faudes::mbDevice::DoWriteSignalsPost  | 
          ( | 
          void  | 
           | ) | 
           | 
         
       
   | 
  
protectedvirtual   | 
   
 
 
 
◆ DoWriteSignalsPre()
  
  
      
        
          | bool faudes::mbDevice::DoWriteSignalsPre  | 
          ( | 
          void  | 
           | ) | 
           | 
         
       
   | 
  
protectedvirtual   | 
   
 
 
 
◆ MbFlushBuffers()
  
  
      
        
          | int faudes::mbDevice::MbFlushBuffers  | 
          ( | 
          void  | 
           | ) | 
           | 
         
       
   | 
  
protected   | 
   
 
 
 
◆ MbReceiveRequest()
  
  
      
        
          | int faudes::mbDevice::MbReceiveRequest  | 
          ( | 
          int  | 
          mastersock | ) | 
           | 
         
       
   | 
  
protected   | 
   
 
 
 
◆ MbReceiveResponse()
  
  
      
        
          | int faudes::mbDevice::MbReceiveResponse  | 
          ( | 
          void  | 
           | ) | 
           | 
         
       
   | 
  
protected   | 
   
 
 
 
◆ MbSendRequest()
  
  
      
        
          | int faudes::mbDevice::MbSendRequest  | 
          ( | 
          int  | 
          id | ) | 
           | 
         
       
   | 
  
protected   | 
   
 
 
 
◆ MbSendResponse()
  
  
      
        
          | int faudes::mbDevice::MbSendResponse  | 
          ( | 
          int  | 
          mastersock | ) | 
           | 
         
       
   | 
  
protected   | 
   
 
 
 
◆ 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
 - 
  
    | rAddr | IP 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. 
 
 
◆ mImageSize
  
  
      
        
          | int faudes::mbDevice::mImageSize | 
         
       
   | 
  
protected   | 
   
 
 
 
◆ mMasterRole
  
  
      
        
          | bool faudes::mbDevice::mMasterRole | 
         
       
   | 
  
protected   | 
   
 
 
 
◆ 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   | 
   
 
 
 
◆ mMessageLen
  
  
      
        
          | int faudes::mbDevice::mMessageLen | 
         
       
   | 
  
protected   | 
   
 
 
 
◆ mpImage
  
  
      
        
          | char* faudes::mbDevice::mpImage | 
         
       
   | 
  
protected   | 
   
 
 
 
◆ mpOutputMask
  
  
      
        
          | char* faudes::mbDevice::mpOutputMask | 
         
       
   | 
  
protected   | 
   
 
 
 
◆ mRequestCount
  
  
      
        
          | int faudes::mbDevice::mRequestCount | 
         
       
   | 
  
protected   | 
   
 
 
 
◆ mRequestId
  
  
      
        
          | int faudes::mbDevice::mRequestId | 
         
       
   | 
  
protected   | 
   
 
 
 
◆ mSlaveAddress
◆ mSlaveIoRanges
  
  
      
        
          | std::vector< IoRange > faudes::mbDevice::mSlaveIoRanges | 
         
       
   | 
  
protected   | 
   
 
 
 
◆ 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   | 
   
 
 
 
◆ pOutputImage
  
  
      
        
          | char* faudes::mbDevice::pOutputImage | 
         
       
   | 
  
protected   | 
   
 
 
 
 The documentation for this class was generated from the following files: 
 
 
 
libFAUDES 2.33l 
--- 2025.09.16  
--- c++ api documentaion by doxygen
 
 |