C#结合串口通信类实现串口通信源代码

  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

mycom是串口通信类,在本blog前一篇中有完整代码。(C#串口通信编程类(修改版)) 下面是串口通讯测试程序的源代码,将mycom类放在此项目中

可以实现简单的串口通信,希望读者能通过这个程序对串口通信过程有一个初步的了解:

usingSystem;

usingSystem.Drawing;

usingSystem.Collections;

ponentModel;

usingSystem.Windows.Forms;

usingSystem.Data;

usingSystem.Threading;

namespaceBusApp

{

///

///Form1的摘要说明。

///

publicclassForm1:System.Windows.Forms.Form

{

bellabel1;

bellabel2;

privateSystem.Windows.Forms.Buttonbutton1;

privateSystem.Windows.Forms.GroupBoxgroupBox1;

bellabel3;

bellabel4;

bellabel5;

bellabel6;

privateSystem.Windows.Forms.Buttonbutton2;

privateSystem.Windows.Forms.Buttonbutton3;

privateSystem.Windows.Forms.Buttonbutton4;

privateSystem.Windows.Forms.TextBoxtextBox8;

bellabel7;

publicintiPort=1;//1,2,3,4

publicintiRate=9600;//1200,2400,4800,9600

publicbytebSize=8;//8bits

publicbytebParity=0;//0-4=no,odd,even,mark,space

publicbytebStopBits=1;//0,1,2=1,1.5,2

publicintiTimeout=1000;

publicmycommycom1=newmycom();

publicbyte[]recb;

privateSystem.Windows.Forms.TextBoxmsg;

privateSystem.Windows.Forms.TextBoxt_port;

privateSystem.Windows.Forms.TextBoxt_rate;

privateSystem.Windows.Forms.TextBoxt_bytesize;

privateSystem.Windows.Forms.TextBoxt_stopbyte;

privateSystem.Windows.Forms.TextBoxt_parity; privateSystem.Windows.Forms.TextBoxt_send; privateSystem.Windows.Forms.Buttonbutton5;//readTimeOut ///

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

///

ponentModel.Containercomponents=null; publicForm1()

{

InitializeComponent();

}

///

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

///

protectedoverridevoidDispose(booldisposing)

{

if(disposing)

{

if(components!=null)

{

components.Dispose();

}

}

base.Dispose(disposing);

}

#regionWindows窗体设计器生成的代码

///

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

///此方法的内容。

///

privatevoidInitializeComponent()

{

this.msg=newSystem.Windows.Forms.TextBox();

bel1=bel();

bel2=bel();

this.t_send=newSystem.Windows.Forms.TextBox();

this.button1=newSystem.Windows.Forms.Button();

this.groupBox1=newSystem.Windows.Forms.GroupBox(); this.button2=newSystem.Windows.Forms.Button();

this.t_port=newSystem.Windows.Forms.TextBox();

bel3=bel();

this.t_rate=newSystem.Windows.Forms.TextBox();

bel4=bel();

this.t_bytesize=newSystem.Windows.Forms.TextBox();

相关文档
最新文档