基于C#的串口通信上位机和下位机源代码

2020-02-21 00:58

基于单片机串口通信的上位机和下位机实践 串口

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;


基于C#的串口通信上位机和下位机源代码.doc 将本文的Word文档下载到电脑 下载失败或者文档不完整,请联系客服人员解决!

下一篇:现如今人们对心脏搭桥手术这个名词

相关阅读
本类排行
× 注册会员免费下载(下载后可以自由复制和排版)

马上注册会员

注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信: QQ: