mirror of
https://github.com/DCC-EX/CommandStation-EX.git
synced 2024-12-25 05:31:24 +01:00
33 lines
803 B
C
33 lines
803 B
C
|
#ifndef ModbusRTUComm_h
|
||
|
#define ModbusRTUComm_h
|
||
|
|
||
|
#include "Arduino.h"
|
||
|
#include "ModbusADU.h"
|
||
|
|
||
|
enum ModbusRTUCommError : uint8_t {
|
||
|
MODBUS_RTU_COMM_SUCCESS = 0,
|
||
|
MODBUS_RTU_COMM_TIMEOUT = 1,
|
||
|
MODBUS_RTU_COMM_FRAME_ERROR = 2,
|
||
|
MODBUS_RTU_COMM_CRC_ERROR = 3
|
||
|
};
|
||
|
|
||
|
class ModbusRTUComm {
|
||
|
public:
|
||
|
ModbusRTUComm(Stream& serial, int8_t dePin = -1, int8_t rePin = -1);
|
||
|
void begin(unsigned long baud, uint32_t config = SERIAL_8N1);
|
||
|
void setTimeout(unsigned long timeout);
|
||
|
ModbusRTUCommError readAdu(ModbusADU& adu);
|
||
|
void writeAdu(ModbusADU& adu);
|
||
|
void clearRxBuffer();
|
||
|
|
||
|
private:
|
||
|
Stream& _serial;
|
||
|
int8_t _dePin;
|
||
|
int8_t _rePin;
|
||
|
unsigned long _charTimeout;
|
||
|
unsigned long _frameTimeout;
|
||
|
unsigned long _postDelay = 0;
|
||
|
unsigned long _readTimeout = 0;
|
||
|
};
|
||
|
|
||
|
#endif
|