Skip to content

Commit 68eb0cf

Browse files
committed
*Always* check that stream isn't null
Signed-off-by: Sara Damiano <sdamiano@stroudcenter.org>
1 parent 9bc2676 commit 68eb0cf

6 files changed

Lines changed: 23 additions & 8 deletions

File tree

ChangeLog.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,14 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
2020

2121
***
2222

23+
## [1.6.6]
24+
25+
### Fixed
26+
27+
- Fix attempt to set timeouts and run other functions on nullptr
28+
29+
***
30+
2331
## [1.6.5]
2432

2533
### Fixed
@@ -322,7 +330,8 @@ This information can now be found in its [own repository](https://github.com/Env
322330

323331
***
324332

325-
[Unreleased]: https://github.com/EnviroDIY/SensorModbusMaster/compare/v1.6.5...HEAD
333+
[Unreleased]: https://github.com/EnviroDIY/SensorModbusMaster/compare/v1.6.6...HEAD
334+
[1.6.6]: https://github.com/EnviroDIY/SensorModbusMaster/releases/tag/v1.6.6
326335
[1.6.5]: https://github.com/EnviroDIY/SensorModbusMaster/releases/tag/v1.6.5
327336
[1.6.4]: https://github.com/EnviroDIY/SensorModbusMaster/releases/tag/v1.6.4
328337
[1.6.3]: https://github.com/EnviroDIY/SensorModbusMaster/releases/tag/v1.6.3

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.6.5
1+
1.6.6

docs/Doxyfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ PROJECT_NAME = SensorModbusMaster
4848
# could be handy for archiving the generated documentation or if some version
4949
# control system is used.
5050

51-
PROJECT_NUMBER = 1.6.5
51+
PROJECT_NUMBER = 1.6.6
5252

5353
# Using the PROJECT_BRIEF tag one can provide an optional one line description
5454
# for a project that appears at the top of each page and should give viewers a

library.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "SensorModbusMaster",
3-
"version": "1.6.5",
3+
"version": "1.6.6",
44
"keywords": "sensor, modbus, master, EnviroDIY",
55
"description": "Arduino library for communicating via modbus with the Arduino acting as master",
66
"repository": {

library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=SensorModbusMaster
2-
version=1.6.5
2+
version=1.6.6
33
author=Sara Damiano <sdamiano@stroudcenter.org>
44
maintainer=Sara Damiano <sdamiano@stroudcenter.org>
55
sentence=Arduino library for communicating via modbus with the Arduino acting as master

src/SensorModbusMaster.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ uint32_t modbusMaster::getCommandTimeout() {
115115
}
116116

117117
void modbusMaster::setFrameTimeout(uint32_t timeout) {
118-
_stream->setTimeout(timeout);
118+
if (_stream != nullptr) { _stream->setTimeout(timeout); }
119119
modbusFrameTimeout = timeout;
120120
}
121121
uint32_t modbusMaster::getFrameTimeout() {
@@ -131,11 +131,11 @@ uint8_t modbusMaster::getCommandRetries() {
131131

132132
void modbusMaster::setStream(Stream* stream) {
133133
_stream = stream;
134-
_stream->setTimeout(modbusFrameTimeout);
134+
if (_stream != nullptr) { _stream->setTimeout(modbusFrameTimeout); }
135135
}
136136
void modbusMaster::setStream(Stream& stream) {
137137
_stream = &stream;
138-
_stream->setTimeout(modbusFrameTimeout);
138+
if (_stream != nullptr) { _stream->setTimeout(modbusFrameTimeout); }
139139
}
140140
Stream* modbusMaster::getStream() {
141141
return _stream;
@@ -1015,6 +1015,12 @@ bool modbusMaster::setCoils(int16_t startCoil, int16_t numCoils, byte* value) {
10151015

10161016
// This sends a command to the sensor bus and listens for a response
10171017
uint16_t modbusMaster::sendCommand(byte* command, int commandLength) {
1018+
if (_stream == nullptr) {
1019+
debugPrint("Modbus Error: No Stream Defined!\n");
1020+
lastError = NO_RESPONSE;
1021+
return static_cast<uint16_t>(lastError) << 12;
1022+
}
1023+
10181024
// Empty the response buffer
10191025
memset(responseBuffer, 0x00, RESPONSE_BUFFER_SIZE);
10201026

0 commit comments

Comments
 (0)