添加项目文件。

This commit is contained in:
liming 蔡
2026-07-14 13:55:17 +08:00
parent 63759495f2
commit 8bbdf78731
335 changed files with 81415 additions and 0 deletions
+279
View File
@@ -0,0 +1,279 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Net.Sockets;
using System.Net;
using System.Windows.Forms;
namespace SimpleCommunication
{
public class Client : IDisposable
{
#region DataMember & Ctor
public TcpClient tcpclient;
private NetworkStream netstream;
public string IP;
public string Port;
private byte[] readBytes;
private object tcpClientLock = new object();//锁TcpClient;Dispose之后就不允许EndRead,远程连接断开以后,就不允许再调用Dispose
private bool closed = false;//包括本地主动断开和远程断开
//在事务处理结束后才触发下列事件
public event DlgNoParam ConnectFailEvent;
public event DlgOneParam<string> NewClientEvent;
public event DlgOneParam<string> RecvMsgEvent;
public event DlgOneParam<string> RemoteDisconnectEvent;
public event DlgNoParam LocalDisconnectEvent;
/// <summary>
/// 客户端是否链接
/// </summary>
public bool IsConnected => (tcpclient != null && tcpclient.Connected) ? true : false;
/// <summary>
/// 服务的client的构造函数
/// </summary>
/// <param name="tcpclient"></param>
public Client(TcpClient tcpclient)
{
this.tcpclient = tcpclient;
readBytes = new byte[tcpclient.ReceiveBufferSize];//接收数据的缓冲区大小,如果太小一段数据会多次接收完成
netstream = tcpclient.GetStream();//如果远程客户端断开一样可以获得netstream
}
/// <summary>
/// 客户端client的构造函数
/// </summary>
public Client()
{
}
#endregion
#region 数据收发
/// <summary>
/// 在建立连接的情况下发送消息
/// </summary>
/// <param name="msg"></param>
/// <returns></returns>
public bool SendMsg(string msg)
{
bool result = false;
try
{
if (netstream != null)
{
if (!string.IsNullOrEmpty(msg))
{
byte[] buff = Encoding.Default.GetBytes(msg);
netstream.Write(buff, 0, buff.Length);
result = true;
}
}
}
catch (Exception ex)
{
throw ex;
}
return result;
}
/// <summary>
/// 服务的接收到客户端连接后最先做的操作之一,客户端接收数据线程起始
/// </summary>
/// <returns></returns>
public bool BeginRead()
{
bool result = false;
try
{
IP = (tcpclient.Client.RemoteEndPoint as IPEndPoint).Address.ToString();
Port = (tcpclient.Client.RemoteEndPoint as IPEndPoint).Port.ToString();
if (NewClientEvent != null)
{
NewClientEvent(IP + " " + Port);
}
netstream.BeginRead(readBytes, 0, readBytes.Length, EndRead, null);//如果远程客户端断开这句话一样可以执行
result = true;
}
catch
{
throw;
}
return result;
}
/// <summary>
/// 有互斥资源
/// 接收数据,远程连接断开,远程程序关闭,本地连接断开,都会按顺序调用进来;因为连接关闭后不再调用BeginRead
/// 服务器listener.stop时不会进入这个函数,客户端照样通讯,服务端只是不能接收新连接而已
/// </summary>
/// <param name="ar"></param>
private void EndRead(IAsyncResult ar)
{
lock (tcpClientLock)
{
if (!closed)//如果本地主动断开就不会进入
{
try
{
string recvStr = "";
int count = netstream.EndRead(ar);
if (count > 0)
{
recvStr = Encoding.Default.GetString(readBytes, 0, count);
recvStr = DateTime.Now.ToString("HH:mm:ss") + " [" + IP + " " + Port + "] :\n" + recvStr + "\n";
if (RecvMsgEvent != null)
{
RecvMsgEvent(recvStr);
}
readBytes = new byte[tcpclient.ReceiveBufferSize];
netstream.BeginRead(readBytes, 0, readBytes.Length, EndRead, null);
}
else//远程客户端主动断开
{
LocalClientClose();
}
}
catch (Exception ex)
{
if (ex.Message.Contains("无法从传输连接中读取数据: 远程主机强迫关闭了一个现有的连接"))
{
LocalClientClose();
}
else
{
LocalClientClose();
}
}
}
}
}
#endregion
#region 客户端连接和关闭
/// <summary>
/// 客户端的client连接服务器
/// </summary>
/// <param name="ip"></param>
/// <param name="port"></param>
/// <returns></returns>
public bool Connect(ComboBox Server_IP, TextBox txtPort)
{
bool result = false;
try
{
if (!string.IsNullOrEmpty(Server_IP.Text) && !string.IsNullOrEmpty(txtPort.Text))
{
IP = Server_IP.Text.Trim();
Port = txtPort.Text.Trim();
IPAddress ipAddress = IPAddress.Parse(IP);
IPEndPoint point = new IPEndPoint(ipAddress, int.Parse(Port));
tcpclient = new TcpClient(AddressFamily.InterNetwork);
readBytes = new byte[tcpclient.ReceiveBufferSize];
tcpclient.Connect(point);
netstream = tcpclient.GetStream();
BeginRead();
closed = false;
result = true;
}
}
catch (Exception ex)
{
if (ex.Message.Contains("由于目标计算机积极拒绝"))
{
if (ConnectFailEvent != null)
{
ConnectFailEvent();
}
}
else
{
}
}
return result;
}
/// <summary>
/// 远程连接断开后(点关闭断开,程序退出断开)本地连接处理
/// </summary>
public void LocalClientClose()
{
closed = true;
DisposeEx();
if (RemoteDisconnectEvent != null)
{
string param = IP + " " + Port;
if (RemoteDisconnectEvent != null)
{
RemoteDisconnectEvent(param);
}
}
}
/// <summary>
/// 有互斥资源
/// 在已连接条件下关闭本地连接和资源释放时调用
/// </summary>
public void Dispose()
{
lock (tcpClientLock)
{
if (!closed)
{
closed = true;
DisposeEx();
if (LocalDisconnectEvent != null)
{
LocalDisconnectEvent();
}
}
}
}
/// <summary>
/// 由Dispose和LocalClientClose调用
/// </summary>
private void DisposeEx()
{
if (netstream != null)
{
netstream.Dispose();
netstream = null;
}
if (tcpclient != null)
{
tcpclient.Close();
tcpclient = null;
}
}
#endregion
}
/// <数据结构类>
/// 数据结构类
/// </数据结构类>
public class StateObject
{
//客户端Socket
public Socket workSocket = null;
//接收数据大小
public const int BufferSize = 64;
// 声明接收数据
public byte[] buffer = new byte[BufferSize];
// 接收数据的内容
public StringBuilder sb = new StringBuilder();
/// <summary>
/// 通信方网络地址
/// </summary>
public EndPoint SEndPoint;
}
}
+76
View File
@@ -0,0 +1,76 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SimpleCommunication
{
public class ComConfig
{
/// <summary>
/// 通讯块数量
/// </summary>
public int Index;
/// <summary>
/// 是否自动链接
/// </summary>
public bool Auto_Connect;
/// <summary>
/// 链接类型,0为服务端,1为客户端
/// </summary>
public int Connect_Typt;
/// <summary>
/// PLC IP地址
/// </summary>
public string TCP_IP;
/// <summary>
/// PLC端口号
/// </summary>
public int TCP_Port;
/// <summary>
/// 串口名
/// </summary>
public string COM_Port;
/// <summary>
/// 串口波特率
/// </summary>
public int COM_BaudRate;
/// <summary>
/// 串口校验
/// </summary>
public string COM_Parity;
/// <summary>
/// 串口数据位
/// </summary>
public int COM_DataBit;
/// <summary>
/// 串口停止位
/// </summary>
public int COM_StopBit;
/// <summary>
/// 是否启用心跳消息
/// </summary>
public bool HeartBeat;
/// <summary>
/// 心跳设置地址
/// </summary>
public string HeartText;
/// <summary>
/// 扫描间隔时间
/// </summary>
public int HeartTime;
/// <summary>
/// 触发模块数量
/// </summary>
public int JobCount;
/// <summary>
/// 结束符号
/// </summary>
public int Endsymbol;
//public List<TriggerParams> lstTgrParams;
}
}
+13
View File
@@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace SimpleCommunication
{
public delegate void DlgOneParam<T>(T param);
public delegate void DlgNoParam();
public class CommonHelper
{
}
}
+907
View File
@@ -0,0 +1,907 @@
namespace SimpleCommunication
{
partial class CommunUI
{
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
/// <param name="disposing">如果应释放托管资源,为 true;否则为 false。</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region 组件设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要修改
/// 使用代码编辑器修改此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
this.info_Lab = new System.Windows.Forms.Label();
this.txtRecv = new System.Windows.Forms.RichTextBox();
this.txtLog = new System.Windows.Forms.TextBox();
this.groupBox2 = new System.Windows.Forms.GroupBox();
this.lbl_sendNum = new System.Windows.Forms.Label();
this.label9 = new System.Windows.Forms.Label();
this.label5 = new System.Windows.Forms.Label();
this.receive_CheckBox = new System.Windows.Forms.CheckBox();
this.lbl_receiveNum = new System.Windows.Forms.Label();
this.btnClear = new System.Windows.Forms.LinkLabel();
this.com_GroupBox = new System.Windows.Forms.GroupBox();
this.label2 = new System.Windows.Forms.Label();
this.label8 = new System.Windows.Forms.Label();
this.stopBits_Box = new System.Windows.Forms.ComboBox();
this.baudRate_Box = new System.Windows.Forms.ComboBox();
this.label11 = new System.Windows.Forms.Label();
this.parity_Box = new System.Windows.Forms.ComboBox();
this.label12 = new System.Windows.Forms.Label();
this.label13 = new System.Windows.Forms.Label();
this.comPort_Box = new System.Windows.Forms.ComboBox();
this.dataBits_Box = new System.Windows.Forms.ComboBox();
this.tcp_GroupBox = new System.Windows.Forms.GroupBox();
this.tbIP = new System.Windows.Forms.ComboBox();
this.tbPort = new System.Windows.Forms.TextBox();
this.label31 = new System.Windows.Forms.Label();
this.label33 = new System.Windows.Forms.Label();
this.tcpType_Box = new System.Windows.Forms.ComboBox();
this.label29 = new System.Windows.Forms.Label();
this.tcpBtn_Panel = new System.Windows.Forms.Panel();
this.reloadtcp_Btn = new System.Windows.Forms.Button();
this.btnStart = new System.Windows.Forms.Button();
this.btnDisconnect = new System.Windows.Forms.Button();
this.btnClose = new System.Windows.Forms.Button();
this.comBtn_Panel = new System.Windows.Forms.Panel();
this.reloadCOM_Btn = new System.Windows.Forms.Button();
this.com_Btn = new System.Windows.Forms.Button();
this.panel3 = new System.Windows.Forms.Panel();
this.Server_GroupBox = new System.Windows.Forms.GroupBox();
this.lbOnline = new System.Windows.Forms.ListBox();
this.info_GroupBox = new System.Windows.Forms.GroupBox();
this.txtSend = new System.Windows.Forms.RichTextBox();
this.groupBox1 = new System.Windows.Forms.GroupBox();
this.sendTest_CheckBox = new System.Windows.Forms.CheckBox();
this.send_CheckBox = new System.Windows.Forms.CheckBox();
this.sendTest_CheckCRLF = new System.Windows.Forms.CheckBox();
this.btnSend = new System.Windows.Forms.Button();
this.panel4 = new System.Windows.Forms.Panel();
this.groupBox3 = new System.Windows.Forms.GroupBox();
this.txtIntervalTime = new System.Windows.Forms.TextBox();
this.cmbEndSymbol = new System.Windows.Forms.ComboBox();
this.label1 = new System.Windows.Forms.Label();
this.label4 = new System.Windows.Forms.Label();
this.label6 = new System.Windows.Forms.Label();
this.pgeAuto_CheckBox = new System.Windows.Forms.CheckBox();
this.txtHeartData = new System.Windows.Forms.TextBox();
this.label3 = new System.Windows.Forms.Label();
this.saveSetting_Btn = new System.Windows.Forms.Button();
this.Auto_CheckBox = new System.Windows.Forms.CheckBox();
this.tmHeart = new System.Windows.Forms.Timer(this.components);
this.checkBox1 = new System.Windows.Forms.CheckBox();
this.groupBox2.SuspendLayout();
this.com_GroupBox.SuspendLayout();
this.tcp_GroupBox.SuspendLayout();
this.tcpBtn_Panel.SuspendLayout();
this.comBtn_Panel.SuspendLayout();
this.panel3.SuspendLayout();
this.Server_GroupBox.SuspendLayout();
this.info_GroupBox.SuspendLayout();
this.groupBox1.SuspendLayout();
this.panel4.SuspendLayout();
this.groupBox3.SuspendLayout();
this.SuspendLayout();
//
// info_Lab
//
this.info_Lab.BackColor = System.Drawing.Color.Red;
this.info_Lab.Font = new System.Drawing.Font("宋体", 15F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.info_Lab.ForeColor = System.Drawing.Color.White;
this.info_Lab.Location = new System.Drawing.Point(475, 0);
this.info_Lab.Name = "info_Lab";
this.info_Lab.Size = new System.Drawing.Size(438, 33);
this.info_Lab.TabIndex = 103;
this.info_Lab.Text = "未连接";
this.info_Lab.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//
// txtRecv
//
this.txtRecv.BackColor = System.Drawing.SystemColors.Window;
this.txtRecv.Dock = System.Windows.Forms.DockStyle.Fill;
this.txtRecv.Location = new System.Drawing.Point(3, 17);
this.txtRecv.Name = "txtRecv";
this.txtRecv.ReadOnly = true;
this.txtRecv.ScrollBars = System.Windows.Forms.RichTextBoxScrollBars.Vertical;
this.txtRecv.Size = new System.Drawing.Size(467, 337);
this.txtRecv.TabIndex = 104;
this.txtRecv.Text = "";
//
// txtLog
//
this.txtLog.BackColor = System.Drawing.SystemColors.Window;
this.txtLog.Dock = System.Windows.Forms.DockStyle.Fill;
this.txtLog.Location = new System.Drawing.Point(3, 16);
this.txtLog.Multiline = true;
this.txtLog.Name = "txtLog";
this.txtLog.ReadOnly = true;
this.txtLog.ScrollBars = System.Windows.Forms.ScrollBars.Vertical;
this.txtLog.Size = new System.Drawing.Size(257, 163);
this.txtLog.TabIndex = 105;
//
// groupBox2
//
this.groupBox2.Controls.Add(this.lbl_sendNum);
this.groupBox2.Controls.Add(this.txtRecv);
this.groupBox2.Controls.Add(this.label9);
this.groupBox2.Controls.Add(this.label5);
this.groupBox2.Controls.Add(this.receive_CheckBox);
this.groupBox2.Controls.Add(this.lbl_receiveNum);
this.groupBox2.Controls.Add(this.btnClear);
this.groupBox2.Location = new System.Drawing.Point(0, 3);
this.groupBox2.Name = "groupBox2";
this.groupBox2.Size = new System.Drawing.Size(473, 357);
this.groupBox2.TabIndex = 107;
this.groupBox2.TabStop = false;
this.groupBox2.Text = "接收文本";
//
// lbl_sendNum
//
this.lbl_sendNum.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.lbl_sendNum.AutoSize = true;
this.lbl_sendNum.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.lbl_sendNum.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(48)))), ((int)(((byte)(48)))), ((int)(((byte)(48)))));
this.lbl_sendNum.Location = new System.Drawing.Point(291, 0);
this.lbl_sendNum.Name = "lbl_sendNum";
this.lbl_sendNum.Size = new System.Drawing.Size(15, 17);
this.lbl_sendNum.TabIndex = 222;
this.lbl_sendNum.Text = "0";
//
// label9
//
this.label9.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.label9.AutoSize = true;
this.label9.Font = new System.Drawing.Font("微软雅黑", 10.5F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.label9.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(48)))), ((int)(((byte)(48)))), ((int)(((byte)(48)))));
this.label9.Location = new System.Drawing.Point(319, -3);
this.label9.Name = "label9";
this.label9.Size = new System.Drawing.Size(79, 20);
this.label9.TabIndex = 219;
this.label9.Text = "接收次数:";
//
// label5
//
this.label5.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.label5.AutoSize = true;
this.label5.Font = new System.Drawing.Font("微软雅黑", 10.5F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.label5.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(48)))), ((int)(((byte)(48)))), ((int)(((byte)(48)))));
this.label5.Location = new System.Drawing.Point(213, -3);
this.label5.Name = "label5";
this.label5.Size = new System.Drawing.Size(79, 20);
this.label5.TabIndex = 221;
this.label5.Text = "发送次数:";
//
// receive_CheckBox
//
this.receive_CheckBox.AutoSize = true;
this.receive_CheckBox.BackColor = System.Drawing.SystemColors.Control;
this.receive_CheckBox.Location = new System.Drawing.Point(79, 0);
this.receive_CheckBox.Name = "receive_CheckBox";
this.receive_CheckBox.Size = new System.Drawing.Size(126, 16);
this.receive_CheckBox.TabIndex = 217;
this.receive_CheckBox.Text = "十六进制显示(Hex)";
this.receive_CheckBox.UseVisualStyleBackColor = false;
//
// lbl_receiveNum
//
this.lbl_receiveNum.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.lbl_receiveNum.AutoSize = true;
this.lbl_receiveNum.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.lbl_receiveNum.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(48)))), ((int)(((byte)(48)))), ((int)(((byte)(48)))));
this.lbl_receiveNum.Location = new System.Drawing.Point(402, 0);
this.lbl_receiveNum.Name = "lbl_receiveNum";
this.lbl_receiveNum.Size = new System.Drawing.Size(15, 17);
this.lbl_receiveNum.TabIndex = 220;
this.lbl_receiveNum.Text = "0";
//
// btnClear
//
this.btnClear.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.btnClear.AutoSize = true;
this.btnClear.Font = new System.Drawing.Font("微软雅黑", 10.5F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.btnClear.Location = new System.Drawing.Point(436, -3);
this.btnClear.Name = "btnClear";
this.btnClear.Size = new System.Drawing.Size(37, 20);
this.btnClear.TabIndex = 218;
this.btnClear.TabStop = true;
this.btnClear.Text = "清空";
this.btnClear.Click += new System.EventHandler(this.btnClear_Click);
//
// com_GroupBox
//
this.com_GroupBox.Controls.Add(this.label2);
this.com_GroupBox.Controls.Add(this.label8);
this.com_GroupBox.Controls.Add(this.stopBits_Box);
this.com_GroupBox.Controls.Add(this.baudRate_Box);
this.com_GroupBox.Controls.Add(this.label11);
this.com_GroupBox.Controls.Add(this.parity_Box);
this.com_GroupBox.Controls.Add(this.label12);
this.com_GroupBox.Controls.Add(this.label13);
this.com_GroupBox.Controls.Add(this.comPort_Box);
this.com_GroupBox.Controls.Add(this.dataBits_Box);
this.com_GroupBox.Location = new System.Drawing.Point(475, 74);
this.com_GroupBox.Name = "com_GroupBox";
this.com_GroupBox.Size = new System.Drawing.Size(202, 147);
this.com_GroupBox.TabIndex = 109;
this.com_GroupBox.TabStop = false;
this.com_GroupBox.Text = "串口设置";
//
// label2
//
this.label2.AutoSize = true;
this.label2.Font = new System.Drawing.Font("宋体", 10F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.label2.Location = new System.Drawing.Point(9, 23);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(63, 14);
this.label2.TabIndex = 3;
this.label2.Text = "端口号:";
//
// label8
//
this.label8.AutoSize = true;
this.label8.Font = new System.Drawing.Font("宋体", 10F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.label8.Location = new System.Drawing.Point(9, 68);
this.label8.Name = "label8";
this.label8.Size = new System.Drawing.Size(63, 14);
this.label8.TabIndex = 11;
this.label8.Text = "校验位:";
//
// stopBits_Box
//
this.stopBits_Box.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.stopBits_Box.FlatStyle = System.Windows.Forms.FlatStyle.System;
this.stopBits_Box.Font = new System.Drawing.Font("宋体", 10F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.stopBits_Box.FormattingEnabled = true;
this.stopBits_Box.Items.AddRange(new object[] {
"1",
"2"});
this.stopBits_Box.Location = new System.Drawing.Point(81, 117);
this.stopBits_Box.Name = "stopBits_Box";
this.stopBits_Box.Size = new System.Drawing.Size(115, 21);
this.stopBits_Box.TabIndex = 8;
//
// baudRate_Box
//
this.baudRate_Box.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.baudRate_Box.FlatStyle = System.Windows.Forms.FlatStyle.System;
this.baudRate_Box.Font = new System.Drawing.Font("宋体", 10F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.baudRate_Box.FormattingEnabled = true;
this.baudRate_Box.Items.AddRange(new object[] {
"9600",
"14400",
"19200",
"38400",
"56000",
"57600",
"115200"});
this.baudRate_Box.Location = new System.Drawing.Point(81, 44);
this.baudRate_Box.Name = "baudRate_Box";
this.baudRate_Box.RightToLeft = System.Windows.Forms.RightToLeft.No;
this.baudRate_Box.Size = new System.Drawing.Size(115, 21);
this.baudRate_Box.TabIndex = 4;
//
// label11
//
this.label11.AutoSize = true;
this.label11.Font = new System.Drawing.Font("宋体", 10F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.label11.Location = new System.Drawing.Point(9, 93);
this.label11.Name = "label11";
this.label11.Size = new System.Drawing.Size(63, 14);
this.label11.TabIndex = 7;
this.label11.Text = "数据位:";
//
// parity_Box
//
this.parity_Box.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.parity_Box.FlatStyle = System.Windows.Forms.FlatStyle.System;
this.parity_Box.Font = new System.Drawing.Font("宋体", 10F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.parity_Box.FormattingEnabled = true;
this.parity_Box.Items.AddRange(new object[] {
"None",
"Odd",
"Even",
"Mark",
"Space"});
this.parity_Box.Location = new System.Drawing.Point(81, 68);
this.parity_Box.Name = "parity_Box";
this.parity_Box.Size = new System.Drawing.Size(115, 21);
this.parity_Box.TabIndex = 10;
//
// label12
//
this.label12.AutoSize = true;
this.label12.Font = new System.Drawing.Font("宋体", 10F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.label12.Location = new System.Drawing.Point(9, 44);
this.label12.Name = "label12";
this.label12.Size = new System.Drawing.Size(63, 14);
this.label12.TabIndex = 5;
this.label12.Text = "波特率:";
//
// label13
//
this.label13.AutoSize = true;
this.label13.Font = new System.Drawing.Font("宋体", 10F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.label13.Location = new System.Drawing.Point(9, 118);
this.label13.Name = "label13";
this.label13.Size = new System.Drawing.Size(63, 14);
this.label13.TabIndex = 9;
this.label13.Text = "停止位:";
//
// comPort_Box
//
this.comPort_Box.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.comPort_Box.FlatStyle = System.Windows.Forms.FlatStyle.System;
this.comPort_Box.Font = new System.Drawing.Font("宋体", 10F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.comPort_Box.FormattingEnabled = true;
this.comPort_Box.ImeMode = System.Windows.Forms.ImeMode.NoControl;
this.comPort_Box.Location = new System.Drawing.Point(81, 21);
this.comPort_Box.Name = "comPort_Box";
this.comPort_Box.Size = new System.Drawing.Size(115, 21);
this.comPort_Box.TabIndex = 10;
//
// dataBits_Box
//
this.dataBits_Box.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.dataBits_Box.FlatStyle = System.Windows.Forms.FlatStyle.System;
this.dataBits_Box.Font = new System.Drawing.Font("宋体", 10F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.dataBits_Box.FormattingEnabled = true;
this.dataBits_Box.Items.AddRange(new object[] {
"8",
"7",
"6",
"5"});
this.dataBits_Box.Location = new System.Drawing.Point(81, 93);
this.dataBits_Box.Name = "dataBits_Box";
this.dataBits_Box.Size = new System.Drawing.Size(115, 21);
this.dataBits_Box.TabIndex = 6;
//
// tcp_GroupBox
//
this.tcp_GroupBox.BackColor = System.Drawing.Color.Transparent;
this.tcp_GroupBox.Controls.Add(this.tbIP);
this.tcp_GroupBox.Controls.Add(this.tbPort);
this.tcp_GroupBox.Controls.Add(this.label31);
this.tcp_GroupBox.Controls.Add(this.label33);
this.tcp_GroupBox.Location = new System.Drawing.Point(696, 74);
this.tcp_GroupBox.Name = "tcp_GroupBox";
this.tcp_GroupBox.Size = new System.Drawing.Size(213, 89);
this.tcp_GroupBox.TabIndex = 108;
this.tcp_GroupBox.TabStop = false;
this.tcp_GroupBox.Text = "TCP设置";
//
// tbIP
//
this.tbIP.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.tbIP.FlatStyle = System.Windows.Forms.FlatStyle.System;
this.tbIP.Font = new System.Drawing.Font("宋体", 10F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.tbIP.FormattingEnabled = true;
this.tbIP.ImeMode = System.Windows.Forms.ImeMode.NoControl;
this.tbIP.Location = new System.Drawing.Point(61, 24);
this.tbIP.Name = "tbIP";
this.tbIP.Size = new System.Drawing.Size(146, 21);
this.tbIP.TabIndex = 39;
//
// tbPort
//
this.tbPort.Font = new System.Drawing.Font("宋体", 10F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.tbPort.Location = new System.Drawing.Point(61, 51);
this.tbPort.Name = "tbPort";
this.tbPort.Size = new System.Drawing.Size(146, 23);
this.tbPort.TabIndex = 38;
this.tbPort.Text = "7100";
//
// label31
//
this.label31.AutoSize = true;
this.label31.Font = new System.Drawing.Font("宋体", 10F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.label31.Location = new System.Drawing.Point(8, 58);
this.label31.Name = "label31";
this.label31.Size = new System.Drawing.Size(63, 14);
this.label31.TabIndex = 11;
this.label31.Text = "端口号:";
//
// label33
//
this.label33.AutoSize = true;
this.label33.Font = new System.Drawing.Font("宋体", 10F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.label33.Location = new System.Drawing.Point(8, 27);
this.label33.Name = "label33";
this.label33.Size = new System.Drawing.Size(63, 14);
this.label33.TabIndex = 5;
this.label33.Text = "IP地址:";
//
// tcpType_Box
//
this.tcpType_Box.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.tcpType_Box.FlatStyle = System.Windows.Forms.FlatStyle.System;
this.tcpType_Box.Font = new System.Drawing.Font("宋体", 10F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.tcpType_Box.FormattingEnabled = true;
this.tcpType_Box.ImeMode = System.Windows.Forms.ImeMode.NoControl;
this.tcpType_Box.Items.AddRange(new object[] {
"串口(COM)",
"服务器(Server)",
"客户端(Client)",
"串口(COM)/客户端(Client)"});
this.tcpType_Box.Location = new System.Drawing.Point(556, 41);
this.tcpType_Box.Name = "tcpType_Box";
this.tcpType_Box.Size = new System.Drawing.Size(153, 21);
this.tcpType_Box.TabIndex = 111;
this.tcpType_Box.SelectedIndexChanged += new System.EventHandler(this.tcpType_Box_SelectedIndexChanged);
//
// label29
//
this.label29.AutoSize = true;
this.label29.Font = new System.Drawing.Font("宋体", 10F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.label29.Location = new System.Drawing.Point(482, 44);
this.label29.Name = "label29";
this.label29.Size = new System.Drawing.Size(77, 14);
this.label29.TabIndex = 110;
this.label29.Text = "链接类型:";
//
// tcpBtn_Panel
//
this.tcpBtn_Panel.Controls.Add(this.reloadtcp_Btn);
this.tcpBtn_Panel.Controls.Add(this.btnStart);
this.tcpBtn_Panel.Controls.Add(this.btnDisconnect);
this.tcpBtn_Panel.Controls.Add(this.btnClose);
this.tcpBtn_Panel.Location = new System.Drawing.Point(696, 191);
this.tcpBtn_Panel.Name = "tcpBtn_Panel";
this.tcpBtn_Panel.Size = new System.Drawing.Size(217, 62);
this.tcpBtn_Panel.TabIndex = 110;
//
// reloadtcp_Btn
//
this.reloadtcp_Btn.Location = new System.Drawing.Point(116, 9);
this.reloadtcp_Btn.Name = "reloadtcp_Btn";
this.reloadtcp_Btn.Size = new System.Drawing.Size(75, 23);
this.reloadtcp_Btn.TabIndex = 117;
this.reloadtcp_Btn.Text = "刷新网口";
this.reloadtcp_Btn.UseVisualStyleBackColor = true;
this.reloadtcp_Btn.Click += new System.EventHandler(this.reloadtcp_Btn_Click);
//
// btnStart
//
this.btnStart.Location = new System.Drawing.Point(9, 9);
this.btnStart.Name = "btnStart";
this.btnStart.Size = new System.Drawing.Size(75, 23);
this.btnStart.TabIndex = 111;
this.btnStart.Text = "启动服务器";
this.btnStart.UseVisualStyleBackColor = true;
this.btnStart.Click += new System.EventHandler(this.btnStart_Click);
//
// btnDisconnect
//
this.btnDisconnect.Location = new System.Drawing.Point(115, 38);
this.btnDisconnect.Name = "btnDisconnect";
this.btnDisconnect.Size = new System.Drawing.Size(76, 23);
this.btnDisconnect.TabIndex = 113;
this.btnDisconnect.Text = "关闭连接";
this.btnDisconnect.UseVisualStyleBackColor = true;
this.btnDisconnect.Click += new System.EventHandler(this.btnDisconnect_Click);
//
// btnClose
//
this.btnClose.Location = new System.Drawing.Point(9, 35);
this.btnClose.Name = "btnClose";
this.btnClose.Size = new System.Drawing.Size(75, 23);
this.btnClose.TabIndex = 112;
this.btnClose.Text = "关闭服务器";
this.btnClose.UseVisualStyleBackColor = true;
this.btnClose.Click += new System.EventHandler(this.btnClose_Click);
//
// comBtn_Panel
//
this.comBtn_Panel.Controls.Add(this.reloadCOM_Btn);
this.comBtn_Panel.Controls.Add(this.com_Btn);
this.comBtn_Panel.Location = new System.Drawing.Point(477, 224);
this.comBtn_Panel.Name = "comBtn_Panel";
this.comBtn_Panel.Size = new System.Drawing.Size(200, 29);
this.comBtn_Panel.TabIndex = 114;
//
// reloadCOM_Btn
//
this.reloadCOM_Btn.Location = new System.Drawing.Point(106, 3);
this.reloadCOM_Btn.Name = "reloadCOM_Btn";
this.reloadCOM_Btn.Size = new System.Drawing.Size(75, 23);
this.reloadCOM_Btn.TabIndex = 116;
this.reloadCOM_Btn.Text = "刷新串口";
this.reloadCOM_Btn.UseVisualStyleBackColor = true;
this.reloadCOM_Btn.Click += new System.EventHandler(this.reloadCOM_Btn_Click);
//
// com_Btn
//
this.com_Btn.ForeColor = System.Drawing.Color.Black;
this.com_Btn.Location = new System.Drawing.Point(16, 3);
this.com_Btn.Name = "com_Btn";
this.com_Btn.Size = new System.Drawing.Size(75, 23);
this.com_Btn.TabIndex = 115;
this.com_Btn.Text = "打开串口";
this.com_Btn.UseVisualStyleBackColor = true;
this.com_Btn.Click += new System.EventHandler(this.com_Btn_Click);
//
// panel3
//
this.panel3.Controls.Add(this.Server_GroupBox);
this.panel3.Controls.Add(this.info_GroupBox);
this.panel3.Location = new System.Drawing.Point(477, 327);
this.panel3.Name = "panel3";
this.panel3.Size = new System.Drawing.Size(436, 185);
this.panel3.TabIndex = 115;
//
// Server_GroupBox
//
this.Server_GroupBox.Controls.Add(this.lbOnline);
this.Server_GroupBox.Location = new System.Drawing.Point(269, 1);
this.Server_GroupBox.Name = "Server_GroupBox";
this.Server_GroupBox.Size = new System.Drawing.Size(167, 181);
this.Server_GroupBox.TabIndex = 106;
this.Server_GroupBox.TabStop = false;
this.Server_GroupBox.Text = "客户端在线列表";
//
// lbOnline
//
this.lbOnline.BackColor = System.Drawing.SystemColors.Control;
this.lbOnline.Dock = System.Windows.Forms.DockStyle.Fill;
this.lbOnline.FormattingEnabled = true;
this.lbOnline.ItemHeight = 12;
this.lbOnline.Location = new System.Drawing.Point(3, 17);
this.lbOnline.Name = "lbOnline";
this.lbOnline.SelectionMode = System.Windows.Forms.SelectionMode.MultiSimple;
this.lbOnline.Size = new System.Drawing.Size(161, 161);
this.lbOnline.TabIndex = 106;
//
// info_GroupBox
//
this.info_GroupBox.Controls.Add(this.txtLog);
this.info_GroupBox.Location = new System.Drawing.Point(3, 2);
this.info_GroupBox.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.info_GroupBox.Name = "info_GroupBox";
this.info_GroupBox.Padding = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.info_GroupBox.Size = new System.Drawing.Size(263, 181);
this.info_GroupBox.TabIndex = 103;
this.info_GroupBox.TabStop = false;
this.info_GroupBox.Text = "通讯日志信息";
//
// txtSend
//
this.txtSend.Dock = System.Windows.Forms.DockStyle.Fill;
this.txtSend.Location = new System.Drawing.Point(3, 17);
this.txtSend.Name = "txtSend";
this.txtSend.ScrollBars = System.Windows.Forms.RichTextBoxScrollBars.Vertical;
this.txtSend.Size = new System.Drawing.Size(461, 100);
this.txtSend.TabIndex = 116;
this.txtSend.Text = "";
//
// groupBox1
//
this.groupBox1.Controls.Add(this.sendTest_CheckBox);
this.groupBox1.Controls.Add(this.send_CheckBox);
this.groupBox1.Controls.Add(this.txtSend);
this.groupBox1.Controls.Add(this.sendTest_CheckCRLF);
this.groupBox1.Location = new System.Drawing.Point(3, 366);
this.groupBox1.Name = "groupBox1";
this.groupBox1.Size = new System.Drawing.Size(467, 120);
this.groupBox1.TabIndex = 117;
this.groupBox1.TabStop = false;
this.groupBox1.Text = "发送文本";
//
// sendTest_CheckBox
//
this.sendTest_CheckBox.AutoSize = true;
this.sendTest_CheckBox.BackColor = System.Drawing.SystemColors.Control;
this.sendTest_CheckBox.Location = new System.Drawing.Point(69, 0);
this.sendTest_CheckBox.Name = "sendTest_CheckBox";
this.sendTest_CheckBox.Size = new System.Drawing.Size(48, 16);
this.sendTest_CheckBox.TabIndex = 118;
this.sendTest_CheckBox.Text = "测试";
this.sendTest_CheckBox.UseVisualStyleBackColor = false;
//
// send_CheckBox
//
this.send_CheckBox.AutoSize = true;
this.send_CheckBox.BackColor = System.Drawing.SystemColors.Control;
this.send_CheckBox.Location = new System.Drawing.Point(136, 0);
this.send_CheckBox.Name = "send_CheckBox";
this.send_CheckBox.Size = new System.Drawing.Size(126, 16);
this.send_CheckBox.TabIndex = 117;
this.send_CheckBox.Text = "十六进制发送(Hex)";
this.send_CheckBox.UseVisualStyleBackColor = false;
//
// sendTest_CheckCRLF
//
this.sendTest_CheckCRLF.AutoSize = true;
this.sendTest_CheckCRLF.BackColor = System.Drawing.SystemColors.Control;
this.sendTest_CheckCRLF.Location = new System.Drawing.Point(396, -1);
this.sendTest_CheckCRLF.Name = "sendTest_CheckCRLF";
this.sendTest_CheckCRLF.Size = new System.Drawing.Size(72, 16);
this.sendTest_CheckCRLF.TabIndex = 119;
this.sendTest_CheckCRLF.Text = "增加CRLF";
this.sendTest_CheckCRLF.UseVisualStyleBackColor = false;
//
// btnSend
//
this.btnSend.Location = new System.Drawing.Point(380, 489);
this.btnSend.Name = "btnSend";
this.btnSend.Size = new System.Drawing.Size(75, 23);
this.btnSend.TabIndex = 118;
this.btnSend.Text = "发送";
this.btnSend.UseVisualStyleBackColor = true;
this.btnSend.Click += new System.EventHandler(this.btnSend_Click);
//
// panel4
//
this.panel4.Controls.Add(this.groupBox3);
this.panel4.Location = new System.Drawing.Point(480, 258);
this.panel4.Name = "panel4";
this.panel4.Size = new System.Drawing.Size(433, 65);
this.panel4.TabIndex = 119;
//
// groupBox3
//
this.groupBox3.Controls.Add(this.txtIntervalTime);
this.groupBox3.Controls.Add(this.cmbEndSymbol);
this.groupBox3.Controls.Add(this.label1);
this.groupBox3.Controls.Add(this.label4);
this.groupBox3.Controls.Add(this.label6);
this.groupBox3.Controls.Add(this.pgeAuto_CheckBox);
this.groupBox3.Controls.Add(this.txtHeartData);
this.groupBox3.Controls.Add(this.label3);
this.groupBox3.Dock = System.Windows.Forms.DockStyle.Fill;
this.groupBox3.Location = new System.Drawing.Point(0, 0);
this.groupBox3.Name = "groupBox3";
this.groupBox3.Size = new System.Drawing.Size(433, 65);
this.groupBox3.TabIndex = 108;
this.groupBox3.TabStop = false;
//
// txtIntervalTime
//
this.txtIntervalTime.Font = new System.Drawing.Font("宋体", 10F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.txtIntervalTime.Location = new System.Drawing.Point(144, 32);
this.txtIntervalTime.Name = "txtIntervalTime";
this.txtIntervalTime.Size = new System.Drawing.Size(47, 23);
this.txtIntervalTime.TabIndex = 122;
this.txtIntervalTime.Text = "1000";
//
// cmbEndSymbol
//
this.cmbEndSymbol.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.cmbEndSymbol.FlatStyle = System.Windows.Forms.FlatStyle.System;
this.cmbEndSymbol.Font = new System.Drawing.Font("宋体", 10F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.cmbEndSymbol.FormattingEnabled = true;
this.cmbEndSymbol.ImeMode = System.Windows.Forms.ImeMode.NoControl;
this.cmbEndSymbol.Items.AddRange(new object[] {
"无",
"CRLF(\\r\\n)",
"LF(\\n)",
"CR(\\r)"});
this.cmbEndSymbol.Location = new System.Drawing.Point(311, 31);
this.cmbEndSymbol.Name = "cmbEndSymbol";
this.cmbEndSymbol.Size = new System.Drawing.Size(112, 21);
this.cmbEndSymbol.TabIndex = 12;
this.cmbEndSymbol.SelectedIndexChanged += new System.EventHandler(this.cmbEndSymbol_SelectedIndexChanged);
//
// label1
//
this.label1.AutoSize = true;
this.label1.Font = new System.Drawing.Font("宋体", 10F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.label1.Location = new System.Drawing.Point(258, 34);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(63, 14);
this.label1.TabIndex = 12;
this.label1.Text = "结束符:";
//
// label4
//
this.label4.AutoSize = true;
this.label4.Font = new System.Drawing.Font("宋体", 10F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.label4.Location = new System.Drawing.Point(197, 38);
this.label4.Name = "label4";
this.label4.Size = new System.Drawing.Size(21, 14);
this.label4.TabIndex = 123;
this.label4.Text = "ms";
//
// label6
//
this.label6.AutoSize = true;
this.label6.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.label6.Location = new System.Drawing.Point(142, 18);
this.label6.Name = "label6";
this.label6.Size = new System.Drawing.Size(65, 12);
this.label6.TabIndex = 121;
this.label6.Text = "间隔时间:";
//
// pgeAuto_CheckBox
//
this.pgeAuto_CheckBox.AutoSize = true;
this.pgeAuto_CheckBox.BackColor = System.Drawing.SystemColors.Control;
this.pgeAuto_CheckBox.Location = new System.Drawing.Point(8, 0);
this.pgeAuto_CheckBox.Name = "pgeAuto_CheckBox";
this.pgeAuto_CheckBox.Size = new System.Drawing.Size(96, 16);
this.pgeAuto_CheckBox.TabIndex = 120;
this.pgeAuto_CheckBox.Text = "启用连续发送";
this.pgeAuto_CheckBox.UseVisualStyleBackColor = false;
//
// txtHeartData
//
this.txtHeartData.Font = new System.Drawing.Font("宋体", 10F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.txtHeartData.Location = new System.Drawing.Point(18, 34);
this.txtHeartData.Name = "txtHeartData";
this.txtHeartData.Size = new System.Drawing.Size(99, 23);
this.txtHeartData.TabIndex = 41;
this.txtHeartData.Text = "1";
//
// label3
//
this.label3.AutoSize = true;
this.label3.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.label3.Location = new System.Drawing.Point(17, 17);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(65, 12);
this.label3.TabIndex = 40;
this.label3.Text = "发送内容:";
//
// saveSetting_Btn
//
this.saveSetting_Btn.Enabled = false;
this.saveSetting_Btn.Location = new System.Drawing.Point(817, 41);
this.saveSetting_Btn.Name = "saveSetting_Btn";
this.saveSetting_Btn.Size = new System.Drawing.Size(70, 22);
this.saveSetting_Btn.TabIndex = 106;
this.saveSetting_Btn.Text = "参数保存";
this.saveSetting_Btn.UseVisualStyleBackColor = true;
this.saveSetting_Btn.Click += new System.EventHandler(this.saveSetting_Btn_Click);
//
// Auto_CheckBox
//
this.Auto_CheckBox.AutoSize = true;
this.Auto_CheckBox.Enabled = false;
this.Auto_CheckBox.Location = new System.Drawing.Point(732, 44);
this.Auto_CheckBox.Name = "Auto_CheckBox";
this.Auto_CheckBox.Size = new System.Drawing.Size(72, 16);
this.Auto_CheckBox.TabIndex = 107;
this.Auto_CheckBox.Text = "自动联机";
this.Auto_CheckBox.UseVisualStyleBackColor = true;
//
// tmHeart
//
this.tmHeart.Enabled = true;
this.tmHeart.Tick += new System.EventHandler(this.tmHeart_Tick);
//
// checkBox1
//
this.checkBox1.AutoSize = true;
this.checkBox1.Enabled = false;
this.checkBox1.Location = new System.Drawing.Point(696, 169);
this.checkBox1.Name = "checkBox1";
this.checkBox1.Size = new System.Drawing.Size(108, 16);
this.checkBox1.TabIndex = 109;
this.checkBox1.Text = "客户端断线重连";
this.checkBox1.UseVisualStyleBackColor = true;
//
// CommunUI
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.Controls.Add(this.checkBox1);
this.Controls.Add(this.saveSetting_Btn);
this.Controls.Add(this.Auto_CheckBox);
this.Controls.Add(this.tcpType_Box);
this.Controls.Add(this.panel4);
this.Controls.Add(this.label29);
this.Controls.Add(this.btnSend);
this.Controls.Add(this.groupBox1);
this.Controls.Add(this.panel3);
this.Controls.Add(this.comBtn_Panel);
this.Controls.Add(this.tcpBtn_Panel);
this.Controls.Add(this.com_GroupBox);
this.Controls.Add(this.tcp_GroupBox);
this.Controls.Add(this.groupBox2);
this.Controls.Add(this.info_Lab);
this.Name = "CommunUI";
this.Size = new System.Drawing.Size(916, 518);
this.Load += new System.EventHandler(this.CommunUI_Load);
this.groupBox2.ResumeLayout(false);
this.groupBox2.PerformLayout();
this.com_GroupBox.ResumeLayout(false);
this.com_GroupBox.PerformLayout();
this.tcp_GroupBox.ResumeLayout(false);
this.tcp_GroupBox.PerformLayout();
this.tcpBtn_Panel.ResumeLayout(false);
this.comBtn_Panel.ResumeLayout(false);
this.panel3.ResumeLayout(false);
this.Server_GroupBox.ResumeLayout(false);
this.info_GroupBox.ResumeLayout(false);
this.info_GroupBox.PerformLayout();
this.groupBox1.ResumeLayout(false);
this.groupBox1.PerformLayout();
this.panel4.ResumeLayout(false);
this.groupBox3.ResumeLayout(false);
this.groupBox3.PerformLayout();
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
public System.Windows.Forms.Label info_Lab;
private System.Windows.Forms.RichTextBox txtRecv;
private System.Windows.Forms.TextBox txtLog;
private System.Windows.Forms.GroupBox groupBox2;
private System.Windows.Forms.GroupBox com_GroupBox;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Label label8;
internal System.Windows.Forms.ComboBox stopBits_Box;
internal System.Windows.Forms.ComboBox baudRate_Box;
private System.Windows.Forms.Label label11;
internal System.Windows.Forms.ComboBox parity_Box;
private System.Windows.Forms.Label label12;
private System.Windows.Forms.Label label13;
internal System.Windows.Forms.ComboBox comPort_Box;
internal System.Windows.Forms.ComboBox dataBits_Box;
private System.Windows.Forms.GroupBox tcp_GroupBox;
internal System.Windows.Forms.ComboBox tbIP;
internal System.Windows.Forms.TextBox tbPort;
private System.Windows.Forms.Label label31;
private System.Windows.Forms.Label label33;
internal System.Windows.Forms.Label lbl_sendNum;
private System.Windows.Forms.Label label9;
private System.Windows.Forms.Label label5;
private System.Windows.Forms.CheckBox receive_CheckBox;
internal System.Windows.Forms.Label lbl_receiveNum;
private System.Windows.Forms.LinkLabel btnClear;
internal System.Windows.Forms.ComboBox tcpType_Box;
private System.Windows.Forms.Label label29;
private System.Windows.Forms.Panel tcpBtn_Panel;
private System.Windows.Forms.Panel comBtn_Panel;
public System.Windows.Forms.Panel panel3;
public System.Windows.Forms.GroupBox Server_GroupBox;
private System.Windows.Forms.ListBox lbOnline;
public System.Windows.Forms.GroupBox info_GroupBox;
private System.Windows.Forms.RichTextBox txtSend;
private System.Windows.Forms.GroupBox groupBox1;
internal System.Windows.Forms.CheckBox sendTest_CheckCRLF;
internal System.Windows.Forms.CheckBox sendTest_CheckBox;
internal System.Windows.Forms.CheckBox send_CheckBox;
private System.Windows.Forms.Button btnSend;
private System.Windows.Forms.Panel panel4;
internal System.Windows.Forms.ComboBox cmbEndSymbol;
private System.Windows.Forms.Label label1;
internal System.Windows.Forms.Button saveSetting_Btn;
internal System.Windows.Forms.CheckBox Auto_CheckBox;
private System.Windows.Forms.GroupBox groupBox3;
private System.Windows.Forms.Label label4;
internal System.Windows.Forms.TextBox txtIntervalTime;
private System.Windows.Forms.Label label6;
internal System.Windows.Forms.CheckBox pgeAuto_CheckBox;
internal System.Windows.Forms.TextBox txtHeartData;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.Timer tmHeart;
public System.Windows.Forms.Button btnStart;
public System.Windows.Forms.Button reloadCOM_Btn;
public System.Windows.Forms.Button com_Btn;
internal System.Windows.Forms.CheckBox checkBox1;
internal System.Windows.Forms.Button btnClose;
internal System.Windows.Forms.Button btnDisconnect;
internal System.Windows.Forms.Button reloadtcp_Btn;
}
}
File diff suppressed because it is too large Load Diff
+123
View File
@@ -0,0 +1,123 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<metadata name="tmHeart.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
</root>
+93
View File
@@ -0,0 +1,93 @@
namespace SimpleCommunication
{
partial class FrmCommunication
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (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.tabCt_ComUI = new System.Windows.Forms.TabControl();
this.tabPage1 = new System.Windows.Forms.TabPage();
this.tabPage2 = new System.Windows.Forms.TabPage();
this.tabCt_ComUI.SuspendLayout();
this.SuspendLayout();
//
// tabCt_ComUI
//
this.tabCt_ComUI.Controls.Add(this.tabPage1);
this.tabCt_ComUI.Controls.Add(this.tabPage2);
this.tabCt_ComUI.Dock = System.Windows.Forms.DockStyle.Fill;
this.tabCt_ComUI.Location = new System.Drawing.Point(0, 0);
this.tabCt_ComUI.Name = "tabCt_ComUI";
this.tabCt_ComUI.SelectedIndex = 0;
this.tabCt_ComUI.Size = new System.Drawing.Size(921, 548);
this.tabCt_ComUI.TabIndex = 0;
//
// tabPage1
//
this.tabPage1.Location = new System.Drawing.Point(4, 22);
this.tabPage1.Name = "tabPage1";
this.tabPage1.Padding = new System.Windows.Forms.Padding(3, 3, 3, 3);
this.tabPage1.Size = new System.Drawing.Size(913, 522);
this.tabPage1.TabIndex = 0;
this.tabPage1.Text = "tabPage1";
this.tabPage1.UseVisualStyleBackColor = true;
//
// tabPage2
//
this.tabPage2.Location = new System.Drawing.Point(4, 22);
this.tabPage2.Name = "tabPage2";
this.tabPage2.Padding = new System.Windows.Forms.Padding(3, 3, 3, 3);
this.tabPage2.Size = new System.Drawing.Size(913, 522);
this.tabPage2.TabIndex = 1;
this.tabPage2.Text = "tabPage2";
this.tabPage2.UseVisualStyleBackColor = true;
//
// FrmCommunication
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(921, 548);
this.Controls.Add(this.tabCt_ComUI);
this.DoubleBuffered = true;
this.MaximizeBox = false;
this.MinimizeBox = false;
this.Name = "FrmCommunication";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "TCP/IP_Com通讯";
this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.FrmCommunication_FormClosing);
this.Load += new System.EventHandler(this.Form1_Load);
this.tabCt_ComUI.ResumeLayout(false);
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.TabControl tabCt_ComUI;
private System.Windows.Forms.TabPage tabPage1;
private System.Windows.Forms.TabPage tabPage2;
}
}
+238
View File
@@ -0,0 +1,238 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace SimpleCommunication
{
public partial class FrmCommunication : Form
{
public List<TabPage> lstComPage = new List<TabPage>();
private int ComCount;
/// <summary>
/// 定义MelsecPLCUI自定义控件List集合
/// </summary>
public List<CommunUI> lstUI = new List<CommunUI>();
/// <summary>
/// 配置文件实体类
/// </summary>
private List<ComConfig> lstComConfig = new List<ComConfig>();
/// <summary>
/// PLC读取寄存器配置文件
/// </summary>
private string ConfigPath = Path.Combine(System.Windows.Forms.Application.StartupPath, "Config\\ComConfig.ini");
public FrmCommunication()
{
InitializeComponent();
//ConfigPath = path;
//ComCount = int.Parse(new IniHelper(ConfigPath).IniReadValue("SystemConfig", "ComCount"));
ComCount = 1;
ReadPlcConfig(ComCount);
LoadUI(ComCount);
}
public void ReadPlcConfig(int Count)
{
try
{
for (int j = 0; j < Count; j++)
{
ComConfig comConfig = new ComConfig();
comConfig.Index = j + 1;
comConfig.Auto_Connect = bool.Parse(new IniHelper(ConfigPath).IniReadValue(comConfig.Index + "#COMMUNICATION_SETTING", "Auto_Connect"));
comConfig.Connect_Typt = int.Parse(new IniHelper(ConfigPath).IniReadValue(comConfig.Index + "#COMMUNICATION_SETTING", "Connect_Typt"));
comConfig.TCP_IP = new IniHelper(ConfigPath).IniReadValue(comConfig.Index + "#COMMUNICATION_SETTING", "TCP_IP");
comConfig.TCP_Port = int.Parse(new IniHelper(ConfigPath).IniReadValue(comConfig.Index + "#COMMUNICATION_SETTING", "TCP_Port"));
comConfig.HeartBeat = bool.Parse(new IniHelper(ConfigPath).IniReadValue(comConfig.Index + "#COMMUNICATION_SETTING", "HeartBeat"));
comConfig.HeartText = new IniHelper(ConfigPath).IniReadValue(comConfig.Index + "#COMMUNICATION_SETTING", "HeartText");
comConfig.HeartTime = int.Parse(new IniHelper(ConfigPath).IniReadValue(comConfig.Index + "#COMMUNICATION_SETTING", "HeartTime"));
comConfig.COM_Port = new IniHelper(ConfigPath).IniReadValue(comConfig.Index + "#COMMUNICATION_SETTING", "COM_Port");
comConfig.COM_BaudRate = int.Parse(new IniHelper(ConfigPath).IniReadValue(comConfig.Index + "#COMMUNICATION_SETTING", "COM_BaudRate"));
comConfig.COM_Parity = new IniHelper(ConfigPath).IniReadValue(comConfig.Index + "#COMMUNICATION_SETTING", "COM_Parity");
comConfig.COM_DataBit = int.Parse(new IniHelper(ConfigPath).IniReadValue(comConfig.Index + "#COMMUNICATION_SETTING", "COM_DataBit"));
comConfig.COM_StopBit = int.Parse(new IniHelper(ConfigPath).IniReadValue(comConfig.Index + "#COMMUNICATION_SETTING", "COM_StopBit"));
comConfig.Endsymbol = int.Parse(new IniHelper(ConfigPath).IniReadValue(comConfig.Index + "#COMMUNICATION_SETTING", "Endsymbol"));
lstComConfig.Add(comConfig);
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
/// <summary>
/// 加载MelsecPLCUI窗口
/// </summary>
/// <param name="Count"></param>
public void LoadUI(int Count)
{
tabCt_ComUI.TabPages.Clear();
for (int i = 0; i < Count; i++)
{
tabCt_ComUI.TabPages.Add(i + 1 + "#通讯模块");
Panel panelUI = new Panel();
panelUI.Dock = DockStyle.Fill;
tabCt_ComUI.TabPages[i].Controls.Add(panelUI);
CommunUI plcUI = new CommunUI(lstComConfig[i]);
plcUI.Dock = DockStyle.Fill;
plcUI.SaveParamsEvent += plcUI_SaveParamsEvent;
lstUI.Add(plcUI);
panelUI.Controls.Add(plcUI);
LoadIni(i);
}
}
/// <summary>
/// 循环保存参数
/// </summary>
/// <param name="comIndex"></param>
/// <param name="trgIndex"></param>
private void plcUI_SaveParamsEvent(int comIndex, int trgIndex)
{
if (trgIndex == 0)
{
for (int i = 0; i < comIndex; i++)
{
SaveComParam(comIndex);
}
}
}
/// <summary>
///
/// </summary>
/// <param name="plcIndex"></param> TCP_Typt
public void SaveComParam(int comIndex)
{
new IniHelper(ConfigPath).IniWriteValue(comIndex + "#COMMUNICATION_SETTING", "Tgr_Count", lstUI[comIndex - 1].ComConfig.Index.ToString());
new IniHelper(ConfigPath).IniWriteValue(comIndex + "#COMMUNICATION_SETTING", "Auto_Connect", lstUI[comIndex - 1].ComConfig.Auto_Connect.ToString());
new IniHelper(ConfigPath).IniWriteValue(comIndex + "#COMMUNICATION_SETTING", "Connect_Typt", lstUI[comIndex - 1].ComConfig.Connect_Typt.ToString());
new IniHelper(ConfigPath).IniWriteValue(comIndex + "#COMMUNICATION_SETTING", "TCP_IP", lstUI[comIndex - 1].ComConfig.TCP_IP.ToString());
new IniHelper(ConfigPath).IniWriteValue(comIndex + "#COMMUNICATION_SETTING", "TCP_Port", lstUI[comIndex - 1].ComConfig.TCP_Port.ToString());
new IniHelper(ConfigPath).IniWriteValue(comIndex + "#COMMUNICATION_SETTING", "HeartBeat", lstUI[comIndex - 1].ComConfig.HeartBeat.ToString());
new IniHelper(ConfigPath).IniWriteValue(comIndex + "#COMMUNICATION_SETTING", "HeartText", lstUI[comIndex - 1].ComConfig.HeartText.ToString());
new IniHelper(ConfigPath).IniWriteValue(comIndex + "#COMMUNICATION_SETTING", "HeartTime", lstUI[comIndex - 1].ComConfig.HeartTime.ToString());
new IniHelper(ConfigPath).IniWriteValue(comIndex + "#COMMUNICATION_SETTING", "COM_Port", lstUI[comIndex - 1].ComConfig.COM_Port.ToString());
new IniHelper(ConfigPath).IniWriteValue(comIndex + "#COMMUNICATION_SETTING", "COM_StopBit", lstUI[comIndex - 1].ComConfig.COM_StopBit.ToString());
new IniHelper(ConfigPath).IniWriteValue(comIndex + "#COMMUNICATION_SETTING", "COM_BaudRate", lstUI[comIndex - 1].ComConfig.COM_BaudRate.ToString());
new IniHelper(ConfigPath).IniWriteValue(comIndex + "#COMMUNICATION_SETTING", "COM_Parity", lstUI[comIndex - 1].ComConfig.COM_Parity.ToString());
new IniHelper(ConfigPath).IniWriteValue(comIndex + "#COMMUNICATION_SETTING", "COM_DataBit", lstUI[comIndex - 1].ComConfig.COM_DataBit.ToString());
new IniHelper(ConfigPath).IniWriteValue(comIndex + "#COMMUNICATION_SETTING", "Endsymbol", lstUI[comIndex - 1].ComConfig.Endsymbol.ToString());
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void LoadIni(int comIndex)
{
lstUI[comIndex].txtHeartData.Text = new IniHelper(ConfigPath).IniReadValue((comIndex + 1) + "#COMMUNICATION_SETTING", "HeartText");
lstUI[comIndex].txtIntervalTime.Text = new IniHelper(ConfigPath).IniReadValue((comIndex + 1) + "#COMMUNICATION_SETTING", "HeartTime");
lstUI[comIndex].pgeAuto_CheckBox.Checked = ((new IniHelper(ConfigPath).IniReadValue((comIndex + 1) + "#COMMUNICATION_SETTING", "HeartBeat") == "True") ? true : false);
lstUI[comIndex].cmbEndSymbol.SelectedIndex = Convert.ToInt32(new IniHelper(ConfigPath).IniReadValue((comIndex + 1) + "#COMMUNICATION_SETTING", "Endsymbol"));
if (new IniHelper(ConfigPath).IniReadValue((comIndex + 1) + "#COMMUNICATION_SETTING", "Auto_Connect") == "True")
{
lstUI[comIndex].Auto_CheckBox.Checked = true;
//串口
if (Convert.ToInt32(new IniHelper(ConfigPath).IniReadValue((comIndex + 1) + "#COMMUNICATION_SETTING", "Connect_Typt")) == 0)
{
lstUI[comIndex].Server_GroupBox.Visible = false;
lstUI[comIndex].info_GroupBox.Dock = DockStyle.Fill;
lstUI[comIndex].tcpType_Box.SelectedIndex = Convert.ToInt32(new IniHelper(ConfigPath).IniReadValue((comIndex + 1) + "#COMMUNICATION_SETTING", "Connect_Typt"));
lstUI[comIndex].comPort_Box.Items.Clear();
lstUI[comIndex].comPort_Box.Items.Add(new IniHelper(ConfigPath).IniReadValue((comIndex + 1) + "#COMMUNICATION_SETTING", "COM_Port"));
lstUI[comIndex].comPort_Box.Text = lstUI[comIndex].comPort_Box.Items[0].ToString();
lstUI[comIndex].baudRate_Box.Text = new IniHelper(ConfigPath).IniReadValue((comIndex + 1) + "#COMMUNICATION_SETTING", "COM_BaudRate");
lstUI[comIndex].parity_Box.Text = new IniHelper(ConfigPath).IniReadValue((comIndex + 1) + "#COMMUNICATION_SETTING", "COM_Parity");
lstUI[comIndex].dataBits_Box.Text = new IniHelper(ConfigPath).IniReadValue((comIndex + 1) + "#COMMUNICATION_SETTING", "COM_DataBit");
lstUI[comIndex].stopBits_Box.Text = new IniHelper(ConfigPath).IniReadValue((comIndex + 1) + "#COMMUNICATION_SETTING", "COM_StopBit");
lstUI[comIndex].COMOpen();
}
//服务端
else if (Convert.ToInt32(new IniHelper(ConfigPath).IniReadValue((comIndex + 1) + "#COMMUNICATION_SETTING", "Connect_Typt")) == 1)
{
lstUI[comIndex].tcpType_Box.SelectedIndex = Convert.ToInt32(new IniHelper(ConfigPath).IniReadValue((comIndex + 1) + "#COMMUNICATION_SETTING", "Connect_Typt"));
lstUI[comIndex].tbIP.Items.Clear();
lstUI[comIndex].tbIP.Items.Add(new IniHelper(ConfigPath).IniReadValue((comIndex + 1) + "#COMMUNICATION_SETTING", "TCP_IP"));
lstUI[comIndex].tbIP.Text = lstUI[comIndex].tbIP.Items[0].ToString();
lstUI[comIndex].tbPort.Text = new IniHelper(ConfigPath).IniReadValue((comIndex + 1) + "#COMMUNICATION_SETTING", "TCP_Port");
//lstUI[comIndex].TCPOpen();
}
//客户端
else if (Convert.ToInt32(new IniHelper(ConfigPath).IniReadValue((comIndex + 1) + "#COMMUNICATION_SETTING", "Connect_Typt")) == 2)
{
lstUI[comIndex].Server_GroupBox.Visible = false;
lstUI[comIndex].info_GroupBox.Dock = DockStyle.Fill;
lstUI[comIndex].tcpType_Box.SelectedIndex = Convert.ToInt32(new IniHelper(ConfigPath).IniReadValue((comIndex + 1) + "#COMMUNICATION_SETTING", "Connect_Typt"));
lstUI[comIndex].tbIP.Items.Clear();
lstUI[comIndex].tbIP.Items.Add(new IniHelper(ConfigPath).IniReadValue((comIndex + 1) + "#COMMUNICATION_SETTING", "TCP_IP"));
lstUI[comIndex].tbIP.Text = lstUI[comIndex].tbIP.Items[0].ToString();
lstUI[comIndex].tbPort.Text = new IniHelper(ConfigPath).IniReadValue((comIndex + 1) + "#COMMUNICATION_SETTING", "TCP_Port");
//lstUI[comIndex].TCPOpen();
}
else
{
//串口
lstUI[comIndex].Server_GroupBox.Visible = false;
lstUI[comIndex].info_GroupBox.Dock = DockStyle.Fill;
lstUI[comIndex].tcpType_Box.SelectedIndex = Convert.ToInt32(new IniHelper(ConfigPath).IniReadValue((comIndex + 1) + "#COMMUNICATION_SETTING", "Connect_Typt"));
lstUI[comIndex].comPort_Box.Items.Clear();
lstUI[comIndex].comPort_Box.Items.Add(new IniHelper(ConfigPath).IniReadValue((comIndex + 1) + "#COMMUNICATION_SETTING", "COM_Port"));
lstUI[comIndex].comPort_Box.Text = lstUI[comIndex].comPort_Box.Items[0].ToString();
lstUI[comIndex].baudRate_Box.Text = new IniHelper(ConfigPath).IniReadValue((comIndex + 1) + "#COMMUNICATION_SETTING", "COM_BaudRate");
lstUI[comIndex].parity_Box.Text = new IniHelper(ConfigPath).IniReadValue((comIndex + 1) + "#COMMUNICATION_SETTING", "COM_Parity");
lstUI[comIndex].dataBits_Box.Text = new IniHelper(ConfigPath).IniReadValue((comIndex + 1) + "#COMMUNICATION_SETTING", "COM_DataBit");
lstUI[comIndex].stopBits_Box.Text = new IniHelper(ConfigPath).IniReadValue((comIndex + 1) + "#COMMUNICATION_SETTING", "COM_StopBit");
lstUI[comIndex].COMOpen();
//客户端
lstUI[comIndex].Server_GroupBox.Visible = false;
lstUI[comIndex].info_GroupBox.Dock = DockStyle.Fill;
lstUI[comIndex].tcpType_Box.SelectedIndex = Convert.ToInt32(new IniHelper(ConfigPath).IniReadValue((comIndex + 1) + "#COMMUNICATION_SETTING", "Connect_Typt"));
lstUI[comIndex].tbIP.Items.Clear();
lstUI[comIndex].tbIP.Items.Add(new IniHelper(ConfigPath).IniReadValue((comIndex + 1) + "#COMMUNICATION_SETTING", "TCP_IP"));
lstUI[comIndex].tbIP.Text = lstUI[comIndex].tbIP.Items[0].ToString();
lstUI[comIndex].tbPort.Text = new IniHelper(ConfigPath).IniReadValue((comIndex + 1) + "#COMMUNICATION_SETTING", "TCP_Port");
//lstUI[comIndex].TCPOpen();
}
}
else
{
lstUI[comIndex].Auto_CheckBox.Checked = false;
lstUI[comIndex].comSerial.LoadComSerial(lstUI[comIndex].comPort_Box);
lstUI[comIndex].LocalIP(lstUI[comIndex].tbIP);
}
}
private void FrmCommunication_FormClosing(object sender, FormClosingEventArgs e)
{
this.Visible = false;
e.Cancel = true;
}
}
}
+123
View File
@@ -0,0 +1,123 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<metadata name="$this.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
</root>
+59
View File
@@ -0,0 +1,59 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
namespace SimpleCommunication
{
public class IniHelper
{
public string path;
public IniHelper(string INIPath)
{
path = INIPath;
}
[DllImport("kernel32", CharSet = CharSet.Unicode)]
private static extern long WritePrivateProfileString(string section, string key, string val, string filePath);
[DllImport("kernel32", CharSet = CharSet.Unicode)]
private static extern int GetPrivateProfileString(string section, string key, string def, StringBuilder retVal, int size, string filePath);
[DllImport("kernel32", CharSet = CharSet.Unicode)]
private static extern int GetPrivateProfileString(string section, string key, string defVal, byte[] retVal, int size, string filePath);
public void IniWriteValue(string Section, string Key, string Value)
{
WritePrivateProfileString(Section, Key, Value, path);
}
public string IniReadValue(string Section, string Key)
{
try
{
StringBuilder temp = new StringBuilder(255);
int i = GetPrivateProfileString(Section, Key, "", temp, 255, path);
return temp.ToString();
}
catch (Exception)
{
return null;
}
}
public byte[] IniReadValues(string section, string key)
{
byte[] temp = new byte[255];
int i = GetPrivateProfileString(section, key, "", temp, 255, path);
return temp;
}
public void ClearAllSection()
{
IniWriteValue(null, null, null);
}
public void ClearSection(string Section)
{
IniWriteValue(Section, null, null);
}
}
}
+73
View File
@@ -0,0 +1,73 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
namespace SimpleCommunication
{
public class LogHelper : IDisposable
{
private static LogHelper logHelper;
private static object singleLock = new object();
private string logPath = Path.Combine(System.Environment.CurrentDirectory, "Log.txt");
private string spaceSymbols = "\r\n\r\n--------------------------------------------\r\n\r\n";
private byte[] spaceSymbolsBytes;
private FileStream fileStream;
private LogHelper()
{
}
public static LogHelper GetInstance()
{
if (logHelper == null)
{
lock (singleLock)
{
if (logHelper == null)
{
logHelper = new LogHelper();
}
}
}
return logHelper;
}
public void SetLogPath(string logPath)
{
this.logPath = Path.Combine(logPath, "Log.txt");
}
public void Init()
{
fileStream = new FileStream(logPath, FileMode.OpenOrCreate, FileAccess.ReadWrite);
spaceSymbolsBytes = Encoding.Default.GetBytes(spaceSymbols);
}
public void SetSpaceSymbols(string spaceSymbols)
{
this.spaceSymbols = spaceSymbols;
this.spaceSymbolsBytes = Encoding.Default.GetBytes(spaceSymbols);
}
public void Log(string content)
{
if (!string.IsNullOrEmpty(content))
{
fileStream.Seek(0, SeekOrigin.End);
byte[] bytes = Encoding.Default.GetBytes(content);
fileStream.Write(bytes, 0, bytes.Length);
fileStream.Write(spaceSymbolsBytes, 0, spaceSymbolsBytes.Length);
fileStream.Flush();
}
}
public void Dispose()
{
if (fileStream != null)
{
fileStream.Dispose();
}
}
}
}
+31
View File
@@ -0,0 +1,31 @@
using System;
using System.Collections.Generic;
using System.Windows.Forms;
using System.Threading;
namespace SimpleCommunication
{
static class Program
{
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
LogHelper.GetInstance().Init();
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.ThreadException += new System.Threading.ThreadExceptionEventHandler(Application_ThreadException);
Application.Run(new FrmCommunication());
LogHelper.GetInstance().Dispose();
}
static void Application_ThreadException(object sender, ThreadExceptionEventArgs e)
{
LogHelper.GetInstance().Log(e.Exception.Message);
}
}
}
+36
View File
@@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// 有关程序集的常规信息通过以下
// 特性集控制。更改这些特性值可修改
// 与程序集关联的信息。
[assembly: AssemblyTitle("SimpleCommunication")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("SimpleCommunication")]
[assembly: AssemblyCopyright("Copyright © 2012")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// 将 ComVisible 设置为 false 使此程序集中的类型
// 对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型,
// 则将该类型上的 ComVisible 特性设置为 true。
[assembly: ComVisible(false)]
// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID
[assembly: Guid("4a5ff5e4-13bc-4f97-b59f-a6fb5123c026")]
// 程序集的版本信息由下面四个值组成:
//
// 主版本
// 次版本
// 内部版本号
// 修订号
//
// 可以指定所有这些值,也可以使用“内部版本号”和“修订号”的默认值,
// 方法是按如下所示使用“*”:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
+63
View File
@@ -0,0 +1,63 @@
//------------------------------------------------------------------------------
// <auto-generated>
// 此代码由工具生成。
// 运行时版本:4.0.30319.42000
//
// 对此文件的更改可能会导致不正确的行为,并且如果
// 重新生成代码,这些更改将会丢失。
// </auto-generated>
//------------------------------------------------------------------------------
namespace SimpleCommunication.Properties {
using System;
/// <summary>
/// 一个强类型的资源类,用于查找本地化的字符串等。
/// </summary>
// 此类是由 StronglyTypedResourceBuilder
// 类通过类似于 ResGen 或 Visual Studio 的工具自动生成的。
// 若要添加或移除成员,请编辑 .ResX 文件,然后重新运行 ResGen
// (以 /str 作为命令选项),或重新生成 VS 项目。
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
internal class Resources {
private static global::System.Resources.ResourceManager resourceMan;
private static global::System.Globalization.CultureInfo resourceCulture;
[global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
internal Resources() {
}
/// <summary>
/// 返回此类使用的缓存的 ResourceManager 实例。
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Resources.ResourceManager ResourceManager {
get {
if (object.ReferenceEquals(resourceMan, null)) {
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("SimpleCommunication.Properties.Resources", typeof(Resources).Assembly);
resourceMan = temp;
}
return resourceMan;
}
}
/// <summary>
/// 重写当前线程的 CurrentUICulture 属性,对
/// 使用此强类型资源类的所有资源查找执行重写。
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Globalization.CultureInfo Culture {
get {
return resourceCulture;
}
set {
resourceCulture = value;
}
}
}
}
+117
View File
@@ -0,0 +1,117 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>
+26
View File
@@ -0,0 +1,26 @@
//------------------------------------------------------------------------------
// <auto-generated>
// 此代码由工具生成。
// 运行时版本:4.0.30319.42000
//
// 对此文件的更改可能会导致不正确的行为,并且如果
// 重新生成代码,这些更改将会丢失。
// </auto-generated>
//------------------------------------------------------------------------------
namespace SimpleCommunication.Properties {
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "17.11.0.0")]
internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {
private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
public static Settings Default {
get {
return defaultInstance;
}
}
}
}
@@ -0,0 +1,7 @@
<?xml version='1.0' encoding='utf-8'?>
<SettingsFile xmlns="http://schemas.microsoft.com/VisualStudio/2004/01/settings" CurrentProfile="(Default)">
<Profiles>
<Profile Name="(Default)" />
</Profiles>
<Settings />
</SettingsFile>
+239
View File
@@ -0,0 +1,239 @@
using System;
using System.Collections.Generic;
using System.IO.Ports;
using System.Linq;
using System.Runtime.Remoting.Messaging;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace SimpleCommunication
{
public class Serial : IDisposable
{
#region DataMember & Ctor
public SerialPort serialPort;
private string[] port;
public SerialPort Comm { get; private set; }
private List<string> list = new List<string>(4096);
//在事务处理结束后才触发下列事件
public event DlgNoParam ComOpenEvent;
public event DlgOneParam<string> RecvMsgEvent;
public event DlgOneParam<string> SendMsgEvent;
public event DlgNoParam ComDisconnectEvent;
public bool IsOpen => (serialPort != null && serialPort.IsOpen) ? true : false;
public Serial()
{
serialPort = new SerialPort();
}
#endregion
/// <summary>
/// 获取窗口名
/// </summary>
/// <returns></returns>
public string getUserPortName()
{
return serialPort.PortName;
}
/// <summary>
/// 加载串口
/// </summary>
/// <param name="ComPort"></param>
public void LoadComSerial(ComboBox ComPort)
{
ComPort.Items.Clear();
list.Clear();
if (!IsOpen)
{
port = SerialPort.GetPortNames();
for (int i = 0; i < port.Count(); i++)
{
try
{
SerialPort serialPort = new SerialPort(port[i]);
serialPort.Open();
serialPort.Close();
list.Add(port[i]);
}
catch
{
}
}
port = list.ToArray();
Array.Sort(port);
ComboBox.ObjectCollection items = ComPort.Items;
object[] items2 = port;
items.AddRange(items2);
if (port.Length != 0)
{
ComPort.Text = port[0];
}
}
else
{
ComPort.Text = getUserPortName();
}
}
/// <summary>
/// 打开串口
/// </summary>
/// <param name="portName"></param>
/// <param name="baudRate"></param>
/// <param name="parity"></param>
/// <param name="dataBits"></param>
/// <param name="stopBits"></param>
public void OpenSerialPort(string portName, int baudRate, Parity parity, int dataBits, StopBits stopBits)
{
serialPort.PortName = portName;
serialPort.BaudRate = baudRate;
serialPort.Parity = parity;
serialPort.DataBits = dataBits;
serialPort.StopBits = stopBits;
try
{
serialPort.ReadBufferSize = 4096;
serialPort.DataReceived += ComReceived;
serialPort.Open();
if (ComOpenEvent != null)
{
ComOpenEvent();
}
}
catch (Exception)
{
MessageBox.Show("串口被占用,请重新选择!");
}
}
/// <summary>
/// 关闭串口
/// </summary>
public void CloseSeriaPort()
{
serialPort.DataReceived -= ComReceived;
serialPort.Close();
}
/// <summary>
///
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ComReceived(object sender, SerialDataReceivedEventArgs e)
{
try
{
if (serialPort.IsOpen)
{
string text = "";
Thread.Sleep(50);
int length = serialPort.BytesToRead;
byte[] data = new byte[length];
serialPort.Read(data, 0, length);
//对串口接收数据的处理,可对data进行解析
string data1 = string.Empty;
for (int i = 0; i < length; i++)
{
data1 += Convert.ToString(data[i], 16).ToUpper();
//data.AppendText(str.Length == 1 ? "0" + str + " " : str + " ");//将接收到的数据以十六进制显示到文本框内
}
//int bytesToRead = serialPort.BytesToRead;
//string data = string.Empty;
//while (serialPort.BytesToRead > 0)
//{
// data += serialPort.ReadExisting(); //数据读取,直到读完缓冲区数据
//}
//for (int i = 0; i < bytesToRead; i++)
//{
// int utf = serialPort.ReadByte();
// //text = serialPort.ReadTo("\r");
// string text2 = char.ConvertFromUtf32(utf);
// text += text2;
//}
if (this.RecvMsgEvent != null)
{
this.RecvMsgEvent(data1);
}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
/// <summary>
/// 同步发送返回数据
/// </summary>
/// <param name="str"></param>
/// <returns></returns>
public string SendReturnData(string str)
{
string text = "";
try
{
if (serialPort.IsOpen)
{
serialPort.Write(str);
Thread.Sleep(100);
text = serialPort.ReadTo("\r");
}
}
catch (Exception ex)
{
}
return text;
}
/// <summary>
/// 发送字符串
/// </summary>
/// <param name="str"></param>
public void SendString(string str)
{
try
{
serialPort.Write(str);
if (this.SendMsgEvent != null)
{
this.SendMsgEvent(str);
}
}
catch (Exception ex)
{
//MessageBox.Show(ex.ToString());
}
}
/// <summary>
///
/// 在已连接条件下关闭本地连接和资源释放时调用
/// </summary>
public void Dispose()
{
if (serialPort != null&& serialPort.IsOpen)
{
CloseSeriaPort();
if (this.ComDisconnectEvent != null)
{
this.ComDisconnectEvent();
}
}
}
}
}
+272
View File
@@ -0,0 +1,272 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Net.Sockets;
using System.Threading;
using System.Net;
using SimpleCommunication;
using System.Windows.Forms;
namespace SimpleCommunication
{
public class Server : IDisposable
{
#region DataMember
public TcpListener listener;
public Client currentClient;
private object listenerLock = new object();//锁TcpListener;在BeginAcceptClient,EndAcceptClient,ServerClose这3函数使用;ServerClose之后不能再调用BeginAcceptClient,EndAcceptClient
/// <summary>
/// 服务器是否启用监听
/// </summary>
public bool serverStart = false;
private EventWaitHandle eventWaitHdl = new EventWaitHandle(false, EventResetMode.ManualReset);
//在事务处理结束后才触发下列事件
public event DlgNoParam ServerStartEvent;
public event DlgNoParam ServerCloseEvent;
public event DlgOneParam<string> NewClientEvent;
public event DlgOneParam<string> RecvMsgEvent;
public event DlgNoParam LocalDisconnectEvent;
public event DlgOneParam<string> RemoteDisconnectEvent;
public bool IsConnected => (listener != null && serverStart) ? true : false;
#endregion
#region 服务器监听启动关闭和连接接收
public bool Start(ComboBox Server_IP, TextBox txtPort, int maxClient = 10)
{
bool result = false;
try
{
if (!string.IsNullOrEmpty(Server_IP.Text) && !string.IsNullOrEmpty(txtPort.Text))
{
if (Convert.ToInt32(txtPort.Text) > 1024)
{
IPAddress ipAddr = IPAddress.Parse(Server_IP.Text);
IPEndPoint point = new IPEndPoint(ipAddr, Convert.ToInt32(txtPort.Text));
listener = new TcpListener(point);
listener.Start();
result = true;
serverStart = true;
if (ServerStartEvent != null)
{
ServerStartEvent();
}
}
}
}
catch(Exception ex)
{
throw ex;
}
return result;
}
/// <summary>
/// 有互斥资源
/// 接收连接主入口,监听启动后调用和每次接收到连接后调用
/// </summary>
public void BeginAcceptClient()
{
try
{
while (true)
{
eventWaitHdl.Reset();
lock (listenerLock)
{
if (serverStart)
{
listener.BeginAcceptTcpClient(EndAcceptClient, null);
}
else
{
return;
}
}
eventWaitHdl.WaitOne();
}
}
catch
{
}
}
/// <summary>
/// 有互斥资源
/// 接收到客户端连接时调用到,关闭listener时也调用到
/// </summary>
/// <param name="ar"></param>
private void EndAcceptClient(IAsyncResult ar)
{
try
{
TcpClient tcpclient = null;
lock (listenerLock)
{
if (serverStart)
{
tcpclient = listener.EndAcceptTcpClient(ar);//在这句话之前或者client.BeginRead之前断掉远程客户端都没事,tcpclient都不为null
}
}
eventWaitHdl.Set();
if (tcpclient != null)//listener.stop后tcpclient == null,不会进入下面代码
{
InitClient(tcpclient);
}
}
catch
{
}
}
/// <summary>
/// 有互斥资源
/// 在listener监听状态下关闭listener时调用,资源释放时调用
/// </summary>
/// <returns></returns>
public bool ServerClose()
{
bool result = false;
try
{
lock (listenerLock)
{
if (serverStart)
{
serverStart = false;
listener.Stop();
result = true;
if (ServerCloseEvent != null)
{
ServerCloseEvent();
}
}
}
}
catch
{
}
return result;
}
#endregion
#region Client相关操作
private void InitClient(TcpClient tcpclient)
{
currentClient = new Client(tcpclient);
ClientDlgSubscribe(true);
currentClient.BeginRead();//即使在这之前服务器断开,该函数返回值也等于1
}
/// <summary>
/// InitClient,CurrentClient_LocalDisconnectEvent,Client_DisconnectEvent调用到
/// 在事务处理结束后调用到
/// </summary>
/// <param name="add"></param>
public void ClientDlgSubscribe(bool add)
{
if (add)
{
currentClient.NewClientEvent += new DlgOneParam<string>(Client_NewClientEvent);
currentClient.RecvMsgEvent += new DlgOneParam<string>(Client_RecvMsgEvent);
currentClient.RemoteDisconnectEvent += new DlgOneParam<string>(Client_DisconnectEvent);
currentClient.LocalDisconnectEvent += new DlgNoParam(CurrentClient_LocalDisconnectEvent);
}
else
{
currentClient.NewClientEvent -= new DlgOneParam<string>(Client_NewClientEvent);
currentClient.RecvMsgEvent -= new DlgOneParam<string>(Client_RecvMsgEvent);
currentClient.RemoteDisconnectEvent -= new DlgOneParam<string>(Client_DisconnectEvent);
currentClient.LocalDisconnectEvent -= new DlgNoParam(CurrentClient_LocalDisconnectEvent);
}
}
public bool SendMsg(string msg)
{
bool result = false;
try
{
if (currentClient.SendMsg(msg))
{
result = true;
}
}
catch
{
}
return result;
}
/// <summary>
/// 客户端连接情况下断开连接时调用,释放资源时调用
/// </summary>
/// <returns></returns>
public bool DisconnectClient()
{
bool result = false;
try
{
if (currentClient != null)
{
currentClient.Dispose();
result = true;
}
}
catch
{
}
return result;
}
public void Client_NewClientEvent(string param)
{
if (NewClientEvent != null)
{
NewClientEvent(param);
}
}
public void Client_RecvMsgEvent(string param)
{
if (RecvMsgEvent != null)
{
RecvMsgEvent(param);
}
}
public void Client_DisconnectEvent(string param)
{
ClientDlgSubscribe(false);
if (RemoteDisconnectEvent != null)
{
RemoteDisconnectEvent(param);
}
}
public void CurrentClient_LocalDisconnectEvent()
{
ClientDlgSubscribe(false);
if (LocalDisconnectEvent != null)
{
LocalDisconnectEvent();
}
}
#endregion
#region 资源释放
public void Dispose()
{
ServerClose();
DisconnectClient();
}
#endregion
}
}
+147
View File
@@ -0,0 +1,147 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">x86</Platform>
<ProductVersion>8.0.30703</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{D73FAE32-AAA3-4A51-BB0A-F1A5DC5A7260}</ProjectGuid>
<OutputType>WinExe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>SimpleCommunication</RootNamespace>
<AssemblyName>SimpleCommunication</AssemblyName>
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<TargetFrameworkProfile />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
<PlatformTarget>x86</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
<PlatformTarget>x86</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'">
<DebugSymbols>true</DebugSymbols>
<OutputPath>bin\x64\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<DebugType>full</DebugType>
<PlatformTarget>x64</PlatformTarget>
<LangVersion>7.3</LangVersion>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'">
<OutputPath>bin\x64\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<Optimize>true</Optimize>
<DebugType>pdbonly</DebugType>
<PlatformTarget>x64</PlatformTarget>
<LangVersion>7.3</LangVersion>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|AnyCPU'">
<DebugSymbols>true</DebugSymbols>
<OutputPath>..\..\..\..\JY.Inspection\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<DebugType>full</DebugType>
<PlatformTarget>AnyCPU</PlatformTarget>
<LangVersion>7.3</LangVersion>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|AnyCPU'">
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<Optimize>true</Optimize>
<DebugType>pdbonly</DebugType>
<PlatformTarget>AnyCPU</PlatformTarget>
<LangVersion>7.3</LangVersion>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Data" />
<Reference Include="System.Deployment" />
<Reference Include="System.Drawing" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Client.cs" />
<Compile Include="ComConfig.cs" />
<Compile Include="CommonHelper.cs" />
<Compile Include="FrmCommunication.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="FrmCommunication.Designer.cs">
<DependentUpon>FrmCommunication.cs</DependentUpon>
</Compile>
<Compile Include="IniHelper.cs" />
<Compile Include="LogHelper.cs" />
<Compile Include="Serial.cs" />
<Compile Include="Server.cs" />
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="CommunUI.cs">
<SubType>UserControl</SubType>
</Compile>
<Compile Include="CommunUI.Designer.cs">
<DependentUpon>CommunUI.cs</DependentUpon>
</Compile>
<Compile Include="StringBox.cs" />
<EmbeddedResource Include="FrmCommunication.resx">
<DependentUpon>FrmCommunication.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="Properties\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
<SubType>Designer</SubType>
</EmbeddedResource>
<Compile Include="Properties\Resources.Designer.cs">
<AutoGen>True</AutoGen>
<DependentUpon>Resources.resx</DependentUpon>
<DesignTime>True</DesignTime>
</Compile>
<EmbeddedResource Include="CommunUI.resx">
<DependentUpon>CommunUI.cs</DependentUpon>
</EmbeddedResource>
<None Include="app.config" />
<None Include="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator>
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
</None>
<Compile Include="Properties\Settings.Designer.cs">
<AutoGen>True</AutoGen>
<DependentUpon>Settings.settings</DependentUpon>
<DesignTimeSharedInput>True</DesignTimeSharedInput>
</Compile>
</ItemGroup>
<ItemGroup />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<ProjectView>ProjectFiles</ProjectView>
</PropertyGroup>
</Project>
+18
View File
@@ -0,0 +1,18 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Sockets;
using System.Text;
using System.Threading.Tasks;
namespace SimpleCommunication
{
public class StringBox
{
public string str = null;
public string ID = null;
public int isConnetMsg = 0;
}
}
+3
View File
@@ -0,0 +1,3 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.8"/></startup></configuration>