-
-
Notifications
You must be signed in to change notification settings - Fork 345
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Modbusino] - simple modbus rtu library (#2043)
* Add modbusino library + patch + sample + Readme. Co-authored-by: mikee47 <[email protected]>
- Loading branch information
Showing
9 changed files
with
97 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
modbusino RTU Library (modbus slave) | ||
==================================== | ||
|
||
modbusino is lightweight RTU `Modbus <https://en.wikipedia.org/wiki/Modbus>`__ | ||
slave library that supports 'read holding registers' and 'write multiple registers' functions. | ||
Please note that prior to commit 02dff3c (branch Sming, port URL https://github.com/kmihaylov/modbusino) | ||
a delay may occur after sending a message (more information can be found in the PR thread #2043, | ||
https://github.com/SmingHub/Sming/pull/2043#issuecomment-615945823). | ||
|
||
|
||
Configuration variables | ||
----------------------- | ||
|
||
|
||
.. envvar:: RS485_RE_PIN | ||
|
||
Default: 15 | ||
|
||
GPIO pin number for RE (Receive-Enable) output. | ||
|
||
|
||
.. envvar:: RS485_TX_LEVEL | ||
|
||
Default: HIGH. | ||
|
||
Active level for RE pin during transmission. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
COMPONENT_SUBMODULES := modbusino | ||
COMPONENT_SRCDIRS := modbusino | ||
COMPONENT_INCDIRS := modbusino | ||
|
||
COMPONENT_VARS += RS485_RE_PIN | ||
RS485_RE_PIN ?= 15 | ||
COMPONENT_CXXFLAGS += -DRS485_RE_PIN=$(RS485_RE_PIN) | ||
|
||
COMPONENT_VARS += RS485_TX_LEVEL | ||
RS485_TX_LEVEL ?= HIGH | ||
COMPONENT_CXXFLAGS += -DRS485_TX_LEVEL=$(RS485_TX_LEVEL) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
##################################################################### | ||
#### Please don't change this file. Use component.mk instead #### | ||
##################################################################### | ||
|
||
ifndef SMING_HOME | ||
$(error SMING_HOME is not set: please configure it as an environment variable) | ||
endif | ||
|
||
include $(SMING_HOME)/project.mk |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
Modbusino RTU generic sample | ||
============================ | ||
|
||
.. highlight:: bash | ||
|
||
The sample code provides three element uint16_t array used for the modbus slave registers. These values are printed each second through UART1. | ||
mbPrint() is triggered on valid write multiple registers (0x10) command. | ||
|
||
Several environment variables (envvar:`RS485_RE_PIN` :envvar:`RS485_TX_LEVEL`) can be used for configuration. | ||
The slave address is defined with envvar:`MB_SLAVE_ADDR`. For example:: | ||
|
||
make MB_SLAVE_ADDR=2 | ||
|
||
These variables can be listed with:: | ||
|
||
make list-config |
Empty file.
24 changes: 24 additions & 0 deletions
24
Sming/Libraries/modbusino/samples/generic/app/application.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#include <SmingCore.h> | ||
#include <Debug.h> | ||
#include <Modbusino.h> | ||
|
||
#define ARRLEN 3 | ||
uint16_t mbDataArray[ARRLEN] = {0, 0, 0}; | ||
ModbusinoSlave mbSlave(MB_SLAVE_ADDR, mbDataArray, ARRLEN); | ||
|
||
HardwareSerial debugComPort(UART1); | ||
|
||
void mbPrint() | ||
{ | ||
debugf("Register values, #0: %d, #1: %d, #2: %d", mbDataArray[0], mbDataArray[1], mbDataArray[2]); | ||
} | ||
|
||
void init() | ||
{ | ||
debugComPort.begin(SERIAL_BAUD_RATE, SERIAL_8N1, SERIAL_TX_ONLY); | ||
debugComPort.systemDebugOutput(true); | ||
Debug.setDebug(debugComPort); | ||
Debug.start(); | ||
mbSlave.setup(SERIAL_BAUD_RATE); | ||
mbSlave.setRxCallback(mbPrint); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
ARDUINO_LIBRARIES := modbusino | ||
DISABLE_SPIFFS = 1 | ||
|
||
CONFIG_VARS += MB_SLAVE_ADDR | ||
MB_SLAVE_ADDR ?= 1 | ||
APP_CFLAGS += -DMB_SLAVE_ADDR=$(MB_SLAVE_ADDR) |