Skip to content

Commit 0bc538d

Browse files
committed
txPin to txEnablePin, direct to txEnableDirect #266
1 parent 4ae0f7d commit 0bc538d

File tree

4 files changed

+39
-39
lines changed

4 files changed

+39
-39
lines changed

documentation/API.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,12 @@ bool removeIreg(uint16_t offset, uint16_t numregs = 1);
4747
### Modbus RTU Specific API
4848

4949
```c
50-
bool begin(SoftwareSerial* port, int16_t txPin=-1, bool direct=true);
51-
bool begin(HardwareSerial* port, int16_t txPin=-1, bool direct=true);
50+
bool begin(SoftwareSerial* port, int16_t txEnablePin=-1, bool txEnableDirect=true);
51+
bool begin(HardwareSerial* port, int16_t txEnablePin=-1, bool txEnableDirect=true);
5252
bool begin(Stream* port);
5353
```
5454
55-
Assing Serial port. txPin controls transmit enable for MAX-485. Pass direct=false if txPin uses inverse logic.
55+
Assing Serial port. txEnablePin controls transmit enable for MAX-485. Pass txEnableDirect=false if txEnablePin uses inverse logic.
5656
5757
```c
5858
void setBaudrte(uint32 baud);

examples/RTU/README.MD

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,16 @@ This example introduces how to use the library for ModbusRTU (typicaly over RS-4
1111
## Modbus RTU Specific API
1212

1313
```c
14-
bool begin(SoftwareSerial* port, int16_t txPin=-1, bool direct=true);
15-
bool begin(HardwareSerial* port, int16_t txPin=-1, bool direct=true);
14+
bool begin(SoftwareSerial* port, int16_t txEnablePin=-1, bool txEnableDirect=true);
15+
bool begin(HardwareSerial* port, int16_t txEnablePin=-1, bool txEnableDirect=true);
1616
bool begin(Stream* port);
1717
```
1818
1919
- `port` Pointer to Serial port
20-
- `txPin` RX/TX control pin. Not assigned (assume auto RX/TX) by default
21-
- `direct` Direct (true, default) or inverse (false) RX/TX pin control.
20+
- `txEnablePin` RX/TX control pin. Not assigned (assume auto RX/TX) by default
21+
- `txEnableDirect` Direct (true, default) or inverse (false) RX/TX pin control.
2222
23-
Assign Serial port. txPin controls transmit enable for MAX-485.
23+
Assign Serial port. txEnablePin controls transmit enable for MAX-485.
2424
2525
```c
2626
void setBaudrate(uint32 baud);

src/ModbusRTU.cpp

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -109,17 +109,17 @@ void ModbusRTUTemplate::setInterFrameTime(uint32_t t_us) {
109109
_t = t_us;
110110
}
111111

112-
bool ModbusRTUTemplate::begin(Stream* port, int16_t txPin, bool direct) {
112+
bool ModbusRTUTemplate::begin(Stream* port, int16_t txEnablePin, bool txEnableDirect) {
113113
_port = port;
114114
_t = 1750UL;
115115
#if defined(MODBUSRTU_FLUSH_DELAY)
116116
_t1 = charSendTime(0);
117117
#endif
118-
if (txPin >= 0) {
119-
_txPin = txPin;
120-
_direct = direct;
121-
pinMode(_txPin, OUTPUT);
122-
digitalWrite(_txPin, _direct?LOW:HIGH);
118+
if (txEnablePin >= 0) {
119+
_txEnablePin = txEnablePin;
120+
_direct = txEnableDirect;
121+
pinMode(_txEnablePin, OUTPUT);
122+
digitalWrite(_txEnablePin, _direct?LOW:HIGH);
123123
}
124124
return true;
125125
}
@@ -134,18 +134,18 @@ bool ModbusRTUTemplate::rawSend(uint8_t slaveId, uint8_t* frame, uint8_t len) {
134134
Serial.println();
135135
#endif
136136
#if defined(MODBUSRTU_REDE)
137-
if (_txPin >= 0 || _rxPin >= 0) {
138-
if (_txPin >= 0)
139-
digitalWrite(_txPin, _direct?HIGH:LOW);
137+
if (_txEnablePin >= 0 || _rxPin >= 0) {
138+
if (_txEnablePin >= 0)
139+
digitalWrite(_txEnablePin, _direct?HIGH:LOW);
140140
if (_rxPin >= 0)
141141
digitalWrite(_rxPin, _direct?HIGH:LOW);
142142
#if !defined(ESP32)
143143
delayMicroseconds(MODBUSRTU_REDE_SWITCH_US);
144144
#endif
145145
}
146146
#else
147-
if (_txPin >= 0) {
148-
digitalWrite(_txPin, _direct?HIGH:LOW);
147+
if (_txEnablePin >= 0) {
148+
digitalWrite(_txEnablePin, _direct?HIGH:LOW);
149149
#if !defined(ESP32)
150150
delayMicroseconds(MODBUSRTU_REDE_SWITCH_US);
151151
#endif
@@ -160,21 +160,21 @@ bool ModbusRTUTemplate::rawSend(uint8_t slaveId, uint8_t* frame, uint8_t len) {
160160
_port->write(newCrc & 0xFF);//Send CRC
161161
_port->flush();
162162
#if defined(MODBUSRTU_REDE)
163-
if (_txPin >= 0 || _rxPin >= 0) {
163+
if (_txEnablePin >= 0 || _rxPin >= 0) {
164164
#if defined(MODBUSRTU_FLUSH_DELAY)
165165
delayMicroseconds(_t1 * MODBUSRTU_FLUSH_DELAY);
166166
#endif
167-
if (_txPin >= 0)
168-
digitalWrite(_txPin, _direct?LOW:HIGH);
167+
if (_txEnablePin >= 0)
168+
digitalWrite(_txEnablePin, _direct?LOW:HIGH);
169169
if (_rxPin >= 0)
170170
digitalWrite(_rxPin, _direct?LOW:HIGH);
171171
}
172172
#else
173-
if (_txPin >= 0) {
173+
if (_txEnablePin >= 0) {
174174
#if defined(MODBUSRTU_FLUSH_DELAY)
175175
delayMicroseconds(_t1 * MODBUSRTU_FLUSH_DELAY);
176176
#endif
177-
digitalWrite(_txPin, _direct?LOW:HIGH);
177+
digitalWrite(_txEnablePin, _direct?LOW:HIGH);
178178
}
179179
#endif
180180
return true;

src/ModbusRTU.h

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@
1111
class ModbusRTUTemplate : public Modbus {
1212
protected:
1313
Stream* _port;
14-
int16_t _txPin = -1;
14+
int16_t _txEnablePin = -1;
1515
#if defined(MODBUSRTU_REDE)
1616
int16_t _rxPin = -1;
1717
#endif
18-
bool _direct = true; // Transmit control logic (true=direct, false=inverse)
18+
bool _direct = true; // Transmit control logic (true=txEnableDirect, false=inverse)
1919
uint32_t _t; // inter-frame delay in uS
2020
#if defined(MODBUSRTU_FLUSH_DELAY)
2121
uint32_t _t1; // char send time
@@ -47,12 +47,12 @@ class ModbusRTUTemplate : public Modbus {
4747
void setInterFrameTime(uint32_t t_us);
4848
uint32_t charSendTime(uint32_t baud, uint8_t char_bits = 11);
4949
template <class T>
50-
bool begin(T* port, int16_t txPin = -1, bool direct = true);
50+
bool begin(T* port, int16_t txEnablePin = -1, bool txEnableDirect = true);
5151
#if defined(MODBUSRTU_REDE)
5252
template <class T>
53-
bool begin(T* port, int16_t txPin, int16_t rxPin, bool direct);
53+
bool begin(T* port, int16_t txEnablePin, int16_t rxEnablePin, bool txEnableDirect);
5454
#endif
55-
bool begin(Stream* port, int16_t txPin = -1, bool direct = true);
55+
bool begin(Stream* port, int16_t txEnablePin = -1, bool txEnableDirect = true);
5656
void task();
5757
void client() { isMaster = true; };
5858
inline void master() {client();}
@@ -64,7 +64,7 @@ class ModbusRTUTemplate : public Modbus {
6464
};
6565

6666
template <class T>
67-
bool ModbusRTUTemplate::begin(T* port, int16_t txPin, bool direct) {
67+
bool ModbusRTUTemplate::begin(T* port, int16_t txEnablePin, bool txEnableDirect) {
6868
uint32_t baud = 0;
6969
#if defined(ESP32) || defined(ESP8266) // baudRate() only available with ESP32+ESP8266
7070
baud = port->baudRate();
@@ -76,20 +76,20 @@ bool ModbusRTUTemplate::begin(T* port, int16_t txPin, bool direct) {
7676
_t1 = charSendTime(baud);
7777
#endif
7878
_port = port;
79-
if (txPin >= 0) {
80-
_txPin = txPin;
81-
_direct = direct;
82-
pinMode(_txPin, OUTPUT);
83-
digitalWrite(_txPin, _direct?LOW:HIGH);
79+
if (txEnablePin >= 0) {
80+
_txEnablePin = txEnablePin;
81+
_direct = txEnableDirect;
82+
pinMode(_txEnablePin, OUTPUT);
83+
digitalWrite(_txEnablePin, _direct?LOW:HIGH);
8484
}
8585
return true;
8686
}
8787
#if defined(MODBUSRTU_REDE)
8888
template <class T>
89-
bool ModbusRTUTemplate::begin(T* port, int16_t txPin, int16_t rxPin, bool direct) {
90-
begin(port, txPin, direct);
91-
if (rxPin > 0) {
92-
_rxPin = rxPin;
89+
bool ModbusRTUTemplate::begin(T* port, int16_t txEnablePin, int16_t rxEnablePin, bool txEnableDirect) {
90+
begin(port, txEnablePin, txEnableDirect);
91+
if (rxEnablePin > 0) {
92+
_rxPin = rxEnablePin;
9393
pinMode(_rxPin, OUTPUT);
9494
digitalWrite(_rxPin, _direct?LOW:HIGH);
9595
}

0 commit comments

Comments
 (0)