基于单片机串口通信的上位机和下位机实践串口是计算机上一种非常通用设备通信的协议(不要与通用串行总线UniversalSerialBus或者USB混淆)
大多数计算机包含两个基于RS232的串口
串口同时也是仪器仪表设备通用的通信协议;很多GPIB兼容的设备也带有RS-232口
同时,串口通信协议也可以用于获取远程采集设备的数据
串口通信的概念非常简单,串口按位(bit)发送和接收字节
尽管比按字节(byte)的并行通信慢,但是串口可以在使用一根线发送数据的同时用另一根线接收数据
它很简单并且能够实现远距离通信
比如IEEE488定义并行通行状态时,规定设备线总常不得超过20米,并且任意两个设备间的长度不得超过2米;而对于串口而言,长度可达1200米
首先亮出C#的源程序吧
主要界面:只是作为简单的运用,可以扩展的
源代码:usingSystem;usingSystem
Collections
Generic;usingSystem
ComponentModel;usingSystem
Data;usingSystem
Drawing;usingSystem
Text;usingSystem
Windows
Forms;usingSystem
Ports;usingSystem
Timers;namespace单片机功能控制{publicpartialclassForm1:Form{publicForm1(){InitializeComponent();}SerialPortsp=newSerialPort();privatevoidbutton1_Click(objectsender,EventArgse){Stringstr1=comboBox1
Text;//串口号Stringstr2=comboBox2
Text;//波特率Stringstr3=comboBox