Skip to content

Commit

Permalink
SerialCommHub: RTS/CTS support
Browse files Browse the repository at this point in the history
Signed-off-by: Cornelius Claussen <[email protected]>
  • Loading branch information
corneliusclaussen committed Jun 13, 2024
1 parent f78c9f1 commit 0aa439f
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 5 deletions.
4 changes: 2 additions & 2 deletions modules/SerialCommHub/main/serial_communication_hubImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ void serial_communication_hubImpl::init() {
rxtx_gpio_settings.inverted = config.rxtx_gpio_tx_high;

if (!modbus.open_device(config.serial_port, config.baudrate, config.ignore_echo, rxtx_gpio_settings,
static_cast<tiny_modbus::Parity>(config.parity), milliseconds(config.initial_timeout_ms),
milliseconds(config.within_message_timeout_ms))) {
static_cast<tiny_modbus::Parity>(config.parity), config.rtscts,
milliseconds(config.initial_timeout_ms), milliseconds(config.within_message_timeout_ms))) {
EVLOG_AND_THROW(Everest::EverestConfigError(fmt::format("Cannot open serial port {}.", config.serial_port)));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ struct Conf {
std::string serial_port;
int baudrate;
int parity;
bool rtscts;

Check notice on line 31 in modules/SerialCommHub/main/serial_communication_hubImpl.hpp

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

modules/SerialCommHub/main/serial_communication_hubImpl.hpp#L31

struct member 'Conf::rtscts' is never used.
bool ignore_echo;
std::string rxtx_gpio_chip;
int rxtx_gpio_line;
Expand Down
4 changes: 4 additions & 0 deletions modules/SerialCommHub/manifest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ provides:
minimum: 0
maximum: 2
default: 0
rtscts:
description: Use RTS/CTS hardware flow control
type: boolean
default: false
ignore_echo:
description: On some hardware every message that is sent is read back, this setting filters the sent message in the reply.
type: boolean
Expand Down
9 changes: 7 additions & 2 deletions modules/SerialCommHub/tiny_modbus_rtu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ TinyModbusRTU::~TinyModbusRTU() {
}

bool TinyModbusRTU::open_device(const std::string& device, int _baud, bool _ignore_echo,
const Everest::GpioSettings& rxtx_gpio_settings, const Parity parity,
const Everest::GpioSettings& rxtx_gpio_settings, const Parity parity, bool rtscts,
std::chrono::milliseconds _initial_timeout,
std::chrono::milliseconds _within_message_timeout) {

Expand Down Expand Up @@ -264,7 +264,12 @@ bool TinyModbusRTU::open_device(const std::string& device, int _baud, bool _igno
tty.c_cflag &= ~(PARENB | PARODD); // shut off parity
}
tty.c_cflag &= ~CSTOPB; // 1 Stop bit
tty.c_cflag &= ~CRTSCTS;

if (rtscts) {
tty.c_cflag |= CRTSCTS;
} else {
tty.c_cflag &= ~CRTSCTS;
}

if (tcsetattr(fd, TCSANOW, &tty) != 0) {
printf("Serial: error %d from tcsetattr\n", errno);
Expand Down
2 changes: 1 addition & 1 deletion modules/SerialCommHub/tiny_modbus_rtu.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class TinyModbusRTU {
~TinyModbusRTU();

bool open_device(const std::string& device, int baud, bool ignore_echo,
const Everest::GpioSettings& rxtx_gpio_settings, const Parity parity,
const Everest::GpioSettings& rxtx_gpio_settings, const Parity parity, bool rtscts,
std::chrono::milliseconds initial_timeout, std::chrono::milliseconds within_message_timeout);

std::vector<uint16_t> txrx(uint8_t device_address, FunctionCode function, uint16_t first_register_address,
Expand Down

0 comments on commit 0aa439f

Please sign in to comment.