From 4794a062dc9be14e7afcb84a015b2878ec8eb6a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=AE=A4=E7=9F=A5=E6=99=BA=E8=83=BD?= <2386089024@qq.com> Date: Mon, 26 May 2025 19:29:55 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=8A=E4=BC=A0=E6=96=87=E4=BB=B6=E8=87=B3?= =?UTF-8?q?=20include?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- include/jlinux_uart.h | 81 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 include/jlinux_uart.h diff --git a/include/jlinux_uart.h b/include/jlinux_uart.h new file mode 100644 index 0000000..2728f04 --- /dev/null +++ b/include/jlinux_uart.h @@ -0,0 +1,81 @@ +/*********************************************************************** + * @file jlinux_uart.h + JLINUX_UART + * @brief header file + * @history + * Date Version Author description + * ========== ======= ========= ======================================= + * 2022-07-27 V1.0 Lucky,lukai@jovision.com Create + * + * @Copyright (C) 2022 Jovision Technology Co., Ltd. +***********************************************************************/ +#ifndef __JLINUX_UART_H__ +#define __JLINUX_UART_H__ + +#ifdef __cplusplus +extern "C" +{ +#endif + +typedef struct _uart_ctx *juart_hdl_t; + +typedef struct +{ + int baudrate; //波特率:1200/2400/4800/9600/19200/38400/57600/115200/230400/380400/460800/921600 + int datawidth; //数据位宽度:5/6/7/8 + int stopbit; //停止位宽度:1/2 + int parity; //奇偶校验:0无校验,1奇校验,2偶校验 +}JUartAttr_t; + +/** + *@brief 打开串口设备设备,如果是485设备请配合jctrl_rs485相关接口使用 + *@param name 设备名称,如:/dev/ttyS0 + *@return 句柄 + */ +juart_hdl_t juart_open(const char *name); + +/** + *@brief 关闭串口 + *@param handle 句柄 + */ +int juart_close(juart_hdl_t handle); + +/** + *@brief 配置串口属性 + *@param handle 句柄 + *@param attr 属性 + */ +int juart_set_attr(juart_hdl_t handle, JUartAttr_t *attr); + +int juart_get_fd(juart_hdl_t uart); +/** + *@brief 通过串口发送数据 + *@param handle 句柄 + *@param data 数据buffer + *@param len 数据长度 + *@return 0成功 + */ +int juart_send(juart_hdl_t handle, char *data, int len); + +/** + *@brief 通过串口接受数据 + *@param handle 句柄 + *@param data 数据buffer + *@param len buffer的长度 + *@param timeout 超时毫秒 + *@return 收到数据的长度 + */ +int juart_recv(juart_hdl_t handle, char *data, int len, int timeout); + +/** + *@brief 设置rs485模式 + *@param handle 句柄 + *@param mode 0:发送后立刻置为接收状态;非0:发送后保持发送状态 + *@return 0 成功 + */ +int juart_set_rs485(juart_hdl_t handle, int mode); + +#ifdef __cplusplus +} +#endif +#endif // __JLINUX_UART_H__