IoT::Modbus::RTU

class RTUMasterPort

File Information

Library: IoT/Modbus/RTU
Package: RTU
Header: IoT/Modbus/RTU/RTUMasterPort.h

Description

This class implements the Modbus RTU protocol over a serial line.

Member Summary

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

Enumerations

ByteOrder

Byte order used by RTU protocol. The Modbus specification required big endian.

RTU_BIG_ENDIAN = 1

RTU_LITTLE_ENDIAN = 2

Constructors

RTUMasterPort

RTUMasterPort(
    Poco::SharedPtr < Poco::Serial::SerialPort > pSerialPort,
    Poco::Timespan frameTimeout = 10000,
    ByteOrder byteOrder = RTU_BIG_ENDIAN
);

Creates a RTUMasterPort using the given SerialPort.

The recommended value for frameTimeout is 10ms.

The SerialPort must be open and properly configured for RS-485 communication with the Modbus slaves.

Destructor

~RTUMasterPort

~RTUMasterPort();

Destroys the RTUMasterPort.

Member Functions

address inline

std::string address() const;

Returns the device name.

decodeFrame inline

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

Decodes the currently buffered Modbus RTU 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 time interval, otherwise false.

receiveFrame

Poco::UInt8 receiveFrame();

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

reset

void reset();

Resets the connection to the bus.

sendFrame inline

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

Sends a Modbus RTU frame over the wire.

checkFrame protected

bool checkFrame(
    std::size_t size
);

Variables

connectionStateChanged

Poco::BasicEvent < const ConnectionState > connectionStateChanged;

Required by MasterPort interface, but not used for RTU.

Securely control IoT edge devices from anywhere   Connect a Device