-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathModbusSerial.h
More file actions
45 lines (39 loc) · 1.17 KB
/
ModbusSerial.h
File metadata and controls
45 lines (39 loc) · 1.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
/*
ModbusSerial.h - Header for ModbusSerial Library
Copyright (C) 2014 André Sarmento Barbosa
*/
#include <Arduino.h>
#include "Modbus.h"
#ifndef MODBUSSERIAL_H
#define MODBUSSERIAL_H
//#define USE_SOFTWARE_SERIAL
#ifdef USE_SOFTWARE_SERIAL
#include <SoftwareSerial.h>
#endif
class ModbusSerial : public Modbus {
protected:
Stream* _port;
long _baud;
u_int _format;
int _txPin;
unsigned int _t15; // inter character time out
unsigned int _t35; // frame delay
byte _slaveId;
word calcCrc(byte address, byte* pduframe, byte pdulen);
public:
ModbusSerial();
bool setSlaveId(byte slaveId);
byte getSlaveId();
bool config(HardwareSerial* port, long baud, u_int format, int txPin=-1);
#ifdef USE_SOFTWARE_SERIAL
bool config(SoftwareSerial* port, long baud, int txPin=-1);
#endif
#ifdef __AVR_ATmega32U4__
bool config(Serial_* port, long baud, u_int format, int txPin=-1);
#endif
void task();
bool receive(byte* frame);
bool sendPDU(byte* pduframe);
bool send(byte* frame);
};
#endif //MODBUSSERIAL_H