71 lines
1.5 KiB
C
71 lines
1.5 KiB
C
|
||
|
||
|
||
|
||
#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
|