新聞中心

        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));

        }

        };



        關鍵詞: 串口通信

        評論


        相關推薦

        技術專區

        關閉
        主站蜘蛛池模板: 黄山市| 安远县| 大同县| 丰县| 丽水市| 呼图壁县| 交口县| 历史| 云和县| 荆门市| 古交市| 汉寿县| 南开区| 肇州县| 沂南县| 漳浦县| 宜都市| 南漳县| 德安县| 方城县| 郯城县| 丰台区| 龙陵县| 宁强县| 江津市| 卢湾区| 家居| 枣庄市| 阳曲县| 浦北县| 新竹县| 垫江县| 司法| 海阳市| 桂林市| 岫岩| 鞍山市| 商水县| 疏附县| 凤山市| 晋城|