【正文】
基于 C++的 RS232 通信 協(xié)議模擬終端 Analog Terminal For RS232 Communication Protocol Based On C++ 學 院: 專 業(yè) 班 級: 學 號: 學 生 姓 名: 指 導 教 師: 2020 年 06 月密級:公開 I 摘 要 隨著科技的迅猛發(fā)展 ,通信技術已經(jīng)成為社會經(jīng)濟、環(huán)境、 生活、工作、學習不可缺少的一部分 。通信的方式多種多樣,以何種方式實現(xiàn)通信主要取決于通信 設備。在工業(yè)控制系統(tǒng)和實驗室中, 由 于串行通信具有實現(xiàn)簡單、使用靈活方便等優(yōu)點,串行通信是計算機與外部設備進行數(shù)據(jù)通信時經(jīng)常使用的方式之一。 圍繞串行通信技術,本文 主要 介紹了串行通信 接口 ——RS232 標準串口,闡述 了RS232 串行通信基本原理和 CRC 校驗 ,通過 VC 界面編程實現(xiàn)串行通信。 傳輸過程中通過 CRC 對數(shù)據(jù)進行校驗。 在研究 RS232 串行通信原理中,主要介紹了 RS232 標準協(xié)議、串口以及串口通信原理。 詳細的分析了幾種主要的通信參數(shù)。 按照其工作原理及 RS232 串口的 標準協(xié)議最終采用串行全雙工的方式實現(xiàn)其通信,本文中的接口使用的是 計算機上的 USB 口 。 在軟件實現(xiàn)方面,本設計在比較了多種方法之后,最終選擇了基于 C++的 MFC 應用程序。利用 MSComm ActiveX 串行通信控件來實現(xiàn)串行通信。文中詳細地介紹了 VC下的 Windows 平臺先進的 ActiveX 控件技術,即 MSComm 控件等。最終實現(xiàn)了兩臺PC 間的串行通信。 串行通信以其成本低、結構簡單等優(yōu)點被人們廣泛應用。用 RS232 協(xié)議實現(xiàn)兩臺PC 機間的串行通信為以后實現(xiàn)更加復雜的設備間通信奠定了基礎。 關鍵詞: RS232 標準 ;串行通信; C++; CRC 校驗 II Abstract With the rapid development of science and technology, munication technology has bee an indispensable part of social economy, environment, living and learning. There are many kinds of munication modes. The selection of munication mode mainly depends on the munication equipment. In industrial control systems and laboratory, serial munication is widely used in puter and external equipment due to the simple and flexible advantage. Around serial munication technology, this paper mainly introduces the serial munication interface RS232 serial port, and expounds the basic principle of RS232 serial munication and CRC check .It is pleted to realize serial munication by VC programming. It can check the data during the process of transmission through the CRC. In the study of RS232 serial munication principle, this design mainly introduces the principle of serial munication, serial port and RS232 protocol, and analyzes munication parameters in detail. Considering RS232 serial port and working principle, this design adopts serial fullduplex mode to realize munication. In the article, the interface is the USB port on the PC. In the aspect of software realization, after several methods are pared,this design selects the MFC application program which is based on C++ .The design realize the serial munication by using MSComm ActiveX serial munication control. This article introduces the ActiveX control technologyMSComm control. Finally, the design realizes serial munication between two puters. Because of the advantages of low cost and simple structure, serial munication is widely used by people. Realization of serial munication between two PC machines is the foundation of realizing more plex munication. Keywords:RS232 protocol。 Serial Communications。 C++。 CRC Cyclic Redundancy Check I 目 錄 摘 要 ..................................................................................................................................... I Abstract ...................................................................................................................................... II 第 1 章 緒論 .............................................................................................................................. 1 課題的研究意義 ......................................................................................................... 1 研究現(xiàn)狀及發(fā)展趨勢 ................................................................................................. 2 RS232 串行通信的研究現(xiàn)狀 ........................................................................... 2 RS232 串行通信的發(fā)展趨勢 ........................................................................... 2 本文主要的研究內(nèi)容 ................................................................................................. 2 第 2 章串行通信基本原理 ........................................................................................................ 4 RS232 通信協(xié)議 .......................................................................................................... 4 RS232 標準 ....................................................................................................... 4 RS232 接口 ....................................................................................................... 4 串行通 信 ..................................................................................................................... 5 串行通信基本原理 .......................................................................................... 5 串行通信參數(shù) .................................................................................................. 6 串行通信的分類 ...................................................................................................... 7 串口的調(diào)制 ................................................................................................................. 8 串口連接 .......................................................................................................... 8 串口調(diào)試 .......................................................................................................... 9 本章小結 ................................................................................................................... 10 第 3 章 CRC 校驗 ................................................................................................................... 11 CRC 校驗原理 ........................................................................................................... 11 CRC 校驗碼的基本原理 ................................................................................ 11 CRC 校驗碼權的形式 .................................................................................... 12 CRC 校驗的實現(xiàn) ....................................................................................................... 13 本章 小結 .................................................................................................................... 13 第 4 章 軟件的實現(xiàn)及其測試 ...........