Skip to content

Commit f746439

Browse files
committed
Minor cleanup, updated example
1 parent 58c1877 commit f746439

File tree

6 files changed

+39
-27
lines changed

6 files changed

+39
-27
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
# KellerModbus
2-
A library to use an Arduino as a master to control and communicate via modbus with the pressure and water level sensors produced by Keller International & [Keller America](https://www.kelleramerica.com).
2+
A library to use an Arduino as a master to control and communicate via modbus with the pressure and water level sensors produced by Keller International & [Keller America](https://www.kelleramerica.com).
33

44
This library depends on the [EnviroDIY/SensorModbusMaster](https://github.com/EnviroDIY/SensorModbusMaster) library.
55
The [EnviroDIY/ModularSensor](https://github.com/EnviroDIY/ModularSensors) library functions for Keller depend on this library.
66

7-
The library has been tested to work with a Keller Acculevel, which is a Keller Series 30, Class 5, Group 20 sensor water level transmitter with a software/firmware version of 5.20-12.28 (i.e. made after the 2012 in the 28th week). The library should also work with all Keller sensors of the same Series/Class/Group with the same or a later software version.
7+
The library has been tested to work with a Keller Nanolevel and a Keller Acculevel, which is a Keller Series 30, Class 5, Group 20 sensor water level transmitter with a software/firmware version of 5.20-12.28 (i.e. made after the 2012 in the 28th week). The library should also work with all Keller sensors of the same Series/Class/Group with the same or a later software version.
88

99
## <a name="functions"></a>Functions
1010

@@ -24,7 +24,7 @@ Documentation is licensed as [Creative Commons Attribution-ShareAlike 4.0](https
2424
[EnviroDIY](http://envirodiy.org/)™ is presented by the Stroud Water Research Center, with contributions from a community of enthusiasts sharing do-it-yourself ideas for environmental science and monitoring.
2525

2626
[Anthony Aufdenakmpe](https://github.com/aufdenkampe) is the primary developer of this library.
27-
We are grateful for the helpful technical assistance from the staff at [Keller America](https://www.kelleramerica.com).
27+
We are grateful for the helpful technical assistance from the staff at [Keller America](https://www.kelleramerica.com).
2828

2929
This library has benefited from the support from the following funders:
3030

examples/GetValues/GetValues.ino

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ For testing individual functions in KellerModbus library
2222
// ie, pin locations, addresses, calibrations and related settings
2323
// ---------------------------------------------------------------------------
2424

25+
// Define the sensor type
26+
kellerModel model = KellerAcculevel;
27+
2528
// Define the sensor's modbus address
2629
byte modbusAddress = 0x01; // The sensor's modbus address, or SlaveID
2730
// Keller defines the following:
@@ -72,7 +75,7 @@ void setup()
7275
modbusSerial.begin(9600); // The modbus serial stream - Baud rate MUST be 9600.
7376

7477
// Start up the modbus sensor
75-
sensor.begin(modbusAddress, &modbusSerial, DEREPin); // bool begin(byte modbusSlaveID, Stream *stream, int enablePin = -1);
78+
sensor.begin(model, modbusAddress, &modbusSerial, DEREPin);
7679

7780
// Turn on debugging
7881
// sensor.setDebugStream(&Serial);

library.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "KellerModbus",
3-
"version": "0.1.1",
3+
"version": "0.2.0",
44
"keywords": "Keller, Modbus, communication, bus, sensor, water level, pressure",
55
"description": "Arduino library for communication with Keller pressure and water level sensors via Modbus.",
66
"repository":
@@ -14,6 +14,9 @@
1414
"name": "Anthony Aufdenkampe",
1515
"email": "aaufdenkampe@limno.com",
1616
"maintainer": true
17+
},
18+
{
19+
"name": "Neil Hancock"
1720
}
1821
],
1922
"license": "BSD-3-Clause",

library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=KellerModbus
2-
version=0.1.1
2+
version=0.2.0
33
author=Anthony Aufdenkampe <aaufdenkampe@limno.com>
44
maintainer=Anthony Aufdenkampe <aaufdenkampe@limno.com>
55
sentence=Arduino library for communication with Keller pressure and water level sensors via Modbus.

src/KellerModbus.cpp

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -93,28 +93,34 @@ bool keller::getValues(float &valueP1, float &valueTOB1)
9393
valueP1 = -9999; // Pressure (bar) for sensor1
9494
valueTOB1 = -9999; // Temperature (C) on board sensor 1
9595

96-
// valueP1 = modbus.float32FromRegister(0x03, 0x0100);
97-
// valueTOB1 = modbus.float32FromRegister(0x03, 0x0102);
98-
if (Nanolevel_kellerModel == _model )
96+
switch(_model)
9997
{
100-
// This gets two values, but as seperate messages
101-
if (modbus.getRegisters(0x03, 0x0002, 2))
98+
case KellerNanolevel: // This gets two values, but as seperate messages
10299
{
103-
valueP1 = modbus.float32FromFrame(bigEndian, 3);
104-
if (modbus.getRegisters(0x03, 0x0006, 2))
100+
if (modbus.getRegisters(0x03, 0x0002, 2))
105101
{
106-
valueTOB1 = modbus.float32FromFrame(bigEndian, 3);
107-
} else return false;
102+
valueP1 = modbus.float32FromFrame(bigEndian, 3);
103+
if (modbus.getRegisters(0x03, 0x0006, 2))
104+
{
105+
valueTOB1 = modbus.float32FromFrame(bigEndian, 3);
106+
break;
107+
}
108+
else return false;
109+
}
110+
else return false;
111+
}
112+
default: // for all other sensors get two values in one message
113+
{
114+
if (modbus.getRegisters(0x03, 0x0100, 4))
115+
{
116+
valueP1 = modbus.float32FromFrame(bigEndian, 3);
117+
valueTOB1 = modbus.float32FromFrame(bigEndian, 7);
118+
break;
119+
}
120+
else return false;
108121
}
109-
else return false;
110-
} else // for all other sensors get two values in one message
111-
if (modbus.getRegisters(0x03, 0x0100, 4))
112-
{
113-
valueP1 = modbus.float32FromFrame(bigEndian, 3);
114-
valueTOB1 = modbus.float32FromFrame(bigEndian, 7);
115122
}
116-
else return false;
117-
123+
118124
_LastTOB1 = valueTOB1;
119125
return true;
120126
}

src/KellerModbus.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ Tested with Acculevel, Nanolevel
1919
// NOTE: not presently used but in place for future. See use in https://github.com/EnviroDIY/YosemitechModbus
2020
typedef enum kellerModel
2121
{
22-
Acculevel = 0,
23-
Nanolevel_kellerModel = 1,
22+
KellerAcculevel = 0,
23+
KellerNanolevel = 1,
2424
OTHER // Use if the sensor model is another model.
2525
} kellerModel;
2626

@@ -32,8 +32,8 @@ class keller
3232
// This function sets up the communication
3333
// It should be run during the arduino "setup" function.
3434
// The "stream" device must be initialized prior to running this.
35-
bool begin(kellerModel model,byte modbusSlaveID, Stream *stream, int enablePin = -1);
36-
bool begin(kellerModel model,byte modbusSlaveID, Stream &stream, int enablePin = -1);
35+
bool begin(kellerModel model, byte modbusSlaveID, Stream *stream, int enablePin = -1);
36+
bool begin(kellerModel model, byte modbusSlaveID, Stream &stream, int enablePin = -1);
3737

3838
// This gets the modbus slave ID.
3939
// NOTE: NOT YET WORKING

0 commit comments

Comments
 (0)