IoT::Modbus::RTU

class RTUDevicePort

File Information

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

Description

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

Member Summary

Member Functions: address, checkFrame, decodeFrame, frameSlaveOrUnitAddress, isConnected, poll, receiveFrame, sendFrame

Constructors

RTUDevicePort

RTUDevicePort(
    Poco::SharedPtr < Poco::Serial::SerialPort > pSerialPort,
    Poco::Timespan frameTimeout = 10000
);

Creates a RTUDevicePort 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

~RTUDevicePort

~RTUDevicePort();

Destroys the RTUDevicePort.

Member Functions

address inline

std::string address() const;

Returns the client 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().

frameSlaveOrUnitAddress inline

Poco::UInt8 frameSlaveOrUnitAddress() const;

Returns the slave or unit address of the most recent frame received by receiveFrame().

isConnected inline

bool isConnected() const;

Always returns true.

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.

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
);

Securely control IoT edge devices from anywhere   Connect a Device