Skip to content

Commit

Permalink
Directly set standard-conforming RTU delays inside Modbus library.
Browse files Browse the repository at this point in the history
  • Loading branch information
aentinger committed Oct 31, 2024
1 parent 760b1e3 commit f6f9127
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ void setup() {

Serial.println("Modbus RTU Client Toggle w/ Parameters");

RS485.setDelays(ModbusRTUDelay::preDelay(baudrate), ModbusRTUDelay::postDelay(baudrate));

// start the Modbus RTU client in 8E1 mode
if (!ModbusRTUClient.begin(baudrate, SERIAL_8E1)) {
Serial.println("Failed to start Modbus RTU Client!");
Expand Down
1 change: 0 additions & 1 deletion src/ArduinoModbus.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
#ifndef _ARDUINO_MODBUS_H_INCLUDED
#define _ARDUINO_MODBUS_H_INCLUDED

#include "ModbusRTUDelay.h"
#include "ModbusRTUClient.h"
#include "ModbusRTUServer.h"

Expand Down
4 changes: 4 additions & 0 deletions src/ModbusRTUClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ extern "C" {

#include "ModbusRTUClient.h"

#include "ModbusRTUDelay.h"

ModbusRTUClientClass::ModbusRTUClientClass() :
ModbusClient(1000)
{
Expand All @@ -42,6 +44,8 @@ ModbusRTUClientClass::~ModbusRTUClientClass()

int ModbusRTUClientClass::begin(unsigned long baudrate, uint16_t config)
{
_rs485->setDelays(ModbusRTUDelay::preDelay(baudrate), ModbusRTUDelay::postDelay(baudrate));

modbus_t* mb = modbus_new_rtu(_rs485, baudrate, config);

if (!ModbusClient::begin(mb, 0x00)) {
Expand Down
5 changes: 5 additions & 0 deletions src/ModbusRTUServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ extern "C" {

#include "ModbusRTUServer.h"

#include "ModbusRTUDelay.h"


ModbusRTUServerClass::ModbusRTUServerClass()
{
}
Expand All @@ -40,6 +43,8 @@ ModbusRTUServerClass::~ModbusRTUServerClass()

int ModbusRTUServerClass::begin(int id, unsigned long baudrate, uint16_t config)
{
_rs485->setDelays(ModbusRTUDelay::preDelay(baudrate), ModbusRTUDelay::postDelay(baudrate));

modbus_t* mb = modbus_new_rtu(_rs485, baudrate, config);

if (!ModbusServer::begin(mb, id)) {
Expand Down

0 comments on commit f6f9127

Please sign in to comment.