Files
2026-02-01 22:23:06 +08:00

79 lines
2.3 KiB
C

/******************************************************************************
File Name : product_com_ctrl.h
Description :
Author :
Version : Initial Draft
------------------------------------------------------------------------------
Modification:
20180120 Created
******************************************************************************/
#ifndef __PRODUCT_COM_CTRL__
#define __PRODUCT_COM_CTRL__
/*------------------------------- Includes -----------------------------------*/
#include <termios.h> // termios, tcgetattr(), tcsetattr()
#include "defines.h"
#ifdef __cplusplus
#if __cplusplus
extern "C"{
#endif
#endif /* __cplusplus */
/*------------------------- Types Definitions --------------------------------*/
typedef s32 ComPortHandle; /* 串口句柄 */
enum ComPortSetting {
ODD_PARITY = 0, /* 奇校验位设置 */
EVEN_PARITY = 1, /* 偶校验位设置 */
NO_FLOW_CTRL = 2, /* 设置无流控 */
HARD_FLOW_CTRL = 3, /* 设置硬件流控方式 */
SOFT_FLOW_CTRL = 4, /* 设置软件流控方式 */
};
enum {
COMPORT_BLOCK = 0, /* 设置阻塞方式处理URAT操作 */
COMPORT_UNBLOCK = 1, /* 设置非阻塞方式处理URAT操作 */
};
typedef struct TagComPortSetting {
s32 s32BaudRate; /* 设置baudrate */
u8 u8DataBit; /* 数据位设置data bits, 5, 6, 7, 8 */
u8 u8StopBit; /* 停止位设置 */
u8 u8ParityBit; /* 校验位设置 */
u8 u8FlowCtrl; /* 流控设置 */
}TComPortSetting;
typedef struct TagComPortOperMode {
struct timeval tTimeOut; /* 设置超时时间 */
u8 u8BlcokOrNot; /* 设置阻塞非阻塞 */
}TComPortOperMode;
/*-------------------------------- APIs --------------------------------------*/
ComPortHandle ComPortOpen(s8 *ps8SerialPortName, TComPortSetting *ptComPortSetting);
s32 ComPortClose(ComPortHandle hComPortID);
s32 ComPortSend(ComPortHandle hComPortID, s8 *ps8DataBuf, s32 s32DataLen, TComPortSetting *ptComPortSetting, TComPortOperMode tComPortOpreMode);
s32 ComPortRecv(ComPortHandle hComPortID, s8 *ps8DataBuf, s32 s32DataLen, TComPortSetting *ptComPortSetting, TComPortOperMode tComPortOpreMode);
#ifdef __cplusplus
#if __cplusplus
}
#endif
#endif /* __cplusplus */
#endif /* __PRODUCT_COM_CTRL__ */