📄 form1.cs
字号:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace PCSerialCom
{
/// <summary>
/// Form1 的摘要说明。
/// </summary>
public partial class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.Label labPort;
private System.Windows.Forms.Label labDataPkg;
private System.Windows.Forms.Button btnSend;
private System.Windows.Forms.GroupBox grpBoxPara;
private System.Windows.Forms.Label labBaudrate;
private System.Windows.Forms.Label labDatabit;
private System.Windows.Forms.Label labStopbit;
private System.Windows.Forms.Label labParitybit;
private System.Windows.Forms.Button btnApply;
private System.Windows.Forms.Button btnClear;
private System.Windows.Forms.Button btnInit;
private System.Windows.Forms.TextBox textBox8;
private System.Windows.Forms.Label labLocalAddr;
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 PCSerialCom PCSerialCom1 = new PCSerialCom();
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 btnShut; //readTimeOut
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null;
public Form1()
{
InitializeComponent();
}
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose(bool disposing)
{
if (disposing)
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose(disposing);
}
#region Windows 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.msg = new System.Windows.Forms.TextBox();
this.labPort = new System.Windows.Forms.Label();
this.labDataPkg = new System.Windows.Forms.Label();
this.t_send = new System.Windows.Forms.TextBox();
this.btnSend = new System.Windows.Forms.Button();
this.grpBoxPara = new System.Windows.Forms.GroupBox();
this.btnApply = new System.Windows.Forms.Button();
this.t_port = new System.Windows.Forms.TextBox();
this.labBaudrate = new System.Windows.Forms.Label();
this.t_rate = new System.Windows.Forms.TextBox();
this.labDatabit = new System.Windows.Forms.Label();
this.t_bytesize = new System.Windows.Forms.TextBox();
this.labStopbit = new System.Windows.Forms.Label();
this.t_stopbyte = new System.Windows.Forms.TextBox();
this.labParitybit = new System.Windows.Forms.Label();
this.t_parity = new System.Windows.Forms.TextBox();
this.btnClear = new System.Windows.Forms.Button();
this.btnInit = new System.Windows.Forms.Button();
this.textBox8 = new System.Windows.Forms.TextBox();
this.labLocalAddr = new System.Windows.Forms.Label();
this.btnShut = new System.Windows.Forms.Button();
this.grpBoxPara.SuspendLayout();
this.SuspendLayout();
//
// msg
//
this.msg.ForeColor = System.Drawing.Color.Green;
this.msg.Location = new System.Drawing.Point(0, 0);
this.msg.Multiline = true;
this.msg.Name = "msg";
this.msg.ScrollBars = System.Windows.Forms.ScrollBars.Vertical;
this.msg.Size = new System.Drawing.Size(512, 264);
this.msg.TabIndex = 0;
//
// labPort
//
this.labPort.Location = new System.Drawing.Point(16, 24);
this.labPort.Name = "labPort";
this.labPort.Size = new System.Drawing.Size(56, 16);
this.labPort.TabIndex = 1;
this.labPort.Text = "端口号:";
//
// labDataPkg
//
this.labDataPkg.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(192)))), ((int)(((byte)(64)))), ((int)(((byte)(0)))));
this.labDataPkg.Location = new System.Drawing.Point(8, 323);
this.labDataPkg.Name = "labDataPkg";
this.labDataPkg.Size = new System.Drawing.Size(80, 16);
this.labDataPkg.TabIndex = 1;
this.labDataPkg.Text = "数据包设置:";
//
// t_send
//
this.t_send.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.t_send.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(255)))), ((int)(((byte)(128)))), ((int)(((byte)(0)))));
this.t_send.Location = new System.Drawing.Point(10, 348);
this.t_send.Name = "t_send";
this.t_send.Size = new System.Drawing.Size(138, 21);
this.t_send.TabIndex = 2;
//
// btnSend
//
this.btnSend.Location = new System.Drawing.Point(177, 349);
this.btnSend.Name = "btnSend";
this.btnSend.Size = new System.Drawing.Size(40, 23);
this.btnSend.TabIndex = 3;
this.btnSend.Text = "发送";
this.btnSend.Click += new System.EventHandler(this.btnSend_Click);
//
// grpBoxPara
//
this.grpBoxPara.Controls.Add(this.btnApply);
this.grpBoxPara.Controls.Add(this.t_port);
this.grpBoxPara.Controls.Add(this.labPort);
this.grpBoxPara.Controls.Add(this.labBaudrate);
this.grpBoxPara.Controls.Add(this.t_rate);
this.grpBoxPara.Controls.Add(this.labDatabit);
this.grpBoxPara.Controls.Add(this.t_bytesize);
this.grpBoxPara.Controls.Add(this.labStopbit);
this.grpBoxPara.Controls.Add(this.t_stopbyte);
this.grpBoxPara.Controls.Add(this.labParitybit);
this.grpBoxPara.Controls.Add(this.t_parity);
this.grpBoxPara.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(192)))), ((int)(((byte)(64)))), ((int)(((byte)(0)))));
this.grpBoxPara.Location = new System.Drawing.Point(305, 289);
this.grpBoxPara.Name = "grpBoxPara";
this.grpBoxPara.Size = new System.Drawing.Size(176, 223);
this.grpBoxPara.TabIndex = 4;
this.grpBoxPara.TabStop = false;
this.grpBoxPara.Text = "参数设置";
//
// btnApply
//
this.btnApply.FlatStyle = System.Windows.Forms.FlatStyle.Popup;
this.btnApply.Location = new System.Drawing.Point(45, 194);
this.btnApply.Name = "btnApply";
this.btnApply.Size = new System.Drawing.Size(75, 23);
this.btnApply.TabIndex = 3;
this.btnApply.Text = "应用";
this.btnApply.Click += new System.EventHandler(this.btnApply_Click);
//
// t_port
//
this.t_port.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.t_port.Location = new System.Drawing.Point(80, 16);
this.t_port.Name = "t_port";
this.t_port.Size = new System.Drawing.Size(80, 21);
this.t_port.TabIndex = 2;
this.t_port.Text = "1";
//
// labBaudrate
//
this.labBaudrate.Location = new System.Drawing.Point(16, 58);
this.labBaudrate.Name = "labBaudrate";
this.labBaudrate.Size = new System.Drawing.Size(56, 16);
this.labBaudrate.TabIndex = 1;
this.labBaudrate.Text = "波特率:";
//
// t_rate
//
this.t_rate.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.t_rate.Location = new System.Drawing.Point(80, 50);
this.t_rate.Name = "t_rate";
this.t_rate.Size = new System.Drawing.Size(80, 21);
this.t_rate.TabIndex = 2;
this.t_rate.Text = "9600";
//
// labDatabit
//
this.labDatabit.Location = new System.Drawing.Point(16, 92);
this.labDatabit.Name = "labDatabit";
this.labDatabit.Size = new System.Drawing.Size(56, 16);
this.labDatabit.TabIndex = 1;
this.labDatabit.Text = "数据位:";
//
// t_bytesize
//
this.t_bytesize.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.t_bytesize.Location = new System.Drawing.Point(80, 84);
this.t_bytesize.Name = "t_bytesize";
this.t_bytesize.Size = new System.Drawing.Size(80, 21);
this.t_bytesize.TabIndex = 2;
this.t_bytesize.Text = "8";
//
// labStopbit
//
this.labStopbit.Location = new System.Drawing.Point(18, 123);
this.labStopbit.Name = "labStopbit";
this.labStopbit.Size = new System.Drawing.Size(56, 16);
this.labStopbit.TabIndex = 1;
this.labStopbit.Text = "停止位:";
//
// t_stopbyte
//
this.t_stopbyte.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.t_stopbyte.Location = new System.Drawing.Point(80, 118);
this.t_stopbyte.Name = "t_stopbyte";
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -