PDF
AUBO SDK  0.26.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
13namespace arcs {
14namespace common_interface {
15
16/**
17 * \chinese
18 * @defgroup Serial Serial (串口通信)
19 * 串口通信
20 * \endchinese
21 *
22 * \english
23 * @defgroup Serial Serial Communication
24 * Serial communication
25 * \endenglish
26 */
27class ARCS_ABI_EXPORT Serial
28{
29public:
31 virtual ~Serial();
32
33 /**
34 * @ingroup Serial
35 * \chinese
36 * 打开TCP/IP以太网通信串口
37 *
38 * @param device 设备名
39 * @param baud 波特率
40 * @param stop_bits 停止位
41 * @param even 校验位
42 * @param serial_name 串口名称
43 * @return 返回值
44 *
45 * @par Python函数原型
46 * serialOpen(self: pyaubo_sdk.Serial, arg0: str, arg1: int, arg2: float,
47 * arg3: int, arg4: str) -> int
48 *
49 * @par Lua函数原型
50 * serialOpen(device: string, baud: number, stop_bits: number, even: number,
51 * serial_name: string) -> nil
52 * \endchinese
53 * \english
54 * Open TCP/IP ethernet communication serial
55 *
56 * @param device
57 * @param baud
58 * @param stop_bits
59 * @param even
60 * @param serial_name
61 * @return
62 *
63 * @par Python function prototype
64 * serialOpen(self: pyaubo_sdk.Serial, arg0: str, arg1: int, arg2: float,
65 * arg3: int, arg4: str) -> int
66 *
67 * @par Lua function prototype
68 * serialOpen(device: string, baud: number, stop_bits: number, even: number,
69 * serial_name: string) -> nil
70 * \endenglish
71 */
72
73 int serialOpen(const std::string &device, int baud, float stop_bits,
74 int even, const std::string &serial_name = "serial_0");
75
76 /**
77 * @ingroup Serial
78 * \chinese
79 * 关闭TCP/IP串口通信
80 * 关闭与服务器的串口连接。
81 *
82 * @param serial_name 串口名称
83 * @return 返回值
84 *
85 * @par Python函数原型
86 * serialClose(self: pyaubo_sdk.Serial, arg0: str) -> int
87 *
88 * @par Lua函数原型
89 * serialClose(serial_name: string) -> nil
90 * \endchinese
91 * \english
92 * Close TCP/IP serial communication
93 * Close down the serial connection to the server.
94 *
95 * @param serial_name
96 * @return
97 *
98 * @par Python function prototype
99 * serialClose(self: pyaubo_sdk.Serial, arg0: str) -> int
100 *
101 * @par Lua function prototype
102 * serialClose(serial_name: string) -> nil
103 * \endenglish
104 */
105 int serialClose(const std::string &serial_name = "serial_0");
106
107 /**
108 * @ingroup Serial
109 * \chinese
110 * 从串口读取指定数量的字节。字节为网络字节序。一次最多可读取30个值。
111 *
112 * @param variable 变量
113 * @param serial_name 串口名称
114 * @return 返回值
115 *
116 * @par Python函数原型
117 * serialReadByte(self: pyaubo_sdk.Serial, arg0: str, arg1: str) -> int
118 *
119 * @par Lua函数原型
120 * serialReadByte(variable: string, serial_name: string) -> number
121 * \endchinese
122 * \english
123 * Reads a number of bytes from the serial. Bytes are in network byte
124 * order. A maximum of 30 values can be read in one command.
125 *
126 * @param variable
127 * @param serial_name
128 * @return
129 *
130 * @par Python function prototype
131 * serialReadByte(self: pyaubo_sdk.Serial, arg0: str, arg1: str) -> int
132 *
133 * @par Lua function prototype
134 * serialReadByte(variable: string, serial_name: string) -> number
135 * \endenglish
136 */
137 int serialReadByte(const std::string &variable,
138 const std::string &serial_name = "serial_0");
139
140 /**
141 * @ingroup Serial
142 * \chinese
143 * 从串口读取指定数量的字节。字节为网络字节序。一次最多可读取30个值。
144 * 返回读取到的数字列表(int列表,长度=number+1)。
145 *
146 * @param number 读取的字节数
147 * @param variable 变量
148 * @param serial_name 串口名称
149 * @return 返回值
150 *
151 * @par Python函数原型
152 * serialReadByteList(self: pyaubo_sdk.Serial, arg0: int, arg1: str, arg2: str) -> int
153 *
154 * @par Lua函数原型
155 * serialReadByteList(number: number, variable: string, serial_name: string) -> number
156 * \endchinese
157 * \english
158 * Reads a number of bytes from the serial. Bytes are in network byte
159 * order. A maximum of 30 values can be read in one command.
160 * A list of numbers read (list of ints, length=number+1)
161 *
162 * @param number Number of bytes to read
163 * @param variable
164 * @param serial_name Serial port name
165 * @return Return value
166 *
167 * @par Python function prototype
168 * serialReadByteList(self: pyaubo_sdk.Serial, arg0: int, arg1: str, arg2: str) -> int
169 *
170 * @par Lua function prototype
171 * serialReadByteList(number: number, variable: string, serial_name: string) -> number
172 * \endenglish
173 */
174 int serialReadByteList(int number, const std::string &variable,
175 const std::string &serial_name = "serial_0");
176
177 /**
178 * @ingroup Serial
179 * \chinese
180 * 从串口读取所有数据,并将数据作为字符串返回。
181 * 字节为网络字节序。
182 *
183 * 可选参数 "prefix" 和 "suffix" 用于指定从串口提取的内容。
184 * "prefix" 指定提取子串(消息)的起始位置。直到 "prefix" 结束的数据会被忽略并从串口移除。
185 * "suffix" 指定提取子串(消息)的结束位置。串口中 "suffix" 之后的剩余数据会被保留。
186 * 例如,如果串口服务器发送字符串 "noise>hello<",控制器可以通过设置 prefix=">" 和 suffix="<" 来接收 "hello"。
187 * 通过使用 "prefix" 和 "suffix",还可以一次向控制器发送多条字符串,因为 "suffix" 定义了消息的结束位置。
188 * 例如发送 ">hello<>world<"
189 *
190 * @param variable 变量
191 * @param serial_name 串口名称
192 * @param prefix 前缀
193 * @param suffix 后缀
194 * @param interpret_escape 是否解释转义字符
195 * @return 返回值
196 *
197 * @par Python函数原型
198 * serialReadString(self: pyaubo_sdk.Serial, arg0: str, arg1: str, arg2: str, arg3: str, arg4: bool) -> int
199 *
200 * @par Lua函数原型
201 * serialReadString(variable: string, serial_name: string, prefix: string, suffix: string, interpret_escape: boolean) -> number
202 * \endchinese
203 * \english
204 * Reads all data from the serial and returns the data as a string.
205 * Bytes are in network byte order.
206 *
207 * The optional parameters "prefix" and "suffix", can be used to express
208 * what is extracted from the serial. The "prefix" specifies the start
209 * of the substring (message) extracted from the serial. The data up to
210 * the end of the "prefix" will be ignored and removed from the serial.
211 * The "suffix" specifies the end of the substring (message) extracted
212 * from the serial. Any remaining data on the serial, after the "suffix",
213 * will be preserved. E.g. if the serial server sends a string
214 * "noise>hello<", the controller can receive the "hello" by calling this
215 * script function with the prefix=">" and suffix="<". By using the
216 * "prefix" and "suffix" it is also possible send multiple string to the
217 * controller at once, because the suffix defines where the message ends.
218 * E.g. sending ">hello<>world<"
219 *
220 * @param variable
221 * @param serial_name
222 * @param prefix
223 * @param suffix
224 * @param interpret_escape
225 * @return
226 *
227 * @par Python function prototype
228 * serialReadString(self: pyaubo_sdk.Serial, arg0: str, arg1: str, arg2: str, arg3: str, arg4: bool) -> int
229 *
230 * @par Lua function prototype
231 * serialReadString(variable: string, serial_name: string, prefix: string, suffix: string, interpret_escape: boolean) -> number
232 * \endenglish
233 */
234 int serialReadString(const std::string &variable,
235 const std::string &serial_name = "serial_0",
236 const std::string &prefix = "",
237 const std::string &suffix = "",
238 bool interpret_escape = false);
239
240 /**
241 * @ingroup Serial
242 * \chinese
243 * 发送一个字节到服务器
244 * 通过串口发送字节 <value>。不期望有响应。可用于发送特殊的ASCII字符;10为换行符,2为文本开始,3为文本结束。
245 *
246 * @param value 字节值
247 * @param serial_name 串口名称
248 * @return 返回值
249 *
250 * @par Python函数原型
251 * serialSendByte(self: pyaubo_sdk.Serial, arg0: str, arg1: str) -> int
252 *
253 * @par Lua函数原型
254 * serialSendByte(value: string, serial_name: string) -> nil
255 * \endchinese
256 * \english
257 * Sends a byte to the server
258 * Sends the byte <value> through the serial. Expects no response. Can
259 * be used to send special ASCII characters; 10 is newline, 2 is start of
260 * text, 3 is end of text.
261 *
262 * @param value
263 * @param serial_name
264 * @return
265 *
266 * @par Python function prototype
267 * serialSendByte(self: pyaubo_sdk.Serial, arg0: str, arg1: str) -> int
268 *
269 * @par Lua function prototype
270 * serialSendByte(value: string, serial_name: string) -> nil
271 * \endenglish
272 */
273 int serialSendByte(char value, const std::string &serial_name = "serial_0");
274
275 /**
276 * @ingroup Serial
277 * \chinese
278 * 发送一个整数(int32_t)到服务器
279 * 通过串口发送整数 <value>。以网络字节序发送。不期望有响应。
280 *
281 * @param value 整数值
282 * @param serial_name 串口名称
283 * @return 返回值
284 *
285 * @par Python函数原型
286 * serialSendInt(self: pyaubo_sdk.Serial, arg0: int, arg1: str) -> int
287 *
288 * @par Lua函数原型
289 * serialSendInt(value: number, serial_name: string) -> nil
290 * \endchinese
291 * \english
292 * Sends an int (int32_t) to the server
293 * Sends the int <value> through the serial. Send in network byte order.
294 * Expects no response.
295 *
296 * @param value
297 * @param serial_name
298 * @return
299 *
300 * @par Python function prototype
301 * serialSendInt(self: pyaubo_sdk.Serial, arg0: int, arg1: str) -> int
302 *
303 * @par Lua function prototype
304 * serialSendInt(value: number, serial_name: string) -> nil
305 * \endenglish
306 */
307 int serialSendInt(int value, const std::string &serial_name = "serial_0");
308
309 /**
310 * @ingroup Serial
311 * \chinese
312 * 发送带有换行符的字符串到服务器
313 * 以ASCII编码通过串口发送字符串<str>,并在末尾添加换行符。不期望有响应。
314 *
315 * @param str 字符串
316 * @param serial_name 串口名称
317 * @return 返回值
318 *
319 * @par Python函数原型
320 * serialSendLine(self: pyaubo_sdk.Serial, arg0: str, arg1: str) -> int
321 *
322 * @par Lua函数原型
323 * serialSendLine(str: string, serial_name: string) -> nil
324 * \endchinese
325 * \english
326 * Sends a string with a newline character to the server
327 * Sends the string <str> through the serial in ASCII coding, appending a newline at the end. Expects no response.
328 *
329 * @param str
330 * @param serial_name
331 * @return
332 *
333 * @par Python function prototype
334 * serialSendLine(self: pyaubo_sdk.Serial, arg0: str, arg1: str) -> int
335 *
336 * @par Lua function prototype
337 * serialSendLine(str: string, serial_name: string) -> nil
338 * \endenglish
339 */
340 int serialSendLine(const std::string &str,
341 const std::string &serial_name = "serial_0");
342
343 /**
344 * @ingroup Serial
345 * \chinese
346 * 发送字符串到服务器
347 * 以ASCII编码通过串口发送字符串<str>。不期望有响应。
348 *
349 * @param str 字符串
350 * @param serial_name 串口名称
351 * @return 返回值
352 *
353 * @par Python函数原型
354 * serialSendString(self: pyaubo_sdk.Serial, arg0: str, arg1: str) -> int
355 *
356 * @par Lua函数原型
357 * serialSendString(str: string, serial_name: string) -> nil
358 * \endchinese
359 * \english
360 * Sends a string to the server
361 * Sends the string <str> through the serial in ASCII coding. Expects no
362 * response.
363 *
364 * @param str
365 * @param serial_name
366 * @return
367 *
368 * @par Python function prototype
369 * serialSendString(self: pyaubo_sdk.Serial, arg0: str, arg1: str) -> int
370 *
371 * @par Lua function prototype
372 * serialSendString(str: string, serial_name: string) -> nil
373 * \endenglish
374 */
375 int serialSendString(const std::string &str,
376 const std::string &serial_name = "serial_0");
377
378 /**
379 * @ingroup Serial
380 * \chinese
381 *
382 * @param is_check 是否校验
383 * @param str 字符串数组
384 * @param serial_name 串口名称
385 * @return 返回值
386 *
387 * @par Python函数原型
388 * serialSendAllString(self: pyaubo_sdk.Serial, arg0: bool, arg1: List[str], arg2: str) -> int
389 *
390 * @par Lua函数原型
391 * serialSendAllString(is_check: boolean, str: table, serial_name: string) -> nil
392 * \endchinese
393 * \english
394 *
395 * @param is_check Whether to check
396 * @param str Array of strings
397 * @param serial_name Serial port name
398 * @return Return value
399 *
400 * @par Python function prototype
401 * serialSendAllString(self: pyaubo_sdk.Serial, arg0: bool, arg1: List[str], arg2: str) -> int
402 *
403 * @par Lua function prototype
404 * serialSendAllString(is_check: boolean, str: table, serial_name: string) -> nil
405 * \endenglish
406 */
407 int serialSendAllString(bool is_check, const std::vector<char> &str,
408 const std::string &serial_name = "serial_0");
409
410protected:
411 void *d_;
412};
413using SerialPtr = std::shared_ptr<Serial>;
414
415} // namespace common_interface
416} // namespace arcs
417#endif
int serialSendAllString(bool is_check, const std::vector< char > &str, const std::string &serial_name="serial_0")
int serialSendLine(const std::string &str, const std::string &serial_name="serial_0")
发送带有换行符的字符串到服务器 以ASCII编码通过串口发送字符串<str>,并在末尾添加换行符。不期望有响应。
int serialSendString(const std::string &str, const std::string &serial_name="serial_0")
发送字符串到服务器 以ASCII编码通过串口发送字符串<str>。不期望有响应。
int serialClose(const std::string &serial_name="serial_0")
关闭TCP/IP串口通信 关闭与服务器的串口连接。
int serialReadByteList(int number, const std::string &variable, const std::string &serial_name="serial_0")
从串口读取指定数量的字节。字节为网络字节序。一次最多可读取30个值。 返回读取到的数字列表(int列表,长度=number+1)。
int serialSendInt(int value, const std::string &serial_name="serial_0")
发送一个整数(int32_t)到服务器 通过串口发送整数 。以网络字节序发送。不期望有响应。
int serialReadByte(const std::string &variable, const std::string &serial_name="serial_0")
从串口读取指定数量的字节。字节为网络字节序。一次最多可读取30个值。
int serialSendByte(char value, const std::string &serial_name="serial_0")
发送一个字节到服务器 通过串口发送字节 。不期望有响应。可用于发送特殊的ASCII字符;10为换行符,2为文本开始,3为文本结束。
int serialOpen(const std::string &device, int baud, float stop_bits, int even, const std::string &serial_name="serial_0")
打开TCP/IP以太网通信串口
int serialReadString(const std::string &variable, const std::string &serial_name="serial_0", const std::string &prefix="", const std::string &suffix="", bool interpret_escape=false)
从串口读取所有数据,并将数据作为字符串返回。 字节为网络字节序。
std::shared_ptr< Serial > SerialPtr
数据类型的定义