========================================================================
We use sample code to implement the Serial port transmission.
1. Create the Windows form project and add below code.
First, we need to using System.IO.Ports to create the Serial Port.
After creating the serial port, we need to initial the serial port parameters like port name, baud rate etc.
2. Add send and receive the data functions.
3. The application run like below picture. We connect the loop back at first. Thus, We can receive the data. We remove the loop back and we does not receive data anymore.
中文
========================================================================
測試 Serial port 是否正常,以下用簡單的 sample code 去實作 Serial port 的傳輸。
1. 創立新的 Windows Form Project,並加入以下程式碼;在程式碼中,可以看到要實作 Serial port,需加入 System.IO.Ports,接著就需要設定 Serial port 的參數(Port name, Baud rate...)
2. 接著在程式碼中加入,Send 和 Receive 的程式碼;Serial port 在傳送與接收資料的 function 為 WriteLine() 和 ReadExisting()
3. 程式執行起來,畫面如下,可以看到一開始有接 loop back,因此有收到資料,後面拔掉 loop back,就僅看到傳送資料的部分
沒有留言:
張貼留言