IModbusAdapter.h 1.61 KB
/****************************************************************************
 * Copyright (c) 2022 Priva b.v.
 ****************************************************************************/

#pragma once

// std
#include <string>
#include <variant>
#include <vector>

using modbusData = std::vector<std::variant<uint8_t, uint16_t>>;

// Forward Declaration
class ConnectionConfig;

/*!
 * \brief The IModbusAdapter class
 */
class IModbusAdapter
{

public:
    virtual ~IModbusAdapter() {}

    virtual bool ModbusConnect( const ConnectionConfig &conncfg ) = 0;

    /*!
     * \brief ModbusDisconnect
     */
    virtual bool ModbusDisconnect() = 0;

    /*!
     * \brief ModbusReadData
     * \param slaveId
     * \param startAddress
     * \param noOfItems
     */
    virtual modbusData ModbusReadData( int slaveId, int functionCode, int startAddress, int noOfItems ) = 0;

    /*!
     * \brief ModbusReadHoldReg
     * \param slaveId
     * \param startAddress
     * \param noOfItems
     * \return
     */
    virtual modbusData ModbusReadHoldReg( int slaveId, int startAddress, int noOfItems ) = 0;

    /*!
     * \brief ModBusWriteData
     * \param slaveId
     * \param funtionCode
     * \param startAddress
     * \param noOfItems
     * \param values
     */
    virtual void ModBusWriteData( int slaveId, int functionCode, int startAddress, int noOfItems, std::vector<int>values ) = 0;

    /*!
     * \brief isConnected
     * \return
     */
    virtual bool isConnected() const = 0;

    /*!
     * \brief ErrorString
     * \param errnum
     * \return
     */
    virtual std::string ErrorString( int errnum ) const = 0;
};