IoT::Modbus::TCP

class TCPMasterPort

File Information

Library: IoT/Modbus/TCP
Package: TCP
Header: IoT/Modbus/TCP/TCPMasterPort.h

Description

This class implements the Modbus TCP protocol over a socket.

Member Summary

Member Functions: address, changeConnectionState, decodeFrame, hasTransactionIDs, maxSimultaneousTransactions, poll, receiveFrame, reset, sendFrame

Constructors

TCPMasterPort

TCPMasterPort(
    const Poco::Net::SocketAddress & serverAddress,
    Poco::Timespan connectTimeout,
    bool connectImmediately = true,
    std::size_t maxSimultaneousTransactions = 16
);

Creates a TCPMasterPort using the given server address.

Try connect to underlying socket in constructor. If connect failed the TCPMasterPort class try reconnect at the begin of every sendFrame() and receiveFrame() function to reconnect. If this also fail an IOException is thrown.

Destructor

~TCPMasterPort

~TCPMasterPort();

Destroys the TCPMasterPort.

Try to close the underlying socket.

Member Functions

address inline

std::string address() const;

Returns the server address.

decodeFrame inline

template < class Message > void decodeFrame(
    Message & message
);

Decodes the currently buffered Modbus TCP frame.

The raw frame must have been read from the wire with receiveFrame().

hasTransactionIDs inline

bool hasTransactionIDs() const;

Returns true if the port supports transaction IDs, otherwise false. Currently, only Modbus/TCP supports transaction IDs.

maxSimultaneousTransactions inline

std::size_t maxSimultaneousTransactions() const;

Returns the maximum number of simultaneous transactions allowed by the port.

poll inline

bool poll(
    const Poco::Timespan & timeout
);

Waits for data to arrive at the port.

Returns true immediately if data is already in the internal buffer, or if data arrives during the specified timeout interval, otherwise false.

receiveFrame

Poco::UInt8 receiveFrame();

Receives the next frame from the wire. Returns the frame's function code.

Throws an IOException if the port is not connected.

reset

void reset();

Closes and re-opens the connection.

sendFrame inline

template < class Message > void sendFrame(
    const Message & message
);

Sends a Modbus TCP frame over the wire.

Throws an IOException if the port is not connected.

changeConnectionState protected inline

void changeConnectionState(
    ConnectionState state
);

Variables

connectionStateChanged

Poco::BasicEvent < const ConnectionState > connectionStateChanged;

Securely control IoT edge devices from anywhere   Connect a Device