satnogs-rotator-firmware
Loading...
Searching...
No Matches
rs485.h
Go to the documentation of this file.
1
10#ifndef RS485_H_
11#define RS485_H_
12
13#include <Arduino.h>
14
15/**************************************************************************/
24/**************************************************************************/
25class rs485 {
26public:
27
28 rs485(uint8_t pin_dir, uint16_t tx_time) {
29 _pin_dir = pin_dir;
30 _tx_time = tx_time;
31 }
32
33 /**************************************************************************/
39 /**************************************************************************/
40 void begin(uint16_t baudrate) {
41 pinMode(_pin_dir, OUTPUT);
42 Serial.begin(baudrate);
43 }
44
45 /**************************************************************************/
51 /**************************************************************************/
52 void print(String str) {
53 digitalWrite(_pin_dir, HIGH);
54 Serial.print(str);
55 delay(_tx_time);
56 digitalWrite(_pin_dir, LOW);
57 }
58
59 /**************************************************************************/
64 /**************************************************************************/
65 uint8_t read() {
66 return Serial.read();
67 }
68
69 /**************************************************************************/
74 /**************************************************************************/
75 uint8_t available(void) {
76 return Serial.available();
77 }
78
79 /**************************************************************************/
83 /**************************************************************************/
84 void flush() {
85 Serial.flush();
86 }
87
88 /**************************************************************************/
92 /**************************************************************************/
93 void end() {
94 Serial.end();
95 }
96
97private:
98 uint8_t _pin_dir;
99 uint16_t _tx_time;
100};
101
102#endif /* RS485_H_ */
Class that functions for interacting with a RS485 transceiver.
Definition rs485.h:25
void end()
Disables RS485 communication.
Definition rs485.h:93
uint16_t _tx_time
Definition rs485.h:99
uint8_t available(void)
The number of chars/uint8_t that are available in RS485 buffer.
Definition rs485.h:75
uint8_t _pin_dir
Definition rs485.h:98
void begin(uint16_t baudrate)
Initialize the RS485 transceiver.
Definition rs485.h:40
uint8_t read()
Read a char/uint8_t from RS485 bus.
Definition rs485.h:65
rs485(uint8_t pin_dir, uint16_t tx_time)
Definition rs485.h:28
void print(String str)
Print a string to RS485 bus.
Definition rs485.h:52
void flush()
Waits for the transmission of outgoing serial data to complete.
Definition rs485.h:84