commCPU_SUPV/code/general/inc/general_serial.h
2025-04-30 16:24:29 +08:00

71 lines
1.5 KiB
C
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#ifndef GENERAL_SERIAL_123_INCLUDED
#define GENERAL_SERIAL_123_INCLUDED
#ifdef __cplusplus
extern "C" {
#endif
/************************************************************************/
#include "glbtypes.h"
//接收缓冲区长度
#include "sysincs.h"
#if defined (_WIN32)
#define SERIAL_HANDLE HANDLE
#else
#define SERIAL_HANDLE ST_INT
#endif
#define SERIAL_RECVBUF_LEN 1024
/****串口连接属性结构体****/
typedef struct
{
//通知外部,打开成功
ST_INT flagOpenSuccess;
SERIAL_HANDLE serialHandle; /***串口**/
ST_INT status; /**当前连接属性 0没有打开1打开成功2打开失败**/
ST_UINT recvCount; /**接收的帧数,累计*/
/***由于缓冲比较大,是否多连接共用缓冲,收到数据立刻处理?? ***/
ST_INT recvDataLen; /***接收到的数据长度**/
ST_UCHAR recvDataBuf[SERIAL_RECVBUF_LEN]; /**接收到的数据缓冲**/
//下面的变量用于设置串口属性
int portNo;
int baudrate;
int databits;
int stopbits;
int parity; //这里是个字符
} SERIAL_ATTRIB;
ST_RET serial_attrib_init( SERIAL_ATTRIB *serial_attrib );
ST_RET serial_attrib_release( SERIAL_ATTRIB *serial_attrib );
ST_RET serial_attrib_set( SERIAL_ATTRIB *serial_attrib,
int portNo,int baudrate,int databits,int stopbits,int parity );
/**** 循环调用,读取数据 ****/
ST_RET serial_attrib_check( SERIAL_ATTRIB *serial_attrib );
ST_RET serial_send(SERIAL_ATTRIB *serial_attrib, ST_UCHAR *sendBuf, ST_INT sendLen );
/************************************************************************/
#ifdef __cplusplus
}
#endif
#endif