diff --git a/.gitmodules b/.gitmodules index 3403f6423b..de26ab39fb 100644 --- a/.gitmodules +++ b/.gitmodules @@ -145,3 +145,7 @@ [submodule "Libraries.Arduino_TensorFlowLite"] path = Sming/Libraries/Arduino_TensorFlowLite url = https://github.com/slaff/Arduino_TensorFlowLite.git +[submodule "Libraries.modbusino"] + path = Sming/Libraries/modbusino/modbusino + url = https://github.com/kmihaylov/modbusino.git + ignore = dirty diff --git a/Sming/Libraries/modbusino/README.rst b/Sming/Libraries/modbusino/README.rst new file mode 100644 index 0000000000..150507a191 --- /dev/null +++ b/Sming/Libraries/modbusino/README.rst @@ -0,0 +1,26 @@ +modbusino RTU Library (modbus slave) +==================================== + +modbusino is lightweight RTU `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. diff --git a/Sming/Libraries/modbusino/component.mk b/Sming/Libraries/modbusino/component.mk new file mode 100644 index 0000000000..2946bc1823 --- /dev/null +++ b/Sming/Libraries/modbusino/component.mk @@ -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) diff --git a/Sming/Libraries/modbusino/modbusino b/Sming/Libraries/modbusino/modbusino new file mode 160000 index 0000000000..02dff3cd04 --- /dev/null +++ b/Sming/Libraries/modbusino/modbusino @@ -0,0 +1 @@ +Subproject commit 02dff3cd04e9b7874ae2c76a78ce5f3ecf6e44a2 diff --git a/Sming/Libraries/modbusino/samples/generic/Makefile b/Sming/Libraries/modbusino/samples/generic/Makefile new file mode 100644 index 0000000000..ff51b6c3a7 --- /dev/null +++ b/Sming/Libraries/modbusino/samples/generic/Makefile @@ -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 diff --git a/Sming/Libraries/modbusino/samples/generic/README.rst b/Sming/Libraries/modbusino/samples/generic/README.rst new file mode 100644 index 0000000000..82ed52c267 --- /dev/null +++ b/Sming/Libraries/modbusino/samples/generic/README.rst @@ -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 diff --git a/Sming/Libraries/modbusino/samples/generic/app/.cs b/Sming/Libraries/modbusino/samples/generic/app/.cs new file mode 100644 index 0000000000..e69de29bb2 diff --git a/Sming/Libraries/modbusino/samples/generic/app/application.cpp b/Sming/Libraries/modbusino/samples/generic/app/application.cpp new file mode 100644 index 0000000000..7256e6509c --- /dev/null +++ b/Sming/Libraries/modbusino/samples/generic/app/application.cpp @@ -0,0 +1,24 @@ +#include +#include +#include + +#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); +} diff --git a/Sming/Libraries/modbusino/samples/generic/component.mk b/Sming/Libraries/modbusino/samples/generic/component.mk new file mode 100644 index 0000000000..4163e3ffed --- /dev/null +++ b/Sming/Libraries/modbusino/samples/generic/component.mk @@ -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)