Commit dd06af9a 张东亮

20221215

1 个父辈 21efea91
正在显示 57 个修改的文件 包含 2047 行增加86 行删除
...@@ -11,8 +11,6 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LoadCSVLibrary", "source\Lo ...@@ -11,8 +11,6 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LoadCSVLibrary", "source\Lo
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CarriageClient", "source\CarriageClient\CarriageClient.csproj", "{0D2542F5-DD62-4352-82D0-383D9A045E74}" Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CarriageClient", "source\CarriageClient\CarriageClient.csproj", "{0D2542F5-DD62-4352-82D0-383D9A045E74}"
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Dolen", "..\..\..\..\Projects\CSharp-Workspace\Dolen\Dolen\Dolen.csproj", "{1D8684A2-5358-4F9C-9B42-9794F8F4B6B6}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "JAKA", "source\JAKA\JAKA.csproj", "{B702AB04-BB76-491F-812A-603298D08FBF}" Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "JAKA", "source\JAKA\JAKA.csproj", "{B702AB04-BB76-491F-812A-603298D08FBF}"
EndProject EndProject
Global Global
...@@ -37,10 +35,6 @@ Global ...@@ -37,10 +35,6 @@ Global
{0D2542F5-DD62-4352-82D0-383D9A045E74}.Debug|Any CPU.Build.0 = Debug|Any CPU {0D2542F5-DD62-4352-82D0-383D9A045E74}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0D2542F5-DD62-4352-82D0-383D9A045E74}.Release|Any CPU.ActiveCfg = Release|Any CPU {0D2542F5-DD62-4352-82D0-383D9A045E74}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0D2542F5-DD62-4352-82D0-383D9A045E74}.Release|Any CPU.Build.0 = Release|Any CPU {0D2542F5-DD62-4352-82D0-383D9A045E74}.Release|Any CPU.Build.0 = Release|Any CPU
{1D8684A2-5358-4F9C-9B42-9794F8F4B6B6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{1D8684A2-5358-4F9C-9B42-9794F8F4B6B6}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1D8684A2-5358-4F9C-9B42-9794F8F4B6B6}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1D8684A2-5358-4F9C-9B42-9794F8F4B6B6}.Release|Any CPU.Build.0 = Release|Any CPU
{B702AB04-BB76-491F-812A-603298D08FBF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {B702AB04-BB76-491F-812A-603298D08FBF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B702AB04-BB76-491F-812A-603298D08FBF}.Debug|Any CPU.Build.0 = Debug|Any CPU {B702AB04-BB76-491F-812A-603298D08FBF}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B702AB04-BB76-491F-812A-603298D08FBF}.Release|Any CPU.ActiveCfg = Release|Any CPU {B702AB04-BB76-491F-812A-603298D08FBF}.Release|Any CPU.ActiveCfg = Release|Any CPU
......
...@@ -113,9 +113,9 @@ ...@@ -113,9 +113,9 @@
// tabPage1 // tabPage1
// //
this.tabPage1.Controls.Add(this.logBox); this.tabPage1.Controls.Add(this.logBox);
this.tabPage1.Location = new System.Drawing.Point(4, 29); this.tabPage1.Location = new System.Drawing.Point(4, 32);
this.tabPage1.Name = "tabPage1"; this.tabPage1.Name = "tabPage1";
this.tabPage1.Size = new System.Drawing.Size(988, 605); this.tabPage1.Size = new System.Drawing.Size(988, 602);
this.tabPage1.TabIndex = 0; this.tabPage1.TabIndex = 0;
this.tabPage1.Text = " 运行日志 "; this.tabPage1.Text = " 运行日志 ";
this.tabPage1.UseVisualStyleBackColor = true; this.tabPage1.UseVisualStyleBackColor = true;
...@@ -128,7 +128,7 @@ ...@@ -128,7 +128,7 @@
this.logBox.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); this.logBox.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.logBox.Location = new System.Drawing.Point(5, 3); this.logBox.Location = new System.Drawing.Point(5, 3);
this.logBox.Name = "logBox"; this.logBox.Name = "logBox";
this.logBox.Size = new System.Drawing.Size(977, 594); this.logBox.Size = new System.Drawing.Size(977, 591);
this.logBox.TabIndex = 106; this.logBox.TabIndex = 106;
this.logBox.Text = ""; this.logBox.Text = "";
this.logBox.VisibleChanged += new System.EventHandler(this.logBox_VisibleChanged); this.logBox.VisibleChanged += new System.EventHandler(this.logBox_VisibleChanged);
...@@ -136,9 +136,9 @@ ...@@ -136,9 +136,9 @@
// tabPage2 // tabPage2
// //
this.tabPage2.Controls.Add(this.panel1); this.tabPage2.Controls.Add(this.panel1);
this.tabPage2.Location = new System.Drawing.Point(4, 29); this.tabPage2.Location = new System.Drawing.Point(4, 32);
this.tabPage2.Name = "tabPage2"; this.tabPage2.Name = "tabPage2";
this.tabPage2.Size = new System.Drawing.Size(988, 605); this.tabPage2.Size = new System.Drawing.Size(988, 602);
this.tabPage2.TabIndex = 1; this.tabPage2.TabIndex = 1;
this.tabPage2.Text = " 设备状态 "; this.tabPage2.Text = " 设备状态 ";
this.tabPage2.UseVisualStyleBackColor = true; this.tabPage2.UseVisualStyleBackColor = true;
...@@ -149,7 +149,7 @@ ...@@ -149,7 +149,7 @@
this.panel1.Dock = System.Windows.Forms.DockStyle.Fill; this.panel1.Dock = System.Windows.Forms.DockStyle.Fill;
this.panel1.Location = new System.Drawing.Point(0, 0); this.panel1.Location = new System.Drawing.Point(0, 0);
this.panel1.Name = "panel1"; this.panel1.Name = "panel1";
this.panel1.Size = new System.Drawing.Size(988, 605); this.panel1.Size = new System.Drawing.Size(988, 602);
this.panel1.TabIndex = 1; this.panel1.TabIndex = 1;
// //
// tableLayoutPanel1 // tableLayoutPanel1
...@@ -173,7 +173,7 @@ ...@@ -173,7 +173,7 @@
this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 25F)); this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 25F));
this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 25F)); this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 25F));
this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 20F)); this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 20F));
this.tableLayoutPanel1.Size = new System.Drawing.Size(988, 605); this.tableLayoutPanel1.Size = new System.Drawing.Size(988, 602);
this.tableLayoutPanel1.TabIndex = 0; this.tableLayoutPanel1.TabIndex = 0;
// //
// robotDataControl // robotDataControl
...@@ -182,10 +182,11 @@ ...@@ -182,10 +182,11 @@
this.robotDataControl.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; this.robotDataControl.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.robotDataControl.ColorStatus = System.Drawing.Color.White; this.robotDataControl.ColorStatus = System.Drawing.Color.White;
this.robotDataControl.Dock = System.Windows.Forms.DockStyle.Fill; this.robotDataControl.Dock = System.Windows.Forms.DockStyle.Fill;
this.robotDataControl.Location = new System.Drawing.Point(3, 456); this.robotDataControl.Location = new System.Drawing.Point(4, 454);
this.robotDataControl.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4);
this.robotDataControl.Name = "robotDataControl"; this.robotDataControl.Name = "robotDataControl";
this.robotDataControl.ReelText = "机器人夹爪物料信息"; this.robotDataControl.ReelText = "机器人夹爪物料信息";
this.robotDataControl.Size = new System.Drawing.Size(488, 146); this.robotDataControl.Size = new System.Drawing.Size(486, 144);
this.robotDataControl.TabIndex = 8; this.robotDataControl.TabIndex = 8;
// //
// robotControl // robotControl
...@@ -196,10 +197,11 @@ ...@@ -196,10 +197,11 @@
this.tableLayoutPanel1.SetColumnSpan(this.robotControl, 2); this.tableLayoutPanel1.SetColumnSpan(this.robotControl, 2);
this.robotControl.Dock = System.Windows.Forms.DockStyle.Fill; this.robotControl.Dock = System.Windows.Forms.DockStyle.Fill;
this.robotControl.EquipText = "机器人运输机构"; this.robotControl.EquipText = "机器人运输机构";
this.robotControl.Location = new System.Drawing.Point(3, 3); this.robotControl.Location = new System.Drawing.Point(4, 4);
this.robotControl.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4);
this.robotControl.MoveInfo = "暂无出入库"; this.robotControl.MoveInfo = "暂无出入库";
this.robotControl.Name = "robotControl"; this.robotControl.Name = "robotControl";
this.robotControl.Size = new System.Drawing.Size(982, 145); this.robotControl.Size = new System.Drawing.Size(980, 142);
this.robotControl.TabIndex = 0; this.robotControl.TabIndex = 0;
this.robotControl.WorkStatus = "暂未启动"; this.robotControl.WorkStatus = "暂未启动";
// //
...@@ -210,10 +212,11 @@ ...@@ -210,10 +212,11 @@
this.inletControl.ColorStatus = System.Drawing.Color.White; this.inletControl.ColorStatus = System.Drawing.Color.White;
this.inletControl.Dock = System.Windows.Forms.DockStyle.Fill; this.inletControl.Dock = System.Windows.Forms.DockStyle.Fill;
this.inletControl.EquipText = "入料口"; this.inletControl.EquipText = "入料口";
this.inletControl.Location = new System.Drawing.Point(3, 154); this.inletControl.Location = new System.Drawing.Point(4, 154);
this.inletControl.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4);
this.inletControl.MoveInfo = "暂无出入库"; this.inletControl.MoveInfo = "暂无出入库";
this.inletControl.Name = "inletControl"; this.inletControl.Name = "inletControl";
this.inletControl.Size = new System.Drawing.Size(488, 145); this.inletControl.Size = new System.Drawing.Size(486, 142);
this.inletControl.TabIndex = 1; this.inletControl.TabIndex = 1;
this.inletControl.WorkStatus = "暂未启动"; this.inletControl.WorkStatus = "暂未启动";
// //
...@@ -224,10 +227,11 @@ ...@@ -224,10 +227,11 @@
this.outletControl.ColorStatus = System.Drawing.Color.White; this.outletControl.ColorStatus = System.Drawing.Color.White;
this.outletControl.Dock = System.Windows.Forms.DockStyle.Fill; this.outletControl.Dock = System.Windows.Forms.DockStyle.Fill;
this.outletControl.EquipText = "出料口"; this.outletControl.EquipText = "出料口";
this.outletControl.Location = new System.Drawing.Point(497, 154); this.outletControl.Location = new System.Drawing.Point(498, 154);
this.outletControl.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4);
this.outletControl.MoveInfo = "暂无出入库"; this.outletControl.MoveInfo = "暂无出入库";
this.outletControl.Name = "outletControl"; this.outletControl.Name = "outletControl";
this.outletControl.Size = new System.Drawing.Size(488, 145); this.outletControl.Size = new System.Drawing.Size(486, 142);
this.outletControl.TabIndex = 2; this.outletControl.TabIndex = 2;
this.outletControl.WorkStatus = "暂未启动"; this.outletControl.WorkStatus = "暂未启动";
// //
...@@ -237,10 +241,11 @@ ...@@ -237,10 +241,11 @@
this.outletDataControl.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; this.outletDataControl.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.outletDataControl.ColorStatus = System.Drawing.Color.White; this.outletDataControl.ColorStatus = System.Drawing.Color.White;
this.outletDataControl.Dock = System.Windows.Forms.DockStyle.Fill; this.outletDataControl.Dock = System.Windows.Forms.DockStyle.Fill;
this.outletDataControl.Location = new System.Drawing.Point(497, 305); this.outletDataControl.Location = new System.Drawing.Point(498, 304);
this.outletDataControl.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4);
this.outletDataControl.Name = "outletDataControl"; this.outletDataControl.Name = "outletDataControl";
this.outletDataControl.ReelText = "出料口物料信息"; this.outletDataControl.ReelText = "出料口物料信息";
this.outletDataControl.Size = new System.Drawing.Size(488, 145); this.outletDataControl.Size = new System.Drawing.Size(486, 142);
this.outletDataControl.TabIndex = 5; this.outletDataControl.TabIndex = 5;
// //
// inletDataControl // inletDataControl
...@@ -249,10 +254,11 @@ ...@@ -249,10 +254,11 @@
this.inletDataControl.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; this.inletDataControl.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.inletDataControl.ColorStatus = System.Drawing.Color.White; this.inletDataControl.ColorStatus = System.Drawing.Color.White;
this.inletDataControl.Dock = System.Windows.Forms.DockStyle.Fill; this.inletDataControl.Dock = System.Windows.Forms.DockStyle.Fill;
this.inletDataControl.Location = new System.Drawing.Point(3, 305); this.inletDataControl.Location = new System.Drawing.Point(4, 304);
this.inletDataControl.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4);
this.inletDataControl.Name = "inletDataControl"; this.inletDataControl.Name = "inletDataControl";
this.inletDataControl.ReelText = "入料口物料信息"; this.inletDataControl.ReelText = "入料口物料信息";
this.inletDataControl.Size = new System.Drawing.Size(488, 145); this.inletDataControl.Size = new System.Drawing.Size(486, 142);
this.inletDataControl.TabIndex = 7; this.inletDataControl.TabIndex = 7;
// //
// ngboxDataControl // ngboxDataControl
...@@ -261,10 +267,11 @@ ...@@ -261,10 +267,11 @@
this.ngboxDataControl.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; this.ngboxDataControl.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.ngboxDataControl.ColorStatus = System.Drawing.Color.White; this.ngboxDataControl.ColorStatus = System.Drawing.Color.White;
this.ngboxDataControl.Dock = System.Windows.Forms.DockStyle.Fill; this.ngboxDataControl.Dock = System.Windows.Forms.DockStyle.Fill;
this.ngboxDataControl.Location = new System.Drawing.Point(497, 456); this.ngboxDataControl.Location = new System.Drawing.Point(498, 454);
this.ngboxDataControl.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4);
this.ngboxDataControl.Name = "ngboxDataControl"; this.ngboxDataControl.Name = "ngboxDataControl";
this.ngboxDataControl.ReelText = "NG箱物料信息"; this.ngboxDataControl.ReelText = "NG箱物料信息";
this.ngboxDataControl.Size = new System.Drawing.Size(488, 146); this.ngboxDataControl.Size = new System.Drawing.Size(486, 144);
this.ngboxDataControl.TabIndex = 6; this.ngboxDataControl.TabIndex = 6;
// //
// lblStatus // lblStatus
...@@ -274,7 +281,7 @@ ...@@ -274,7 +281,7 @@
this.lblStatus.ForeColor = System.Drawing.Color.Green; this.lblStatus.ForeColor = System.Drawing.Color.Green;
this.lblStatus.Location = new System.Drawing.Point(29, 46); this.lblStatus.Location = new System.Drawing.Point(29, 46);
this.lblStatus.Name = "lblStatus"; this.lblStatus.Name = "lblStatus";
this.lblStatus.Size = new System.Drawing.Size(65, 20); this.lblStatus.Size = new System.Drawing.Size(82, 24);
this.lblStatus.TabIndex = 92; this.lblStatus.TabIndex = 92;
this.lblStatus.Text = "等待启动"; this.lblStatus.Text = "等待启动";
// //
...@@ -302,29 +309,30 @@ ...@@ -302,29 +309,30 @@
// contextMenuStrip1 // contextMenuStrip1
// //
this.contextMenuStrip1.Font = new System.Drawing.Font("微软雅黑", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); this.contextMenuStrip1.Font = new System.Drawing.Font("微软雅黑", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.contextMenuStrip1.ImageScalingSize = new System.Drawing.Size(20, 20);
this.contextMenuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { this.contextMenuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.显示ToolStripMenuItem, this.显示ToolStripMenuItem,
this.toolStripSeparator8, this.toolStripSeparator8,
this.toolStripMenuItem1}); this.toolStripMenuItem1});
this.contextMenuStrip1.Name = "contextMenuStrip1"; this.contextMenuStrip1.Name = "contextMenuStrip1";
this.contextMenuStrip1.Size = new System.Drawing.Size(113, 62); this.contextMenuStrip1.Size = new System.Drawing.Size(125, 74);
// //
// 显示ToolStripMenuItem // 显示ToolStripMenuItem
// //
this.显示ToolStripMenuItem.Name = "显示ToolStripMenuItem"; this.显示ToolStripMenuItem.Name = "显示ToolStripMenuItem";
this.显示ToolStripMenuItem.Size = new System.Drawing.Size(112, 26); this.显示ToolStripMenuItem.Size = new System.Drawing.Size(124, 32);
this.显示ToolStripMenuItem.Text = "显示"; this.显示ToolStripMenuItem.Text = "显示";
this.显示ToolStripMenuItem.Click += new System.EventHandler(this.显示ToolStripMenuItem_Click); this.显示ToolStripMenuItem.Click += new System.EventHandler(this.显示ToolStripMenuItem_Click);
// //
// toolStripSeparator8 // toolStripSeparator8
// //
this.toolStripSeparator8.Name = "toolStripSeparator8"; this.toolStripSeparator8.Name = "toolStripSeparator8";
this.toolStripSeparator8.Size = new System.Drawing.Size(109, 6); this.toolStripSeparator8.Size = new System.Drawing.Size(121, 6);
// //
// toolStripMenuItem1 // toolStripMenuItem1
// //
this.toolStripMenuItem1.Name = "toolStripMenuItem1"; this.toolStripMenuItem1.Name = "toolStripMenuItem1";
this.toolStripMenuItem1.Size = new System.Drawing.Size(112, 26); this.toolStripMenuItem1.Size = new System.Drawing.Size(124, 32);
this.toolStripMenuItem1.Text = "退出"; this.toolStripMenuItem1.Text = "退出";
this.toolStripMenuItem1.Click += new System.EventHandler(this.toolStripMenuItem1_Click); this.toolStripMenuItem1.Click += new System.EventHandler(this.toolStripMenuItem1_Click);
// //
...@@ -346,60 +354,60 @@ ...@@ -346,60 +354,60 @@
this.toolStripSeparator2, this.toolStripSeparator2,
this.退出ToolStripMenuItem}); this.退出ToolStripMenuItem});
this.操作ToolStripMenuItem.Name = "操作ToolStripMenuItem"; this.操作ToolStripMenuItem.Name = "操作ToolStripMenuItem";
this.操作ToolStripMenuItem.Size = new System.Drawing.Size(96, 25); this.操作ToolStripMenuItem.Size = new System.Drawing.Size(118, 31);
this.操作ToolStripMenuItem.Text = " 设备操作 "; this.操作ToolStripMenuItem.Text = " 设备操作 ";
// //
// toolStripSeparator1 // toolStripSeparator1
// //
this.toolStripSeparator1.Name = "toolStripSeparator1"; this.toolStripSeparator1.Name = "toolStripSeparator1";
this.toolStripSeparator1.Size = new System.Drawing.Size(114, 6); this.toolStripSeparator1.Size = new System.Drawing.Size(141, 6);
// //
// 启动AToolStripMenuItem // 启动AToolStripMenuItem
// //
this.启动AToolStripMenuItem.Name = "启动AToolStripMenuItem"; this.启动AToolStripMenuItem.Name = "启动AToolStripMenuItem";
this.启动AToolStripMenuItem.Size = new System.Drawing.Size(117, 26); this.启动AToolStripMenuItem.Size = new System.Drawing.Size(144, 32);
this.启动AToolStripMenuItem.Text = "启动 "; this.启动AToolStripMenuItem.Text = "启动 ";
this.启动AToolStripMenuItem.Click += new System.EventHandler(this.启动所有料仓AToolStripMenuItem_Click); this.启动AToolStripMenuItem.Click += new System.EventHandler(this.启动所有料仓AToolStripMenuItem_Click);
// //
// toolStripSeparator4 // toolStripSeparator4
// //
this.toolStripSeparator4.Name = "toolStripSeparator4"; this.toolStripSeparator4.Name = "toolStripSeparator4";
this.toolStripSeparator4.Size = new System.Drawing.Size(114, 6); this.toolStripSeparator4.Size = new System.Drawing.Size(141, 6);
// //
// 复位RToolStripMenuItem // 复位RToolStripMenuItem
// //
this.复位RToolStripMenuItem.Name = "复位RToolStripMenuItem"; this.复位RToolStripMenuItem.Name = "复位RToolStripMenuItem";
this.复位RToolStripMenuItem.Size = new System.Drawing.Size(117, 26); this.复位RToolStripMenuItem.Size = new System.Drawing.Size(144, 32);
this.复位RToolStripMenuItem.Text = "复位"; this.复位RToolStripMenuItem.Text = "复位";
this.复位RToolStripMenuItem.Click += new System.EventHandler(this.复位RToolStripMenuItem_Click); this.复位RToolStripMenuItem.Click += new System.EventHandler(this.复位RToolStripMenuItem_Click);
// //
// toolStripSeparator3 // toolStripSeparator3
// //
this.toolStripSeparator3.Name = "toolStripSeparator3"; this.toolStripSeparator3.Name = "toolStripSeparator3";
this.toolStripSeparator3.Size = new System.Drawing.Size(114, 6); this.toolStripSeparator3.Size = new System.Drawing.Size(141, 6);
// //
// 停止TToolStripMenuItem // 停止TToolStripMenuItem
// //
this.停止TToolStripMenuItem.Name = "停止TToolStripMenuItem"; this.停止TToolStripMenuItem.Name = "停止TToolStripMenuItem";
this.停止TToolStripMenuItem.Size = new System.Drawing.Size(117, 26); this.停止TToolStripMenuItem.Size = new System.Drawing.Size(144, 32);
this.停止TToolStripMenuItem.Text = "停止"; this.停止TToolStripMenuItem.Text = "停止";
this.停止TToolStripMenuItem.Click += new System.EventHandler(this.停止所有料仓TToolStripMenuItem_Click); this.停止TToolStripMenuItem.Click += new System.EventHandler(this.停止所有料仓TToolStripMenuItem_Click);
// //
// toolStripSeparator5 // toolStripSeparator5
// //
this.toolStripSeparator5.Name = "toolStripSeparator5"; this.toolStripSeparator5.Name = "toolStripSeparator5";
this.toolStripSeparator5.Size = new System.Drawing.Size(114, 6); this.toolStripSeparator5.Size = new System.Drawing.Size(141, 6);
// //
// toolStripSeparator2 // toolStripSeparator2
// //
this.toolStripSeparator2.Name = "toolStripSeparator2"; this.toolStripSeparator2.Name = "toolStripSeparator2";
this.toolStripSeparator2.Size = new System.Drawing.Size(114, 6); this.toolStripSeparator2.Size = new System.Drawing.Size(141, 6);
this.toolStripSeparator2.Visible = false; this.toolStripSeparator2.Visible = false;
// //
// 退出ToolStripMenuItem // 退出ToolStripMenuItem
// //
this.退出ToolStripMenuItem.Name = "退出ToolStripMenuItem"; this.退出ToolStripMenuItem.Name = "退出ToolStripMenuItem";
this.退出ToolStripMenuItem.Size = new System.Drawing.Size(117, 26); this.退出ToolStripMenuItem.Size = new System.Drawing.Size(144, 32);
this.退出ToolStripMenuItem.Text = "退出"; this.退出ToolStripMenuItem.Text = "退出";
this.退出ToolStripMenuItem.Click += new System.EventHandler(this.退出ToolStripMenuItem_Click_1); this.退出ToolStripMenuItem.Click += new System.EventHandler(this.退出ToolStripMenuItem_Click_1);
// //
...@@ -413,42 +421,42 @@ ...@@ -413,42 +421,42 @@
this.toolStripSeparator16, this.toolStripSeparator16,
this.toolStripMenuItem3}); this.toolStripMenuItem3});
this.设置TToolStripMenuItem.Name = "设置TToolStripMenuItem"; this.设置TToolStripMenuItem.Name = "设置TToolStripMenuItem";
this.设置TToolStripMenuItem.Size = new System.Drawing.Size(91, 25); this.设置TToolStripMenuItem.Size = new System.Drawing.Size(112, 31);
this.设置TToolStripMenuItem.Text = "设备调试 "; this.设置TToolStripMenuItem.Text = "设备调试 ";
// //
// toolStripSeparator6 // toolStripSeparator6
// //
this.toolStripSeparator6.Name = "toolStripSeparator6"; this.toolStripSeparator6.Name = "toolStripSeparator6";
this.toolStripSeparator6.Size = new System.Drawing.Size(173, 6); this.toolStripSeparator6.Size = new System.Drawing.Size(215, 6);
this.toolStripSeparator6.Visible = false; this.toolStripSeparator6.Visible = false;
// //
// 二维码学习ToolStripMenuItem // 二维码学习ToolStripMenuItem
// //
this.二维码学习ToolStripMenuItem.Name = "二维码学习ToolStripMenuItem"; this.二维码学习ToolStripMenuItem.Name = "二维码学习ToolStripMenuItem";
this.二维码学习ToolStripMenuItem.Size = new System.Drawing.Size(176, 26); this.二维码学习ToolStripMenuItem.Size = new System.Drawing.Size(218, 32);
this.二维码学习ToolStripMenuItem.Text = "二维码学习"; this.二维码学习ToolStripMenuItem.Text = "二维码学习";
this.二维码学习ToolStripMenuItem.Click += new System.EventHandler(this.二维码学习ToolStripMenuItem_Click); this.二维码学习ToolStripMenuItem.Click += new System.EventHandler(this.二维码学习ToolStripMenuItem_Click);
// //
// toolStripSeparator7 // toolStripSeparator7
// //
this.toolStripSeparator7.Name = "toolStripSeparator7"; this.toolStripSeparator7.Name = "toolStripSeparator7";
this.toolStripSeparator7.Size = new System.Drawing.Size(173, 6); this.toolStripSeparator7.Size = new System.Drawing.Size(215, 6);
// //
// 托盘初始化ToolStripMenuItem // 托盘初始化ToolStripMenuItem
// //
this.托盘初始化ToolStripMenuItem.Name = "托盘初始化ToolStripMenuItem"; this.托盘初始化ToolStripMenuItem.Name = "托盘初始化ToolStripMenuItem";
this.托盘初始化ToolStripMenuItem.Size = new System.Drawing.Size(176, 26); this.托盘初始化ToolStripMenuItem.Size = new System.Drawing.Size(218, 32);
this.托盘初始化ToolStripMenuItem.Text = "托盘编码"; this.托盘初始化ToolStripMenuItem.Text = "托盘编码";
// //
// toolStripSeparator16 // toolStripSeparator16
// //
this.toolStripSeparator16.Name = "toolStripSeparator16"; this.toolStripSeparator16.Name = "toolStripSeparator16";
this.toolStripSeparator16.Size = new System.Drawing.Size(173, 6); this.toolStripSeparator16.Size = new System.Drawing.Size(215, 6);
// //
// toolStripMenuItem3 // toolStripMenuItem3
// //
this.toolStripMenuItem3.Name = "toolStripMenuItem3"; this.toolStripMenuItem3.Name = "toolStripMenuItem3";
this.toolStripMenuItem3.Size = new System.Drawing.Size(176, 26); this.toolStripMenuItem3.Size = new System.Drawing.Size(218, 32);
this.toolStripMenuItem3.Text = "脆盘料号配置"; this.toolStripMenuItem3.Text = "脆盘料号配置";
this.toolStripMenuItem3.Click += new System.EventHandler(this.toolStripMenuItem3_Click); this.toolStripMenuItem3.Click += new System.EventHandler(this.toolStripMenuItem3_Click);
// //
...@@ -461,37 +469,37 @@ ...@@ -461,37 +469,37 @@
this.toolStripSeparator11, this.toolStripSeparator11,
this.版本号ToolStripMenuItem}); this.版本号ToolStripMenuItem});
this.帮助ToolStripMenuItem.Name = "帮助ToolStripMenuItem"; this.帮助ToolStripMenuItem.Name = "帮助ToolStripMenuItem";
this.帮助ToolStripMenuItem.Size = new System.Drawing.Size(69, 25); this.帮助ToolStripMenuItem.Size = new System.Drawing.Size(84, 31);
this.帮助ToolStripMenuItem.Text = " 系统 "; this.帮助ToolStripMenuItem.Text = " 系统 ";
// //
// 清空日志ToolStripMenuItem // 清空日志ToolStripMenuItem
// //
this.清空日志ToolStripMenuItem.Name = "清空日志ToolStripMenuItem"; this.清空日志ToolStripMenuItem.Name = "清空日志ToolStripMenuItem";
this.清空日志ToolStripMenuItem.Size = new System.Drawing.Size(144, 26); this.清空日志ToolStripMenuItem.Size = new System.Drawing.Size(178, 32);
this.清空日志ToolStripMenuItem.Text = "清空日志"; this.清空日志ToolStripMenuItem.Text = "清空日志";
this.清空日志ToolStripMenuItem.Click += new System.EventHandler(this.清空日志ToolStripMenuItem_Click); this.清空日志ToolStripMenuItem.Click += new System.EventHandler(this.清空日志ToolStripMenuItem_Click);
// //
// toolStripSeparator10 // toolStripSeparator10
// //
this.toolStripSeparator10.Name = "toolStripSeparator10"; this.toolStripSeparator10.Name = "toolStripSeparator10";
this.toolStripSeparator10.Size = new System.Drawing.Size(141, 6); this.toolStripSeparator10.Size = new System.Drawing.Size(175, 6);
// //
// 复制日志ToolStripMenuItem // 复制日志ToolStripMenuItem
// //
this.复制日志ToolStripMenuItem.Name = "复制日志ToolStripMenuItem"; this.复制日志ToolStripMenuItem.Name = "复制日志ToolStripMenuItem";
this.复制日志ToolStripMenuItem.Size = new System.Drawing.Size(144, 26); this.复制日志ToolStripMenuItem.Size = new System.Drawing.Size(178, 32);
this.复制日志ToolStripMenuItem.Text = "复制日志"; this.复制日志ToolStripMenuItem.Text = "复制日志";
this.复制日志ToolStripMenuItem.Click += new System.EventHandler(this.复制日志ToolStripMenuItem_Click); this.复制日志ToolStripMenuItem.Click += new System.EventHandler(this.复制日志ToolStripMenuItem_Click);
// //
// toolStripSeparator11 // toolStripSeparator11
// //
this.toolStripSeparator11.Name = "toolStripSeparator11"; this.toolStripSeparator11.Name = "toolStripSeparator11";
this.toolStripSeparator11.Size = new System.Drawing.Size(141, 6); this.toolStripSeparator11.Size = new System.Drawing.Size(175, 6);
// //
// 版本号ToolStripMenuItem // 版本号ToolStripMenuItem
// //
this.版本号ToolStripMenuItem.Name = "版本号ToolStripMenuItem"; this.版本号ToolStripMenuItem.Name = "版本号ToolStripMenuItem";
this.版本号ToolStripMenuItem.Size = new System.Drawing.Size(144, 26); this.版本号ToolStripMenuItem.Size = new System.Drawing.Size(178, 32);
this.版本号ToolStripMenuItem.Text = "关于软件"; this.版本号ToolStripMenuItem.Text = "关于软件";
this.版本号ToolStripMenuItem.Click += new System.EventHandler(this.版本号ToolStripMenuItem_Click); this.版本号ToolStripMenuItem.Click += new System.EventHandler(this.版本号ToolStripMenuItem_Click);
// //
...@@ -499,6 +507,7 @@ ...@@ -499,6 +507,7 @@
// //
this.menuStrip1.BackColor = System.Drawing.Color.White; this.menuStrip1.BackColor = System.Drawing.Color.White;
this.menuStrip1.Font = new System.Drawing.Font("微软雅黑", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); this.menuStrip1.Font = new System.Drawing.Font("微软雅黑", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.menuStrip1.ImageScalingSize = new System.Drawing.Size(20, 20);
this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.操作ToolStripMenuItem, this.操作ToolStripMenuItem,
this.运行参数ToolStripMenuItem, this.运行参数ToolStripMenuItem,
...@@ -506,7 +515,7 @@ ...@@ -506,7 +515,7 @@
this.帮助ToolStripMenuItem}); this.帮助ToolStripMenuItem});
this.menuStrip1.Location = new System.Drawing.Point(0, 0); this.menuStrip1.Location = new System.Drawing.Point(0, 0);
this.menuStrip1.Name = "menuStrip1"; this.menuStrip1.Name = "menuStrip1";
this.menuStrip1.Size = new System.Drawing.Size(1004, 29); this.menuStrip1.Size = new System.Drawing.Size(1004, 35);
this.menuStrip1.TabIndex = 4; this.menuStrip1.TabIndex = 4;
this.menuStrip1.Text = "menuStrip1"; this.menuStrip1.Text = "menuStrip1";
// //
...@@ -522,37 +531,37 @@ ...@@ -522,37 +531,37 @@
this.禁用安全光栅ToolStripMenuItem, this.禁用安全光栅ToolStripMenuItem,
this.启用门禁ToolStripMenuItem}); this.启用门禁ToolStripMenuItem});
this.运行参数ToolStripMenuItem.Name = "运行参数ToolStripMenuItem"; this.运行参数ToolStripMenuItem.Name = "运行参数ToolStripMenuItem";
this.运行参数ToolStripMenuItem.Size = new System.Drawing.Size(86, 25); this.运行参数ToolStripMenuItem.Size = new System.Drawing.Size(106, 31);
this.运行参数ToolStripMenuItem.Text = "运行参数"; this.运行参数ToolStripMenuItem.Text = "运行参数";
// //
// 开机自动启动ToolStripMenuItem // 开机自动启动ToolStripMenuItem
// //
this.开机自动启动ToolStripMenuItem.Name = "开机自动启动ToolStripMenuItem"; this.开机自动启动ToolStripMenuItem.Name = "开机自动启动ToolStripMenuItem";
this.开机自动启动ToolStripMenuItem.Size = new System.Drawing.Size(206, 26); this.开机自动启动ToolStripMenuItem.Size = new System.Drawing.Size(254, 32);
this.开机自动启动ToolStripMenuItem.Text = "开机自动启动"; this.开机自动启动ToolStripMenuItem.Text = "开机自动启动";
this.开机自动启动ToolStripMenuItem.Click += new System.EventHandler(this.开机自动启动ToolStripMenuItem_Click); this.开机自动启动ToolStripMenuItem.Click += new System.EventHandler(this.开机自动启动ToolStripMenuItem_Click);
// //
// toolStripSeparator15 // toolStripSeparator15
// //
this.toolStripSeparator15.Name = "toolStripSeparator15"; this.toolStripSeparator15.Name = "toolStripSeparator15";
this.toolStripSeparator15.Size = new System.Drawing.Size(203, 6); this.toolStripSeparator15.Size = new System.Drawing.Size(251, 6);
// //
// 启用蜂鸣器ToolStripMenuItem // 启用蜂鸣器ToolStripMenuItem
// //
this.启用蜂鸣器ToolStripMenuItem.Name = "启用蜂鸣器ToolStripMenuItem"; this.启用蜂鸣器ToolStripMenuItem.Name = "启用蜂鸣器ToolStripMenuItem";
this.启用蜂鸣器ToolStripMenuItem.Size = new System.Drawing.Size(206, 26); this.启用蜂鸣器ToolStripMenuItem.Size = new System.Drawing.Size(254, 32);
this.启用蜂鸣器ToolStripMenuItem.Text = "启用蜂鸣器"; this.启用蜂鸣器ToolStripMenuItem.Text = "启用蜂鸣器";
this.启用蜂鸣器ToolStripMenuItem.Click += new System.EventHandler(this.启用蜂鸣器ToolStripMenuItem_Click); this.启用蜂鸣器ToolStripMenuItem.Click += new System.EventHandler(this.启用蜂鸣器ToolStripMenuItem_Click);
// //
// toolStripSeparator25 // toolStripSeparator25
// //
this.toolStripSeparator25.Name = "toolStripSeparator25"; this.toolStripSeparator25.Name = "toolStripSeparator25";
this.toolStripSeparator25.Size = new System.Drawing.Size(203, 6); this.toolStripSeparator25.Size = new System.Drawing.Size(251, 6);
// //
// aGVCancelStateToolStripMenuItem // aGVCancelStateToolStripMenuItem
// //
this.aGVCancelStateToolStripMenuItem.Name = "aGVCancelStateToolStripMenuItem"; this.aGVCancelStateToolStripMenuItem.Name = "aGVCancelStateToolStripMenuItem";
this.aGVCancelStateToolStripMenuItem.Size = new System.Drawing.Size(206, 26); this.aGVCancelStateToolStripMenuItem.Size = new System.Drawing.Size(254, 32);
this.aGVCancelStateToolStripMenuItem.Text = "AGV cancelState"; this.aGVCancelStateToolStripMenuItem.Text = "AGV cancelState";
this.aGVCancelStateToolStripMenuItem.Visible = false; this.aGVCancelStateToolStripMenuItem.Visible = false;
this.aGVCancelStateToolStripMenuItem.Click += new System.EventHandler(this.aGVCancelStateToolStripMenuItem_Click); this.aGVCancelStateToolStripMenuItem.Click += new System.EventHandler(this.aGVCancelStateToolStripMenuItem_Click);
...@@ -560,20 +569,20 @@ ...@@ -560,20 +569,20 @@
// toolStripSeparator17 // toolStripSeparator17
// //
this.toolStripSeparator17.Name = "toolStripSeparator17"; this.toolStripSeparator17.Name = "toolStripSeparator17";
this.toolStripSeparator17.Size = new System.Drawing.Size(203, 6); this.toolStripSeparator17.Size = new System.Drawing.Size(251, 6);
this.toolStripSeparator17.Visible = false; this.toolStripSeparator17.Visible = false;
// //
// 禁用安全光栅ToolStripMenuItem // 禁用安全光栅ToolStripMenuItem
// //
this.禁用安全光栅ToolStripMenuItem.Name = "禁用安全光栅ToolStripMenuItem"; this.禁用安全光栅ToolStripMenuItem.Name = "禁用安全光栅ToolStripMenuItem";
this.禁用安全光栅ToolStripMenuItem.Size = new System.Drawing.Size(206, 26); this.禁用安全光栅ToolStripMenuItem.Size = new System.Drawing.Size(254, 32);
this.禁用安全光栅ToolStripMenuItem.Text = "启用安全光栅"; this.禁用安全光栅ToolStripMenuItem.Text = "启用安全光栅";
this.禁用安全光栅ToolStripMenuItem.Click += new System.EventHandler(this.启用安全光栅ToolStripMenuItem_Click); this.禁用安全光栅ToolStripMenuItem.Click += new System.EventHandler(this.启用安全光栅ToolStripMenuItem_Click);
// //
// 启用门禁ToolStripMenuItem // 启用门禁ToolStripMenuItem
// //
this.启用门禁ToolStripMenuItem.Name = "启用门禁ToolStripMenuItem"; this.启用门禁ToolStripMenuItem.Name = "启用门禁ToolStripMenuItem";
this.启用门禁ToolStripMenuItem.Size = new System.Drawing.Size(206, 26); this.启用门禁ToolStripMenuItem.Size = new System.Drawing.Size(254, 32);
this.启用门禁ToolStripMenuItem.Text = "启用门禁"; this.启用门禁ToolStripMenuItem.Text = "启用门禁";
this.启用门禁ToolStripMenuItem.Click += new System.EventHandler(this.启用门禁ToolStripMenuItem_Click); this.启用门禁ToolStripMenuItem.Click += new System.EventHandler(this.启用门禁ToolStripMenuItem_Click);
// //
......
...@@ -288,7 +288,7 @@ namespace OnlineStore.DeviceLibrary ...@@ -288,7 +288,7 @@ namespace OnlineStore.DeviceLibrary
case RunStatus.Runing: case RunStatus.Runing:
if ((isInSuddenDown.Equals(false) && isNoAirpressure_Check.Equals(false))) if ((isInSuddenDown.Equals(false) && isNoAirpressure_Check.Equals(false)))
{ {
//清理超时异常 //清理异常
IOTimeOutProcess(); IOTimeOutProcess();
} }
break; break;
......
...@@ -399,6 +399,7 @@ namespace OnlineStore.DeviceLibrary ...@@ -399,6 +399,7 @@ namespace OnlineStore.DeviceLibrary
getPosIdMsg = result.Msg; getPosIdMsg = result.Msg;
Thread.Sleep(ms); Thread.Sleep(ms);
LogUtil.error(Name + "【" + pos.barcode + "】第[" + count + "]次 " + MoveInfo.SLog + " 结果【" + result.Result + "】,等待" + ms + "后重新获取"); LogUtil.error(Name + "【" + pos.barcode + "】第[" + count + "]次 " + MoveInfo.SLog + " 结果【" + result.Result + "】,等待" + ms + "后重新获取");
continue;
} }
else if (!result.Result.Equals(0)) else if (!result.Result.Equals(0))
{ {
......
...@@ -58,20 +58,18 @@ namespace OnlineStore.DeviceLibrary ...@@ -58,20 +58,18 @@ namespace OnlineStore.DeviceLibrary
} }
else if (MoveInfo.IsStep(StepEnum.Outlet_02_CheckTray)) else if (MoveInfo.IsStep(StepEnum.Outlet_02_CheckTray))
{ {
if (TrayCheck()) //if (TrayCheck())
{ {
NextMoveStep(StepEnum.Outlet_03_CheckAllowFeedOut, "有料盘,准备送走"); NextMoveStep(StepEnum.Outlet_03_CheckAllowFeedOut, "有料盘,准备送走");
AddWaitAllowFeedOut(true); AddWaitAllowFeedOut(true);
AddWaitTime(2000);
MoveInfo.OneWaitCanEndStep = true;
}
else//无料盘
{
NextMoveStep(StepEnum.Outlet_05_JackUp, "无料盘,顶升抬起,准备料盘放入");
JackUp(true);
if (BufferDataManager.TrayInOutletInfo != null)
BufferDataManager.TrayInOutletInfo = null;
} }
//else//无料盘
//{
// NextMoveStep(StepEnum.Outlet_05_JackUp, "无料盘,顶升抬起,准备料盘放入");
// JackUp(true);
// if (BufferDataManager.TrayInOutletInfo != null)
// BufferDataManager.TrayInOutletInfo = null;
//}
} }
else if (MoveInfo.IsStep(StepEnum.Outlet_03_CheckAllowFeedOut)) else if (MoveInfo.IsStep(StepEnum.Outlet_03_CheckAllowFeedOut))
{ {
...@@ -79,7 +77,7 @@ namespace OnlineStore.DeviceLibrary ...@@ -79,7 +77,7 @@ namespace OnlineStore.DeviceLibrary
OutletRun(true); OutletRun(true);
AddWaitTrayCheck1(false); AddWaitTrayCheck1(false);
AddWaitTrayCheck2(false); AddWaitTrayCheck2(false);
//AddWaitAllowFeedOut(false); AddWaitAllowFeedOut(false);
} }
else if (MoveInfo.IsStep(StepEnum.Outlet_04_WaitTrayLeave)) else if (MoveInfo.IsStep(StepEnum.Outlet_04_WaitTrayLeave))
{ {
......
...@@ -214,7 +214,7 @@ namespace OnlineStore.DeviceLibrary ...@@ -214,7 +214,7 @@ namespace OnlineStore.DeviceLibrary
{ {
MoveInfo.EndMove(); MoveInfo.EndMove();
runStatus = RunStatus.Runing; runStatus = RunStatus.Runing;
BufferDataManager.TrayInRobotInfo=null; BufferDataManager.TrayInRobotInfo = null;
} }
else else
{ {
...@@ -438,6 +438,7 @@ namespace OnlineStore.DeviceLibrary ...@@ -438,6 +438,7 @@ namespace OnlineStore.DeviceLibrary
#region NG #region NG
bool preNgSig = false; bool preNgSig = false;
bool curNgSig = false; bool curNgSig = false;
AlarmType preAlram = AlarmType.None;
void NGBoxProcess() void NGBoxProcess()
{ {
preNgSig = curNgSig; preNgSig = curNgSig;
...@@ -449,10 +450,23 @@ namespace OnlineStore.DeviceLibrary ...@@ -449,10 +450,23 @@ namespace OnlineStore.DeviceLibrary
if (NGBoxAlarm()) if (NGBoxAlarm())
{ {
SetWarnMsg($"NG箱中的料盘需要处理,数量大于{validityCnt}或者料盘放置时间大于{validityPeriod}分钟"); SetWarnMsg($"NG箱中的料盘需要处理,数量大于{validityCnt}或者料盘放置时间大于{validityPeriod}分钟");
if (alarmType <= AlarmType.AxisAlarm)
{
preAlram = alarmType;
Alarm(AlarmType.NGBoxWarn);
}
} }
else else
{ {
ClearSpecifiedAlarm($"NG箱中的料盘需要处理,数量大于"); ClearSpecifiedAlarm($"NG箱中的料盘需要处理,数量大于");
if (isInSuddenDown || isNoAirpressure_Check)
{
return;
}
if (alarmType.Equals(AlarmType.NGBoxWarn))
{
alarmType = preAlram;
}
} }
} }
#endregion #endregion
......
...@@ -84,6 +84,7 @@ namespace OnlineStore.DeviceLibrary ...@@ -84,6 +84,7 @@ namespace OnlineStore.DeviceLibrary
if (!bean.RobotData.Online) if (!bean.RobotData.Online)
{ {
SetWarnMsg("无法读取机器人状态,因机器人离线"); SetWarnMsg("无法读取机器人状态,因机器人离线");
Alarm(AlarmType.RobotError);
robotOnline = false; robotOnline = false;
return false; return false;
} }
......
...@@ -405,6 +405,10 @@ namespace OnlineStore.DeviceLibrary ...@@ -405,6 +405,10 @@ namespace OnlineStore.DeviceLibrary
/// 收到急停 /// 收到急停
/// </summary> /// </summary>
SuddenStop = 10000, SuddenStop = 10000,
/// <summary>
/// 机器人报警
/// </summary>
RobotError=20000,
NGBoxWarn=30000
} }
} }
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Dolen.Agv
{
class Client
{
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Dolen.Agv
{
/// <summary>
/// 客户端的动作
/// </summary>
public enum ClientAction : byte
{
/// <summary>
/// 没有动作
/// </summary>
None,
#region 服务器发送
/// <summary>
/// 到达线体(服务端)
/// </summary>
Arrive,
/// <summary>
/// 小车准备好(服务端)
/// </summary>
Ready,
/// <summary>
/// 料架请求进入线体(服务端)
/// </summary>
ReadyEnter,
/// <summary>
/// 料架正在进入线体(服务端)
/// </summary>
Entering,
/// <summary>
/// 料架请求离开线体(服务端)
/// </summary>
ReadyLeave,
/// <summary>
/// 料架正在离开线体(服务端)
/// </summary>
Leaving,
/// <summary>
/// 完成进入/离开(服务端)
/// </summary>
Complete,
#endregion
#region 客户端
/// <summary>
/// 线体需要流入料架(客户端)
/// </summary>
NeedEnter,
/// <summary>
/// 线体需要流出料架(客户端)
/// </summary>
NeedLeave,
/// <summary>
/// 线体可以进入料架/线体可以流出料架(客户端)
/// </summary>
NeedEnterLeave,
/// <summary>
/// 允许料架进入线体(客户端)
/// </summary>
MayEnter,
/// <summary>
/// 允许料架流出线体(客户端)
/// </summary>
MayLeave,
/// <summary>
/// 料架进入线体完成(客户端)
/// </summary>
FinishEnter,
/// <summary>
/// 料架流出线体完成(客户端)
/// </summary>
FinishLeave,
/// <summary>
/// 不允许料架进入线体(客户端)
/// </summary>
MayNotEnter,
/// <summary>
/// 不允许料架流出线体(客户端)
/// </summary>
MayNotLeave,
#endregion
}
/// <summary>
/// 客户端的优先级
/// </summary>
public enum ClientLevel : byte
{
None,
/// <summary>
/// 低
/// </summary>
Low,
/// <summary>
/// 中等
/// </summary>
Middle,
/// <summary>
/// 高
/// </summary>
High
}
/// <summary>
/// 客户端的料架类型
/// </summary>
public enum ClientShelf : byte
{
/// <summary>
/// 没有架子
/// </summary>
None,
/// <summary>
/// 空架子
/// </summary>
Empty,
/// <summary>
/// 满架子
/// </summary>
Full,
/// <summary>
/// 空的料串
/// </summary>
EmptyString,
/// <summary>
/// 满料串
/// </summary>
FullString,
/// <summary>
/// 空料架
/// </summary>
EmptyShelf,
/// <summary>
/// 满料架
/// </summary>
FullShelf,
/// <summary>
/// 空包装料架
/// </summary>
EmptyPack,
/// <summary>
/// 满包装料架
/// </summary>
FullPack,
}
/// <summary>
/// 客户端类型
/// </summary>
public enum ClientType : byte
{
/// <summary>
/// 无
/// </summary>
None,
/// <summary>
/// 紧急料线体
/// </summary>
Urgent,
/// <summary>
/// 包装料线体
/// </summary>
Pack,
/// <summary>
/// 分盘料线体
/// </summary>
Cut,
/// <summary>
/// 混合料线体
/// </summary>
Mix
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Dolen.Agv
{
/// <summary>
/// 客户端节点
/// </summary>
public class ClientNode
{
/// <summary>
/// 编号
/// </summary>
public int ID { get; private set; }
/// <summary>
/// IP地址
/// </summary>
public string IP { get; private set; }
/// <summary>
/// 名称
/// </summary>
public string Name { get; private set; }
/// <summary>
/// 别名
/// </summary>
public string AliceName { get; set; } = "";
/// <summary>
/// 料架号
/// </summary>
public string RFID { set; get; } = "";
/// <summary>
/// 备注
/// </summary>
public string Remark { set; get; } = "";
/// <summary>
/// 在线状态
/// </summary>
public bool Online { get; private set; } = false;
/// <summary>
/// 是否开启
/// </summary>
public bool Enabled { private set; get; }
/// <summary>
/// 动作
/// </summary>
public ClientAction Action { set; get; } = ClientAction.None;
/// <summary>
/// 优先级
/// </summary>
public ClientLevel Level { set; get; } = ClientLevel.None;
/// <summary>
/// 客户端类型
/// </summary>
public ClientType Type {private set; get; } = ClientType.None;
/// <summary>
/// 料架类型
/// </summary>
public ClientShelf Shelf { private set; get; } = ClientShelf.None;
public ClientNode(int id,string ip,string name,bool enabled=false,ClientType clientType = ClientType.None)
{
ID = id;
IP = ip;
Name = name;
AliceName = name;
Enabled = enabled;
Type = clientType;
}
/// <summary>
/// 修改节点状态
/// </summary>
/// <param name="action">动作</param>
/// <param name="rfid">rfid</param>
/// <param name="clientShelf">料架类型</param>
/// <param name="level">紧急程度</param>
public void ChangeState(ClientAction action, string rfid = "",ClientShelf clientShelf = ClientShelf.None,ClientLevel level= ClientLevel.None)
{
Action = action;
RFID = rfid;
Level = level;
}
/// <summary>
/// 所有属性的文本形式
/// </summary>
/// <returns></returns>
public string ToText()
{
System.Reflection.PropertyInfo[] info = this.GetType().GetProperties();
string[] arr = new string[info.Length];
for (int i = 0; i < info.Length; i++)
arr[i] = info[i].Name + "=" + info[i].GetValue(this).ToString();
return string.Join(",", arr);
}
public override bool Equals(object obj)
{
if (obj is ClientNode)
{
ClientNode node = (ClientNode)obj;
if (ID.Equals(node.ID) && RFID.Equals(node.RFID) && Remark.Equals(node.Remark) &&
Action.Equals(node.Action) && Level.Equals(node.Level) && Type.Equals(node.Type) &&
Shelf.Equals(node.Shelf))
return true;
else
return false;
}
return false;
}
///// <summary>
///// 拷贝一个新的实例
///// </summary>
///// <returns></returns>
//public Node ToCopy()
//{
// Node node = new Node();
// System.Reflection.PropertyInfo[] info1 = node.GetType().GetProperties();
// System.Reflection.PropertyInfo[] info2 = this.GetType().GetProperties();
// for (int i = 0; i < info1.Length; i++)
// info1[i].SetValue(node, info2[i].GetValue(this));
// return node;
//}
/// <summary>
/// 节点离线
/// </summary>
public void Offline()
{
RFID = "";
Remark = "";
Action = ClientAction.None;
Level = ClientLevel.None;
Shelf = ClientShelf.None;
Online = false;
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Sockets;
using System.Threading;
using Dolen;
namespace Dolen.Agv
{
public class Server
{
private bool loop;
private Socket _server; //服务端
Dictionary<string, Client> dictClient = new Dictionary<string, Client>(); //所有客户端
private Thread tListenClient; //监听客户端连接
private Thread tKeepLive;//心跳线程
private Dictionary<string, bool> nodeOnline = new Dictionary<string, bool>();
public delegate void NodeChangedEvent(Node clientNode);
public delegate void NodeOnlineEvent(string nodeName, bool online);
public event NodeChangedEvent NodeChanged;
public event NodeOnlineEvent NodeOnline;
private string serverIp;
private int serverPort;
private Dictionary<string, Node> nodeMap = new Dictionary<string, Node>();
private static Log log = new Log();
/// <summary>
/// 服务端信息
/// </summary>
public string ServerInfo
{
get
{
return string.Format("{0}:{1}", serverIp, serverPort.ToString());
}
}
/// <summary>
/// 开启服务
/// </summary>
public void Start(string ip = "0.0.0.0", int port = 12000)
{
try
{
log.Info($"AGV 服务端开启:{ip}:{port}");
serverIp = ip;
serverPort = port;
IPEndPoint localEP;
if (ip.Equals("0.0.0.0"))
localEP = new IPEndPoint(IPAddress.Any, serverPort);
else
localEP = new IPEndPoint(IPAddress.Parse(ip), serverPort);
_server = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
_server.Bind(localEP);
_server.Listen(100);
loop = true;
tListenClient = new Thread(new ThreadStart(ListenClient));
tListenClient.IsBackground = true;
tListenClient.Start();
tKeepLive = new Thread(new ThreadStart(KeepClientLive));
tKeepLive.IsBackground = true;
tKeepLive.Start();
}
catch (Exception ex)
{
log.Error($"AGV 服务端开启:{ip}:{port}", ex);
}
}
/// <summary>
/// 停止服务
/// </summary>
public void Stop()
{
try
{
loop = false;
foreach (string c in dictClient.Keys)
{
try
{
dictClient[c].ListenNet.Abort();
}
catch (Exception ex)
{
log.Error(string.Format("关闭连接客户端[{0}]线程失败", c), ex);
}
try
{
dictClient[c].Socket.Close();
}
catch (Exception ex)
{
log.Error(string.Format("关闭连接客户端[{0}]Socket失败", c), ex);
}
}
if (dictClient.Count > 0) dictClient.Clear();
if (nodeMap.Count > 0)
nodeMap.Clear();
if (_server != null)
{
_server.Close();
_server.Dispose();
}
}
catch (Exception ex)
{
log.Error("AGV 服务端关闭", ex);
}
}
/// <summary>
/// 向客户端发送命令
/// </summary>
/// <param name="info"></param>
/// <returns></returns>
public bool SendToClient(int id, string RFID, ClientAction action)
{
string tar = "";
int n = 0;
do
{
tar = FindClient(nodeName);
if (tar.Equals(""))
{
log.Error("没有找到" + nodeName);
Thread.Sleep(500);
n++;
}
else
{
n = 10;
}
} while (n < 4);
if (tar.Equals("")) return false;
Node node = new Node(nodeName, RFID, action);
log.info("SendTo " + nodeName + " RFID=" + RFID + " " + action);
byte[] buff = Common.Encode(node);
return Send(tar, buff);
}
/// <summary>
/// 小车到达
/// </summary>
/// <param name="info"></param>
/// <returns></returns>
public bool Arrive(string nodeName, string RFID = "")
{
string tar = "";
int n = 0;
do
{
tar = FindClient(nodeName);
if (tar.Equals(""))
{
log.error("Arrive: 没有找到" + nodeName);
Thread.Sleep(500);
n++;
}
else
{
n = 10;
}
} while (n < 4);
if (tar.Equals("")) return false;
Node node = new Node(nodeName, RFID, ClientAction.Arrive);
log.info("SendTo " + nodeName + " RFID=" + RFID + " " + ClientAction.Arrive);
byte[] buff = Common.Encode(node);
return Send(tar, buff);
}
/// <summary>
/// 小车已准备好
/// </summary>
/// <param name="info"></param>
/// <returns></returns>
public bool Ready(string nodeName, string RFID = "")
{
string tar = "";
int n = 0;
do
{
tar = FindClient(nodeName);
if (tar.Equals(""))
{
log.error("Ready: 没有找到" + nodeName);
Thread.Sleep(500);
n++;
}
else
{
n = 10;
}
} while (n < 4);
if (tar.Equals("")) return false;
Node node = new Node(nodeName, RFID, ClientAction.Ready);
log.info("SendTo " + nodeName + " RFID=" + RFID + " " + ClientAction.Ready);
byte[] buff = Common.Encode(node);
return Send(tar, buff);
}
/// <summary>
/// 关门
/// </summary>
/// <param name="info"></param>
/// <returns></returns>
public bool CloseDoor(string nodeName, string RFID = "")
{
string tar = "";
int n = 0;
do
{
tar = FindClient(nodeName);
if (tar.Equals(""))
{
log.debug("CloseDoor: 没有找到" + nodeName);
Thread.Sleep(500);
n++;
}
else
{
n = 10;
}
} while (n < 4);
if (tar.Equals("")) return false;
Node node = new Node(nodeName, RFID, ClientAction.CloseDoor);
log.info("SendTo " + nodeName + " RFID=" + RFID + " " + ClientAction.CloseDoor);
byte[] buff = Common.Encode(node);
return Send(tar, buff);
}
/// <summary>
/// 监听客户端连接
/// </summary>
private void ListenClient()
{
while (loop)
{
try
{
// 开始监听客户端连接请求,Accept方法会阻断当前的线程;
Socket sokConnection = _server.Accept(); // 一旦监听到一个客户端的请求,就返回一个与该客户端通信的 套接字;
IPEndPoint endPoint = (IPEndPoint)sokConnection.RemoteEndPoint;
string ip = endPoint.Address.ToString();
int port = endPoint.Port;
if (dictClient.TryGetValue(ip, out Client client1))
{
Offline(client1);
Thread.Sleep(2000);
log.debug(string.Format("断开"));
}
Thread thr = new Thread(ListenNet);
Client client = new Client(sokConnection, thr, ip, endPoint.ToString());
thr.IsBackground = true;
dictClient.Add(ip, client);
thr.Start(client);
log.info(string.Format("客户端[{0}]连接服务端[{1}]成功", endPoint.ToString(), ServerInfo));
}
catch (SocketException)
{
//关闭连接,退出阻塞Accept
}
catch (Exception ex)
{
log.error("ListenClient", ex);
}
}
}
#region 粘包处理
//线程安全的字典
ConcurrentDictionary<string, byte[]> dic = new ConcurrentDictionary<string, byte[]>();
/// <summary>
/// 处理客户端发来的数据
/// </summary>
/// <param name="obj">每个客户的会话ID</param>
/// <param name="bytes">缓冲区数据</param>
/// <returns></returns>
private void StickyBagHandle(Client client, byte[] bytes)
{
//bytes 为系统缓冲区数据
//bytesRead为系统缓冲区长度
int bytesRead = bytes.Length;
string endpoint = client.IP;
if (bytesRead > 0)
{
byte[] surplusBuffer = null;
if (dic.TryGetValue(endpoint, out surplusBuffer))
{
byte[] curBuffer = surplusBuffer.Concat(bytes).ToArray();//拼接上一次剩余的包
if (Common.CheckHeadChar(bytes, out int startIdx))//检查是否存在指定包头识别字符
{
byte[] tmp = new byte[bytesRead - startIdx];
Buffer.BlockCopy(bytes, startIdx, tmp, 0, bytesRead - startIdx);
//更新会话ID 的最新字节
dic.TryUpdate(endpoint, tmp, surplusBuffer);
surplusBuffer = curBuffer;//同步
}
else
{
byte[] xbtye = null;
dic.TryRemove(endpoint, out xbtye);
}
}
else
{
if (Common.CheckHeadChar(bytes, out int startIdx))//检查是否存在指定包头识别字符
{
//添加会话ID的bytes
byte[] tmp = new byte[bytesRead - startIdx];
Buffer.BlockCopy(bytes, startIdx, tmp, 0, bytesRead - startIdx);
dic.TryAdd(endpoint, tmp);
surplusBuffer = tmp;//同步
}
else
return;
}
//已经完成读取每个数据包长度
int haveRead = 0;
//这里totalLen的长度有可能大于缓冲区大小的(因为 这里的surplusBuffer 是系统缓冲区+不完整的数据包)
int totalLen = surplusBuffer.Length;
while (haveRead <= totalLen)
{
//如果在N次拆解后剩余的数据包连一个包头的长度都不够
//说明是上次读取N个完整数据包后,剩下的最后一个非完整的数据包
if (totalLen - haveRead < Common.headSize)
{
byte[] byteSub = new byte[totalLen - haveRead];
//把剩下不够一个完整的数据包存起来
Buffer.BlockCopy(surplusBuffer, haveRead, byteSub, 0, totalLen - haveRead);
dic.TryUpdate(endpoint, byteSub, surplusBuffer);
surplusBuffer = byteSub;
totalLen = 0;
break;
}
//如果够了一个完整包,则读取包头的数据
byte[] headByte = new byte[Common.headSize];
Buffer.BlockCopy(surplusBuffer, haveRead, headByte, 0, Common.headSize);//从缓冲区里读取包头的字节
//判断包头起始符
int bodySize = BitConverter.ToUInt16(headByte, 2);//从包头里面分析出包体的长度
//这里的 haveRead=等于N个数据包的长度 从0开始;0,1,2,3....N
//如果自定义缓冲区拆解N个包后的长度 大于 总长度,说最后一段数据不够一个完整的包了,拆出来保存
if (haveRead + Common.headSize + bodySize > totalLen)
{
byte[] byteSub = new byte[totalLen - haveRead];
Buffer.BlockCopy(surplusBuffer, haveRead, byteSub, 0, totalLen - haveRead);
dic.TryUpdate(endpoint, byteSub, surplusBuffer);
surplusBuffer = byteSub;
break;
}
else
{
//挨个分解每个包,解析成实际文字
//String strc = Encoding.UTF8.GetString(surplusBuffer, haveRead + headSize, bodySize);
byte[] resBytes = new byte[bodySize];
Buffer.BlockCopy(surplusBuffer, haveRead + Common.headSize, resBytes, 0, bodySize);
log.debug(string.Format("[Receive data from:{0}] -> {1}", endpoint, Common.HexBuff(resBytes)));
DecodeNode(client, resBytes);
//依次累加当前的数据包的长度
haveRead = haveRead + Common.headSize + bodySize;
if (Common.headSize + bodySize == bytesRead)//如果当前接收的数据包长度正好等于缓冲区长度,则待拼接的不规则数据长度归0
{
byte[] xbtye = null;
dic.TryRemove(endpoint, out xbtye);
surplusBuffer = null;//设置空 回到原始状态
totalLen = 0;//清0
}
}
}
}
}
#endregion
private void DecodeNode(Client client, byte[] resultBytes)
{
//解码单个节点
if (Common.EnDecodeSingleNode)
{
Node node = Common.Decode(resultBytes);
if (node == null)
{
log.error("命令解析失败: " + Common.HexBuff(resultBytes));
}
else
{
//CommonVar.LogUtil.info("Receive[" + client.IP + "] " + node.ToText());
int idx = client.nodeName.FindIndex(s => s == node.Name);
if (idx == -1) client.nodeName.Add(node.Name);
UpdateNode(node);
}
}
else
{
//解码多个节点
List<Node> nodes = Common.DecodeNodes(resultBytes);
if (nodes == null)
{
log.error("命令解析失败: " + Common.HexBuff(resultBytes));
}
else
{
int idx = -1;
foreach (var node in nodes)
{
idx = client.nodeName.FindIndex(s => s == node.Name);
if (idx == -1) client.nodeName.Add(node.Name);
}
UpdateNodes(nodes);
}
}
}
/// <summary>
/// 客户端数据接收
/// </summary>
/// <param name="obj">索引</param>
private void ListenNet(object obj)
{
Client client = obj as Client;
Socket sokClient = client.Socket;
while (client.Loop)
{
Thread.Sleep(100);
try
{
// 定义一个缓存区;
byte[] arrMsgRec = new byte[1024];
// 将接收到的数据存入到输入 arrMsgRec中;
int length = -1;
if (!client.Loop) return;
if (sokClient != null && sokClient.Poll(-1, SelectMode.SelectRead))
{
length = sokClient.Receive(arrMsgRec); // 接收数据,并返回数据的长度;
if (length == 0)//连接正常断开
{
Offline(client);
log.info(string.Format("客户端[{0}]断开与服务端[{1}]的连接", sokClient.RemoteEndPoint.ToString(), ServerInfo));
return;
}
}
if (length > 0)
{
byte[] buff = new byte[length];
Array.Copy(arrMsgRec, 0, buff, 0, length);
StickyBagHandle(client, buff);
}
}
catch (Exception e)
{
}
}
}
/// <summary>
/// 查找客户端
/// </summary>
/// <param name="nodeName"></param>
/// <returns></returns>
private string FindClient(int id)
{
foreach (string item in dictClient.Keys)
{
if (dictClient[item].nodeName.Contains(nodeName))
return item;
}
return "";
}
private void UpdateNode(Node node)
{
if (!nodeOnline.Keys.Contains(node.Name))
{
nodeOnline.Add(node.Name, true);
NodeOnline?.Invoke(node.Name, true);
}
else if (nodeOnline[node.Name].Equals(false))
{
nodeOnline[node.Name] = true;
NodeOnline?.Invoke(node.Name, true);
}
if (!nodeMap.Keys.Contains(node.Name))
{
nodeMap.Add(node.Name, node);
NodeChanged?.Invoke(node);
log.info(string.Format("节点添加并状态更新[{0}]", node.ToText()));
}
else if (!nodeMap[node.Name].Equals(node))
{
nodeMap[node.Name] = node;
NodeChanged?.Invoke(node);
log.debug(string.Format("节点状态更新[{0}]", node.ToText()));
}
}
private void UpdateNodes(List<Node> nodes)
{
foreach (var node in nodes)
{
UpdateNode(node);
Thread.Sleep(200);
}
}
private void Offline(Client client)
{
try
{
client.Loop = false;
dictClient.Remove(client.IP);
if (client.Socket != null)
{
client.Socket.Close();
client.Socket = null;
}
for (int i = 0; i < client.nodeName.Count; i++)
{
if (!nodeOnline.Keys.Contains(client.nodeName[i]))
{
nodeOnline.Add(client.nodeName[i], false);
NodeOnline?.Invoke(client.nodeName[i], false);
}
else if (nodeOnline[client.nodeName[i]].Equals(true))
{
nodeOnline[client.nodeName[i]] = false;
NodeOnline?.Invoke(client.nodeName[i], false);
}
if (nodeMap.ContainsKey(client.nodeName[i]))
nodeMap.Remove(client.nodeName[i]);
}
client.nodeName.Clear();
client.ListenNet.Abort();
log.info(string.Format("关闭对客户端[{0}]的监听线程", client.Endpoint));
}
catch (ThreadAbortException)
{
log.error(string.Format("关闭对客户端[{0}]的监听线程", client.Endpoint));
}
}
private void Offline(string clientKey)
{
if (!dictClient.Keys.Contains(clientKey))
return;
Client client = dictClient[clientKey];
client.Loop = false;
client.Socket.Close();
for (int i = 0; i < client.nodeName.Count; i++)
{
if (!nodeOnline.Keys.Contains(client.nodeName[i]))
{
nodeOnline.Add(client.nodeName[i], false);
NodeOnline?.Invoke(client.nodeName[i], false);
}
else if (nodeOnline[client.nodeName[i]].Equals(true))
{
nodeOnline[client.nodeName[i]] = false;
NodeOnline?.Invoke(client.nodeName[i], false);
}
}
client.nodeName.Clear();
client.ListenNet.Abort();
client.Socket = null;
dictClient.Remove(client.IP);
}
private void KeepClientLive()
{
Node node = new Node("", "Heartbeat package", ClientAction.None);
byte[] buff = Common.Encode(node);
while (loop)
{
try
{
Thread.Sleep(2000);
foreach (string client in dictClient.Keys)
{
Send(client, buff);
}
}
catch (Exception ex)
{
}
}
}
/// <summary>
/// 发送命令
/// </summary>
/// <param name="idx"></param>
/// <param name="buff"></param>
/// <returns></returns>
private bool Send(string clientKey, byte[] buff)
{
for (int i = 1; i <= 3; i++)
{
try
{
dictClient[clientKey].Socket.Send(buff);
log.debug(string.Format("服务端[{0}]向客户端[{1}]发送消息:[{2}]", ServerInfo, clientKey, Common.HexBuff(buff)));
return true;
}
catch (Exception ex)
{
log.error("发送失败" + i + "次:" + ex.Message);
}
Thread.Sleep(100);
}
Offline(clientKey);
return false;
}
private class Client
{
public bool Loop;
public string Endpoint;
public string IP;
public List<string> nodeName;
public Socket Socket;
public Thread ListenNet;
public Client(Socket socket, Thread thread, string ip, string Endpoint)
{
Socket = socket;
ListenNet = thread;
Loop = true;
IP = ip;
this.Endpoint = Endpoint;
nodeName = new List<string>();
}
}
}
}
文件属性发生变化
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false"/>
</configSections>
<entityFramework>
<providers>
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer"/>
<provider invariantName="System.Data.SQLite.EF6" type="System.Data.SQLite.EF6.SQLiteProviderServices, System.Data.SQLite.EF6"/>
</providers>
</entityFramework>
<system.data>
<DbProviderFactories>
<remove invariant="System.Data.SQLite.EF6"/>
<add name="SQLite Data Provider (Entity Framework 6)" invariant="System.Data.SQLite.EF6" description=".NET Framework Data Provider for SQLite (Entity Framework 6)" type="System.Data.SQLite.EF6.SQLiteProviderFactory, System.Data.SQLite.EF6"/>
<remove invariant="System.Data.SQLite"/><add name="SQLite Data Provider" invariant="System.Data.SQLite" description=".NET Framework Data Provider for SQLite" type="System.Data.SQLite.SQLiteFactory, System.Data.SQLite"/></DbProviderFactories>
</system.data>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.8"/></startup></configuration>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Sockets;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace Dolen.Communication.TCP
{
public class TCPClient
{
Thread threadRecv = null; // 负责接收消息的线程;
Socket clientSocket = null;
int buffLength = 1024;// 定义一个1M的缓存区;
log4net.ILog Log;
private bool loop = false;
/// <summary>
/// 消息变化委托
/// </summary>
/// <param name="msg">服务端发送的消息</param>
public delegate void MsgEventHandler(string msg);
public delegate void ConnectedStateEventHandler(bool state);
/// <summary>
/// 消息事件
/// </summary>
public event MsgEventHandler MsgEvent;
public event ConnectedStateEventHandler ConnectedStateEvent;
/// <summary>
/// 是否打开调试
/// </summary>
public bool IsDebug { get; set; } = false;
/// <summary>
/// 服务端信息
/// </summary>
public string ServerInfo { get
{
return string.Format("{0}:{1}",ip,port.ToString());
} }
/// <summary>
/// 服务端IP
/// </summary>
private string ip;
/// <summary>
/// 服务端端口
/// </summary>
private int port;
private bool connectState = false;
/// <summary>
/// 连接状态
/// </summary>
public bool Connected { get { if (clientSocket == null) return false; else return connectState && clientSocket.Connected; } }
public TCPClient(string ip = "127.0.0.1", int port = 8888, string logName = "TCPClient")
{
Log = log4net.LogManager.GetLogger(logName);
this.ip = ip;
this.port = port;
}
/// <summary>
/// 开启服务
/// </summary>
public void Connect()
{
loop = true;
IPAddress address = IPAddress.Parse(ip);
// 创建包含ip和端口号的网络节点对象;
IPEndPoint endPoint = new IPEndPoint(address, port);
try
{
clientSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
clientSocket.Connect(endPoint);
threadRecv = new Thread(RecMsg);
threadRecv.Start(clientSocket);
connectState = true;
Log.Info(string.Format("客户端[{0}]连接服务端[{1}]成功", clientSocket.RemoteEndPoint.ToString(), ServerInfo));
}
catch(Exception ex)
{
connectState = false;
Log.Error(string.Format("客户端[{0}]连接服务端[{1}]失败", clientSocket.RemoteEndPoint.ToString(), ServerInfo),ex);
}
ConnectedStateEvent?.Invoke(connectState && clientSocket.Connected);
}
public void DisConnect()
{
if(clientSocket.Connected)
{
loop = false;
try
{
string client = clientSocket.RemoteEndPoint.ToString();
connectState = false;
threadRecv.Abort();
threadRecv = null;
clientSocket.Close();
Log.Info(string.Format("客户端[{0}]断开服务端[{1}]成功", client, ServerInfo));
}
catch(Exception e)
{
Log.Error(string.Format("客户端[{0}]断开服务端[{1}]成功", clientSocket.RemoteEndPoint.ToString(), ServerInfo),e);
}
ConnectedStateEvent?.Invoke(connectState && clientSocket.Connected);
}
}
void RecMsg(object sokConnectionparn)
{
Socket sokClient = sokConnectionparn as Socket;
while (loop)
{
// 定义一个缓存区;
byte[] arrMsgRec = new byte[buffLength];
// 将接收到的数据存入到输入 arrMsgRec中;
int length = -1;
if (sokClient.Poll(-1, SelectMode.SelectRead))
{
try
{
length = sokClient.Receive(arrMsgRec); // 接收数据,并返回数据的长度;
if (length == 0)//连接正常断开
{
connectState = false;
Log.Info(string.Format("服务端[{1}]断开与客户端[{0}]的连接", clientSocket.RemoteEndPoint.ToString(), ServerInfo));
ConnectedStateEvent?.Invoke(connectState && clientSocket.Connected);
break;
}
}
catch (SocketException se)
{
connectState = false;
Log.Error(string.Format("客户端[{0}]接收服务端[{1}]的消息出现异常", clientSocket.RemoteEndPoint.ToString(), ServerInfo), se);
ConnectedStateEvent?.Invoke(connectState && clientSocket.Connected);
break;
}
catch (Exception e)
{
connectState = false;
Log.Error(string.Format("客户端[{0}]接收服务端[{1}]的消息出现异常", clientSocket.RemoteEndPoint.ToString(), ServerInfo), e);
ConnectedStateEvent?.Invoke(connectState && clientSocket.Connected);
break;
}
}
if (length > 0)
{
string strMsg = System.Text.Encoding.UTF8.GetString(arrMsgRec, 0, length);// 将接收到的字节数据转化成字符串;
if (IsDebug)
Log.Debug(string.Format("客户端[{0}]收到服务端[{1}]的消息:{2}[{3}]", clientSocket.RemoteEndPoint.ToString(), ServerInfo, strMsg, string.Join(" ", arrMsgRec)));
Log.Info(string.Format("客户端[{0}]收到服务端[{1}]的消息:{2}", clientSocket.RemoteEndPoint.ToString(), ServerInfo, strMsg));
MsgEvent?.Invoke(strMsg);
}
}
}
/// <summary>
/// 向客户端发送信息
/// </summary>
public void SendMsg(string txt)
{
try
{
byte[] arrMsg = System.Text.Encoding.UTF8.GetBytes(txt); // 将要发送的字符串转换成Utf-8字节数组;
// arrSendMsg[0] = 0; // 表示发送的是消息数据
//Buffer.BlockCopy(arrMsg, 0, arrSendMsg, 1, arrMsg.Length);
if (Connected)
{
int len = clientSocket.Send(arrMsg);
Log.Info(string.Format("客户端[{0}]向服务端[{1}]发送消息:{2}[{3} Bytes]", clientSocket.RemoteEndPoint.ToString(), ServerInfo, txt, len));
}
else
{
Log.Info(string.Format("客户端[{0}]向服务端[{1}]发送消息失败,网络已断开:{2}", clientSocket.RemoteEndPoint.ToString(), ServerInfo, txt));
}
}
catch (Exception e)
{
connectState = false;
Log.Error(string.Format("客户端[{0}]向服务端[{1}]发送消息异常:{2}", clientSocket.RemoteEndPoint.ToString(), ServerInfo, txt), e);
ConnectedStateEvent?.Invoke(connectState && clientSocket.Connected);
}
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Sockets;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace Dolen.Communication.TCP
{
public class TCPServer
{
Thread threadWatch = null; // 负责监听客户端连接请求的线程;
Socket socketWatch = null;
int buffLength = 1024;// 定义一个1M的缓存区;
List<Client> Clients = new List<Client>();
//Dictionary<string, Socket> dict = new Dictionary<string, Socket>();
//Dictionary<string, Thread> dictThread = new Dictionary<string, Thread>();
log4net.ILog Log;
private bool loop = false;
/// <summary>
/// 消息变化委托
/// </summary>
/// <param name="clientKey">客户端信息</param>
/// <param name="msg">客户端发送的消息</param>
public delegate void MsgEventHandler(string clientKey, string msg);
public delegate void ClientChangedEventHandler(List<Client> clients);
public delegate void ServerStateChangedEventHandler(bool state);
/// <summary>
/// 消息接收事件 (string clientKey, string msg)
/// </summary>
public event MsgEventHandler RecvMsgEvent;
/// <summary>
/// 客户端变化事件 (List<string> clientKey)
/// </summary>
public event ClientChangedEventHandler ClientChangedEvent;
public event ServerStateChangedEventHandler ServerStateChangedEvent;
/// <summary>
/// 是否打开调试
/// </summary>
public bool IsDebug { get; set; } = false;
/// <summary>
/// 服务端IP
/// </summary>
public string IP { get; private set; }
/// <summary>
/// 服务端信息
/// </summary>
public string ServerInfo
{
get
{
return string.Format("{0}:{1}", IP, Port.ToString());
}
}
/// <summary>
/// 服务端端口
/// </summary>
public int Port { get; private set; }
/// <summary>
/// 启动状态
/// </summary>
public bool Started { get; private set; }
public TCPServer(string ip = "0.0.0.0", int port = 8888, string logName = "TCPServer")
{
Log = log4net.LogManager.GetLogger(logName);
IP = ip;
Port = port;
// 创建负责监听的套接字,注意其中的参数;
socketWatch = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
// 获得文本框中的IP对象;
IPAddress address = IPAddress.Parse(IP);
// 创建包含ip和端口号的网络节点对象;
IPEndPoint endPoint = new IPEndPoint(address, Port);
try
{
// 将负责监听的套接字绑定到唯一的ip和端口上;
socketWatch.Bind(endPoint);
}
catch (SocketException se)
{
Log.Error(string.Format("套接字绑定到服务端[{0}]出现异常", ServerInfo), se);
return;
}
// 设置监听队列的长度;
socketWatch.Listen(10);
// 创建负责监听的线程;
threadWatch = new Thread(WatchConnecting);
threadWatch.IsBackground = true;
threadWatch.Start();
}
/// <summary>
/// 设置缓存区长度
/// </summary>
public void SetBuffLength(int len)
{
buffLength = len;
}
/// <summary>
/// 开启服务
/// </summary>
public void Start()
{
if (Started)
return;
loop = true;
Started = true;
Log.Info(string.Format("TCP服务端[{0}]开启监听成功!", ServerInfo));
ServerStateChangedEvent?.Invoke(Started);
}
public void Stop()
{
loop = false;
//foreach (string t in dictThread.Keys)
//{
// try
// {
// dictThread[t].Abort();
// }
// catch (Exception ex)
// {
// Log.Error(string.Format("关闭连接客户端[{0}]的线程失败", t), ex);
// }
//}
foreach (Client client in Clients)
{
try
{
client.RecvMsgThread.Abort();
}
catch (Exception ex)
{
Log.Error(string.Format("关闭连接客户端[{0}]的线程失败", client.EndPoint), ex);
}
try
{
client.Socket.Close();
}
catch (Exception ex)
{
Log.Error(string.Format("关闭连接客户端[{0}]Socket失败", client.EndPoint), ex);
}
}
if (Clients.Count > 0) Clients.Clear();
//foreach (string socket in dict.Keys)
//{
// try
// {
// dict[socket].Close();
// }
// catch (Exception ex)
// {
// Log.Error(string.Format("关闭连接客户端[{0}]Socket失败", socket), ex);
// }
//}
Started = false;
ServerStateChangedEvent?.Invoke(Started);
ClientChangedEvent?.Invoke(Clients);
Log.Info(string.Format("TCP服务端[{0}]关闭监听成功!", ServerInfo));
}
/// <summary>
/// 监听客户端请求的方法;
/// </summary>
void WatchConnecting()
{
while (true) // 持续不断的监听客户端的连接请求;
{
while (loop)
{
// 开始监听客户端连接请求,Accept方法会阻断当前的线程;
Socket sokConnection = socketWatch.Accept(); // 一旦监听到一个客户端的请求,就返回一个与该客户端通信的 套接字;
Client client = new Client();
client.EndPoint = sokConnection.RemoteEndPoint.ToString();
client.Socket = sokConnection;
if (CheckExistClient(sokConnection.RemoteEndPoint.ToString()))
{
Client remove = Clients.Find(s => s.IP.Equals(client.IP));
try
{
remove.RecvMsgThread.Abort();
remove.Socket.Close();
}
catch (Exception ex)
{
Log.Error("WatchConnecting", ex);
}
Clients.Remove(remove);
}
Log.Info(string.Format("客户端[{0}]连接服务端[{1}]成功", sokConnection.RemoteEndPoint.ToString(), ServerInfo));
Thread thr = new Thread(RecMsg);
thr.IsBackground = true;
thr.Start(sokConnection);
client.RecvMsgThread = thr;
Clients.Add(client);
ClientChangedEvent?.Invoke(Clients);
}
}
}
void RecMsg(object sokConnectionparn)
{
Socket sokClient = sokConnectionparn as Socket;
while (loop)
{
// 定义一个缓存区;
byte[] arrMsgRec = new byte[buffLength];
// 将接收到的数据存入到输入 arrMsgRec中;
int length = -1;
if (sokClient.Poll(-1, SelectMode.SelectRead))
{
try
{
length = sokClient.Receive(arrMsgRec); // 接收数据,并返回数据的长度;
if (length == 0)//连接正常断开
{
Log.Info(string.Format("客户端[{0}]断开与服务端[{1}]的连接", sokClient.RemoteEndPoint.ToString(), ServerInfo));
// 从 通信套接字 集合中删除被中断连接的通信套接字;
RemoveClient(sokClient.RemoteEndPoint.ToString());
ClientChangedEvent?.Invoke(Clients);
break;
}
}
catch (SocketException se)
{
Log.Error(string.Format("客户端[{0}]接收服务端[{1}]的消息出现异常", sokClient.RemoteEndPoint.ToString(), ServerInfo), se);
// 从 通信套接字 集合中删除被中断连接的通信套接字;
RemoveClient(sokClient.RemoteEndPoint.ToString());
break;
}
catch (Exception e)
{
Log.Error(string.Format("客户端[{0}]接收服务端[{1}]的消息出现异常", sokClient.RemoteEndPoint.ToString(), ServerInfo), e);
RemoveClient(sokClient.RemoteEndPoint.ToString());
ClientChangedEvent?.Invoke(Clients);
break;
}
}
if (length > 0)
{
string strMsg = System.Text.Encoding.UTF8.GetString(arrMsgRec, 0, length);// 将接收到的字节数据转化成字符串;
//if (IsDebug)
Log.Debug(string.Format("服务端[{0}]收到客户端[{1}]的消息:{2}[{3}][{4} Bytes]",
ServerInfo, sokClient.RemoteEndPoint.ToString(), strMsg, string.Join(" ", arrMsgRec.Take(length)), length));
//Log.Info(string.Format("服务端[{0}]收到客户端[{1}]的消息:{2}[{3} Bytes]", ServerInfo, sokClient.RemoteEndPoint.ToString(), strMsg,length));
RecvMsgEvent?.Invoke(sokClient.RemoteEndPoint.ToString(), strMsg);
}
}
}
/// <summary>
/// 向客户端发送信息
/// </summary>
public void SendMsg(string clientKey, string txt)
{
try
{
byte[] arrMsg = System.Text.Encoding.UTF8.GetBytes(txt); // 将要发送的字符串转换成Utf-8字节数组;
// arrSendMsg[0] = 0; // 表示发送的是消息数据
//Buffer.BlockCopy(arrMsg, 0, arrSendMsg, 1, arrMsg.Length);
int len = GetClient(clientKey).Socket.Send(arrMsg);
Log.Debug(string.Format("服务端[{0}]向客户端[{1}]发送消息:{2}[{3}][{4} Bytes]", ServerInfo, clientKey, txt, string.Join(" ", arrMsg), len));
}
catch (Exception e)
{
Log.Error(string.Format("服务端[{0}]向客户端[{1}]发送消息异常:{2}", ServerInfo, clientKey, txt), e);
RemoveClient(clientKey);
ClientChangedEvent?.Invoke(Clients);
}
}
bool CheckExistClient(string endpoint)
{
string ip = endpoint.Split(':')[0];
Client client = Clients.Find(s => s.IP.Equals(ip));
return client != null;
}
void RemoveClient(string endpoint)
{
Client client = Clients.Find(s => s.EndPoint.Equals(endpoint));
Clients.Remove(client);
}
Client GetClient(string endpoint)
{
return Clients.Find(s => s.EndPoint.Equals(endpoint));
}
}
public class Client
{
/// <summary>
/// 终端信息
/// </summary>
public string EndPoint { get; set; }
public string IP { get { return EndPoint.Split(':')[0]; } }
/// <summary>
/// 套接字
/// </summary>
public Socket Socket { get; set; }
/// <summary>
/// 接收的消息的线程
/// </summary>
public Thread RecvMsgThread { get; set; }
}
}
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="..\packages\EntityFramework.6.4.4\build\EntityFramework.props" Condition="Exists('..\packages\EntityFramework.6.4.4\build\EntityFramework.props')" />
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{1D8684A2-5358-4F9C-9B42-9794F8F4B6B6}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Dolen</RootNamespace>
<AssemblyName>Dolen</AssemblyName>
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<Deterministic>true</Deterministic>
<NuGetPackageImportStamp>
</NuGetPackageImportStamp>
<TargetFrameworkProfile />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
<ItemGroup>
<Reference Include="EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL">
<HintPath>..\packages\EntityFramework.6.4.4\lib\net45\EntityFramework.dll</HintPath>
</Reference>
<Reference Include="EntityFramework.SqlServer, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL">
<HintPath>..\packages\EntityFramework.6.4.4\lib\net45\EntityFramework.SqlServer.dll</HintPath>
</Reference>
<Reference Include="log4net">
<HintPath>dll\log4net.dll</HintPath>
</Reference>
<Reference Include="MySql.Data">
<HintPath>dll\MySql.Data.8.0.22\lib\net452\MySql.Data.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.ComponentModel.DataAnnotations" />
<Reference Include="System.Core" />
<Reference Include="System.Data.SQLite, Version=1.0.115.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139, processorArchitecture=MSIL">
<HintPath>..\packages\Stub.System.Data.SQLite.Core.NetFramework.1.0.115.0\lib\net46\System.Data.SQLite.dll</HintPath>
</Reference>
<Reference Include="System.Data.SQLite.EF6, Version=1.0.115.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139, processorArchitecture=MSIL">
<HintPath>..\packages\System.Data.SQLite.EF6.1.0.115.0\lib\net46\System.Data.SQLite.EF6.dll</HintPath>
</Reference>
<Reference Include="System.Data.SQLite.Linq, Version=1.0.115.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139, processorArchitecture=MSIL">
<HintPath>..\packages\System.Data.SQLite.Linq.1.0.115.0\lib\net46\System.Data.SQLite.Linq.dll</HintPath>
</Reference>
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Communication\TCP\TCPClient.cs" />
<Compile Include="Communication\TCP\TCPServer.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup />
<ItemGroup>
<None Include="App.config" />
<None Include="packages.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>这台计算机上缺少此项目引用的 NuGet 程序包。使用“NuGet 程序包还原”可下载这些程序包。有关更多信息,请参见 http://go.microsoft.com/fwlink/?LinkID=322105。缺少的文件是 {0}。</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\packages\EntityFramework.6.4.4\build\EntityFramework.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\EntityFramework.6.4.4\build\EntityFramework.props'))" />
<Error Condition="!Exists('..\packages\EntityFramework.6.4.4\build\EntityFramework.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\EntityFramework.6.4.4\build\EntityFramework.targets'))" />
<Error Condition="!Exists('..\packages\Stub.System.Data.SQLite.Core.NetFramework.1.0.115.0\build\net46\Stub.System.Data.SQLite.Core.NetFramework.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Stub.System.Data.SQLite.Core.NetFramework.1.0.115.0\build\net46\Stub.System.Data.SQLite.Core.NetFramework.targets'))" />
</Target>
<Import Project="..\packages\EntityFramework.6.4.4\build\EntityFramework.targets" Condition="Exists('..\packages\EntityFramework.6.4.4\build\EntityFramework.targets')" />
<Import Project="..\packages\Stub.System.Data.SQLite.Core.NetFramework.1.0.115.0\build\net46\Stub.System.Data.SQLite.Core.NetFramework.targets" Condition="Exists('..\packages\Stub.System.Data.SQLite.Core.NetFramework.1.0.115.0\build\net46\Stub.System.Data.SQLite.Core.NetFramework.targets')" />
</Project>
\ No newline at end of file \ No newline at end of file
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// 有关程序集的一般信息由以下
// 控制。更改这些特性值可修改
// 与程序集关联的信息。
[assembly: AssemblyTitle("Dolen")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Dolen")]
[assembly: AssemblyCopyright("Copyright © 2020")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// 将 ComVisible 设置为 false 会使此程序集中的类型
//对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型
//请将此类型的 ComVisible 特性设置为 true。
[assembly: ComVisible(false)]
// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID
[assembly: Guid("1d8684a2-5358-4f9c-9b42-9794f8f4b6b6")]
// 程序集的版本信息由下列四个值组成:
//
// 主版本
// 次版本
// 生成号
// 修订号
//
//可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值
//通过使用 "*",如下所示:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
文件属性发生变化
此文件的差异太大,无法显示。
此文件的差异太大,无法显示。
此文件的差异太大,无法显示。
此文件类型无法预览
文件属性发生变化
此文件类型无法预览
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="EntityFramework" version="6.4.4" targetFramework="net472" />
<package id="Stub.System.Data.SQLite.Core.NetFramework" version="1.0.115.0" targetFramework="net472" />
<package id="System.Data.SQLite" version="1.0.115.0" targetFramework="net472" />
<package id="System.Data.SQLite.Core" version="1.0.115.0" targetFramework="net472" />
<package id="System.Data.SQLite.EF6" version="1.0.115.0" targetFramework="net472" />
<package id="System.Data.SQLite.Linq" version="1.0.115.0" targetFramework="net472" />
</packages>
\ No newline at end of file \ No newline at end of file
...@@ -56,6 +56,7 @@ ...@@ -56,6 +56,7 @@
<Compile Include="JAKATYPE.cs" /> <Compile Include="JAKATYPE.cs" />
<Compile Include="RobotData.cs" /> <Compile Include="RobotData.cs" />
<Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="TCPServer.cs" />
<Compile Include="UCJoint.cs"> <Compile Include="UCJoint.cs">
<SubType>UserControl</SubType> <SubType>UserControl</SubType>
</Compile> </Compile>
...@@ -97,11 +98,5 @@ ...@@ -97,11 +98,5 @@
<CopyToOutputDirectory>Always</CopyToOutputDirectory> <CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content> </Content>
</ItemGroup> </ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\..\..\..\Projects\CSharp-Workspace\Dolen\Dolen\Dolen.csproj">
<Project>{1D8684A2-5358-4F9C-9B42-9794F8F4B6B6}</Project>
<Name>Dolen</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project> </Project>
\ No newline at end of file \ No newline at end of file
using Dolen.Communication.TCP; 
using Dolen.Communication.TCP;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
namespace JAKA namespace JAKA
......
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Sockets;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace Dolen.Communication.TCP
{
public class TCPServer
{
Thread threadWatch = null; // 负责监听客户端连接请求的线程;
Socket socketWatch = null;
int buffLength = 1024;// 定义一个1M的缓存区;
List<Client> Clients = new List<Client>();
//Dictionary<string, Socket> dict = new Dictionary<string, Socket>();
//Dictionary<string, Thread> dictThread = new Dictionary<string, Thread>();
log4net.ILog Log;
private bool loop = false;
/// <summary>
/// 消息变化委托
/// </summary>
/// <param name="clientKey">客户端信息</param>
/// <param name="msg">客户端发送的消息</param>
public delegate void MsgEventHandler(string clientKey, string msg);
public delegate void ClientChangedEventHandler(List<Client> clients);
public delegate void ServerStateChangedEventHandler(bool state);
/// <summary>
/// 消息接收事件 (string clientKey, string msg)
/// </summary>
public event MsgEventHandler RecvMsgEvent;
/// <summary>
/// 客户端变化事件 (List<string> clientKey)
/// </summary>
public event ClientChangedEventHandler ClientChangedEvent;
public event ServerStateChangedEventHandler ServerStateChangedEvent;
/// <summary>
/// 是否打开调试
/// </summary>
public bool IsDebug { get; set; } = false;
/// <summary>
/// 服务端IP
/// </summary>
public string IP { get; private set; }
/// <summary>
/// 服务端信息
/// </summary>
public string ServerInfo
{
get
{
return string.Format("{0}:{1}", IP, Port.ToString());
}
}
/// <summary>
/// 服务端端口
/// </summary>
public int Port { get; private set; }
/// <summary>
/// 启动状态
/// </summary>
public bool Started { get; private set; }
public TCPServer(string ip = "0.0.0.0", int port = 8888, string logName = "TCPServer")
{
Log = log4net.LogManager.GetLogger(logName);
IP = ip;
Port = port;
// 创建负责监听的套接字,注意其中的参数;
socketWatch = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
// 获得文本框中的IP对象;
IPAddress address = IPAddress.Parse(IP);
// 创建包含ip和端口号的网络节点对象;
IPEndPoint endPoint = new IPEndPoint(address, Port);
try
{
// 将负责监听的套接字绑定到唯一的ip和端口上;
socketWatch.Bind(endPoint);
}
catch (SocketException se)
{
Log.Error(string.Format("套接字绑定到服务端[{0}]出现异常", ServerInfo), se);
return;
}
// 设置监听队列的长度;
socketWatch.Listen(10);
// 创建负责监听的线程;
threadWatch = new Thread(WatchConnecting);
threadWatch.IsBackground = true;
threadWatch.Start();
}
/// <summary>
/// 设置缓存区长度
/// </summary>
public void SetBuffLength(int len)
{
buffLength = len;
}
/// <summary>
/// 开启服务
/// </summary>
public void Start()
{
if (Started)
return;
loop = true;
Started = true;
Log.Info(string.Format("TCP服务端[{0}]开启监听成功!", ServerInfo));
ServerStateChangedEvent?.Invoke(Started);
}
public void Stop()
{
loop = false;
//foreach (string t in dictThread.Keys)
//{
// try
// {
// dictThread[t].Abort();
// }
// catch (Exception ex)
// {
// Log.Error(string.Format("关闭连接客户端[{0}]的线程失败", t), ex);
// }
//}
foreach (Client client in Clients)
{
try
{
client.RecvMsgThread.Abort();
}
catch (Exception ex)
{
Log.Error(string.Format("关闭连接客户端[{0}]的线程失败", client.EndPoint), ex);
}
try
{
client.Socket.Close();
}
catch (Exception ex)
{
Log.Error(string.Format("关闭连接客户端[{0}]Socket失败", client.EndPoint), ex);
}
}
if (Clients.Count > 0) Clients.Clear();
//foreach (string socket in dict.Keys)
//{
// try
// {
// dict[socket].Close();
// }
// catch (Exception ex)
// {
// Log.Error(string.Format("关闭连接客户端[{0}]Socket失败", socket), ex);
// }
//}
Started = false;
ServerStateChangedEvent?.Invoke(Started);
ClientChangedEvent?.Invoke(Clients);
Log.Info(string.Format("TCP服务端[{0}]关闭监听成功!", ServerInfo));
}
/// <summary>
/// 监听客户端请求的方法;
/// </summary>
void WatchConnecting()
{
while (true) // 持续不断的监听客户端的连接请求;
{
while (loop)
{
// 开始监听客户端连接请求,Accept方法会阻断当前的线程;
Socket sokConnection = socketWatch.Accept(); // 一旦监听到一个客户端的请求,就返回一个与该客户端通信的 套接字;
Client client = new Client();
client.EndPoint = sokConnection.RemoteEndPoint.ToString();
client.Socket = sokConnection;
if (CheckExistClient(sokConnection.RemoteEndPoint.ToString()))
{
Client remove = Clients.Find(s => s.IP.Equals(client.IP));
try
{
remove.RecvMsgThread.Abort();
remove.Socket.Close();
}
catch (Exception ex)
{
Log.Error("WatchConnecting", ex);
}
Clients.Remove(remove);
}
Log.Info(string.Format("客户端[{0}]连接服务端[{1}]成功", sokConnection.RemoteEndPoint.ToString(), ServerInfo));
Thread thr = new Thread(RecMsg);
thr.IsBackground = true;
thr.Start(sokConnection);
client.RecvMsgThread = thr;
Clients.Add(client);
ClientChangedEvent?.Invoke(Clients);
}
}
}
void RecMsg(object sokConnectionparn)
{
Socket sokClient = sokConnectionparn as Socket;
while (loop)
{
// 定义一个缓存区;
byte[] arrMsgRec = new byte[buffLength];
// 将接收到的数据存入到输入 arrMsgRec中;
int length = -1;
if (sokClient.Poll(-1, SelectMode.SelectRead))
{
try
{
length = sokClient.Receive(arrMsgRec); // 接收数据,并返回数据的长度;
if (length == 0)//连接正常断开
{
Log.Info(string.Format("客户端[{0}]断开与服务端[{1}]的连接", sokClient.RemoteEndPoint.ToString(), ServerInfo));
// 从 通信套接字 集合中删除被中断连接的通信套接字;
RemoveClient(sokClient.RemoteEndPoint.ToString());
ClientChangedEvent?.Invoke(Clients);
break;
}
}
catch (SocketException se)
{
Log.Error(string.Format("客户端[{0}]接收服务端[{1}]的消息出现异常", sokClient.RemoteEndPoint.ToString(), ServerInfo), se);
// 从 通信套接字 集合中删除被中断连接的通信套接字;
RemoveClient(sokClient.RemoteEndPoint.ToString());
break;
}
catch (Exception e)
{
Log.Error(string.Format("客户端[{0}]接收服务端[{1}]的消息出现异常", sokClient.RemoteEndPoint.ToString(), ServerInfo), e);
RemoveClient(sokClient.RemoteEndPoint.ToString());
ClientChangedEvent?.Invoke(Clients);
break;
}
}
if (length > 0)
{
string strMsg = System.Text.Encoding.UTF8.GetString(arrMsgRec, 0, length);// 将接收到的字节数据转化成字符串;
//if (IsDebug)
Log.Debug(string.Format("服务端[{0}]收到客户端[{1}]的消息:{2}[{3}][{4} Bytes]",
ServerInfo, sokClient.RemoteEndPoint.ToString(), strMsg, string.Join(" ", arrMsgRec.Take(length)), length));
//Log.Info(string.Format("服务端[{0}]收到客户端[{1}]的消息:{2}[{3} Bytes]", ServerInfo, sokClient.RemoteEndPoint.ToString(), strMsg,length));
RecvMsgEvent?.Invoke(sokClient.RemoteEndPoint.ToString(), strMsg);
}
}
}
/// <summary>
/// 向客户端发送信息
/// </summary>
public void SendMsg(string clientKey, string txt)
{
try
{
byte[] arrMsg = System.Text.Encoding.UTF8.GetBytes(txt); // 将要发送的字符串转换成Utf-8字节数组;
// arrSendMsg[0] = 0; // 表示发送的是消息数据
//Buffer.BlockCopy(arrMsg, 0, arrSendMsg, 1, arrMsg.Length);
int len = GetClient(clientKey).Socket.Send(arrMsg);
Log.Debug(string.Format("服务端[{0}]向客户端[{1}]发送消息:{2}[{3}][{4} Bytes]", ServerInfo, clientKey, txt, string.Join(" ", arrMsg), len));
}
catch (Exception e)
{
Log.Error(string.Format("服务端[{0}]向客户端[{1}]发送消息异常:{2}", ServerInfo, clientKey, txt), e);
RemoveClient(clientKey);
ClientChangedEvent?.Invoke(Clients);
}
}
bool CheckExistClient(string endpoint)
{
string ip = endpoint.Split(':')[0];
Client client = Clients.Find(s => s.IP.Equals(ip));
return client != null;
}
void RemoveClient(string endpoint)
{
Client client = Clients.Find(s => s.EndPoint.Equals(endpoint));
Clients.Remove(client);
}
Client GetClient(string endpoint)
{
return Clients.Find(s => s.EndPoint.Equals(endpoint));
}
}
public class Client
{
/// <summary>
/// 终端信息
/// </summary>
public string EndPoint { get; set; }
public string IP { get { return EndPoint.Split(':')[0]; } }
/// <summary>
/// 套接字
/// </summary>
public Socket Socket { get; set; }
/// <summary>
/// 接收的消息的线程
/// </summary>
public Thread RecvMsgThread { get; set; }
}
}
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!