⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 seriallink_api.h

📁 蓝牙芯片ZV4301的调试工具源码.做蓝牙产品时很有参考价值内部有串口的编程序源码,对有串口编成需求的同志有参考价值.
💻 H
字号:
#ifndef _SERIALLINK_API_H_
#define _SERIALLINK_API_H_
#include <windows.h>

#define MAX_PORT_NUM            256

#define ERR_NONE                0x0000
#define ERR_PORT_INVALID        0x0001
#define ERR_PORT_OCCUPIED       0x0002
#define ERR_PORT_NOTOPENED      0x0003
#define ERR_INTERNAL            0xFFFF

#define SER_STATUS_NONE         0x0000
#define SER_STATUS_LINK         0x0001
#define SER_STATUS_UNLINK       0x0002
#define SER_STATUS_OPENED       0x0004
//#define SER_STATUS_WAIT         0x0010
//#define SER_STATUS_RECEIVE      0x0020
//#define SER_STATUS_SEND         0x0040
#define MAX_READ_BLOCK 4096
//#define MAX_SEND_BLOCK 2048
#define MAX_SEND_BLOCK 2048

typedef unsigned __int8  UINT8  ;
typedef unsigned __int16 UINT16 ;
typedef unsigned __int32 UINT32 ;

typedef enum {b_110,    b_300,    b_600 ,
              b_1200,   b_2400,   b_4800,  b_9600,
              b_14400,  b_19200,  b_38400, b_56000, b_57600,
              b_115200, b_128000, b_256000
              }TBaudrate;
typedef enum {d_5, d_6, d_7, d_8}TDatabit;
typedef enum {p_none, p_odd, p_even}TParity;
typedef enum {s_1}TStopbit;

extern const UINT32 serial_baudrate[];
extern const UINT8  serial_databit[];
extern const char   serial_parity[];
extern const UINT8  serial_stopbit[];

typedef struct{
        int    PORT_NUMBER;
	bool   PORT_EXIST;
        char   info[256];
}tPORT_INFO;

typedef struct{
  int       port;
  TBaudrate baudrate;
  TDatabit  databit;
  TParity   parity;
  TStopbit  stopbit;
  bool dtrdsr, rtscts, xonxoff, rts, cts, dtr, dsr;
} T_PORT_SET;

typedef void(*ON_RECEIVE_HANDLE)(char *data, UINT16 count);
typedef void(*ON_TXEMPTY_HANDLE)(void);

class SERIAL_CLASS{
  private:
       void      *self;
       UINT16     ser_read_index;
       UINT16     ser_write_index;
       UINT16     ser_unread_size;
       tPORT_INFO PORT_INFO[MAX_PORT_NUM];
       UINT8      PORT_NUM;
       UINT8      PORT_OPEN;
       UINT8      CURRENT_OPENED_PORT;
       COMMTIMEOUTS  CommTimeOuts;

       void       RESET(void);
       void       serial_force2close(void);
       void       collect_device(void);
       char       buff[MAX_SEND_BLOCK + 1];

  public:
     SERIAL_CLASS(void);
     void   ReInitialize(void);
     UINT8  GetDevNum(void);
     void   GetDevicePortList(int *list_num, int *list);
     UINT16 Open(T_PORT_SET*);
     UINT16 Close(void);
     ON_RECEIVE_HANDLE OnReceiveHandle;
     ON_TXEMPTY_HANDLE OnTxEmptyHandle;
     UINT16 CheckStatus(int*);
     UINT16 Send(char *, int, int*);
     UINT16 SetParam(T_PORT_SET*);
     UINT16 SetBaudrate(DWORD baudrate);
     UINT8  GetCurrentPort(void);
     bool GetPortInfo(int port, char *buff);

     DWORD Evt;
     OVERLAPPED  osWrite, osRead;
     OVERLAPPED  lpOverlapped;
     HANDLE     SERIAL_HANDLE;
     HANDLE     SERIAL_THREAD;
     DWORD      SERIAL_THREAD_ID;
     UINT32     SERIAL_THREAD_PARAMETER;
     UINT16     STATE;
     _DCB       _dcb;
     void       serial_read_input(void);
};


#endif/*_SERIALLINK_API_H_*/

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -