Ver código fonte

开始模拟

张泳健 7 anos atrás
pai
commit
9d0e886830

+ 15 - 5
DotNettyFrom/DotNettyFrom.csproj Ver arquivo

@@ -130,17 +130,27 @@
130 130
     <Compile Include="common\DataModel.cs" />
131 131
     <Compile Include="common\UIInfoModel..cs" />
132 132
     <Compile Include="config\SystemConfig.cs" />
133
-    <Compile Include="Form1.cs">
133
+    <Compile Include="dialog\HeartBeatTime.cs">
134 134
       <SubType>Form</SubType>
135 135
     </Compile>
136
-    <Compile Include="Form1.Designer.cs">
137
-      <DependentUpon>Form1.cs</DependentUpon>
136
+    <Compile Include="dialog\HeartBeatTime.Designer.cs">
137
+      <DependentUpon>HeartBeatTime.cs</DependentUpon>
138
+    </Compile>
139
+    <Compile Include="MainForm.cs">
140
+      <SubType>Form</SubType>
141
+    </Compile>
142
+    <Compile Include="MainForm.Designer.cs">
143
+      <DependentUpon>MainForm.cs</DependentUpon>
138 144
     </Compile>
139 145
     <Compile Include="netty\NettyClient.cs" />
140 146
     <Compile Include="Program.cs" />
141 147
     <Compile Include="Properties\AssemblyInfo.cs" />
142
-    <EmbeddedResource Include="Form1.resx">
143
-      <DependentUpon>Form1.cs</DependentUpon>
148
+    <Compile Include="util\AryUtil.cs" />
149
+    <EmbeddedResource Include="dialog\HeartBeatTime.resx">
150
+      <DependentUpon>HeartBeatTime.cs</DependentUpon>
151
+    </EmbeddedResource>
152
+    <EmbeddedResource Include="MainForm.resx">
153
+      <DependentUpon>MainForm.cs</DependentUpon>
144 154
     </EmbeddedResource>
145 155
     <EmbeddedResource Include="Properties\Resources.resx">
146 156
       <Generator>ResXFileCodeGenerator</Generator>

+ 0 - 171
DotNettyFrom/Form1.Designer.cs Ver arquivo

@@ -1,171 +0,0 @@
1
-namespace DotNettyFrom
2
-{
3
-    partial class Form1
4
-    {
5
-        /// <summary>
6
-        /// 必需的设计器变量。
7
-        /// </summary>
8
-        private System.ComponentModel.IContainer components = null;
9
-
10
-        /// <summary>
11
-        /// 清理所有正在使用的资源。
12
-        /// </summary>
13
-        /// <param name="disposing">如果应释放托管资源,为 true;否则为 false。</param>
14
-        protected override void Dispose(bool disposing)
15
-        {
16
-            if (disposing && (components != null))
17
-            {
18
-                components.Dispose();
19
-            }
20
-            base.Dispose(disposing);
21
-        }
22
-
23
-        #region Windows 窗体设计器生成的代码
24
-
25
-        /// <summary>
26
-        /// 设计器支持所需的方法 - 不要修改
27
-        /// 使用代码编辑器修改此方法的内容。
28
-        /// </summary>
29
-        private void InitializeComponent()
30
-        {
31
-            this.listBox1 = new System.Windows.Forms.ListBox();
32
-            this.TbHost = new System.Windows.Forms.TextBox();
33
-            this.TbPort = new System.Windows.Forms.TextBox();
34
-            this.BtnConnection = new System.Windows.Forms.Button();
35
-            this.BtnDisConn = new System.Windows.Forms.Button();
36
-            this.BtnLogin = new System.Windows.Forms.Button();
37
-            this.BtnSendData = new System.Windows.Forms.Button();
38
-            this.menuStrip1 = new System.Windows.Forms.MenuStrip();
39
-            this.文件FToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
40
-            this.statusStrip1 = new System.Windows.Forms.StatusStrip();
41
-            this.menuStrip1.SuspendLayout();
42
-            this.SuspendLayout();
43
-            // 
44
-            // listBox1
45
-            // 
46
-            this.listBox1.FormattingEnabled = true;
47
-            this.listBox1.ItemHeight = 12;
48
-            this.listBox1.Location = new System.Drawing.Point(12, 60);
49
-            this.listBox1.Name = "listBox1";
50
-            this.listBox1.Size = new System.Drawing.Size(820, 436);
51
-            this.listBox1.TabIndex = 0;
52
-            // 
53
-            // TbHost
54
-            // 
55
-            this.TbHost.Location = new System.Drawing.Point(39, 23);
56
-            this.TbHost.Name = "TbHost";
57
-            this.TbHost.Size = new System.Drawing.Size(241, 21);
58
-            this.TbHost.TabIndex = 1;
59
-            this.TbHost.Text = "127.0.0.1";
60
-            // 
61
-            // TbPort
62
-            // 
63
-            this.TbPort.Location = new System.Drawing.Point(286, 23);
64
-            this.TbPort.Name = "TbPort";
65
-            this.TbPort.Size = new System.Drawing.Size(72, 21);
66
-            this.TbPort.TabIndex = 1;
67
-            this.TbPort.Text = "4001";
68
-            // 
69
-            // BtnConnection
70
-            // 
71
-            this.BtnConnection.Location = new System.Drawing.Point(364, 23);
72
-            this.BtnConnection.Name = "BtnConnection";
73
-            this.BtnConnection.Size = new System.Drawing.Size(75, 23);
74
-            this.BtnConnection.TabIndex = 2;
75
-            this.BtnConnection.Text = "连接";
76
-            this.BtnConnection.UseVisualStyleBackColor = true;
77
-            this.BtnConnection.Click += new System.EventHandler(this.BtnConnection_Click);
78
-            // 
79
-            // BtnDisConn
80
-            // 
81
-            this.BtnDisConn.Location = new System.Drawing.Point(445, 23);
82
-            this.BtnDisConn.Name = "BtnDisConn";
83
-            this.BtnDisConn.Size = new System.Drawing.Size(75, 23);
84
-            this.BtnDisConn.TabIndex = 2;
85
-            this.BtnDisConn.Text = "断开";
86
-            this.BtnDisConn.UseVisualStyleBackColor = true;
87
-            this.BtnDisConn.Click += new System.EventHandler(this.BtnDisConn_Click);
88
-            // 
89
-            // BtnLogin
90
-            // 
91
-            this.BtnLogin.Location = new System.Drawing.Point(526, 23);
92
-            this.BtnLogin.Name = "BtnLogin";
93
-            this.BtnLogin.Size = new System.Drawing.Size(75, 23);
94
-            this.BtnLogin.TabIndex = 2;
95
-            this.BtnLogin.Text = "登录";
96
-            this.BtnLogin.UseVisualStyleBackColor = true;
97
-            // 
98
-            // BtnSendData
99
-            // 
100
-            this.BtnSendData.Location = new System.Drawing.Point(607, 23);
101
-            this.BtnSendData.Name = "BtnSendData";
102
-            this.BtnSendData.Size = new System.Drawing.Size(75, 23);
103
-            this.BtnSendData.TabIndex = 2;
104
-            this.BtnSendData.Text = "发送数据";
105
-            this.BtnSendData.UseVisualStyleBackColor = true;
106
-            this.BtnSendData.Click += new System.EventHandler(this.BtnSendData_Click);
107
-            // 
108
-            // menuStrip1
109
-            // 
110
-            this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
111
-            this.文件FToolStripMenuItem});
112
-            this.menuStrip1.Location = new System.Drawing.Point(0, 0);
113
-            this.menuStrip1.Name = "menuStrip1";
114
-            this.menuStrip1.Size = new System.Drawing.Size(844, 25);
115
-            this.menuStrip1.TabIndex = 3;
116
-            this.menuStrip1.Text = "menuStrip1";
117
-            // 
118
-            // 文件FToolStripMenuItem
119
-            // 
120
-            this.文件FToolStripMenuItem.Name = "文件FToolStripMenuItem";
121
-            this.文件FToolStripMenuItem.Size = new System.Drawing.Size(58, 21);
122
-            this.文件FToolStripMenuItem.Text = "文件(&F)";
123
-            // 
124
-            // statusStrip1
125
-            // 
126
-            this.statusStrip1.Location = new System.Drawing.Point(0, 508);
127
-            this.statusStrip1.Name = "statusStrip1";
128
-            this.statusStrip1.Size = new System.Drawing.Size(844, 22);
129
-            this.statusStrip1.TabIndex = 4;
130
-            this.statusStrip1.Text = "statusStrip1";
131
-            // 
132
-            // Form1
133
-            // 
134
-            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
135
-            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
136
-            this.ClientSize = new System.Drawing.Size(844, 530);
137
-            this.Controls.Add(this.statusStrip1);
138
-            this.Controls.Add(this.BtnDisConn);
139
-            this.Controls.Add(this.BtnSendData);
140
-            this.Controls.Add(this.BtnLogin);
141
-            this.Controls.Add(this.BtnConnection);
142
-            this.Controls.Add(this.TbPort);
143
-            this.Controls.Add(this.TbHost);
144
-            this.Controls.Add(this.listBox1);
145
-            this.Controls.Add(this.menuStrip1);
146
-            this.MainMenuStrip = this.menuStrip1;
147
-            this.Name = "Form1";
148
-            this.Text = "Form1";
149
-            this.Load += new System.EventHandler(this.Form1_Load);
150
-            this.menuStrip1.ResumeLayout(false);
151
-            this.menuStrip1.PerformLayout();
152
-            this.ResumeLayout(false);
153
-            this.PerformLayout();
154
-
155
-        }
156
-
157
-        #endregion
158
-
159
-        private System.Windows.Forms.ListBox listBox1;
160
-        private System.Windows.Forms.TextBox TbHost;
161
-        private System.Windows.Forms.TextBox TbPort;
162
-        private System.Windows.Forms.Button BtnConnection;
163
-        private System.Windows.Forms.Button BtnDisConn;
164
-        private System.Windows.Forms.Button BtnLogin;
165
-        private System.Windows.Forms.Button BtnSendData;
166
-        private System.Windows.Forms.MenuStrip menuStrip1;
167
-        private System.Windows.Forms.ToolStripMenuItem 文件FToolStripMenuItem;
168
-        private System.Windows.Forms.StatusStrip statusStrip1;
169
-    }
170
-}
171
-

+ 0 - 64
DotNettyFrom/Form1.cs Ver arquivo

@@ -1,64 +0,0 @@
1
-using System;
2
-using System.Collections.Generic;
3
-using System.ComponentModel;
4
-using System.Data;
5
-using System.Drawing;
6
-using System.Linq;
7
-using System.Text;
8
-using System.Threading;
9
-using System.Threading.Tasks;
10
-using System.Windows.Forms;
11
-using DotNettyFrom.common;
12
-using DotNettyFrom.netty;
13
-
14
-namespace DotNettyFrom
15
-{
16
-    public partial class Form1 : Form
17
-    {
18
-        public Form1()
19
-        {
20
-            InitializeComponent();
21
-        }
22
-
23
-        private NettyClient nc;
24
-        private Thread t;
25
-        private void BtnConnection_Click(object sender, EventArgs e)
26
-        {
27
-            /* var producer = Task.Factory.StartNew(() =>
28
-             {
29
-                 for (int count = 0; count < 1000; count++)
30
-                 {
31
-
32
-
33
-                 }
34
-                 //                blockingCollection.CompleteAdding();
35
-             });*/
36
-            nc = new NettyClient();
37
-            t = new Thread(() => { nc.StartNetty("127.0.0.1", 4001); });
38
-            t.Start();
39
-
40
-        }
41
-
42
-        private void Form1_Load(object sender, EventArgs e)
43
-        {
44
-            var consumer = Task.Factory.StartNew(() =>
45
-            {
46
-                foreach (UIInfoModel value in DataModel.ReceCollection.GetConsumingEnumerable())
47
-                {
48
-                    Invoke(new ThreadStart(delegate { listBox1.Items.Add(value); }));
49
-                }
50
-            });
51
-        }
52
-
53
-        private void BtnDisConn_Click(object sender, EventArgs e)
54
-        {
55
-            nc?.StopNetty();
56
-            t?.Abort();
57
-        }
58
-
59
-        private void BtnSendData_Click(object sender, EventArgs e)
60
-        {
61
-            nc?.SendData("");
62
-        }
63
-    }
64
-}

+ 438 - 0
DotNettyFrom/MainForm.Designer.cs Ver arquivo

@@ -0,0 +1,438 @@
1
+namespace DotNettyFrom
2
+{
3
+    partial class MainForm
4
+    {
5
+        /// <summary>
6
+        /// 必需的设计器变量。
7
+        /// </summary>
8
+        private System.ComponentModel.IContainer components = null;
9
+
10
+        /// <summary>
11
+        /// 清理所有正在使用的资源。
12
+        /// </summary>
13
+        /// <param name="disposing">如果应释放托管资源,为 true;否则为 false。</param>
14
+        protected override void Dispose(bool disposing)
15
+        {
16
+            if (disposing && (components != null))
17
+            {
18
+                components.Dispose();
19
+            }
20
+            base.Dispose(disposing);
21
+        }
22
+
23
+        #region Windows 窗体设计器生成的代码
24
+
25
+        /// <summary>
26
+        /// 设计器支持所需的方法 - 不要修改
27
+        /// 使用代码编辑器修改此方法的内容。
28
+        /// </summary>
29
+        private void InitializeComponent()
30
+        {
31
+            this.LBLogShow = new System.Windows.Forms.ListBox();
32
+            this.TbHost = new System.Windows.Forms.TextBox();
33
+            this.TbPort = new System.Windows.Forms.TextBox();
34
+            this.BtnConnection = new System.Windows.Forms.Button();
35
+            this.BtnDisConn = new System.Windows.Forms.Button();
36
+            this.BtnLogin = new System.Windows.Forms.Button();
37
+            this.BtnSendData = new System.Windows.Forms.Button();
38
+            this.menuStrip1 = new System.Windows.Forms.MenuStrip();
39
+            this.文件FToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
40
+            this.时间TToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
41
+            this.RT_HB_Time = new System.Windows.Forms.ToolStripMenuItem();
42
+            this.toolStripSeparator1 = new System.Windows.Forms.ToolStripSeparator();
43
+            this.历史HToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
44
+            this.RT_HI_Host = new System.Windows.Forms.ToolStripMenuItem();
45
+            this.RT_HI_DeviceId = new System.Windows.Forms.ToolStripMenuItem();
46
+            this.RT_HI_CCID = new System.Windows.Forms.ToolStripMenuItem();
47
+            this.toolStripSeparator2 = new System.Windows.Forms.ToolStripSeparator();
48
+            this.RT_HI_SendData = new System.Windows.Forms.ToolStripMenuItem();
49
+            this.statusStrip1 = new System.Windows.Forms.StatusStrip();
50
+            this.toolStripStatusLabel1 = new System.Windows.Forms.ToolStripStatusLabel();
51
+            this.StatusItemHbTime = new System.Windows.Forms.ToolStripStatusLabel();
52
+            this.groupBox1 = new System.Windows.Forms.GroupBox();
53
+            this.BtnTest = new System.Windows.Forms.Button();
54
+            this.BtnCmdManager = new System.Windows.Forms.Button();
55
+            this.label4 = new System.Windows.Forms.Label();
56
+            this.TbCCID = new System.Windows.Forms.TextBox();
57
+            this.label3 = new System.Windows.Forms.Label();
58
+            this.TbDeviceId = new System.Windows.Forms.TextBox();
59
+            this.label2 = new System.Windows.Forms.Label();
60
+            this.label1 = new System.Windows.Forms.Label();
61
+            this.label5 = new System.Windows.Forms.Label();
62
+            this.TbSendData = new System.Windows.Forms.TextBox();
63
+            this.menuStrip1.SuspendLayout();
64
+            this.statusStrip1.SuspendLayout();
65
+            this.groupBox1.SuspendLayout();
66
+            this.SuspendLayout();
67
+            // 
68
+            // LBLogShow
69
+            // 
70
+            this.LBLogShow.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 
71
+            | System.Windows.Forms.AnchorStyles.Left) 
72
+            | System.Windows.Forms.AnchorStyles.Right)));
73
+            this.LBLogShow.FormattingEnabled = true;
74
+            this.LBLogShow.ItemHeight = 16;
75
+            this.LBLogShow.Location = new System.Drawing.Point(12, 277);
76
+            this.LBLogShow.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
77
+            this.LBLogShow.Name = "LBLogShow";
78
+            this.LBLogShow.Size = new System.Drawing.Size(961, 404);
79
+            this.LBLogShow.TabIndex = 0;
80
+            // 
81
+            // TbHost
82
+            // 
83
+            this.TbHost.Location = new System.Drawing.Point(47, 15);
84
+            this.TbHost.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
85
+            this.TbHost.Name = "TbHost";
86
+            this.TbHost.Size = new System.Drawing.Size(280, 22);
87
+            this.TbHost.TabIndex = 1;
88
+            this.TbHost.Text = "127.0.0.1";
89
+            // 
90
+            // TbPort
91
+            // 
92
+            this.TbPort.Location = new System.Drawing.Point(371, 15);
93
+            this.TbPort.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
94
+            this.TbPort.Name = "TbPort";
95
+            this.TbPort.Size = new System.Drawing.Size(57, 22);
96
+            this.TbPort.TabIndex = 1;
97
+            this.TbPort.Text = "15440";
98
+            this.TbPort.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.TbPort_KeyPress);
99
+            // 
100
+            // BtnConnection
101
+            // 
102
+            this.BtnConnection.Location = new System.Drawing.Point(192, 45);
103
+            this.BtnConnection.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
104
+            this.BtnConnection.Name = "BtnConnection";
105
+            this.BtnConnection.Size = new System.Drawing.Size(87, 31);
106
+            this.BtnConnection.TabIndex = 2;
107
+            this.BtnConnection.Text = "连接";
108
+            this.BtnConnection.UseVisualStyleBackColor = true;
109
+            this.BtnConnection.Click += new System.EventHandler(this.BtnConnection_Click);
110
+            // 
111
+            // BtnDisConn
112
+            // 
113
+            this.BtnDisConn.Enabled = false;
114
+            this.BtnDisConn.Location = new System.Drawing.Point(99, 45);
115
+            this.BtnDisConn.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
116
+            this.BtnDisConn.Name = "BtnDisConn";
117
+            this.BtnDisConn.Size = new System.Drawing.Size(87, 31);
118
+            this.BtnDisConn.TabIndex = 2;
119
+            this.BtnDisConn.Text = "断开";
120
+            this.BtnDisConn.UseVisualStyleBackColor = true;
121
+            this.BtnDisConn.Click += new System.EventHandler(this.BtnDisConn_Click);
122
+            // 
123
+            // BtnLogin
124
+            // 
125
+            this.BtnLogin.Location = new System.Drawing.Point(6, 45);
126
+            this.BtnLogin.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
127
+            this.BtnLogin.Name = "BtnLogin";
128
+            this.BtnLogin.Size = new System.Drawing.Size(87, 31);
129
+            this.BtnLogin.TabIndex = 2;
130
+            this.BtnLogin.Text = "连接.登录";
131
+            this.BtnLogin.UseVisualStyleBackColor = true;
132
+            this.BtnLogin.Click += new System.EventHandler(this.BtnLogin_Click);
133
+            // 
134
+            // BtnSendData
135
+            // 
136
+            this.BtnSendData.Enabled = false;
137
+            this.BtnSendData.Location = new System.Drawing.Point(285, 45);
138
+            this.BtnSendData.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
139
+            this.BtnSendData.Name = "BtnSendData";
140
+            this.BtnSendData.Size = new System.Drawing.Size(87, 31);
141
+            this.BtnSendData.TabIndex = 2;
142
+            this.BtnSendData.Text = "发送数据";
143
+            this.BtnSendData.UseVisualStyleBackColor = true;
144
+            this.BtnSendData.Click += new System.EventHandler(this.BtnSendData_Click);
145
+            // 
146
+            // menuStrip1
147
+            // 
148
+            this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
149
+            this.文件FToolStripMenuItem,
150
+            this.时间TToolStripMenuItem,
151
+            this.历史HToolStripMenuItem});
152
+            this.menuStrip1.Location = new System.Drawing.Point(0, 0);
153
+            this.menuStrip1.Name = "menuStrip1";
154
+            this.menuStrip1.Padding = new System.Windows.Forms.Padding(7, 3, 0, 3);
155
+            this.menuStrip1.Size = new System.Drawing.Size(985, 27);
156
+            this.menuStrip1.TabIndex = 3;
157
+            this.menuStrip1.Text = "menuStrip1";
158
+            // 
159
+            // 文件FToolStripMenuItem
160
+            // 
161
+            this.文件FToolStripMenuItem.Name = "文件FToolStripMenuItem";
162
+            this.文件FToolStripMenuItem.Size = new System.Drawing.Size(58, 21);
163
+            this.文件FToolStripMenuItem.Text = "文件(&F)";
164
+            // 
165
+            // 时间TToolStripMenuItem
166
+            // 
167
+            this.时间TToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
168
+            this.RT_HB_Time,
169
+            this.toolStripSeparator1});
170
+            this.时间TToolStripMenuItem.Name = "时间TToolStripMenuItem";
171
+            this.时间TToolStripMenuItem.Size = new System.Drawing.Size(59, 21);
172
+            this.时间TToolStripMenuItem.Text = "时间(&T)";
173
+            // 
174
+            // RT_HB_Time
175
+            // 
176
+            this.RT_HB_Time.Name = "RT_HB_Time";
177
+            this.RT_HB_Time.Size = new System.Drawing.Size(141, 22);
178
+            this.RT_HB_Time.Text = "心跳超时(&H)";
179
+            this.RT_HB_Time.Click += new System.EventHandler(this.RT_HB_Time_Click);
180
+            // 
181
+            // toolStripSeparator1
182
+            // 
183
+            this.toolStripSeparator1.Name = "toolStripSeparator1";
184
+            this.toolStripSeparator1.Size = new System.Drawing.Size(138, 6);
185
+            // 
186
+            // 历史HToolStripMenuItem
187
+            // 
188
+            this.历史HToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
189
+            this.RT_HI_Host,
190
+            this.RT_HI_DeviceId,
191
+            this.RT_HI_CCID,
192
+            this.toolStripSeparator2,
193
+            this.RT_HI_SendData});
194
+            this.历史HToolStripMenuItem.Name = "历史HToolStripMenuItem";
195
+            this.历史HToolStripMenuItem.Size = new System.Drawing.Size(61, 21);
196
+            this.历史HToolStripMenuItem.Text = "历史(&H)";
197
+            // 
198
+            // RT_HI_Host
199
+            // 
200
+            this.RT_HI_Host.Name = "RT_HI_Host";
201
+            this.RT_HI_Host.Size = new System.Drawing.Size(124, 22);
202
+            this.RT_HI_Host.Text = "Host";
203
+            // 
204
+            // RT_HI_DeviceId
205
+            // 
206
+            this.RT_HI_DeviceId.Name = "RT_HI_DeviceId";
207
+            this.RT_HI_DeviceId.Size = new System.Drawing.Size(124, 22);
208
+            this.RT_HI_DeviceId.Text = "地址";
209
+            // 
210
+            // RT_HI_CCID
211
+            // 
212
+            this.RT_HI_CCID.Name = "RT_HI_CCID";
213
+            this.RT_HI_CCID.Size = new System.Drawing.Size(124, 22);
214
+            this.RT_HI_CCID.Text = "CCID";
215
+            // 
216
+            // toolStripSeparator2
217
+            // 
218
+            this.toolStripSeparator2.Name = "toolStripSeparator2";
219
+            this.toolStripSeparator2.Size = new System.Drawing.Size(121, 6);
220
+            // 
221
+            // RT_HI_SendData
222
+            // 
223
+            this.RT_HI_SendData.Name = "RT_HI_SendData";
224
+            this.RT_HI_SendData.Size = new System.Drawing.Size(124, 22);
225
+            this.RT_HI_SendData.Text = "发送数据";
226
+            // 
227
+            // statusStrip1
228
+            // 
229
+            this.statusStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
230
+            this.toolStripStatusLabel1,
231
+            this.StatusItemHbTime});
232
+            this.statusStrip1.Location = new System.Drawing.Point(0, 685);
233
+            this.statusStrip1.Name = "statusStrip1";
234
+            this.statusStrip1.Padding = new System.Windows.Forms.Padding(1, 0, 16, 0);
235
+            this.statusStrip1.Size = new System.Drawing.Size(985, 22);
236
+            this.statusStrip1.TabIndex = 4;
237
+            this.statusStrip1.Text = "statusStrip1";
238
+            // 
239
+            // toolStripStatusLabel1
240
+            // 
241
+            this.toolStripStatusLabel1.Name = "toolStripStatusLabel1";
242
+            this.toolStripStatusLabel1.Size = new System.Drawing.Size(35, 17);
243
+            this.toolStripStatusLabel1.Text = "心跳:";
244
+            // 
245
+            // StatusItemHbTime
246
+            // 
247
+            this.StatusItemHbTime.Name = "StatusItemHbTime";
248
+            this.StatusItemHbTime.Size = new System.Drawing.Size(0, 17);
249
+            // 
250
+            // groupBox1
251
+            // 
252
+            this.groupBox1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 
253
+            | System.Windows.Forms.AnchorStyles.Right)));
254
+            this.groupBox1.Controls.Add(this.TbSendData);
255
+            this.groupBox1.Controls.Add(this.label5);
256
+            this.groupBox1.Controls.Add(this.BtnTest);
257
+            this.groupBox1.Controls.Add(this.BtnCmdManager);
258
+            this.groupBox1.Controls.Add(this.label4);
259
+            this.groupBox1.Controls.Add(this.TbCCID);
260
+            this.groupBox1.Controls.Add(this.BtnSendData);
261
+            this.groupBox1.Controls.Add(this.BtnDisConn);
262
+            this.groupBox1.Controls.Add(this.BtnLogin);
263
+            this.groupBox1.Controls.Add(this.label3);
264
+            this.groupBox1.Controls.Add(this.TbDeviceId);
265
+            this.groupBox1.Controls.Add(this.label2);
266
+            this.groupBox1.Controls.Add(this.BtnConnection);
267
+            this.groupBox1.Controls.Add(this.label1);
268
+            this.groupBox1.Controls.Add(this.TbHost);
269
+            this.groupBox1.Controls.Add(this.TbPort);
270
+            this.groupBox1.Location = new System.Drawing.Point(12, 30);
271
+            this.groupBox1.Name = "groupBox1";
272
+            this.groupBox1.Size = new System.Drawing.Size(961, 126);
273
+            this.groupBox1.TabIndex = 5;
274
+            this.groupBox1.TabStop = false;
275
+            this.groupBox1.Text = " ";
276
+            // 
277
+            // BtnTest
278
+            // 
279
+            this.BtnTest.Enabled = false;
280
+            this.BtnTest.Location = new System.Drawing.Point(471, 45);
281
+            this.BtnTest.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
282
+            this.BtnTest.Name = "BtnTest";
283
+            this.BtnTest.Size = new System.Drawing.Size(87, 31);
284
+            this.BtnTest.TabIndex = 8;
285
+            this.BtnTest.Text = "测试";
286
+            this.BtnTest.UseVisualStyleBackColor = true;
287
+            // 
288
+            // BtnCmdManager
289
+            // 
290
+            this.BtnCmdManager.Enabled = false;
291
+            this.BtnCmdManager.Location = new System.Drawing.Point(378, 45);
292
+            this.BtnCmdManager.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
293
+            this.BtnCmdManager.Name = "BtnCmdManager";
294
+            this.BtnCmdManager.Size = new System.Drawing.Size(87, 31);
295
+            this.BtnCmdManager.TabIndex = 8;
296
+            this.BtnCmdManager.Text = "命令管理";
297
+            this.BtnCmdManager.UseVisualStyleBackColor = true;
298
+            // 
299
+            // label4
300
+            // 
301
+            this.label4.AutoSize = true;
302
+            this.label4.Location = new System.Drawing.Point(635, 16);
303
+            this.label4.Name = "label4";
304
+            this.label4.Size = new System.Drawing.Size(37, 17);
305
+            this.label4.TabIndex = 7;
306
+            this.label4.Text = "CCID";
307
+            // 
308
+            // TbCCID
309
+            // 
310
+            this.TbCCID.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 
311
+            | System.Windows.Forms.AnchorStyles.Right)));
312
+            this.TbCCID.Location = new System.Drawing.Point(673, 13);
313
+            this.TbCCID.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
314
+            this.TbCCID.Name = "TbCCID";
315
+            this.TbCCID.Size = new System.Drawing.Size(282, 22);
316
+            this.TbCCID.TabIndex = 6;
317
+            this.TbCCID.Text = "3839383630324731313931353530333339393137";
318
+            // 
319
+            // label3
320
+            // 
321
+            this.label3.AutoSize = true;
322
+            this.label3.Location = new System.Drawing.Point(434, 18);
323
+            this.label3.Name = "label3";
324
+            this.label3.Size = new System.Drawing.Size(32, 17);
325
+            this.label3.TabIndex = 5;
326
+            this.label3.Text = "地址";
327
+            // 
328
+            // TbDeviceId
329
+            // 
330
+            this.TbDeviceId.Location = new System.Drawing.Point(472, 15);
331
+            this.TbDeviceId.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
332
+            this.TbDeviceId.Name = "TbDeviceId";
333
+            this.TbDeviceId.Size = new System.Drawing.Size(157, 22);
334
+            this.TbDeviceId.TabIndex = 4;
335
+            this.TbDeviceId.Text = "000000000001";
336
+            // 
337
+            // label2
338
+            // 
339
+            this.label2.AutoSize = true;
340
+            this.label2.Location = new System.Drawing.Point(333, 18);
341
+            this.label2.Name = "label2";
342
+            this.label2.Size = new System.Drawing.Size(32, 17);
343
+            this.label2.TabIndex = 3;
344
+            this.label2.Text = "Port";
345
+            // 
346
+            // label1
347
+            // 
348
+            this.label1.AutoSize = true;
349
+            this.label1.Location = new System.Drawing.Point(6, 18);
350
+            this.label1.Name = "label1";
351
+            this.label1.Size = new System.Drawing.Size(35, 17);
352
+            this.label1.TabIndex = 2;
353
+            this.label1.Text = "Host";
354
+            // 
355
+            // label5
356
+            // 
357
+            this.label5.AutoSize = true;
358
+            this.label5.Location = new System.Drawing.Point(319, 86);
359
+            this.label5.Name = "label5";
360
+            this.label5.Size = new System.Drawing.Size(56, 17);
361
+            this.label5.TabIndex = 9;
362
+            this.label5.Text = "发送数据";
363
+            // 
364
+            // TbSendData
365
+            // 
366
+            this.TbSendData.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 
367
+            | System.Windows.Forms.AnchorStyles.Right)));
368
+            this.TbSendData.Location = new System.Drawing.Point(381, 83);
369
+            this.TbSendData.Name = "TbSendData";
370
+            this.TbSendData.Size = new System.Drawing.Size(574, 22);
371
+            this.TbSendData.TabIndex = 10;
372
+            this.TbSendData.Text = "7e7e7e000000000001b00056020004071008011709221059290200000217092210592900000003170" +
373
+    "92210592902000004170922105929020000051709221059290001160617092210592900012f07170" +
374
+    "92210592902000008170922105929020000cd";
375
+            // 
376
+            // MainForm
377
+            // 
378
+            this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 16F);
379
+            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
380
+            this.ClientSize = new System.Drawing.Size(985, 707);
381
+            this.Controls.Add(this.groupBox1);
382
+            this.Controls.Add(this.statusStrip1);
383
+            this.Controls.Add(this.LBLogShow);
384
+            this.Controls.Add(this.menuStrip1);
385
+            this.Font = new System.Drawing.Font("微软雅黑", 8.5F);
386
+            this.MainMenuStrip = this.menuStrip1;
387
+            this.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
388
+            this.Name = "MainForm";
389
+            this.Text = "模拟器";
390
+            this.Load += new System.EventHandler(this.MainForm_Load);
391
+            this.menuStrip1.ResumeLayout(false);
392
+            this.menuStrip1.PerformLayout();
393
+            this.statusStrip1.ResumeLayout(false);
394
+            this.statusStrip1.PerformLayout();
395
+            this.groupBox1.ResumeLayout(false);
396
+            this.groupBox1.PerformLayout();
397
+            this.ResumeLayout(false);
398
+            this.PerformLayout();
399
+
400
+        }
401
+
402
+        #endregion
403
+
404
+        private System.Windows.Forms.ListBox LBLogShow;
405
+        private System.Windows.Forms.TextBox TbHost;
406
+        private System.Windows.Forms.TextBox TbPort;
407
+        private System.Windows.Forms.Button BtnConnection;
408
+        private System.Windows.Forms.Button BtnDisConn;
409
+        private System.Windows.Forms.Button BtnLogin;
410
+        private System.Windows.Forms.Button BtnSendData;
411
+        private System.Windows.Forms.MenuStrip menuStrip1;
412
+        private System.Windows.Forms.ToolStripMenuItem 文件FToolStripMenuItem;
413
+        private System.Windows.Forms.StatusStrip statusStrip1;
414
+        private System.Windows.Forms.ToolStripMenuItem 时间TToolStripMenuItem;
415
+        private System.Windows.Forms.ToolStripMenuItem RT_HB_Time;
416
+        private System.Windows.Forms.ToolStripSeparator toolStripSeparator1;
417
+        private System.Windows.Forms.ToolStripStatusLabel toolStripStatusLabel1;
418
+        private System.Windows.Forms.ToolStripStatusLabel StatusItemHbTime;
419
+        private System.Windows.Forms.GroupBox groupBox1;
420
+        private System.Windows.Forms.Label label4;
421
+        private System.Windows.Forms.TextBox TbCCID;
422
+        private System.Windows.Forms.Label label3;
423
+        private System.Windows.Forms.TextBox TbDeviceId;
424
+        private System.Windows.Forms.Label label2;
425
+        private System.Windows.Forms.Label label1;
426
+        private System.Windows.Forms.ToolStripMenuItem 历史HToolStripMenuItem;
427
+        private System.Windows.Forms.ToolStripMenuItem RT_HI_Host;
428
+        private System.Windows.Forms.ToolStripMenuItem RT_HI_DeviceId;
429
+        private System.Windows.Forms.ToolStripMenuItem RT_HI_CCID;
430
+        private System.Windows.Forms.ToolStripSeparator toolStripSeparator2;
431
+        private System.Windows.Forms.ToolStripMenuItem RT_HI_SendData;
432
+        private System.Windows.Forms.Button BtnCmdManager;
433
+        private System.Windows.Forms.Button BtnTest;
434
+        private System.Windows.Forms.TextBox TbSendData;
435
+        private System.Windows.Forms.Label label5;
436
+    }
437
+}
438
+

+ 176 - 0
DotNettyFrom/MainForm.cs Ver arquivo

@@ -0,0 +1,176 @@
1
+using System;
2
+using System.Collections.Generic;
3
+using System.ComponentModel;
4
+using System.Data;
5
+using System.Drawing;
6
+using System.Linq;
7
+using System.Text;
8
+using System.Threading;
9
+using System.Threading.Tasks;
10
+using System.Windows.Forms;
11
+using DotNettyFrom.common;
12
+using DotNettyFrom.config;
13
+using DotNettyFrom.dialog;
14
+using DotNettyFrom.netty;
15
+
16
+namespace DotNettyFrom
17
+{
18
+    public partial class MainForm : Form
19
+    {
20
+        #region 属性
21
+
22
+        private NettyClient _nettyClient;
23
+        private string host;
24
+        private int port;
25
+
26
+        #endregion
27
+
28
+
29
+        public MainForm()
30
+        {
31
+            InitializeComponent();
32
+        }
33
+
34
+        private void MainForm_Load(object sender, EventArgs e)
35
+        {
36
+            updateUIComponent();
37
+
38
+            var consumer = Task.Factory.StartNew(() =>
39
+            {
40
+                foreach (UIInfoModel value in DataModel.ReceCollection.GetConsumingEnumerable())
41
+                {
42
+                    Invoke(new ThreadStart(delegate { CallUI(value); }));
43
+                }
44
+            });
45
+        }
46
+
47
+
48
+        private void CallUI(UIInfoModel value)
49
+        {
50
+            LBLogShow.Items.Add(value);
51
+            switch (value.action)
52
+            {
53
+                case -1: //连接不上,服务器没开启
54
+                    break;
55
+                case 1: //连接成功.ChannelActive
56
+                    ConnectionActive();
57
+                    break;
58
+                case 2: //连接断开 ChannelInactive
59
+                    ConnectionInActive();
60
+                    break;
61
+                case 3: //异常. ExceptionCaught
62
+                    break;
63
+            }
64
+        }
65
+
66
+        private void ConnectionActive()
67
+        {
68
+            TbHost.Enabled = false;
69
+            TbPort.Enabled = false;
70
+            TbDeviceId.Enabled = false;
71
+            TbCCID.Enabled = false;
72
+
73
+            BtnConnection.Enabled = false;
74
+            BtnLogin.Enabled = false;
75
+
76
+            BtnDisConn.Enabled = true;
77
+            BtnSendData.Enabled = true;
78
+        }
79
+
80
+
81
+        private void ConnectionInActive()
82
+        {
83
+            TbHost.Enabled = true;
84
+            TbPort.Enabled = true;
85
+            TbDeviceId.Enabled = true;
86
+            TbCCID.Enabled = true;
87
+
88
+            BtnConnection.Enabled = true;
89
+            BtnLogin.Enabled = true;
90
+
91
+            BtnDisConn.Enabled = false;
92
+            BtnSendData.Enabled = false;
93
+        }
94
+
95
+        private void beforeConnection()
96
+        {
97
+            this.host = TbHost.Text.Trim();
98
+            this.port = int.Parse(TbPort.Text.Trim());
99
+            updateUIComponent();
100
+        }
101
+
102
+        private void updateUIComponent()
103
+        {
104
+            StatusItemHbTime.Text = "R:" + SystemConfig.ReaderIdleTimeSeconds + "/s,W:" +
105
+                                    SystemConfig.WriterIdleTimeSeconds + "/s,A:" + SystemConfig.AllIdleTimeSeconds +
106
+                                    "/s";
107
+        }
108
+
109
+        #region Component Event
110
+
111
+        private void BtnConnection_Click(object sender, EventArgs e)
112
+        {
113
+            /* var producer = Task.Factory.StartNew(() =>
114
+             {
115
+                 for (int count = 0; count < 1000; count++)
116
+                 {
117
+
118
+
119
+                 }
120
+                 //                blockingCollection.CompleteAdding();
121
+             });*/
122
+            /*_nettyClient = new NettyClient();
123
+            t = new Thread(() => { _nettyClient.StartNetty("127.0.0.1", 4001); });
124
+            t.Start();*/
125
+
126
+            beforeConnection();
127
+
128
+            Task startNew = Task.Factory.StartNew(() =>
129
+            {
130
+                _nettyClient = new NettyClient();
131
+                _nettyClient.StartNetty(host, port);
132
+            });
133
+        }
134
+
135
+        private void BtnLogin_Click(object sender, EventArgs e)
136
+        {
137
+            beforeConnection();
138
+
139
+            Task startNew = Task.Factory.StartNew(() =>
140
+            {
141
+                _nettyClient = new NettyClient();
142
+                _nettyClient.StartNetty(host, port);
143
+
144
+            });
145
+        }
146
+
147
+        private void BtnDisConn_Click(object sender, EventArgs e)
148
+        {
149
+            _nettyClient?.StopNetty();
150
+            //t?.Abort();
151
+        }
152
+
153
+        private void BtnSendData_Click(object sender, EventArgs e)
154
+        {
155
+            string cmd = TbSendData.Text.Trim();
156
+            _nettyClient?.SendData(cmd);
157
+        }
158
+
159
+
160
+        private void RT_HB_Time_Click(object sender, EventArgs e)
161
+        {
162
+            HeartBeatTime hbt = new HeartBeatTime();
163
+            hbt.ShowDialog();
164
+        }
165
+
166
+        private void TbPort_KeyPress(object sender, KeyPressEventArgs e)
167
+        {
168
+            if (e.KeyChar != 8 && !Char.IsDigit(e.KeyChar))
169
+            {
170
+                e.Handled = true;
171
+            }
172
+        }
173
+
174
+        #endregion
175
+    }
176
+}

DotNettyFrom/Form1.resx → DotNettyFrom/MainForm.resx Ver arquivo


+ 1 - 1
DotNettyFrom/Program.cs Ver arquivo

@@ -16,7 +16,7 @@ namespace DotNettyFrom
16 16
         {
17 17
             Application.EnableVisualStyles();
18 18
             Application.SetCompatibleTextRenderingDefault(false);
19
-            Application.Run(new Form1());
19
+            Application.Run(new MainForm());
20 20
         }
21 21
     }
22 22
 }

+ 12 - 5
DotNettyFrom/common/UIInfoModel..cs Ver arquivo

@@ -11,7 +11,7 @@ namespace DotNettyFrom.common
11 11
     public class UIInfoModel
12 12
     {
13 13
         public int action = int.MinValue;
14
-        public DateTime time = DateTime.Now;
14
+        public string time = DateTime.Now.ToLongTimeString().ToString();
15 15
         public string info = "";
16 16
 
17 17
         public string cmd = "";
@@ -63,15 +63,22 @@ namespace DotNettyFrom.common
63 63
             string res = time + " - ";
64 64
             if (!info.Trim().Equals(""))
65 65
             {
66
-                res += this.info + " . ";
66
+                res += this.info;
67 67
             }
68 68
 
69 69
             if (!cmd.Trim().Equals(""))
70 70
             {
71
-                res += "cmdId=" + cmd.Substring(SystemConfig.FunctionCodeStartPos, SystemConfig.FunctionCodeLength) +
72
-                       ".cmd=[" + cmd + "]";
71
+                try
72
+                {
73
+                    string cmdId = cmd.Substring(SystemConfig.FunctionCodeStartPos, SystemConfig.FunctionCodeLength);
74
+                    res += ". cmdId=" + cmdId;
75
+                }
76
+                catch (Exception e)
77
+                {
78
+                }
79
+                res += ". cmd=[" + cmd + "]";
73 80
             }
74
-            return res;
81
+            return res + ".";
75 82
         }
76 83
     }
77 84
 }

+ 10 - 0
DotNettyFrom/config/SystemConfig.cs Ver arquivo

@@ -10,5 +10,15 @@ namespace DotNettyFrom.config
10 10
     {
11 11
         public static int FunctionCodeStartPos = 18;
12 12
         public static int FunctionCodeLength = 2;
13
+
14
+        public static int ReaderIdleTimeSeconds = 30;
15
+        public static int WriterIdleTimeSeconds = 35;
16
+        public static int AllIdleTimeSeconds = 25;
17
+
18
+
19
+        public static int LengthFieldOffset = 10;
20
+        public static int LengthFieldLength = 2;
21
+        public static int LengthAdjustment = 1;
22
+        public static int InitialBytesToStrip = 0;
13 23
     }
14 24
 }

+ 172 - 0
DotNettyFrom/dialog/HeartBeatTime.Designer.cs Ver arquivo

@@ -0,0 +1,172 @@
1
+namespace DotNettyFrom.dialog
2
+{
3
+    partial class HeartBeatTime
4
+    {
5
+        /// <summary>
6
+        /// Required designer variable.
7
+        /// </summary>
8
+        private System.ComponentModel.IContainer components = null;
9
+
10
+        /// <summary>
11
+        /// Clean up any resources being used.
12
+        /// </summary>
13
+        /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
14
+        protected override void Dispose(bool disposing)
15
+        {
16
+            if (disposing && (components != null))
17
+            {
18
+                components.Dispose();
19
+            }
20
+            base.Dispose(disposing);
21
+        }
22
+
23
+        #region Windows Form Designer generated code
24
+
25
+        /// <summary>
26
+        /// Required method for Designer support - do not modify
27
+        /// the contents of this method with the code editor.
28
+        /// </summary>
29
+        private void InitializeComponent()
30
+        {
31
+            this.buttonCancle = new System.Windows.Forms.Button();
32
+            this.label1 = new System.Windows.Forms.Label();
33
+            this.label2 = new System.Windows.Forms.Label();
34
+            this.label3 = new System.Windows.Forms.Label();
35
+            this.buttonOK = new System.Windows.Forms.Button();
36
+            this.textBox4 = new System.Windows.Forms.TextBox();
37
+            this.NumReadTime = new System.Windows.Forms.NumericUpDown();
38
+            this.NumWriteTime = new System.Windows.Forms.NumericUpDown();
39
+            this.NumAllTime = new System.Windows.Forms.NumericUpDown();
40
+            ((System.ComponentModel.ISupportInitialize)(this.NumReadTime)).BeginInit();
41
+            ((System.ComponentModel.ISupportInitialize)(this.NumWriteTime)).BeginInit();
42
+            ((System.ComponentModel.ISupportInitialize)(this.NumAllTime)).BeginInit();
43
+            this.SuspendLayout();
44
+            // 
45
+            // buttonCancle
46
+            // 
47
+            this.buttonCancle.DialogResult = System.Windows.Forms.DialogResult.Cancel;
48
+            this.buttonCancle.Location = new System.Drawing.Point(149, 203);
49
+            this.buttonCancle.Margin = new System.Windows.Forms.Padding(3, 5, 3, 5);
50
+            this.buttonCancle.Name = "buttonCancle";
51
+            this.buttonCancle.Size = new System.Drawing.Size(99, 37);
52
+            this.buttonCancle.TabIndex = 0;
53
+            this.buttonCancle.Text = "取消";
54
+            this.buttonCancle.UseVisualStyleBackColor = true;
55
+            // 
56
+            // label1
57
+            // 
58
+            this.label1.AutoSize = true;
59
+            this.label1.Location = new System.Drawing.Point(131, 56);
60
+            this.label1.Name = "label1";
61
+            this.label1.Size = new System.Drawing.Size(105, 20);
62
+            this.label1.TabIndex = 1;
63
+            this.label1.Text = "心跳-读超时/秒";
64
+            // 
65
+            // label2
66
+            // 
67
+            this.label2.AutoSize = true;
68
+            this.label2.Location = new System.Drawing.Point(117, 147);
69
+            this.label2.Name = "label2";
70
+            this.label2.Size = new System.Drawing.Size(119, 20);
71
+            this.label2.TabIndex = 3;
72
+            this.label2.Text = "心跳-全部超时/秒";
73
+            // 
74
+            // label3
75
+            // 
76
+            this.label3.AutoSize = true;
77
+            this.label3.Location = new System.Drawing.Point(131, 98);
78
+            this.label3.Name = "label3";
79
+            this.label3.Size = new System.Drawing.Size(105, 20);
80
+            this.label3.TabIndex = 5;
81
+            this.label3.Text = "心跳-写超时/秒";
82
+            // 
83
+            // buttonOK
84
+            // 
85
+            this.buttonOK.Location = new System.Drawing.Point(257, 203);
86
+            this.buttonOK.Margin = new System.Windows.Forms.Padding(3, 5, 3, 5);
87
+            this.buttonOK.Name = "buttonOK";
88
+            this.buttonOK.Size = new System.Drawing.Size(99, 37);
89
+            this.buttonOK.TabIndex = 0;
90
+            this.buttonOK.Text = "确定";
91
+            this.buttonOK.UseVisualStyleBackColor = true;
92
+            this.buttonOK.Click += new System.EventHandler(this.buttonOK_Click);
93
+            // 
94
+            // textBox4
95
+            // 
96
+            this.textBox4.Location = new System.Drawing.Point(149, 271);
97
+            this.textBox4.Name = "textBox4";
98
+            this.textBox4.ReadOnly = true;
99
+            this.textBox4.Size = new System.Drawing.Size(207, 25);
100
+            this.textBox4.TabIndex = 7;
101
+            this.textBox4.Text = "下次连接生效";
102
+            this.textBox4.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;
103
+            // 
104
+            // NumReadTime
105
+            // 
106
+            this.NumReadTime.Location = new System.Drawing.Point(257, 54);
107
+            this.NumReadTime.Name = "NumReadTime";
108
+            this.NumReadTime.Size = new System.Drawing.Size(120, 25);
109
+            this.NumReadTime.TabIndex = 8;
110
+            // 
111
+            // NumWriteTime
112
+            // 
113
+            this.NumWriteTime.Location = new System.Drawing.Point(257, 96);
114
+            this.NumWriteTime.Name = "NumWriteTime";
115
+            this.NumWriteTime.Size = new System.Drawing.Size(120, 25);
116
+            this.NumWriteTime.TabIndex = 8;
117
+            // 
118
+            // NumAllTime
119
+            // 
120
+            this.NumAllTime.Location = new System.Drawing.Point(257, 145);
121
+            this.NumAllTime.Name = "NumAllTime";
122
+            this.NumAllTime.Size = new System.Drawing.Size(120, 25);
123
+            this.NumAllTime.TabIndex = 8;
124
+            // 
125
+            // HeartBeatTime
126
+            // 
127
+            this.AcceptButton = this.buttonOK;
128
+            this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 19F);
129
+            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
130
+            this.CancelButton = this.buttonCancle;
131
+            this.ClientSize = new System.Drawing.Size(519, 325);
132
+            this.Controls.Add(this.NumAllTime);
133
+            this.Controls.Add(this.NumWriteTime);
134
+            this.Controls.Add(this.NumReadTime);
135
+            this.Controls.Add(this.textBox4);
136
+            this.Controls.Add(this.label3);
137
+            this.Controls.Add(this.label2);
138
+            this.Controls.Add(this.label1);
139
+            this.Controls.Add(this.buttonOK);
140
+            this.Controls.Add(this.buttonCancle);
141
+            this.Font = new System.Drawing.Font("微软雅黑", 10F);
142
+            this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
143
+            this.Margin = new System.Windows.Forms.Padding(3, 5, 3, 5);
144
+            this.MaximizeBox = false;
145
+            this.MinimizeBox = false;
146
+            this.Name = "HeartBeatTime";
147
+            this.ShowIcon = false;
148
+            this.ShowInTaskbar = false;
149
+            this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
150
+            this.Text = "心跳时间";
151
+            this.Load += new System.EventHandler(this.HeartBeatTime_Load);
152
+            ((System.ComponentModel.ISupportInitialize)(this.NumReadTime)).EndInit();
153
+            ((System.ComponentModel.ISupportInitialize)(this.NumWriteTime)).EndInit();
154
+            ((System.ComponentModel.ISupportInitialize)(this.NumAllTime)).EndInit();
155
+            this.ResumeLayout(false);
156
+            this.PerformLayout();
157
+
158
+        }
159
+
160
+        #endregion
161
+
162
+        private System.Windows.Forms.Button buttonCancle;
163
+        private System.Windows.Forms.Label label1;
164
+        private System.Windows.Forms.Label label2;
165
+        private System.Windows.Forms.Label label3;
166
+        private System.Windows.Forms.Button buttonOK;
167
+        private System.Windows.Forms.TextBox textBox4;
168
+        private System.Windows.Forms.NumericUpDown NumReadTime;
169
+        private System.Windows.Forms.NumericUpDown NumWriteTime;
170
+        private System.Windows.Forms.NumericUpDown NumAllTime;
171
+    }
172
+}

+ 36 - 0
DotNettyFrom/dialog/HeartBeatTime.cs Ver arquivo

@@ -0,0 +1,36 @@
1
+using System;
2
+using System.Collections.Generic;
3
+using System.ComponentModel;
4
+using System.Data;
5
+using System.Drawing;
6
+using System.Linq;
7
+using System.Text;
8
+using System.Threading.Tasks;
9
+using System.Windows.Forms;
10
+using DotNettyFrom.config;
11
+
12
+namespace DotNettyFrom.dialog
13
+{
14
+    public partial class HeartBeatTime : Form
15
+    {
16
+        public HeartBeatTime()
17
+        {
18
+            InitializeComponent();
19
+        }
20
+
21
+        private void HeartBeatTime_Load(object sender, EventArgs e)
22
+        {
23
+            NumReadTime.Value = SystemConfig.ReaderIdleTimeSeconds;
24
+            NumWriteTime.Value = SystemConfig.WriterIdleTimeSeconds;
25
+            NumAllTime.Value = SystemConfig.AllIdleTimeSeconds;
26
+        }
27
+
28
+        private void buttonOK_Click(object sender, EventArgs e)
29
+        {
30
+            SystemConfig.ReaderIdleTimeSeconds = (int) NumReadTime.Value;
31
+            SystemConfig.WriterIdleTimeSeconds = (int) NumWriteTime.Value;
32
+            SystemConfig.AllIdleTimeSeconds = (int) NumAllTime.Value;
33
+            this.Close();
34
+        }
35
+    }
36
+}

+ 120 - 0
DotNettyFrom/dialog/HeartBeatTime.resx Ver arquivo

@@ -0,0 +1,120 @@
1
+<?xml version="1.0" encoding="utf-8"?>
2
+<root>
3
+  <!-- 
4
+    Microsoft ResX Schema 
5
+    
6
+    Version 2.0
7
+    
8
+    The primary goals of this format is to allow a simple XML format 
9
+    that is mostly human readable. The generation and parsing of the 
10
+    various data types are done through the TypeConverter classes 
11
+    associated with the data types.
12
+    
13
+    Example:
14
+    
15
+    ... ado.net/XML headers & schema ...
16
+    <resheader name="resmimetype">text/microsoft-resx</resheader>
17
+    <resheader name="version">2.0</resheader>
18
+    <resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
19
+    <resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
20
+    <data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
21
+    <data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
22
+    <data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
23
+        <value>[base64 mime encoded serialized .NET Framework object]</value>
24
+    </data>
25
+    <data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
26
+        <value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
27
+        <comment>This is a comment</comment>
28
+    </data>
29
+                
30
+    There are any number of "resheader" rows that contain simple 
31
+    name/value pairs.
32
+    
33
+    Each data row contains a name, and value. The row also contains a 
34
+    type or mimetype. Type corresponds to a .NET class that support 
35
+    text/value conversion through the TypeConverter architecture. 
36
+    Classes that don't support this are serialized and stored with the 
37
+    mimetype set.
38
+    
39
+    The mimetype is used for serialized objects, and tells the 
40
+    ResXResourceReader how to depersist the object. This is currently not 
41
+    extensible. For a given mimetype the value must be set accordingly:
42
+    
43
+    Note - application/x-microsoft.net.object.binary.base64 is the format 
44
+    that the ResXResourceWriter will generate, however the reader can 
45
+    read any of the formats listed below.
46
+    
47
+    mimetype: application/x-microsoft.net.object.binary.base64
48
+    value   : The object must be serialized with 
49
+            : System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
50
+            : and then encoded with base64 encoding.
51
+    
52
+    mimetype: application/x-microsoft.net.object.soap.base64
53
+    value   : The object must be serialized with 
54
+            : System.Runtime.Serialization.Formatters.Soap.SoapFormatter
55
+            : and then encoded with base64 encoding.
56
+
57
+    mimetype: application/x-microsoft.net.object.bytearray.base64
58
+    value   : The object must be serialized into a byte array 
59
+            : using a System.ComponentModel.TypeConverter
60
+            : and then encoded with base64 encoding.
61
+    -->
62
+  <xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
63
+    <xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
64
+    <xsd:element name="root" msdata:IsDataSet="true">
65
+      <xsd:complexType>
66
+        <xsd:choice maxOccurs="unbounded">
67
+          <xsd:element name="metadata">
68
+            <xsd:complexType>
69
+              <xsd:sequence>
70
+                <xsd:element name="value" type="xsd:string" minOccurs="0" />
71
+              </xsd:sequence>
72
+              <xsd:attribute name="name" use="required" type="xsd:string" />
73
+              <xsd:attribute name="type" type="xsd:string" />
74
+              <xsd:attribute name="mimetype" type="xsd:string" />
75
+              <xsd:attribute ref="xml:space" />
76
+            </xsd:complexType>
77
+          </xsd:element>
78
+          <xsd:element name="assembly">
79
+            <xsd:complexType>
80
+              <xsd:attribute name="alias" type="xsd:string" />
81
+              <xsd:attribute name="name" type="xsd:string" />
82
+            </xsd:complexType>
83
+          </xsd:element>
84
+          <xsd:element name="data">
85
+            <xsd:complexType>
86
+              <xsd:sequence>
87
+                <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
88
+                <xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
89
+              </xsd:sequence>
90
+              <xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
91
+              <xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
92
+              <xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
93
+              <xsd:attribute ref="xml:space" />
94
+            </xsd:complexType>
95
+          </xsd:element>
96
+          <xsd:element name="resheader">
97
+            <xsd:complexType>
98
+              <xsd:sequence>
99
+                <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
100
+              </xsd:sequence>
101
+              <xsd:attribute name="name" type="xsd:string" use="required" />
102
+            </xsd:complexType>
103
+          </xsd:element>
104
+        </xsd:choice>
105
+      </xsd:complexType>
106
+    </xsd:element>
107
+  </xsd:schema>
108
+  <resheader name="resmimetype">
109
+    <value>text/microsoft-resx</value>
110
+  </resheader>
111
+  <resheader name="version">
112
+    <value>2.0</value>
113
+  </resheader>
114
+  <resheader name="reader">
115
+    <value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
116
+  </resheader>
117
+  <resheader name="writer">
118
+    <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
119
+  </resheader>
120
+</root>

+ 49 - 31
DotNettyFrom/netty/NettyClient.cs Ver arquivo

@@ -3,29 +3,34 @@ using System.Collections.Concurrent;
3 3
 using System.Collections.Generic;
4 4
 using System.Linq;
5 5
 using System.Net;
6
+using System.Runtime.Remoting.Contexts;
6 7
 using System.Text;
7 8
 using System.Threading;
8 9
 using System.Threading.Tasks;
9 10
 using DotNetty.Buffers;
11
+using DotNetty.Codecs;
10 12
 using DotNetty.Handlers.Timeout;
11 13
 using DotNetty.Transport.Bootstrapping;
12 14
 using DotNetty.Transport.Channels;
13 15
 using DotNetty.Transport.Channels.Sockets;
14 16
 using DotNettyFrom.common;
17
+using DotNettyFrom.config;
18
+using DotNettyFrom.util;
15 19
 
16 20
 namespace DotNettyFrom.netty
17 21
 {
18 22
     public class NettyClient
19 23
     {
20
-        public static IChannelHandlerContext Context;
21 24
         private MultithreadEventLoopGroup _group;
22 25
         private NettyClientHandler _clientHandler;
26
+        private static bool _isSendLoginCmd = true;
23 27
 
24
-        public void StartNetty(string host, int port)
28
+        public void StartNetty(string host, int port, bool isSendLoginCmd = true)
25 29
         {
30
+            _isSendLoginCmd = isSendLoginCmd;
26 31
             IPAddress hostIp = IPAddress.Parse(host);
27 32
             RunClientAsync(hostIp, port);
28
-            DataModel.ReceCollection.Add(new UIInfoModel("开启连接"));
33
+            DataModel.ReceCollection.Add(new UIInfoModel("StartNetty:开始尝试连接"));
29 34
         }
30 35
 
31 36
         private async void RunClientAsync(IPAddress HostIP, int Port)
@@ -39,10 +44,16 @@ namespace DotNettyFrom.netty
39 44
                 .Handler(new ActionChannelInitializer<ISocketChannel>(channel =>
40 45
                 {
41 46
                     IChannelPipeline pipeline = channel.Pipeline;
42
-                    //                    pipeline.AddLast("framing-dec", new LengthFieldBasedFrameDecoder(ushort.MaxValue, 10, 2, 1, 0));
43
-                    pipeline.AddLast("idle", new IdleStateHandler(10, 20, 15));
47
+                    /*pipeline.AddLast(new LengthFieldBasedFrameDecoder(ushort.MaxValue,
48
+                        SystemConfig.LengthFieldOffset,
49
+                        SystemConfig.LengthFieldLength,
50
+                        SystemConfig.LengthAdjustment,
51
+                        SystemConfig.InitialBytesToStrip));*/
52
+                    pipeline.AddLast(new IdleStateHandler(SystemConfig.ReaderIdleTimeSeconds,
53
+                        SystemConfig.WriterIdleTimeSeconds,
54
+                        SystemConfig.AllIdleTimeSeconds));
44 55
                     _clientHandler = new NettyClientHandler();
45
-                    pipeline.AddLast("echo", _clientHandler);
56
+                    pipeline.AddLast(_clientHandler);
46 57
                 }));
47 58
             try
48 59
             {
@@ -52,7 +63,7 @@ namespace DotNettyFrom.netty
52 63
             {
53 64
                 //连接出错,服务器没开启....
54 65
                 //Console.WriteLine(e);
55
-                DataModel.ReceCollection.Add(new UIInfoModel("远程服务器连接失败").setAction(-1));
66
+                DataModel.ReceCollection.Add(new UIInfoModel("远程服务器连接失败." + e.Message).setAction(-1));
56 67
                 await _group.ShutdownGracefullyAsync(TimeSpan.FromMilliseconds(100), TimeSpan.FromSeconds(1));
57 68
             }
58 69
         }
@@ -60,42 +71,49 @@ namespace DotNettyFrom.netty
60 71
 
61 72
         public void SendData(string hex)
62 73
         {
63
-            if (Context.Channel.Active)
74
+            if (NettyClientHandler.Context.Channel.Active)
64 75
             {
65
-                IByteBuffer msg = Unpooled.Buffer(128);
66
-                byte[] messageBytes = Encoding.UTF8.GetBytes(DateTime.Now.ToLongDateString());
67
-                msg.WriteBytes(messageBytes);
68
-                Context.Channel.WriteAndFlushAsync(msg);
76
+                IByteBuffer msg = AryUtil.Hex2IByteBuffer(hex);
77
+                NettyClientHandler.Context.WriteAndFlushAsync(msg);
69 78
                 DataModel.ReceCollection.Add(new UIInfoModel("发送", hex).setIsSend(true));
70 79
             }
71 80
             else
72 81
             {
73
-                DataModel.ReceCollection.Add(new UIInfoModel("连接已经断开"));
82
+                DataModel.ReceCollection.Add(new UIInfoModel("SendData:连接已经断开"));
74 83
             }
75 84
         }
76 85
 
77 86
 
78 87
         public void StopNetty()
79 88
         {
80
-            Context?.Channel.CloseAsync();
89
+            NettyClientHandler.Context?.Channel.CloseAsync();
81 90
             _group?.ShutdownGracefullyAsync(TimeSpan.FromMilliseconds(100), TimeSpan.FromSeconds(1));
82 91
             _group = null;
83
-            Context = null;
92
+            NettyClientHandler.Context = null;
84 93
             _clientHandler = null;
85
-            DataModel.ReceCollection.Add(new UIInfoModel("停止连接"));
94
+            DataModel.ReceCollection.Add(new UIInfoModel("StopNetty:停止连接"));
86 95
         }
87 96
 
88 97
 
89
-        class NettyClientHandler : ChannelHandlerAdapter
98
+        public class NettyClientHandler : ChannelHandlerAdapter
90 99
         {
100
+            internal static IChannelHandlerContext Context;
101
+
91 102
             public override void ChannelActive(IChannelHandlerContext context)
92 103
             {
93 104
                 Context = context;
94
-                IByteBuffer msg = Unpooled.Buffer(128);
95
-                byte[] messageBytes = Encoding.UTF8.GetBytes(DateTime.Now.ToLongDateString());
96
-                msg.WriteBytes(messageBytes);
97
-                context.WriteAndFlushAsync(msg);
98
-                DataModel.ReceCollection.Add(new UIInfoModel("连接成功").setAction(1));
105
+                DataModel.ReceCollection.Add(new UIInfoModel("ChannelActive:连接成功").setAction(1));
106
+
107
+                if (_isSendLoginCmd)
108
+                {
109
+                    //发送登录指令
110
+                    IByteBuffer cmd =
111
+                        AryUtil.Hex2IByteBuffer("7e7e7e0000000000018200143839383630324731313931353530333339393137e3");
112
+                    context.WriteAndFlushAsync(cmd);
113
+                    DataModel.ReceCollection.Add(
114
+                        new UIInfoModel("发送登录", "7e7e7e0000000000018200143839383630324731313931353530333339393137e3")
115
+                            .setAction(1).setIsSend(true));
116
+                }
99 117
             }
100 118
 
101 119
 
@@ -103,15 +121,14 @@ namespace DotNettyFrom.netty
103 121
             {
104 122
                 if (message is IByteBuffer buffer)
105 123
                 {
106
-                    string abc = buffer.ToString(Encoding.UTF8);
124
+                    //string recCmd = AryUtil.ByteBuffer2Hex(buffer);
107 125
 
108
-                    DataModel.ReceCollection.Add(new UIInfoModel("", "收到:-----------" + abc));
109
-                }
126
+                    byte[] byteBufferArray = new byte[buffer.ReadableBytes];
127
+                    buffer.ReadBytes(byteBufferArray);
128
+                    string recCmd = AryUtil.Bytes2Hex(byteBufferArray);
110 129
 
111
-//                IByteBuffer msg = Unpooled.Buffer(128);
112
-//                byte[] messageBytes = Encoding.UTF8.GetBytes(DateTime.Now.ToLongDateString());
113
-//                msg.WriteBytes(messageBytes);
114
-//                context.WriteAndFlushAsync(msg);
130
+                    DataModel.ReceCollection.Add(new UIInfoModel("收到", recCmd));
131
+                }
115 132
             }
116 133
 
117 134
             public override void ChannelReadComplete(IChannelHandlerContext context)
@@ -128,13 +145,14 @@ namespace DotNettyFrom.netty
128 145
             {
129 146
                 base.ExceptionCaught(context, exception);
130 147
                 Console.WriteLine(exception.Message);
131
-                DataModel.ReceCollection.Add(new UIInfoModel("", "ExceptionCaught:" + exception.Message).setAction(3));
148
+                DataModel.ReceCollection.Add(new UIInfoModel("ExceptionCaught:" + exception.Message).setAction(3));
132 149
             }
133 150
 
134 151
             public override void ChannelInactive(IChannelHandlerContext context)
135 152
             {
136 153
                 base.ChannelInactive(context);
137
-                DataModel.ReceCollection.Add(new UIInfoModel("", "ChannelInactive").setAction(2));
154
+                DataModel.ReceCollection.Add(new UIInfoModel("ChannelInactive:" + context.Channel)
155
+                    .setAction(2));
138 156
             }
139 157
         }
140 158
     }

+ 45 - 0
DotNettyFrom/util/AryUtil.cs Ver arquivo

@@ -0,0 +1,45 @@
1
+using System;
2
+using System.Collections.Generic;
3
+using System.Linq;
4
+using System.Text;
5
+using System.Threading.Tasks;
6
+using DotNetty.Buffers;
7
+using DotNettyFrom.netty;
8
+
9
+namespace DotNettyFrom.util
10
+{
11
+    public class AryUtil
12
+    {
13
+        public static string Bytes2Hex(byte[] bs)
14
+        {
15
+            return BitConverter.ToString(bs, 0, bs.Length).Replace("-", "").ToUpper();
16
+        }
17
+
18
+
19
+        public static byte[] Hex2Bytes(string hex)
20
+        {
21
+            hex = hex.Replace(" ", "");
22
+            if (hex.Length % 2 != 0)
23
+                hex += " ";
24
+            byte[] returnBytes = new byte[hex.Length / 2];
25
+            for (int i = 0; i < returnBytes.Length; i++)
26
+                returnBytes[i] = Convert.ToByte(hex.Substring(i * 2, 2).Trim(), 16);
27
+            return returnBytes;
28
+        }
29
+
30
+        public static IByteBuffer Hex2IByteBuffer(string hex)
31
+        {
32
+            byte[] bytes = AryUtil.Hex2Bytes(hex);
33
+            IByteBuffer msg = Unpooled.Buffer(bytes.Length);
34
+            msg.WriteBytes(bytes);
35
+            return msg;
36
+        }
37
+
38
+        public static string ByteBuffer2Hex(IByteBuffer msg)
39
+        {
40
+            byte[] byteBufferArray = new byte[msg.ReadableBytes];
41
+            msg.ReadBytes(byteBufferArray);
42
+            return AryUtil.Bytes2Hex(byteBufferArray);
43
+        }
44
+    }
45
+}