-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathRS485CommClass.h
132 lines (115 loc) · 5.02 KB
/
RS485CommClass.h
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
/**
* @file RS485CommClass.h
* @author Leonardo Cavagnis
* @brief Header file for the RS485CommClass used to initialize and interact with RS485 and RS232 communication protocols on the Portenta Machine Control board.
*
* This library provides a class to manage the RS485 and RS232 communication protocols of the Portenta Machine Control board.
* It allows initializing and interacting with the serial protocols. The library also initializes the corresponding LEDs.
*/
#ifndef __RS485_COMM_CLASS_H
#define __RS485_COMM_CLASS_H
/* Includes -------------------------------------------------------------------*/
#include <ArduinoRS485.h>
#include <Arduino.h>
#include <mbed.h>
#include "pins_mc.h"
/* Class ----------------------------------------------------------------------*/
/**
* @class RS485CommClass
* @brief Class for managing the RS485 and RS232 communication protocols of the Portenta Machine Control.
*
* The `RS485CommClass` is a subclass of `RS485Class` and provides methods to work with the RS485 and RS232 communication protocols on the Portenta Machine Control board.
* It includes features to initialize, configure, and interact with the serial protocols. The library also initializes the corresponding LED for RS485.
*/
class RS485CommClass : public RS485Class {
public:
/**
* @brief Construct a RS485CommClass object.
*
* This constructor initializes a RS485CommClass object with the specified UART interface and pins.
*
* @param uart_itf The UART interface to use for communication.
* @param rs_tx_pin The pin for transmitting data on the RS485 Bus.
* @param rs_de_pin The pin for enabling the RS485 driver.
* @param rs_re_pin The pin for setting the RS485 driver in receive or transmit mode.
*/
RS485CommClass(arduino::UART& uart_itf, PinName rs_tx_pin = MC_RS485_TX_PIN, PinName rs_de_pin = MC_RS485_DE_PIN, PinName rs_re_pin = MC_RS485_RE_PIN);
/**
* @brief Destruct the RS485CommClass object.
*
* This destructor releases any resources used by the RS485CommClass object.
* It will automatically be called when the object goes out of scope.
*/
~RS485CommClass();
/**
* @brief Begin the RS485 communication protocol.
*
* This method initializes the RS485 communication protocol with the specified baud rate and pre/post delays.
*
* @param baudrate The desired baud rate for the RS485 communication.
* @param predelay The delay before sending data in the RS485 communication (default: RS485_DEFAULT_PRE_DELAY).
* @param postdelay The delay after sending data in the RS485 communication (default: RS485_DEFAULT_POST_DELAY).
*/
void begin(unsigned long baudrate = 115200, int predelay = RS485_DEFAULT_PRE_DELAY, int postdelay = RS485_DEFAULT_POST_DELAY);
/**
* @brief Close the RS485 communication protocol.
*
* This method de-initializes the RS485 communication protocol, stopping communication on the RS485 Bus.
*/
void end();
/**
* @brief Set RS485 mode to RS232.
*
* This method sets the RS485 mode to RS232 or RS485.
*
* @param enable If true, sets the RS485 mode to RS232, else sets to RS485 mode.
*/
void setModeRS232(bool enable);
/**
* @brief Set YZ termination for RS485 communication.
*
* This method enables or disables YZ termination for RS485 communication.
*
* @param enable If true, enables YZ termination, else disables it.
*/
void setYZTerm(bool enable);
/**
* @brief Set AB termination for RS485 communication.
*
* This method enables or disables AB termination for RS485 communication.
*
* @param enable If true, enables AB termination, else disables it.
*/
void setABTerm(bool enable);
/**
* @brief Set the slew rate for RS485 communication.
*
* This method enables or disables the slew rate control for RS485 communication.
*
* @param enable If true, enables the slew rate control, else disables it.
*/
void setSlew(bool enable);
/**
* @brief Set RS485 communication to Full Duplex mode.
*
* This method sets RS485 communication to Full Duplex or Half Duplex mode.
*
* @param enable If true, sets RS485 communication to Full Duplex mode, else to Half Duplex mode.
*/
void setFullDuplex(bool enable);
private:
/**
* @brief Enable RS485 communication.
*
* This method enables RS485 communication.
*/
void _enable();
/**
* @brief Disable RS485 communication.
*
* This method disables RS485 communication.
*/
void _disable();
};
extern RS485CommClass MachineControl_RS485Comm;
#endif /* __RS485_COMM_CLASS_H */