基于单片机串口通信的上位机和下位机实践 串口
Universal Serial Bus或者USBRS232
GPIB兼容的设备也带有RS-232获取远程采集设备的数据。
byte
发送数据的同时用另一根线接收数据。它很简单并且能够实现远距离通信。比如IEEE48820
1200米。
首先亮出C#的源程序吧。
2bit
using System;
using System.Collections.Generic; using System.ComponentModel; using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO.Ports;
using System.Timers;
namespace 单片机功能控制 {
public partial class Form1 : Form public Form1() {
{ InitializeComponent(); }
SerialPort sp = new SerialPort();
private void button1_Click(object sender, EventArgs e) {
String str1 = comboBox1.Text;//串口号 String str2 = comboBox2.Text;//波特率 String str3 = comboBox3.Text;//校验位 String str4 = comboBox5.Text;//停止位 String str5 = comboBox4.Text;//数据位
Int32 int2 = Convert.ToInt32(str2);//将字符串转为整型 Int32 int5 = Convert.ToInt32(str5);//将字符串转为整型 groupBox3.Enabled = true;//LED控制界面变可选
try {
if (button1.Text == \打开串口\
{
if (str1 == null)
{
MessageBox.Show(\\
\
return; } sp.Close(); sp = new SerialPort(); sp.PortName = comboBox1.Text;//串口编号 sp.BaudRate = int2;//波特率 switch (str4)//停止位 { case \
sp.StopBits = StopBits.One;
break;
default:
确\
case \ sp.StopBits = StopBits.OnePointFive; break; case \ sp.StopBits = StopBits.Two; break; MessageBox.Show(\ break;