📄 form1.cs
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Text;
using System.Threading;
using System.Text.RegularExpressions;
namespace IPP.SMS
{
/// <summary>
/// Summary description for Form1.
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.GroupBox grpSend;
private System.Windows.Forms.GroupBox groupBox3;
private System.Windows.Forms.TextBox txtRetryCount;
private System.Windows.Forms.Label label5;
private System.Windows.Forms.ComboBox cboPort;
private System.Windows.Forms.Label ConnectState;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.Label label4;
private System.Windows.Forms.ComboBox cboBps;
private System.Windows.Forms.Button btnConnect;
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;
private System.Windows.Forms.Label lblMessage;
private System.Windows.Forms.Label lblCenterNo;
private System.Windows.Forms.Button btnDisConnect;
private System.Windows.Forms.Button btnStop;
private static int logIndex=0;
private int retryCount=0;
private int retryTimeOut = 50;
private int sendInterval = 5*60*1000;
private int readInterval = 1*60*1000;
private string newLine="";
static CommPort ss_port = new CommPort();
private System.Windows.Forms.GroupBox groupBox1;
PDUdecoding sms = new PDUdecoding();
private System.Windows.Forms.Button btnStart;
//读com口的锁
//对于收发,有两个方案
//1 收发交替,这样不需要锁
//2 收发同时进行,都用各自的线程,这样就需要锁
//本程序用2
private object comLock = new object();
#region ENUM SMSStatus
private enum SMSStatus : int
{
Abandon = -1,
SendOrg = 0,
SendOK = 1,
}
#endregion
#region stop lock
private object stopLock = new object();
private System.Windows.Forms.GroupBox groupBox4;
private System.Windows.Forms.GroupBox groupBox2;
private System.Windows.Forms.TextBox txtSendLog;
private System.Windows.Forms.TextBox txtRecvLog;
private System.Windows.Forms.TextBox txtSendBuffer;
private System.Windows.Forms.TextBox txtRecvBuffer;
private bool _stopped = false;
private bool Stopped
{
set
{
lock (stopLock)
{
_stopped = value;
}
}
get
{
lock (stopLock)
{
return _stopped;
}
}
}
#endregion
public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
//
// TODO: Add any constructor code after InitializeComponent call
//
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.txtSendLog = new System.Windows.Forms.TextBox();
this.grpSend = new System.Windows.Forms.GroupBox();
this.groupBox3 = new System.Windows.Forms.GroupBox();
this.lblCenterNo = new System.Windows.Forms.Label();
this.txtRetryCount = new System.Windows.Forms.TextBox();
this.label5 = new System.Windows.Forms.Label();
this.cboBps = new System.Windows.Forms.ComboBox();
this.cboPort = new System.Windows.Forms.ComboBox();
this.ConnectState = new System.Windows.Forms.Label();
this.label3 = new System.Windows.Forms.Label();
this.label4 = new System.Windows.Forms.Label();
this.btnConnect = new System.Windows.Forms.Button();
this.lblMessage = new System.Windows.Forms.Label();
this.btnDisConnect = new System.Windows.Forms.Button();
this.btnStop = new System.Windows.Forms.Button();
this.groupBox1 = new System.Windows.Forms.GroupBox();
this.txtSendBuffer = new System.Windows.Forms.TextBox();
this.btnStart = new System.Windows.Forms.Button();
this.groupBox4 = new System.Windows.Forms.GroupBox();
this.txtRecvLog = new System.Windows.Forms.TextBox();
this.groupBox2 = new System.Windows.Forms.GroupBox();
this.txtRecvBuffer = new System.Windows.Forms.TextBox();
this.grpSend.SuspendLayout();
this.groupBox3.SuspendLayout();
this.groupBox1.SuspendLayout();
this.groupBox4.SuspendLayout();
this.groupBox2.SuspendLayout();
this.SuspendLayout();
//
// txtSendLog
//
this.txtSendLog.BackColor = System.Drawing.SystemColors.WindowText;
this.txtSendLog.ForeColor = System.Drawing.Color.Lime;
this.txtSendLog.Location = new System.Drawing.Point(10, 17);
this.txtSendLog.Multiline = true;
this.txtSendLog.Name = "txtSendLog";
this.txtSendLog.ScrollBars = System.Windows.Forms.ScrollBars.Vertical;
this.txtSendLog.Size = new System.Drawing.Size(556, 104);
this.txtSendLog.TabIndex = 4;
this.txtSendLog.Text = "";
//
// grpSend
//
this.grpSend.Controls.Add(this.txtSendLog);
this.grpSend.Location = new System.Drawing.Point(250, 146);
this.grpSend.Name = "grpSend";
this.grpSend.Size = new System.Drawing.Size(576, 130);
this.grpSend.TabIndex = 5;
this.grpSend.TabStop = false;
this.grpSend.Text = "Send Log";
//
// groupBox3
//
this.groupBox3.Controls.Add(this.lblCenterNo);
this.groupBox3.Controls.Add(this.txtRetryCount);
this.groupBox3.Controls.Add(this.label5);
this.groupBox3.Controls.Add(this.cboBps);
this.groupBox3.Controls.Add(this.cboPort);
this.groupBox3.Controls.Add(this.ConnectState);
this.groupBox3.Controls.Add(this.label3);
this.groupBox3.Controls.Add(this.label4);
this.groupBox3.Location = new System.Drawing.Point(10, 9);
this.groupBox3.Name = "groupBox3";
this.groupBox3.Size = new System.Drawing.Size(220, 241);
this.groupBox3.TabIndex = 7;
this.groupBox3.TabStop = false;
this.groupBox3.Text = "Config";
//
// lblCenterNo
//
this.lblCenterNo.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
this.lblCenterNo.ForeColor = System.Drawing.SystemColors.ControlText;
this.lblCenterNo.Location = new System.Drawing.Point(48, 121);
this.lblCenterNo.Name = "lblCenterNo";
this.lblCenterNo.Size = new System.Drawing.Size(144, 24);
this.lblCenterNo.TabIndex = 15;
//
// txtRetryCount
//
this.txtRetryCount.Location = new System.Drawing.Point(106, 86);
this.txtRetryCount.Name = "txtRetryCount";
this.txtRetryCount.Size = new System.Drawing.Size(57, 21);
this.txtRetryCount.TabIndex = 14;
this.txtRetryCount.Text = "30";
//
// label5
//
this.label5.Location = new System.Drawing.Point(19, 86);
this.label5.Name = "label5";
this.label5.Size = new System.Drawing.Size(77, 17);
this.label5.TabIndex = 13;
this.label5.Text = "Retry Count";
//
// cboBps
//
this.cboBps.Items.AddRange(new object[] {
"9600",
"14400",
"19200",
"57600"});
this.cboBps.Location = new System.Drawing.Point(106, 52);
this.cboBps.Name = "cboBps";
this.cboBps.Size = new System.Drawing.Size(80, 20);
this.cboBps.TabIndex = 12;
this.cboBps.Text = "19200";
//
// cboPort
//
this.cboPort.Items.AddRange(new object[] {
"COM1",
"COM2",
"COM3",
"COM4",
"COM5"});
this.cboPort.Location = new System.Drawing.Point(106, 26);
this.cboPort.Name = "cboPort";
this.cboPort.Size = new System.Drawing.Size(80, 20);
this.cboPort.TabIndex = 11;
this.cboPort.Text = "COM1";
//
// ConnectState
//
this.ConnectState.BackColor = System.Drawing.Color.LightSteelBlue;
this.ConnectState.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
this.ConnectState.ForeColor = System.Drawing.Color.Tomato;
this.ConnectState.Location = new System.Drawing.Point(48, 155);
this.ConnectState.Name = "ConnectState";
this.ConnectState.Size = new System.Drawing.Size(144, 78);
this.ConnectState.TabIndex = 10;
this.ConnectState.Text = "尚未与任何设备连接";
//
// label3
//
this.label3.AutoSize = true;
this.label3.Location = new System.Drawing.Point(58, 26);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(29, 17);
this.label3.TabIndex = 7;
this.label3.Text = "Port";
//
// label4
//
this.label4.AutoSize = true;
this.label4.Location = new System.Drawing.Point(58, 52);
this.label4.Name = "label4";
this.label4.Size = new System.Drawing.Size(23, 17);
this.label4.TabIndex = 8;
this.label4.Text = "Bps";
//
// btnConnect
//
this.btnConnect.Location = new System.Drawing.Point(134, 267);
this.btnConnect.Name = "btnConnect";
this.btnConnect.Size = new System.Drawing.Size(90, 25);
this.btnConnect.TabIndex = 15;
this.btnConnect.Text = "Connect";
this.btnConnect.Click += new System.EventHandler(this.btnConnect_Click);
//
// lblMessage
//
this.lblMessage.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
this.lblMessage.Location = new System.Drawing.Point(19, 267);
this.lblMessage.Name = "lblMessage";
this.lblMessage.Size = new System.Drawing.Size(96, 121);
this.lblMessage.TabIndex = 17;
this.lblMessage.Text = "Logo Here";
//
// btnDisConnect
//
this.btnDisConnect.Enabled = false;
this.btnDisConnect.Location = new System.Drawing.Point(134, 293);
this.btnDisConnect.Name = "btnDisConnect";
this.btnDisConnect.Size = new System.Drawing.Size(90, 25);
this.btnDisConnect.TabIndex = 18;
this.btnDisConnect.Text = "DisConnect";
this.btnDisConnect.Click += new System.EventHandler(this.btnDisConnect_Click);
//
// btnStop
//
this.btnStop.Enabled = false;
this.btnStop.Location = new System.Drawing.Point(134, 362);
this.btnStop.Name = "btnStop";
this.btnStop.Size = new System.Drawing.Size(90, 25);
this.btnStop.TabIndex = 19;
this.btnStop.Text = "Stop";
this.btnStop.Click += new System.EventHandler(this.btnStop_Click);
//
// groupBox1
//
this.groupBox1.Controls.Add(this.txtSendBuffer);
this.groupBox1.Location = new System.Drawing.Point(250, 17);
this.groupBox1.Name = "groupBox1";
this.groupBox1.Size = new System.Drawing.Size(288, 129);
this.groupBox1.TabIndex = 20;
this.groupBox1.TabStop = false;
this.groupBox1.Text = "Send Buffer";
//
// txtSendBuffer
//
this.txtSendBuffer.Location = new System.Drawing.Point(10, 17);
this.txtSendBuffer.Multiline = true;
this.txtSendBuffer.Name = "txtSendBuffer";
this.txtSendBuffer.ScrollBars = System.Windows.Forms.ScrollBars.Vertical;
this.txtSendBuffer.Size = new System.Drawing.Size(268, 104);
this.txtSendBuffer.TabIndex = 2;
this.txtSendBuffer.Text = "";
//
// btnStart
//
this.btnStart.Enabled = false;
this.btnStart.Location = new System.Drawing.Point(134, 327);
this.btnStart.Name = "btnStart";
this.btnStart.Size = new System.Drawing.Size(90, 25);
this.btnStart.TabIndex = 21;
this.btnStart.Text = "Start";
this.btnStart.Click += new System.EventHandler(this.btnStart_Click);
//
// groupBox4
//
this.groupBox4.Controls.Add(this.txtRecvLog);
this.groupBox4.Location = new System.Drawing.Point(250, 276);
this.groupBox4.Name = "groupBox4";
this.groupBox4.Size = new System.Drawing.Size(576, 129);
this.groupBox4.TabIndex = 22;
this.groupBox4.TabStop = false;
this.groupBox4.Text = "Recv Log";
//
// txtRecvLog
//
this.txtRecvLog.BackColor = System.Drawing.SystemColors.WindowText;
this.txtRecvLog.ForeColor = System.Drawing.Color.Lime;
this.txtRecvLog.Location = new System.Drawing.Point(10, 17);
this.txtRecvLog.Multiline = true;
this.txtRecvLog.Name = "txtRecvLog";
this.txtRecvLog.ScrollBars = System.Windows.Forms.ScrollBars.Vertical;
this.txtRecvLog.Size = new System.Drawing.Size(556, 104);
this.txtRecvLog.TabIndex = 4;
this.txtRecvLog.Text = "";
//
// groupBox2
//
this.groupBox2.Controls.Add(this.txtRecvBuffer);
this.groupBox2.Location = new System.Drawing.Point(538, 17);
this.groupBox2.Name = "groupBox2";
this.groupBox2.Size = new System.Drawing.Size(288, 129);
this.groupBox2.TabIndex = 21;
this.groupBox2.TabStop = false;
this.groupBox2.Text = "Recv Buffer";
//
// txtRecvBuffer
//
this.txtRecvBuffer.Location = new System.Drawing.Point(10, 17);
this.txtRecvBuffer.Multiline = true;
this.txtRecvBuffer.Name = "txtRecvBuffer";
this.txtRecvBuffer.ScrollBars = System.Windows.Forms.ScrollBars.Vertical;
this.txtRecvBuffer.Size = new System.Drawing.Size(268, 104);
this.txtRecvBuffer.TabIndex = 2;
this.txtRecvBuffer.Text = "";
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.BackColor = System.Drawing.Color.LightSteelBlue;
this.ClientSize = new System.Drawing.Size(835, 418);
this.Controls.Add(this.groupBox4);
this.Controls.Add(this.btnStart);
this.Controls.Add(this.groupBox1);
this.Controls.Add(this.btnStop);
this.Controls.Add(this.btnDisConnect);
this.Controls.Add(this.groupBox3);
this.Controls.Add(this.grpSend);
this.Controls.Add(this.btnConnect);
this.Controls.Add(this.lblMessage);
this.Controls.Add(this.groupBox2);
this.MaximizeBox = false;
this.Name = "Form1";
this.Text = "IPP SMS";
this.Closed += new System.EventHandler(this.Form1_Closed);
this.grpSend.ResumeLayout(false);
this.groupBox3.ResumeLayout(false);
this.groupBox1.ResumeLayout(false);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -