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