Modbus Component

Installation

The component requires ESP-IDF 5.3 and higher and is installed using IDF Component Manager.

Add this to the idf_component.yml in the project main directory or in the component directory:

dependencies:
  plasmapper/pl_modbus: "^1.2.1"

Add this to the source code:

#include "pl_modbus.h"

Add extern "C" to the app_main function:

extern "C" void app_main(void) {...}

Add this to the sdkconfig.defaults in the project directory or configure the values using Project Configuration:

CONFIG_COMPILER_CXX_RTTI=y
CONFIG_LWIP_SO_RCVBUF=y

Features

  1. PL::ModbusClient - a Modbus client class.

  2. PL::ModbusServer - a Modbus server class.

Thread safety

Class method thread safety is implemented by having the PL::Lockable as a base class and creating the class object lock guard at the beginning of the methods.

The stream PL::ModbusClient locks both the PL::ModbusClient and the PL::Stream objects for the duration of the transaction. The network PL::ModbusClient locks both the PL::ModbusClient and the PL::TcpClient objects for the duration of the transaction.

The stream PL::ModbusServer task method locks both the underlying PL::StreamServer and the PL::Stream objects for the duration of the transaction. The network PL::ModbusServer task method locks both the underlying PL::TcpServer and the client PL::NetworkStream objects for the duration of the transaction. The default PL::ModbusServer::HandleRequest() locks the accessed PL::ModbusMemoryArea for the duration of the transaction.

Examples

API reference