Skip to content

Commit bb0cac8

Browse files
committed
More constructors
Signed-off-by: Sara Damiano <[email protected]>
1 parent 2418a3f commit bb0cac8

File tree

2 files changed

+49
-1
lines changed

2 files changed

+49
-1
lines changed

src/SensorModbusMaster.cpp

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,11 @@ byte modbusMaster::crcFrame[2] = {
2626
// CONSTRUCTORS, BEGINS, SETTERS, GETTERS
2727
//----------------------------------------------------------------------------
2828

29-
modbusMaster::modbusMaster() {}
29+
modbusMaster::modbusMaster() {
30+
setSlaveID(0);
31+
setStream(nullptr);
32+
setEnablePin(-1);
33+
}
3034
modbusMaster::modbusMaster(byte modbusSlaveID, Stream* stream) {
3135
setSlaveID(modbusSlaveID);
3236
setStream(stream);
@@ -47,6 +51,26 @@ modbusMaster::modbusMaster(byte modbusSlaveID, Stream& stream, int8_t enablePin)
4751
setStream(&stream);
4852
setEnablePin(enablePin);
4953
}
54+
modbusMaster::modbusMaster(Stream* stream) {
55+
setSlaveID(0);
56+
setStream(stream);
57+
setEnablePin(-1);
58+
}
59+
modbusMaster::modbusMaster(Stream& stream) {
60+
setSlaveID(0);
61+
setStream(&stream);
62+
setEnablePin(-1);
63+
}
64+
modbusMaster::modbusMaster(Stream* stream, int8_t enablePin) {
65+
setSlaveID(0);
66+
setStream(stream);
67+
setEnablePin(enablePin);
68+
}
69+
modbusMaster::modbusMaster(Stream& stream, int8_t enablePin) {
70+
setSlaveID(0);
71+
setStream(&stream);
72+
setEnablePin(enablePin);
73+
}
5074

5175
// This function sets up the communication
5276
// It should be run during the arduino "setup" function.

src/SensorModbusMaster.h

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,30 @@ class modbusMaster {
201201
* to an RS485 to TTL adapter. Use a negative number if this does not apply.
202202
*/
203203
modbusMaster(byte modbusSlaveID, Stream& stream, int8_t enablePin);
204+
/**
205+
* @brief Construct a new modbus Master object
206+
*
207+
* @param stream A pointer to the Arduino stream object to communicate with.
208+
*/
209+
modbusMaster(Stream* stream);
210+
/**
211+
* @brief Construct a new modbus Master object
212+
*
213+
* @param stream A reference to the Arduino stream object to communicate with.
214+
*/
215+
modbusMaster(Stream& stream);
216+
/**
217+
* @copydoc modbusMaster(Stream* stream)
218+
* @param enablePin A pin on the Arduino processor to use to send an enable signal
219+
* to an RS485 to TTL adapter. Use a negative number if this does not apply.
220+
*/
221+
modbusMaster(Stream* stream, int8_t enablePin);
222+
/**
223+
* @copydoc modbusMaster(Stream& stream)
224+
* @param enablePin A pin on the Arduino processor to use to send an enable signal
225+
* to an RS485 to TTL adapter. Use a negative number if this does not apply.
226+
*/
227+
modbusMaster(Stream& stream, int8_t enablePin);
204228

205229
/**
206230
* @brief Equivalent to a constructor to assign members of the modbusMaster object

0 commit comments

Comments
 (0)