Skip to content

Commit 19c9aa8

Browse files
RS485CommClass: add started flag
1 parent 812e591 commit 19c9aa8

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

src/RS485CommClass.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ void RS485CommClass::begin(unsigned long baudrate, uint16_t config)
3333
}
3434

3535
void RS485CommClass::begin(unsigned long baudrate, uint16_t config, int predelay, int postdelay) {
36+
if (_started) return;
37+
_started = true;
38+
3639
/* Pinout configuration */
3740
pinMode(PinNameToIndex(MC_RS485_TX_PIN), OUTPUT);
3841
pinMode(PinNameToIndex(MC_RS485_RX_PIN), OUTPUT);
@@ -70,6 +73,8 @@ void RS485CommClass::end() {
7073

7174
/* Call end() base class to de-initialize RS485 communication */
7275
RS485Class::end();
76+
77+
_started = false;
7378
}
7479

7580
void RS485CommClass::setModeRS232(bool enable) {

src/RS485CommClass.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ class RS485CommClass : public RS485Class {
143143
void setFullDuplex(bool enable);
144144

145145
private:
146+
bool _started = false; // Flag to indicate if RS485 communication has been started
146147
/**
147148
* @brief Enable RS485 communication.
148149
*

0 commit comments

Comments
 (0)