设为首页 加入收藏

TOP

C#结合串口通信类实现串口通信源代码(一)
2014-11-24 13:12:24 来源: 作者: 【 】 浏览:0
Tags:结合 串口 通信 实现 源代码

下面是串口通讯测试程序的源代码,将mycom类放在此项目中
可以实现简单的串口通信,希望读者能通过这个程序对串口通信过程有一个初步的了解:


using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Threading;
namespace BusApp
{
///


/// Form1 的摘要说明。
///

public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.GroupBox groupBox1;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.Label label4;
private System.Windows.Forms.Label label5;
private System.Windows.Forms.Label label6;
private System.Windows.Forms.Button button2;
private System.Windows.Forms.Button button3;
private System.Windows.Forms.Button button4;
private System.Windows.Forms.TextBox textBox8;
private System.Windows.Forms.Label label7;


public int iPort=1; //1,2,3,4
public int iRate=9600; //1200,2400,4800,9600
public byte bSize=8; //8 bits
public byte bParity=0; // 0-4=no,odd,even,mark,space
public byte bStopBits=1; // 0,1,2 = 1, 1.5, 2
public int iTimeout=1000;
public mycom mycom1=new mycom();
public byte[] recb;


private System.Windows.Forms.TextBox msg;
private System.Windows.Forms.TextBox t_port;
private System.Windows.Forms.TextBox t_rate;
private System.Windows.Forms.TextBox t_bytesize;
private System.Windows.Forms.TextBox t_stopbyte;
private System.Windows.Forms.TextBox t_parity;
private System.Windows.Forms.TextBox t_send;
private System.Windows.Forms.Button button5; //readTimeOut
///


/// 必需的设计器变量。
///

private System.ComponentModel.Container components = null;


public Form1()
{
InitializeComponent();
}


///


/// 清理所有正在使用的资源。
///

protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}


#region Windows 窗体设计器生成的代码
///


/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
///

private void InitializeComponent()
{
this.msg = new System.Windows.Forms.TextBox();
this.label1 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.t_send = new System.Windows.Forms.TextBox();
this.button1 = new System.Windows.Forms.Button();
this.groupBox1 = new System.Windows.Forms.GroupBox();
this.button2 = new System.Windows.Forms.Button();
this.t_port = new System.Windows.Forms.TextBox();
this.label3 = new System.Windows.Forms.Label();
this.t_rate = new System.Windows.Forms.TextBox();
this.label4 = new System.Windows.Forms.Label();
this.t_bytesize = new System.Windows.Forms.TextBox();
this.label5 = new System.Windows.Forms.Label();
this.t_stopbyte = new System.Windows.Forms.TextBox();
this.label6 = new System.Windows.Forms.Label();
this.t_parity = new System.Windows.Forms.TextBox();
this.button3 = new System.Windows.Forms.Button();
this.button4 = new System.Windows.Forms.Button();
this.textBox8 = new System.Windows.Forms.TextBox();
this.label7 = new System.Windows.Forms.Label();
this.button5 = new System.Windows.Forms.Button();
this.groupBox1.SuspendLayout();
this.SuspendLayout();
//
// msg
//
this.msg.ForeColor = System.Drawing.Color.Green;
this.
首页 上一页 1 2 3 4 5 下一页 尾页 1/5/5
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇C#串口通信编程类(修改版) 下一篇Java里关于日期Date的相关代码实现

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: