IoT::Modbus

class ModbusMasterRemoteObject

File Information

Library: IoT/Modbus
Package: Generated
Header: IoT/Modbus/ModbusMasterRemoteObject.h

Description

This class defines the interface for Modbus clients.

The interface supports two basic modes of operation:

  • Asynchronous requests: One of the sendXXXRequest() methods is used to send a request to the device. The method returns as soon as the request has been queued to be sent over the wire (actual sending is done in a separate thread). The device's response, is reported asynchronously via an appropriate XXXResponseReceived event. Errors encountered during sending are reported via requestFailed. Modbus exception responses are reported via exceptionReceived. A timeout waiting for the response is reported via the timeout event.
  • Synchronous requests: After sending the request, the method waits for the response from the device and directly returns it to the caller. In case no response is received within the specified timeout, a Poco::TimeoutException is thrown. If an exception message is received from the device, a ModbusException is thrown. If an incomplete or invalid message is received, a Poco::ProtocolException is thrown.

Note that asynchronous and synchronous (blocking) mode cannot be used simultaneously. Calling one of the asynchronous request methods will enable asynchronous mode. Calling one of the synchronous request methods will disable asynchronous mode. Switching to synchronous mode while a response to an asynchronous request is pending will lead to undefined results, including possible mismatch of requests and responses.

In asynchronous operation, requests are associated with a transaction ID, to tell apart multiple concurrent transactions. Transaction IDs are not guaranteed to be unique for subsequent requests. In fact, for Modbus RTU, which does not allow multiple simultaneous requests, the transaction ID will always be zero.

Inheritance

Direct Base Classes: IModbusMaster, Poco::RemotingNG::RemoteObject

All Base Classes: IModbusMaster, Poco::OSP::Service, Poco::RefCountedObject, Poco::RemotingNG::Identifiable, Poco::RemotingNG::RemoteObject

Member Summary

Member Functions: address, event__badFrameReceived, event__connectionStateChanged, event__error, event__exceptionReceived, event__maskWriteRegisterResponseReceived, event__readCoilsResponseReceived, event__readDiscreteInputsResponseReceived, event__readExceptionStatusResponseReceived, event__readFIFOQueueResponseReceived, event__readHoldingRegistersResponseReceived, event__readInputRegistersResponseReceived, event__readWriteMultipleRegistersResponseReceived, event__requestFailed, event__responseReceived, event__timeout, event__writeMultipleCoilsResponseReceived, event__writeMultipleRegistersResponseReceived, event__writeSingleCoilResponseReceived, event__writeSingleRegisterResponseReceived, hasTransactionIDs, maskWriteRegister, maxSimultaneousTransactions, pendingTransactions, readCoils, readDiscreteInputs, readExceptionStatus, readFIFOQueue, readHoldingRegisters, readInputRegisters, readWriteMultipleRegisters, remoting__enableEvents, remoting__enableRemoteEvents, remoting__hasEvents, remoting__typeId, reset, sendMaskWriteRegisterRequest, sendReadCoilsRequest, sendReadDiscreteInputsRequest, sendReadExceptionStatusRequest, sendReadFIFOQueueRequest, sendReadHoldingRegistersRequest, sendReadInputRegistersRequest, sendReadWriteMultipleRegistersRequest, sendRequest, sendWriteMultipleCoilsRequest, sendWriteMultipleRegistersRequest, sendWriteSingleCoilRequest, sendWriteSingleRegisterRequest, writeMultipleCoils, writeMultipleRegisters, writeSingleCoil, writeSingleRegister

Inherited Functions: address, duplicate, hasTransactionIDs, isA, maskWriteRegister, maxSimultaneousTransactions, mutex, pendingTransactions, readCoils, readDiscreteInputs, readExceptionStatus, readFIFOQueue, readHoldingRegisters, readInputRegisters, readWriteMultipleRegisters, referenceCount, release, remoting__enableEvents, remoting__enableRemoteEvents, remoting__getURI, remoting__hasEvents, remoting__objectId, remoting__setURI, remoting__typeId, reset, sendMaskWriteRegisterRequest, sendReadCoilsRequest, sendReadDiscreteInputsRequest, sendReadExceptionStatusRequest, sendReadFIFOQueueRequest, sendReadHoldingRegistersRequest, sendReadInputRegistersRequest, sendReadWriteMultipleRegistersRequest, sendRequest, sendWriteMultipleCoilsRequest, sendWriteMultipleRegistersRequest, sendWriteSingleCoilRequest, sendWriteSingleRegisterRequest, type, writeMultipleCoils, writeMultipleRegisters, writeSingleCoil, writeSingleRegister

Types Aliases

Ptr

using Ptr = Poco::AutoPtr < ModbusMasterRemoteObject >;

Constructors

ModbusMasterRemoteObject

ModbusMasterRemoteObject(
    const Poco::RemotingNG::Identifiable::ObjectId & oid,
    Poco::SharedPtr < IoT::Modbus::ModbusMaster > pServiceObject
);

Destructor

~ModbusMasterRemoteObject virtual

virtual ~ModbusMasterRemoteObject();

Destroys the ModbusMasterRemoteObject.

Member Functions

address virtual inline

virtual std::string address() const;

Returns the Modbus master address as a string.

hasTransactionIDs virtual inline

virtual bool hasTransactionIDs() const;

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

maskWriteRegister virtual inline

virtual void maskWriteRegister(
    Poco::UInt8 slaveAddress,
    Poco::UInt16 referenceAddress,
    Poco::UInt16 andMask,
    Poco::UInt16 orMask
);

Sends a Mask Write register request to the device and waits for the response.

Throws a Poco::TimeoutException if the device does not respond within the specified timeout. Throws a ModbusException if the device responds with an exception message.

maxSimultaneousTransactions virtual inline

virtual std::size_t maxSimultaneousTransactions() const;

Returns the maximum allowed number of in-flight requests.

pendingTransactions virtual inline

virtual std::size_t pendingTransactions() const;

Returns the current number of in-flight requests.

readCoils virtual inline

virtual std::vector < bool > readCoils(
    Poco::UInt8 slaveAddress,
    Poco::UInt16 startingAddress,
    Poco::UInt16 nOfCoils
);

Sends a Read Coils request to the device and waits for the response.

Note: due to the wire format of the Modbus protocol, the returned vector will always have a size that is a multiple of 8, and may thus contain up to 7 more values than specified in nOfCoils.

Throws a Poco::TimeoutException if the device does not respond within the specified timeout. Throws a ModbusException if the device responds with an exception message.

readDiscreteInputs virtual inline

virtual std::vector < bool > readDiscreteInputs(
    Poco::UInt8 slaveAddress,
    Poco::UInt16 startingAddress,
    Poco::UInt16 nOfInputs
);

Sends a Read Discrete Inputs request to the device and waits for the response.

Note: due to the wire format of the Modbus protocol, the returned vector will always have a size that is a multiple of 8, and may thus contain up to 7 more values than specified in nOfInputs.

Throws a Poco::TimeoutException if the device does not respond within the specified timeout. Throws a ModbusException if the device responds with an exception message.

readExceptionStatus virtual inline

virtual Poco::UInt8 readExceptionStatus(
    Poco::UInt8 slaveAddress
);

Sends a Read Exception Status request to the device and waits for the response.

Throws a Poco::TimeoutException if the device does not respond within the specified timeout. Throws a ModbusException if the device responds with an exception message.

readFIFOQueue virtual inline

virtual std::vector < Poco::UInt16 > readFIFOQueue(
    Poco::UInt8 slaveAddress,
    Poco::UInt16 fifoPointerAddress
);

Sends a Read FIFO Queue request to the device and waits for the response.

Throws a Poco::TimeoutException if the device does not respond within the specified timeout. Throws a ModbusException if the device responds with an exception message.

readHoldingRegisters virtual inline

virtual std::vector < Poco::UInt16 > readHoldingRegisters(
    Poco::UInt8 slaveAddress,
    Poco::UInt16 startingAddress,
    Poco::UInt16 nOfRegisters
);

Sends a Read Holding Registers request to the device and waits for the response.

Throws a Poco::TimeoutException if the device does not respond within the specified timeout. Throws a ModbusException if the device responds with an exception message.

readInputRegisters virtual inline

virtual std::vector < Poco::UInt16 > readInputRegisters(
    Poco::UInt8 slaveAddress,
    Poco::UInt16 startingAddress,
    Poco::UInt16 nOfRegisters
);

Sends a Read Input Registers request to the device and waits for the response.

Throws a Poco::TimeoutException if the device does not respond within the specified timeout. Throws a ModbusException if the device responds with an exception message.

readWriteMultipleRegisters virtual inline

virtual std::vector < Poco::UInt16 > readWriteMultipleRegisters(
    Poco::UInt8 slaveAddress,
    Poco::UInt16 writeStartingAddress,
    const std::vector < Poco::UInt16 > & writeValues,
    Poco::UInt16 readStartingAddress,
    Poco::UInt8 nOfReadRegisters
);

Sends a Read/Write Multiple registers request to the device and waits for the response.

Throws a Poco::TimeoutException if the device does not respond within the specified timeout. Throws a ModbusException if the device responds with an exception message.

remoting__enableEvents virtual

virtual std::string remoting__enableEvents(
    Poco::RemotingNG::Listener::Ptr pListener,
    bool enable = bool (true)
);

remoting__enableRemoteEvents virtual

virtual void remoting__enableRemoteEvents(
    const std::string & protocol
);

remoting__hasEvents virtual

virtual bool remoting__hasEvents() const;

remoting__typeId virtual inline

virtual const Poco::RemotingNG::Identifiable::TypeId & remoting__typeId() const;

reset virtual inline

virtual void reset();

Resets the connection to the bus or device.

sendMaskWriteRegisterRequest virtual inline

virtual Poco::UInt16 sendMaskWriteRegisterRequest(
    const IoT::Modbus::MaskWriteRegisterRequest & request
);

Sends a Mask Write Register request.

A response from the device will be reported via the maskWriteRegisterResponseReceived event.

Returns the transaction ID for the request.

sendReadCoilsRequest virtual inline

virtual Poco::UInt16 sendReadCoilsRequest(
    const IoT::Modbus::ReadCoilsRequest & request
);

Sends a Read Coils request.

A response from the device will be reported via the readCoilsResponseReceived event.

Returns the transaction ID for the request.

sendReadDiscreteInputsRequest virtual inline

virtual Poco::UInt16 sendReadDiscreteInputsRequest(
    const IoT::Modbus::ReadDiscreteInputsRequest & request
);

Sends a Read Discrete Inputs request.

A response from the device will be reported via the readDiscreteInputsResponseReceived event.

Returns the transaction ID for the request.

sendReadExceptionStatusRequest virtual inline

virtual Poco::UInt16 sendReadExceptionStatusRequest(
    const IoT::Modbus::ReadExceptionStatusRequest & request
);

Sends a Read Exception Status request.

A response from the device will be reported via the readExceptionStatusResponseReceived event.

Returns the transaction ID for the request.

sendReadFIFOQueueRequest virtual inline

virtual Poco::UInt16 sendReadFIFOQueueRequest(
    const IoT::Modbus::ReadFIFOQueueRequest & request
);

Sends a Read FIFO Queue request.

A response from the device will be reported via the readFIFOQueueResponseReceived event.

Returns the transaction ID for the request.

sendReadHoldingRegistersRequest virtual inline

virtual Poco::UInt16 sendReadHoldingRegistersRequest(
    const IoT::Modbus::ReadHoldingRegistersRequest & request
);

Sends a Read Holding Registers request.

A response from the device will be reported via the readHoldingRegistersResponseReceived event.

Returns the transaction ID for the request.

sendReadInputRegistersRequest virtual inline

virtual Poco::UInt16 sendReadInputRegistersRequest(
    const IoT::Modbus::ReadInputRegistersRequest & request
);

Sends a Read Input Registers request.

A response from the device will be reported via the readInputRegistersResponseReceived event.

Returns the transaction ID for the request.

sendReadWriteMultipleRegistersRequest virtual inline

virtual Poco::UInt16 sendReadWriteMultipleRegistersRequest(
    const IoT::Modbus::ReadWriteMultipleRegistersRequest & request
);

Sends a Read Write Multiple Registers request.

A response from the device will be reported via the readWriteMultipleRegistersResponseReceived event.

Returns the transaction ID for the request.

sendRequest virtual inline

virtual Poco::UInt16 sendRequest(
    const IoT::Modbus::GenericMessage & message
);

Sends a generic Modbus message.

The caller is responsible for correct formatting of the messages's data field.

This can be used to send Modbus requests not directly supported by the ModbusMaster interface.

A response from the device will be reported via the responseReceived event or a more specific event if the response message type is supported.

Returns the transaction ID for the request.

sendWriteMultipleCoilsRequest virtual inline

virtual Poco::UInt16 sendWriteMultipleCoilsRequest(
    const IoT::Modbus::WriteMultipleCoilsRequest & request
);

Sends a Write Multiple Coils request.

A response from the device will be reported via the writeMultipleCoilsResponseReceived event.

Returns the transaction ID for the request.

sendWriteMultipleRegistersRequest virtual inline

virtual Poco::UInt16 sendWriteMultipleRegistersRequest(
    const IoT::Modbus::WriteMultipleRegistersRequest & request
);

Sends a Write Multiple Registers request.

A response from the device will be reported via the writeMultipleRegistersResponseReceived event.

Returns the transaction ID for the request.

sendWriteSingleCoilRequest virtual inline

virtual Poco::UInt16 sendWriteSingleCoilRequest(
    const IoT::Modbus::WriteSingleCoilRequest & request
);

Sends a Write Single Coil request.

A response from the device will be reported via the writeSingleCoilResponseReceived event.

Returns the transaction ID for the request.

sendWriteSingleRegisterRequest virtual inline

virtual Poco::UInt16 sendWriteSingleRegisterRequest(
    const IoT::Modbus::WriteSingleRegisterRequest & request
);

Sends a Write Single Register request.

A response from the device will be reported via the writeSingleRegisterResponseReceived event.

Returns the transaction ID for the request.

writeMultipleCoils virtual inline

virtual void writeMultipleCoils(
    Poco::UInt8 slaveAddress,
    Poco::UInt16 startingAddress,
    const std::vector < bool > & values
);

Sends a Write Multiple Coils request to the device and waits for the response.

Throws a Poco::TimeoutException if the device does not respond within the specified timeout. Throws a ModbusException if the device responds with an exception message.

writeMultipleRegisters virtual inline

virtual void writeMultipleRegisters(
    Poco::UInt8 slaveAddress,
    Poco::UInt16 startingAddress,
    const std::vector < Poco::UInt16 > & values
);

Sends a Write Multiple Registers request to the device and waits for the response.

Throws a Poco::TimeoutException if the device does not respond within the specified timeout. Throws a ModbusException if the device responds with an exception message.

writeSingleCoil virtual inline

virtual void writeSingleCoil(
    Poco::UInt8 slaveAddress,
    Poco::UInt16 outputAddress,
    bool value
);

Sends a Write Single Coils request to the device and waits for the response.

Throws a Poco::TimeoutException if the device does not respond within the specified timeout. Throws a ModbusException if the device responds with an exception message.

writeSingleRegister virtual inline

virtual void writeSingleRegister(
    Poco::UInt8 slaveAddress,
    Poco::UInt16 registerAddress,
    Poco::UInt16 value
);

Sends a Write Single Register request to the device and waits for the response.

Throws a Poco::TimeoutException if the device does not respond within the specified timeout. Throws a ModbusException if the device responds with an exception message.

event__badFrameReceived protected

void event__badFrameReceived();

event__connectionStateChanged protected

void event__connectionStateChanged(
    const IoT::Modbus::ConnectionState & data
);

event__error protected

void event__error(
    const std::string & data
);

event__exceptionReceived protected

void event__exceptionReceived(
    const IoT::Modbus::ModbusExceptionMessage & data
);

event__maskWriteRegisterResponseReceived protected

void event__maskWriteRegisterResponseReceived(
    const IoT::Modbus::MaskWriteRegisterResponse & data
);

event__readCoilsResponseReceived protected

void event__readCoilsResponseReceived(
    const IoT::Modbus::ReadCoilsResponse & data
);

event__readDiscreteInputsResponseReceived protected

void event__readDiscreteInputsResponseReceived(
    const IoT::Modbus::ReadDiscreteInputsResponse & data
);

event__readExceptionStatusResponseReceived protected

void event__readExceptionStatusResponseReceived(
    const IoT::Modbus::ReadExceptionStatusResponse & data
);

event__readFIFOQueueResponseReceived protected

void event__readFIFOQueueResponseReceived(
    const IoT::Modbus::ReadFIFOQueueResponse & data
);

event__readHoldingRegistersResponseReceived protected

void event__readHoldingRegistersResponseReceived(
    const IoT::Modbus::ReadHoldingRegistersResponse & data
);

event__readInputRegistersResponseReceived protected

void event__readInputRegistersResponseReceived(
    const IoT::Modbus::ReadInputRegistersResponse & data
);

event__readWriteMultipleRegistersResponseReceived protected

void event__readWriteMultipleRegistersResponseReceived(
    const IoT::Modbus::ReadWriteMultipleRegistersResponse & data
);

event__requestFailed protected

void event__requestFailed(
    const IoT::Modbus::RequestFailure & data
);

event__responseReceived protected

void event__responseReceived(
    const IoT::Modbus::GenericMessage & data
);

event__timeout protected

void event__timeout(
    const Poco::UInt16 & data
);

event__writeMultipleCoilsResponseReceived protected

void event__writeMultipleCoilsResponseReceived(
    const IoT::Modbus::WriteMultipleCoilsResponse & data
);

event__writeMultipleRegistersResponseReceived protected

void event__writeMultipleRegistersResponseReceived(
    const IoT::Modbus::WriteMultipleRegistersResponse & data
);

event__writeSingleCoilResponseReceived protected

void event__writeSingleCoilResponseReceived(
    const IoT::Modbus::WriteSingleCoilResponse & data
);

event__writeSingleRegisterResponseReceived protected

void event__writeSingleRegisterResponseReceived(
    const IoT::Modbus::WriteSingleRegisterResponse & data
);

Securely control IoT edge devices from anywhere   Connect a Device