BusBricks: /Users/felixschulke/Developement/Arduino/Modbus_RTU/Modbus_RTU/Modbus-RTU/lib/ModbusRTU/CommInterface_modbusRTU.h Source File
BusBricks  0.1
Customize bus-communication
Loading...
Searching...
No Matches
CommInterface_modbusRTU.h
Go to the documentation of this file.
1
24#ifndef COMMINTERFACE_MODBUSRTU
25#define COMMINTERFACE_MODBUSRTU
26#ifdef ARDUINO
27 #include <Arduino.h>
28 #include <SoftwareSerial.h>
29 typedef SoftwareSerial SoftwareSerial; // typedef for clang-build
30#else
31 #include <mockSoftwareSerial.h> // include Library to support testing with SoftwareSerial in native-environment
32 #include <mockArduino.h> // include Library to support testing with Arduino-specific functions in native-environment
33 typedef arduinoMocking::SoftwareSerial SoftwareSerial; // typedef for clang-build
34 using namespace arduinoMocking;
35#endif
36
37#include <CommInterface.h>
38
40//#define DEBUG
41
43#define MAXFRAMESIZE 256
44
50class CommInterface_modbusRTU: public CommInterface<SoftwareSerial>{
51 public:
59 CommInterface_modbusRTU(SoftwareSerial* softwareserial ,uint16_t baudrate, char deviceId);
60
66
74 bool send() override;
75
100 bool receive() override;
101
107 char getDeviceId();
108
109 private:
111 const char deviceId;
112
114 unsigned long _charTimeout;
115
117 unsigned long _frameTimeout;
118
120 unsigned long _recTimeout = 1000000;
121
123 unsigned long _nullByteSilenece;
124
130 void _calculateTimeouts(uint16_t baud);
131
136 size_t _clearRxBuffer();
137
138};
139
140#endif // COMMINTERFACE_MODBUSRTU
The Modbus-RTU CommInterface-class specifies a communication interface with SoftwareSerial as interfa...
Definition CommInterface_modbusRTU.h:50
bool send() override
Override of CommInterface send-function. Send the frame, sendBuffer is pointing to by writing and flu...
Definition CommInterface_modbusRTU.cpp:38
bool receive() override
Receives a Modbus RTU frame and writes it to receiveBuffer.
Definition CommInterface_modbusRTU.cpp:49
CommInterface_modbusRTU(SoftwareSerial *softwareserial, uint16_t baudrate, char deviceId)
Construct a new CommInterface_modbusRTU object.
Definition CommInterface_modbusRTU.cpp:27
char getDeviceId()
Get Modbus-specific device-identifier.
Definition CommInterface_modbusRTU.cpp:134
~CommInterface_modbusRTU()
Destroy the CommInterface_modbusRTU object.
Definition CommInterface_modbusRTU.cpp:34
Template for generic communication-interface specifies a standardized interface to use for integratin...
Definition CommInterface.h:123
Mock class to simulate the SoftwareSerial library for native builds.
Definition mockSoftwareSerial.h:65
Provides mock implementations of Arduino framework functions and classes for native builds.
Definition mockArduino.cpp:28