新聞中心

        EEPW首頁 > 手機與無線通信 > 設(shè)計應(yīng)用 > 基于Virtools 和串口通信的界面交互性的設(shè)計與實現(xiàn)

        基于Virtools 和串口通信的界面交互性的設(shè)計與實現(xiàn)

        作者: 時間:2010-07-08 來源:網(wǎng)絡(luò) 收藏

        基類_base_com 的聲明如下。

        class _base_com //虛基類基本串口接口

        {

        protected:

        volatile int _PORT; //串口號

        volatile HANDLE _com_handle;//串口句柄

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

        int _in_buf, _out_buf; // 緩沖區(qū)

        COMMTIMEOUTS _co; // 超時時間

        //虛函數(shù),用于不同方式的串口打開

        virtual bool open_PORT() = 0;

        void init(); //初始化

        public:

        _base_com()

        {

        init();

        }

        virtual ~_base_com();

        /*基本參數(shù)設(shè)置*/

        //設(shè)置串口參數(shù):波特率,停止位,等

        inline bool set_para();

        //支持設(shè)置字符串 "9600, 8, n, 1"

        bool set_dcb(char *set_str);

        //設(shè)置內(nèi)置結(jié)構(gòu)串口參數(shù):波特率,停止位

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

        ONESTOPBIT);

        //設(shè)置緩沖區(qū)大小

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

        //關(guān)閉串口

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

        }

        };



        關(guān)鍵詞: 串口通信

        評論


        相關(guān)推薦

        技術(shù)專區(qū)

        關(guān)閉
        主站蜘蛛池模板: 怀仁县| 连江县| 西畴县| 涿鹿县| 通江县| 廊坊市| 陆河县| 广河县| 平江县| 广州市| 日照市| 濮阳县| 崇州市| 确山县| 来凤县| 勃利县| 禄劝| 海口市| 清水河县| 郯城县| 兴化市| 汉阴县| 肇庆市| 九台市| 合江县| 正镶白旗| 湄潭县| 如皋市| 奉节县| 曲周县| 上蔡县| 安多县| 泰安市| 桃园市| 乡宁县| 枞阳县| 武鸣县| 北流市| 略阳县| 崇信县| 五峰|