ARCS SDK API  0.24.0
serial.h
浏览该文件的文档.
1 /** @file serial.h
2  * @brief 串口通信
3  */
4 #ifndef AUBO_SDK_SERIAL_INTERFACE_H
5 #define AUBO_SDK_SERIAL_INTERFACE_H
6 
7 #include <vector>
8 #include <memory>
9 
10 #include <aubo/type_def.h>
11 #include <aubo/global_config.h>
12 
13 namespace arcs {
14 namespace common_interface {
15 
16 class ARCS_ABI_EXPORT Serial
17 {
18 public:
19  Serial();
20  virtual ~Serial();
21 
22  /**
23  * Open TCP/IP ethernet communication serial
24  *
25  * @param device
26  * @param baud
27  * @param stop_bits
28  * @param even
29  * @param serial_name
30  * @return
31  *
32  * @par Python函数原型
33  * serialOpen(self: pyaubo_sdk.Serial, arg0: str, arg1: int, arg2: float,
34  * arg3: int, arg4: str) -> int
35  *
36  * @par Lua函数原型
37  * serialOpen(device: string, baud: number, stop_bits: number, even: number,
38  * serial_name: string) -> nil
39  *
40  */
41  int serialOpen(const std::string &device, int baud, float stop_bits,
42  int even, const std::string &serial_name = "serial_0");
43 
44  /**
45  * Closes TCP/IP serial communication
46  * Closes down the serial connection to the server.
47  *
48  * @param serial_name
49  * @return
50  *
51  * @par Python函数原型
52  * serialClose(self: pyaubo_sdk.Serial, arg0: str) -> int
53  *
54  * @par Lua函数原型
55  * serialClose(serial_name: string) -> nil
56  *
57  */
58  int serialClose(const std::string &serial_name = "serial_0");
59 
60  /**
61  * Reads a number of bytes from the serial. Bytes are in network byte
62  * order. A maximum of 30 values can be read in one command.
63  * A list of numbers read (list of ints, length=number+1)
64  *
65  * @param variable
66  * @param serial_name
67  * @return
68  *
69  * @par Python函数原型
70  * serialReadByte(self: pyaubo_sdk.Serial, arg0: str, arg1: str) -> int
71  *
72  * @par Lua函数原型
73  * serialReadByte(variable: string, serial_name: string) -> number
74  *
75  */
76  int serialReadByte(const std::string &variable,
77  const std::string &serial_name = "serial_0");
78 
79  /**
80  * Reads a number of bytes from the serial. Bytes are in network byte
81  * order. A maximum of 30 values can be read in one command.
82  * A list of numbers read (list of ints, length=number+1)
83  *
84  * @param number
85  * @param variable
86  * @param serial_name
87  * @return
88  *
89  * @par Python函数原型
90  * serialReadByteList(self: pyaubo_sdk.Serial, arg0: int, arg1: str, arg2:
91  * str) -> int
92  *
93  * @par Lua函数原型
94  * serialReadByteList(number: number, variable: string, serial_name: string)
95  * -> number
96  *
97  */
98  int serialReadByteList(int number, const std::string &variable,
99  const std::string &serial_name = "serial_0");
100 
101  /**
102  * Reads all data from the serial and returns the data as a string.
103  * Bytes are in network byte order.
104  *
105  * The optional parameters "prefix" and "suffix", can be used to express
106  * what is extracted from the serial. The "prefix" specifies the start
107  * of the substring (message) extracted from the serial. The data up to
108  * the end of the "prefix" will be ignored and removed from the serial.
109  * The "suffix" specifies the end of the substring (message) extracted
110  * from the serial. Any remaining data on the serial, after the "suffix",
111  * will be preserved. E.g. if the serial server sends a string
112  * "noise>hello<", the controller can receive the "hello" by calling this
113  * script function with the prefix=">" and suffix="<". By using the
114  * "prefix" and "suffix" it is also possible send multiple string to the
115  * controller at once, because the suffix defines where the message ends.
116  * E.g. sending ">hello<>world<"
117  *
118  * @param variable
119  * @param serial_name
120  * @param prefix
121  * @param suffix
122  * @param interpret_escape
123  * @return
124  *
125  * @par Python函数原型
126  * serialReadString(self: pyaubo_sdk.Serial, arg0: str, arg1: str, arg2:
127  * str, arg3: str, arg4: bool) -> int
128  *
129  * @par Lua函数原型
130  * serialReadString(variable: string, serial_name: string, prefix: string,
131  * suffix: string, interpret_escape: boolean) -> number
132  *
133  */
134  int serialReadString(const std::string &variable,
135  const std::string &serial_name = "serial_0",
136  const std::string &prefix = "",
137  const std::string &suffix = "",
138  bool interpret_escape = false);
139 
140  /**
141  * Sends a byte to the server
142  * Sends the byte <value> through the serial. Expects no response. Can
143  * be used to send special ASCII characters; 10 is newline, 2 is start of
144  * text, 3 is end of text.
145  *
146  * @param value
147  * @param serial_name
148  * @return
149  *
150  * @par Python函数原型
151  * serialSendByte(self: pyaubo_sdk.Serial, arg0: str, arg1: str) -> int
152  *
153  * @par Lua函数原型
154  * serialSendByte(value: string, serial_name: string) -> nil
155  *
156  */
157  int serialSendByte(char value, const std::string &serial_name = "serial_0");
158 
159  /**
160  * Sends an int (int32_t) to the server
161  * Sends the int <value> through the serial. Send in network byte order.
162  * Expects no response
163  *
164  * @param value
165  * @param serial_name
166  * @return
167  *
168  * @par Python函数原型
169  * serialSendInt(self: pyaubo_sdk.Serial, arg0: int, arg1: str) -> int
170  *
171  * @par Lua函数原型
172  * serialSendInt(value: number, serial_name: string) -> nil
173  *
174  */
175  int serialSendInt(int value, const std::string &serial_name = "serial_0");
176 
177  /**
178  * Sends a string with a newline character to the server - useful for
179  * communicatin with the UR dashboard server
180  * Sends the string <str> through the serial in ASCII coding. Expects no
181  * response.
182  *
183  * @param str
184  * @param serial_name
185  * @return
186  *
187  * @par Python函数原型
188  * serialSendLine(self: pyaubo_sdk.Serial, arg0: str, arg1: str) -> int
189  *
190  * @par Lua函数原型
191  * serialSendLine(str: string, serial_name: string) -> nil
192  *
193  */
194  int serialSendLine(const std::string &str,
195  const std::string &serial_name = "serial_0");
196 
197  /**
198  * Sends a string to the server
199  * Sends the string <str> through the serial in ASCII coding. Expects no
200  * response.
201  *
202  * @param str
203  * @param serial_name
204  * @return
205  *
206  * @par Python函数原型
207  * serialSendString(self: pyaubo_sdk.Serial, arg0: str, arg1: str) -> int
208  *
209  * @par Lua函数原型
210  * serialSendString(str: string, serial_name: string) -> nil
211  *
212  */
213  int serialSendString(const std::string &str,
214  const std::string &serial_name = "serial_0");
215 
216  /**
217  *
218  * @param is_check
219  * @param str
220  * @param serial_name
221  * @return
222  *
223  * @par Python函数原型
224  * serialSendAllString(self: pyaubo_sdk.Serial, arg0: bool, arg1: List[str],
225  * arg2: str) -> int
226  *
227  * @par Lua函数原型
228  * serialSendAllString(is_check: boolean, str: table, serial_name: string)
229  * -> nil
230  *
231  */
232  int serialSendAllString(bool is_check, const std::vector<char> &str,
233  const std::string &serial_name = "serial_0");
234 
235 protected:
236  void *d_;
237 };
238 using SerialPtr = std::shared_ptr<Serial>;
239 
240 // clang-format off
241 #define Serial_DECLARES \
242  _INST(Serial, 5, serialOpen, device, baud, stop_bits, even, serial_name) \
243  _INST(Serial, 1, serialClose, serial_name) \
244  _FUNC(Serial, 2, serialReadByte, variable, serial_name) \
245  _FUNC(Serial, 3, serialReadByteList, number, variable, serial_name) \
246  _FUNC(Serial, 5, serialReadString, variable, serial_name, prefix, suffix, interpret_escape) \
247  _INST(Serial, 2, serialSendByte, value, serial_name) \
248  _INST(Serial, 2, serialSendInt, value, serial_name) \
249  _INST(Serial, 2, serialSendLine, str, serial_name) \
250  _INST(Serial, 2, serialSendString, str, serial_name) \
251  _INST(Serial, 3, serialSendAllString, is_check, str, serial_name)
252 // clang-format on
253 
254 } // namespace common_interface
255 } // namespace arcs
256 #endif
数据类型的定义
std::shared_ptr< Serial > SerialPtr
Definition: serial.h:238
Definition: aubo_api.h:17