新闻中心

EEPW首页>手机与无线通信>设计应用> 基于Virtools 和串口通信的界面交互性的设计与实现

基于Virtools 和串口通信的界面交互性的设计与实现

作者: 时间:2010-07-08 来源:网络 收藏

基类_base_com 的声明如下。

class _base_com //虚基类基本串口接口

{

protected:

volatile int _PORT; //串口号

volatile HANDLE _com_handle;//串口句柄

DCB _dcb; //波特率,停止位,等

int _in_buf, _out_buf; // 缓冲区

COMMTIMEOUTS _co; // 超时时间

//虚函数,用于不同方式的串口打开

virtual bool open_PORT() = 0;

void init(); //初始化

public:

_base_com()

{

init();

}

virtual ~_base_com();

/*基本参数设置*/

//设置串口参数:波特率,停止位,等

inline bool set_para();

//支持设置字符串 "9600, 8, n, 1"

bool set_dcb(char *set_str);

//设置内置结构串口参数:波特率,停止位

bool set_dcb(int BaudRate, int ByteSize = 8, int Parity = NOPARITY, int StopBits =

ONESTOPBIT);

//设置缓冲区大小

inline bool set_buf(int in_buf, int out_buf);

//打开串口缺省 9600, 8, n, 1

inline bool open(int PORT);

//打开串口缺省 baud_rate, 8, n, 1

inline bool open(int PORT, int baud_rate);

//打开串口

inline bool open(int PORT, char *set_str);

//关闭串口

inline virtual void close();

//判断串口是或打开

inline bool is_open();

//获得串口句炳

HANDLE get_handle();

};

异步类_sync_com 的声明如下。

class _sync_com : public _base_com

{

protected:

//打开串口

virtual bool open_PORT();

public:

_sync_com();

//同步读

int read(char *buf, int buf_len);

//同步写

int write(char *buf, int buf_len)

//同步写

inline int write(char *buf)

{

assert(buf);

return write(buf, strlen(buf));

}

};



关键词:串口通信

评论


相关推荐

技术专区

关闭