alejoseb / Modbus-STM32-HAL-FreeRTOS

Modbus TCP and RTU, Master and Slave for STM32 using Cube HAL and FreeRTOS
GNU Lesser General Public License v2.1
519 stars 182 forks source link

add broad cast function for slave type #100

Closed bigjiongeagle closed 4 months ago

bigjiongeagle commented 4 months ago

test with F030 example

broadCast

bigjiongeagle commented 4 months ago

if this commit merge to the master branch. all the other example project private configfile named "ModbusConfig.h" should be edit to add the code like this: " #define MODBUS_BROADCAST_ADDRESS 0 // The broadcast address number "

alejoseb commented 4 months ago

Hi, Thanks for this PR. I have some comments:

  1. The MODBUS_BROADCAST_ADDRESS is always 0, it is a reserved address. So adding it as a configuration parameter is not needed and must be avoided altogether. Please refer to the official Modbus specification here: https://www.modbus.org/docs/Modbus_over_serial_line_V1_02.pdf page 8 section 2.2

  2. Broadcast must be implemented only for writing operations (section 2.1 of the aforementioned document), so all reading function codes must be ignored. The current implementation is not answering the master, but still processing the request which is not desirable.

  3. If a PR breaks the examples, it must correct all examples, otherwise it will be rejected. There is no exception.

Thanks, Alejandro

bigjiongeagle commented 4 months ago

Hi, Thanks for this comments.

The code will be update later.

Thanks, bigjiongeagle

bigjiongeagle commented 4 months ago

Hi, The code has been updated:

1.add enum mb_address_t to the file named "Modbus.h", to Identifies whether it is a broadcast command.

2.Broadcast was implemented only for writing operations , all reading function codes has been ignored.

3.reset private configfile, so the PR will not breaks the examples.

4.In broadcast mode, when the validateRequest function returns an error, it does not reply to the data frame.

Thanks, bigjiongeagle

alejoseb commented 4 months ago

thanks for the PR