stephane / libmodbus

A Modbus library for Linux, Mac OS, FreeBSD and Windows
http://libmodbus.org
GNU Lesser General Public License v2.1
3.52k stars 1.77k forks source link

Discuss libmodbus on FreeRTOS / esp-idf #767

Open franzhoepfinger opened 3 months ago

franzhoepfinger commented 3 months ago

libmodbus version

3.1.10 plus Modifications

OS and/or distribution

ESP-IDF Release v5.3 https://github.com/espressif/esp-idf/releases/tag/v5.3

OS is a FreeRTOS https://www.freertos.org/

Environment

Planned to run on all ESP32 Derivates, so Architecture is RISC-V as well as the Xtensa

Description

PR: https://github.com/stephane/libmodbus/pull/766

and

https://github.com/stephane/libmodbus/pull/765

Example for modbus-tcp: https://github.com/Fliegl-Agrartechnik-GmbH/libmodbus-examples-esp-idf/tree/main/modbus-tcp

(this was tested against diagslave-3.5 from https://www.modbusdriver.com/diagslave.html)

Example for modbus-rtu: https://github.com/Fliegl-Agrartechnik-GmbH/libmodbus-examples-esp-idf/tree/main/modbus-rtu

(this lets blink a LED on a Waveshare Output Module: https://www.waveshare.com/wiki/Modbus_RTU_IO_8CH)

the TCP Sample is nothing to discuss, with the PR https://github.com/stephane/libmodbus/pull/765 everything runs out of the Box.

the RTU Sample runs as given, PR https://github.com/stephane/libmodbus/pull/766 BUT there is some un-nice duplication in the code: see:

L46 and L76 for the Baud Rate,

L47 and L76 for the Data Bits, and so on.

so frankly speaking,

L40-L65 could also be part of the Driver, but it works also this way, however it is not sooooo nice.

happy to discuss this.

https://groups.google.com/g/libmodbus/c/9DJpfgxUowA

https://www.esp32.com/viewtopic.php?f=13&t=3302

diplfranzhoepfinger commented 3 months ago

i overlooked:

745

he did almost the same work, and solved some of the Questions above already.