Because it was a test, I used only a single point computer.
Tool: one serial cable
Method: Link The serial port of the computer, and short the 2 and 3rd pointers in the serial line.
Reason: The 2nd pointer indicates the sending of data. The No. 3rd pointer indicates acceptance data.
C # Software interface
Run the process:
1, click on the COM1 button to open the serial port
2. Enter the content you want to send in TextBox2
3, click the Send button to send out the content
4, click the Receive button to receive the data sent over
5, the received data will be displayed in the TextBox3.
Software source code:
# The name of the project works is: WindowsApplication2
1 usingSystem;2 usingSystem.Collections.Generic;3 usingSystem.ComponentModel;4 usingSystem.Data;5 usingSystem.Drawing;6 usingSystem.Linq;7 usingSystem.Text;8 usingSystem.Windows.Forms;9 usingSystem.IO.Ports;Ten One namespaceWindowsApplication2 A { - Public Partial classForm1:form - { the PublicForm1 () - { - InitializeComponent (); - } +SerialPort SP =NULL; - Private voidForm1_Load (Objectsender, EventArgs e) + { A } at - //How to open the COM1 button - Private voidButton1_Click (Objectsender, EventArgs e) - { - string[] str = Serialport.getportnames ();//get the serial name - if(str = =NULL) in { -MessageBox.Show ("This machine does not have serial port"); to return; + } - Else the { * foreach(stringAinchstr) $ {Panax NotoginsengConsole.Write (a);//The output is the name of the serial port you are connected to - } the } + A theSP =NewSerialPort (); +Sp. PortName ="COM1"; -Sp. Open ();//Open the serial port $ $ } - - the //Send Button Method - Private voidButton2_Click (Objectsender, EventArgs e)Wuyi { theSp. WriteLine (TextBox2.Text);//write data to a string - } Wu - Private voidButton3_Click (Objectsender, EventArgs e) About { $ stringDate = sp. Readexisting ();//receiving data from a string -TextBox3.Text = Date;//Show Data - } - } A}
C # simple Serial link Communication detailed introduction