From 42b0b353a41889e4ffeba5ea900e0e3fbdd265fd Mon Sep 17 00:00:00 2001 From: "U-JOHNLIU\\jonhl" Date: Tue, 6 Apr 2021 01:14:54 +0800 Subject: [PATCH] init --- .vs/dgiot_dtu/v14/.suo | Bin 0 -> 28160 bytes DD-All.ico | Bin 0 -> 4286 bytes MainForm.Designer.cs | 486 +++++++++++++++++++++ MainForm.cs | 719 +++++++++++++++++++++++++++++++ MainForm.resx | 200 +++++++++ Program.cs | 20 + Properties/AssemblyInfo.cs | 36 ++ Properties/Resources.Designer.cs | 63 +++ Properties/Resources.resx | 117 +++++ Properties/Settings.Designer.cs | 26 ++ Properties/Settings.settings | 7 + StringHelper.cs | 59 +++ app.config | 3 + dgiot_dtu.csproj | 92 ++++ dgiot_dtu.sln | 22 + 15 files changed, 1850 insertions(+) create mode 100644 .vs/dgiot_dtu/v14/.suo create mode 100644 DD-All.ico create mode 100644 MainForm.Designer.cs create mode 100644 MainForm.cs create mode 100644 MainForm.resx create mode 100644 Program.cs create mode 100644 Properties/AssemblyInfo.cs create mode 100644 Properties/Resources.Designer.cs create mode 100644 Properties/Resources.resx create mode 100644 Properties/Settings.Designer.cs create mode 100644 Properties/Settings.settings create mode 100644 StringHelper.cs create mode 100644 app.config create mode 100644 dgiot_dtu.csproj create mode 100644 dgiot_dtu.sln diff --git a/.vs/dgiot_dtu/v14/.suo b/.vs/dgiot_dtu/v14/.suo new file mode 100644 index 0000000000000000000000000000000000000000..a62e94c99d206d8acae2773a71f2e12d5cb1beba GIT binary patch literal 28160 zcmeHPdypK(d7qUK=*2^bVB%o2fD97cEPK1Nk3&e-zD^R>NoVdP;b>)fZ+G@?@Ah%* z?&$${juIPUFor;|V;l#f;5=*-9FvD};z#Tx#Bt()V;ondQmKS;Qk1LsBP6M~k_yW2 zH$A;KJGYP7y{F9e)^8p?J>6e-f8W<%f8Db$zqI9_&wcUj|DxE!Ze^|V=J^fE#g=#% zuGh%>D-`8g^Zw2A=g%{GEr83_Z~?WzT}lb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s @@ -0,0 +1,486 @@ +namespace dgiot_dtu +{ + partial class MainForm + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.components = new System.ComponentModel.Container(); + System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(MainForm)); + this.buttonStartStop = new System.Windows.Forms.Button(); + this.textBoxLog = new System.Windows.Forms.TextBox(); + this.linkLabel1 = new System.Windows.Forms.LinkLabel(); + this.checkBoxReconnect = new System.Windows.Forms.CheckBox(); + this.checkBoxDisplayHex = new System.Windows.Forms.CheckBox(); + this.buttonClear = new System.Windows.Forms.Button(); + this.groupBoxSerialPort = new System.Windows.Forms.GroupBox(); + this.label5 = new System.Windows.Forms.Label(); + this.label4 = new System.Windows.Forms.Label(); + this.label1 = new System.Windows.Forms.Label(); + this.comboBoxStopBits = new System.Windows.Forms.ComboBox(); + this.comboBoxDataBits = new System.Windows.Forms.ComboBox(); + this.comboBoxBaudRate = new System.Windows.Forms.ComboBox(); + this.labelSerialPort = new System.Windows.Forms.Label(); + this.comboBoxSerialPort = new System.Windows.Forms.ComboBox(); + this.groupBox1 = new System.Windows.Forms.GroupBox(); + this.label6 = new System.Windows.Forms.Label(); + this.textlogin = new System.Windows.Forms.TextBox(); + this.textBoxReadOnlyPort = new System.Windows.Forms.TextBox(); + this.label2 = new System.Windows.Forms.Label(); + this.textBoxTargetPort = new System.Windows.Forms.TextBox(); + this.labelTargetPort = new System.Windows.Forms.Label(); + this.textBoxIPAddress = new System.Windows.Forms.TextBox(); + this.checkBoxTelnet = new System.Windows.Forms.CheckBox(); + this.labelTargetIP = new System.Windows.Forms.Label(); + this.radioButtonServer = new System.Windows.Forms.RadioButton(); + this.radioButtonClient = new System.Windows.Forms.RadioButton(); + this.label3 = new System.Windows.Forms.Label(); + this.linkLabel2 = new System.Windows.Forms.LinkLabel(); + this.toolTip1 = new System.Windows.Forms.ToolTip(this.components); + this.groupBoxSerialPort.SuspendLayout(); + this.groupBox1.SuspendLayout(); + this.SuspendLayout(); + // + // buttonStartStop + // + this.buttonStartStop.Location = new System.Drawing.Point(693, 38); + this.buttonStartStop.Margin = new System.Windows.Forms.Padding(4); + this.buttonStartStop.Name = "buttonStartStop"; + this.buttonStartStop.Size = new System.Drawing.Size(112, 32); + this.buttonStartStop.TabIndex = 4; + this.buttonStartStop.Text = "Start"; + this.buttonStartStop.UseVisualStyleBackColor = true; + this.buttonStartStop.Click += new System.EventHandler(this.ButtonStartStopClick); + // + // textBoxLog + // + this.textBoxLog.Location = new System.Drawing.Point(18, 255); + this.textBoxLog.Margin = new System.Windows.Forms.Padding(4); + this.textBoxLog.Multiline = true; + this.textBoxLog.Name = "textBoxLog"; + this.textBoxLog.ScrollBars = System.Windows.Forms.ScrollBars.Vertical; + this.textBoxLog.Size = new System.Drawing.Size(835, 372); + this.textBoxLog.TabIndex = 9; + // + // linkLabel1 + // + this.linkLabel1.AutoSize = true; + this.linkLabel1.LinkColor = System.Drawing.Color.Silver; + this.linkLabel1.Location = new System.Drawing.Point(550, 633); + this.linkLabel1.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); + this.linkLabel1.Name = "linkLabel1"; + this.linkLabel1.Size = new System.Drawing.Size(179, 18); + this.linkLabel1.TabIndex = 10; + this.linkLabel1.TabStop = true; + this.linkLabel1.Text = "Dynamic Devices Ltd"; + this.linkLabel1.LinkClicked += new System.Windows.Forms.LinkLabelLinkClickedEventHandler(this.LinkLabel1LinkClicked); + // + // checkBoxReconnect + // + this.checkBoxReconnect.AutoSize = true; + this.checkBoxReconnect.Location = new System.Drawing.Point(693, 88); + this.checkBoxReconnect.Margin = new System.Windows.Forms.Padding(4); + this.checkBoxReconnect.Name = "checkBoxReconnect"; + this.checkBoxReconnect.Size = new System.Drawing.Size(160, 22); + this.checkBoxReconnect.TabIndex = 5; + this.checkBoxReconnect.Text = "Auto Reconnect"; + this.checkBoxReconnect.UseVisualStyleBackColor = true; + this.checkBoxReconnect.CheckedChanged += new System.EventHandler(this.CheckBoxReconnectCheckedChanged); + // + // checkBoxDisplayHex + // + this.checkBoxDisplayHex.AutoSize = true; + this.checkBoxDisplayHex.Location = new System.Drawing.Point(693, 124); + this.checkBoxDisplayHex.Margin = new System.Windows.Forms.Padding(4); + this.checkBoxDisplayHex.Name = "checkBoxDisplayHex"; + this.checkBoxDisplayHex.Size = new System.Drawing.Size(133, 22); + this.checkBoxDisplayHex.TabIndex = 11; + this.checkBoxDisplayHex.Text = "Display Hex"; + this.checkBoxDisplayHex.UseVisualStyleBackColor = true; + this.checkBoxDisplayHex.CheckedChanged += new System.EventHandler(this.CheckBoxDisplayHexCheckedChanged); + // + // buttonClear + // + this.buttonClear.Location = new System.Drawing.Point(693, 178); + this.buttonClear.Margin = new System.Windows.Forms.Padding(4); + this.buttonClear.Name = "buttonClear"; + this.buttonClear.Size = new System.Drawing.Size(112, 32); + this.buttonClear.TabIndex = 12; + this.buttonClear.Text = "Clear Log"; + this.buttonClear.UseVisualStyleBackColor = true; + this.buttonClear.Click += new System.EventHandler(this.ButtonClearClick); + // + // groupBoxSerialPort + // + this.groupBoxSerialPort.Controls.Add(this.label5); + this.groupBoxSerialPort.Controls.Add(this.label4); + this.groupBoxSerialPort.Controls.Add(this.label1); + this.groupBoxSerialPort.Controls.Add(this.comboBoxStopBits); + this.groupBoxSerialPort.Controls.Add(this.comboBoxDataBits); + this.groupBoxSerialPort.Controls.Add(this.comboBoxBaudRate); + this.groupBoxSerialPort.Controls.Add(this.labelSerialPort); + this.groupBoxSerialPort.Controls.Add(this.comboBoxSerialPort); + this.groupBoxSerialPort.Location = new System.Drawing.Point(18, 18); + this.groupBoxSerialPort.Margin = new System.Windows.Forms.Padding(4); + this.groupBoxSerialPort.Name = "groupBoxSerialPort"; + this.groupBoxSerialPort.Padding = new System.Windows.Forms.Padding(4); + this.groupBoxSerialPort.Size = new System.Drawing.Size(246, 218); + this.groupBoxSerialPort.TabIndex = 13; + this.groupBoxSerialPort.TabStop = false; + this.groupBoxSerialPort.Text = "Serial Port"; + // + // label5 + // + this.label5.AutoSize = true; + this.label5.Location = new System.Drawing.Point(20, 146); + this.label5.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); + this.label5.Name = "label5"; + this.label5.Size = new System.Drawing.Size(80, 18); + this.label5.TabIndex = 12; + this.label5.Text = "stopBits"; + // + // label4 + // + this.label4.AutoSize = true; + this.label4.Location = new System.Drawing.Point(20, 106); + this.label4.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); + this.label4.Name = "label4"; + this.label4.Size = new System.Drawing.Size(80, 18); + this.label4.TabIndex = 12; + this.label4.Text = "dataBits"; + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Location = new System.Drawing.Point(20, 68); + this.label1.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(89, 18); + this.label1.TabIndex = 12; + this.label1.Text = "Baud Rate"; + // + // comboBoxStopBits + // + this.comboBoxStopBits.FormattingEnabled = true; + this.comboBoxStopBits.Items.AddRange(new object[] { + "1", + "2", + "1.5"}); + this.comboBoxStopBits.Location = new System.Drawing.Point(136, 141); + this.comboBoxStopBits.Margin = new System.Windows.Forms.Padding(4); + this.comboBoxStopBits.Name = "comboBoxStopBits"; + this.comboBoxStopBits.Size = new System.Drawing.Size(98, 26); + this.comboBoxStopBits.TabIndex = 11; + // + // comboBoxDataBits + // + this.comboBoxDataBits.FormattingEnabled = true; + this.comboBoxDataBits.Items.AddRange(new object[] { + "8", + "7", + "6", + "5"}); + this.comboBoxDataBits.Location = new System.Drawing.Point(136, 102); + this.comboBoxDataBits.Margin = new System.Windows.Forms.Padding(4); + this.comboBoxDataBits.Name = "comboBoxDataBits"; + this.comboBoxDataBits.Size = new System.Drawing.Size(98, 26); + this.comboBoxDataBits.TabIndex = 11; + // + // comboBoxBaudRate + // + this.comboBoxBaudRate.FormattingEnabled = true; + this.comboBoxBaudRate.Items.AddRange(new object[] { + "1200", + "2400", + "4800", + "9600", + "19200", + "38400", + "57600", + "115200"}); + this.comboBoxBaudRate.Location = new System.Drawing.Point(136, 63); + this.comboBoxBaudRate.Margin = new System.Windows.Forms.Padding(4); + this.comboBoxBaudRate.Name = "comboBoxBaudRate"; + this.comboBoxBaudRate.Size = new System.Drawing.Size(98, 26); + this.comboBoxBaudRate.TabIndex = 11; + // + // labelSerialPort + // + this.labelSerialPort.AutoSize = true; + this.labelSerialPort.Location = new System.Drawing.Point(20, 30); + this.labelSerialPort.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); + this.labelSerialPort.Name = "labelSerialPort"; + this.labelSerialPort.Size = new System.Drawing.Size(44, 18); + this.labelSerialPort.TabIndex = 10; + this.labelSerialPort.Text = "Port"; + // + // comboBoxSerialPort + // + this.comboBoxSerialPort.FormattingEnabled = true; + this.comboBoxSerialPort.Location = new System.Drawing.Point(136, 26); + this.comboBoxSerialPort.Margin = new System.Windows.Forms.Padding(4); + this.comboBoxSerialPort.Name = "comboBoxSerialPort"; + this.comboBoxSerialPort.Size = new System.Drawing.Size(98, 26); + this.comboBoxSerialPort.TabIndex = 9; + // + // groupBox1 + // + this.groupBox1.Controls.Add(this.label6); + this.groupBox1.Controls.Add(this.textlogin); + this.groupBox1.Controls.Add(this.textBoxReadOnlyPort); + this.groupBox1.Controls.Add(this.label2); + this.groupBox1.Controls.Add(this.textBoxTargetPort); + this.groupBox1.Controls.Add(this.labelTargetPort); + this.groupBox1.Controls.Add(this.textBoxIPAddress); + this.groupBox1.Controls.Add(this.checkBoxTelnet); + this.groupBox1.Controls.Add(this.labelTargetIP); + this.groupBox1.Controls.Add(this.radioButtonServer); + this.groupBox1.Controls.Add(this.radioButtonClient); + this.groupBox1.Location = new System.Drawing.Point(291, 18); + this.groupBox1.Margin = new System.Windows.Forms.Padding(4); + this.groupBox1.Name = "groupBox1"; + this.groupBox1.Padding = new System.Windows.Forms.Padding(4); + this.groupBox1.Size = new System.Drawing.Size(369, 218); + this.groupBox1.TabIndex = 14; + this.groupBox1.TabStop = false; + this.groupBox1.Text = "TCP/IP"; + // + // label6 + // + this.label6.AutoSize = true; + this.label6.Location = new System.Drawing.Point(23, 185); + this.label6.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); + this.label6.Name = "label6"; + this.label6.Size = new System.Drawing.Size(125, 18); + this.label6.TabIndex = 13; + this.label6.Text = "login payload"; + // + // textlogin + // + this.textlogin.Location = new System.Drawing.Point(196, 182); + this.textlogin.Margin = new System.Windows.Forms.Padding(4); + this.textlogin.Name = "textlogin"; + this.textlogin.Size = new System.Drawing.Size(148, 28); + this.textlogin.TabIndex = 12; + this.textlogin.Text = "12345678"; + this.toolTip1.SetToolTip(this.textlogin, "Connect to this port then you can send and receive data to/from Serial port.\r\nThe" + + "re can only be one connection at a time."); + // + // textBoxReadOnlyPort + // + this.textBoxReadOnlyPort.Location = new System.Drawing.Point(195, 144); + this.textBoxReadOnlyPort.Margin = new System.Windows.Forms.Padding(4); + this.textBoxReadOnlyPort.Name = "textBoxReadOnlyPort"; + this.textBoxReadOnlyPort.Size = new System.Drawing.Size(148, 28); + this.textBoxReadOnlyPort.TabIndex = 7; + this.textBoxReadOnlyPort.Text = "8066"; + this.toolTip1.SetToolTip(this.textBoxReadOnlyPort, "Connect to this port then you can receive data from Serial port"); + // + // label2 + // + this.label2.AutoSize = true; + this.label2.Location = new System.Drawing.Point(22, 148); + this.label2.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); + this.label2.Name = "label2"; + this.label2.Size = new System.Drawing.Size(134, 18); + this.label2.TabIndex = 8; + this.label2.Text = "Read-olny Port"; + // + // textBoxTargetPort + // + this.textBoxTargetPort.Location = new System.Drawing.Point(195, 104); + this.textBoxTargetPort.Margin = new System.Windows.Forms.Padding(4); + this.textBoxTargetPort.Name = "textBoxTargetPort"; + this.textBoxTargetPort.Size = new System.Drawing.Size(148, 28); + this.textBoxTargetPort.TabIndex = 7; + this.textBoxTargetPort.Text = "8067"; + this.toolTip1.SetToolTip(this.textBoxTargetPort, "Connect to this port then you can send and receive data to/from Serial port.\r\nThe" + + "re can only be one connection at a time."); + // + // labelTargetPort + // + this.labelTargetPort.AutoSize = true; + this.labelTargetPort.Location = new System.Drawing.Point(22, 108); + this.labelTargetPort.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); + this.labelTargetPort.Name = "labelTargetPort"; + this.labelTargetPort.Size = new System.Drawing.Size(44, 18); + this.labelTargetPort.TabIndex = 8; + this.labelTargetPort.Text = "Port"; + // + // textBoxIPAddress + // + this.textBoxIPAddress.Location = new System.Drawing.Point(195, 63); + this.textBoxIPAddress.Margin = new System.Windows.Forms.Padding(4); + this.textBoxIPAddress.Name = "textBoxIPAddress"; + this.textBoxIPAddress.Size = new System.Drawing.Size(148, 28); + this.textBoxIPAddress.TabIndex = 5; + this.textBoxIPAddress.Text = "127.0.0.1"; + // + // checkBoxTelnet + // + this.checkBoxTelnet.AutoSize = true; + this.checkBoxTelnet.Checked = true; + this.checkBoxTelnet.CheckState = System.Windows.Forms.CheckState.Checked; + this.checkBoxTelnet.Location = new System.Drawing.Point(208, 27); + this.checkBoxTelnet.Margin = new System.Windows.Forms.Padding(4); + this.checkBoxTelnet.Name = "checkBoxTelnet"; + this.checkBoxTelnet.Size = new System.Drawing.Size(88, 22); + this.checkBoxTelnet.TabIndex = 11; + this.checkBoxTelnet.Text = "Telnet"; + this.toolTip1.SetToolTip(this.checkBoxTelnet, "Process client data as Telnet protocol"); + this.checkBoxTelnet.UseVisualStyleBackColor = true; + this.checkBoxTelnet.CheckedChanged += new System.EventHandler(this.checkBoxTelnet_CheckedChanged); + // + // labelTargetIP + // + this.labelTargetIP.AutoSize = true; + this.labelTargetIP.Location = new System.Drawing.Point(21, 66); + this.labelTargetIP.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); + this.labelTargetIP.Name = "labelTargetIP"; + this.labelTargetIP.Size = new System.Drawing.Size(161, 18); + this.labelTargetIP.TabIndex = 6; + this.labelTargetIP.Text = "Server IP address"; + // + // radioButtonServer + // + this.radioButtonServer.AutoSize = true; + this.radioButtonServer.Checked = true; + this.radioButtonServer.Location = new System.Drawing.Point(111, 27); + this.radioButtonServer.Margin = new System.Windows.Forms.Padding(4); + this.radioButtonServer.Name = "radioButtonServer"; + this.radioButtonServer.Size = new System.Drawing.Size(87, 22); + this.radioButtonServer.TabIndex = 1; + this.radioButtonServer.TabStop = true; + this.radioButtonServer.Text = "Server"; + this.radioButtonServer.UseVisualStyleBackColor = true; + this.radioButtonServer.CheckedChanged += new System.EventHandler(this.radioButtonServer_CheckedChanged); + // + // radioButtonClient + // + this.radioButtonClient.AutoSize = true; + this.radioButtonClient.Location = new System.Drawing.Point(26, 27); + this.radioButtonClient.Margin = new System.Windows.Forms.Padding(4); + this.radioButtonClient.Name = "radioButtonClient"; + this.radioButtonClient.Size = new System.Drawing.Size(87, 22); + this.radioButtonClient.TabIndex = 0; + this.radioButtonClient.Text = "Client"; + this.radioButtonClient.UseVisualStyleBackColor = true; + // + // label3 + // + this.label3.AutoSize = true; + this.label3.ForeColor = System.Drawing.Color.Silver; + this.label3.Location = new System.Drawing.Point(471, 633); + this.label3.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); + this.label3.Name = "label3"; + this.label3.Size = new System.Drawing.Size(71, 18); + this.label3.TabIndex = 15; + this.label3.Text = "Author:"; + // + // linkLabel2 + // + this.linkLabel2.AutoSize = true; + this.linkLabel2.LinkColor = System.Drawing.Color.Silver; + this.linkLabel2.Location = new System.Drawing.Point(740, 633); + this.linkLabel2.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); + this.linkLabel2.Name = "linkLabel2"; + this.linkLabel2.Size = new System.Drawing.Size(89, 18); + this.linkLabel2.TabIndex = 16; + this.linkLabel2.TabStop = true; + this.linkLabel2.Text = "YeLincoln"; + this.linkLabel2.LinkClicked += new System.Windows.Forms.LinkLabelLinkClickedEventHandler(this.linkLabel2_LinkClicked); + // + // toolTip1 + // + this.toolTip1.AutoPopDelay = 10000; + this.toolTip1.InitialDelay = 200; + this.toolTip1.ReshowDelay = 100; + // + // MainForm + // + this.AutoScaleDimensions = new System.Drawing.SizeF(9F, 18F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(878, 663); + this.Controls.Add(this.linkLabel2); + this.Controls.Add(this.label3); + this.Controls.Add(this.groupBox1); + this.Controls.Add(this.groupBoxSerialPort); + this.Controls.Add(this.buttonClear); + this.Controls.Add(this.checkBoxDisplayHex); + this.Controls.Add(this.checkBoxReconnect); + this.Controls.Add(this.linkLabel1); + this.Controls.Add(this.textBoxLog); + this.Controls.Add(this.buttonStartStop); + this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle; + this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon"))); + this.Margin = new System.Windows.Forms.Padding(4); + this.MaximizeBox = false; + this.Name = "MainForm"; + this.Text = "dgiot_dtu"; + this.groupBoxSerialPort.ResumeLayout(false); + this.groupBoxSerialPort.PerformLayout(); + this.groupBox1.ResumeLayout(false); + this.groupBox1.PerformLayout(); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private System.Windows.Forms.Button buttonStartStop; + private System.Windows.Forms.TextBox textBoxLog; + private System.Windows.Forms.LinkLabel linkLabel1; + private System.Windows.Forms.CheckBox checkBoxReconnect; + private System.Windows.Forms.CheckBox checkBoxDisplayHex; + private System.Windows.Forms.Button buttonClear; + private System.Windows.Forms.GroupBox groupBoxSerialPort; + private System.Windows.Forms.Label label1; + private System.Windows.Forms.ComboBox comboBoxBaudRate; + private System.Windows.Forms.Label labelSerialPort; + private System.Windows.Forms.ComboBox comboBoxSerialPort; + private System.Windows.Forms.GroupBox groupBox1; + private System.Windows.Forms.TextBox textBoxTargetPort; + private System.Windows.Forms.Label labelTargetPort; + private System.Windows.Forms.TextBox textBoxIPAddress; + private System.Windows.Forms.Label labelTargetIP; + private System.Windows.Forms.RadioButton radioButtonServer; + private System.Windows.Forms.RadioButton radioButtonClient; + private System.Windows.Forms.TextBox textBoxReadOnlyPort; + private System.Windows.Forms.Label label2; + private System.Windows.Forms.Label label3; + private System.Windows.Forms.LinkLabel linkLabel2; + private System.Windows.Forms.Label label4; + private System.Windows.Forms.ComboBox comboBoxDataBits; + private System.Windows.Forms.Label label5; + private System.Windows.Forms.ComboBox comboBoxStopBits; + private System.Windows.Forms.CheckBox checkBoxTelnet; + private System.Windows.Forms.ToolTip toolTip1; + private System.Windows.Forms.Label label6; + private System.Windows.Forms.TextBox textlogin; + } +} + diff --git a/MainForm.cs b/MainForm.cs new file mode 100644 index 0000000..6b276e5 --- /dev/null +++ b/MainForm.cs @@ -0,0 +1,719 @@ +using System; +using System.Diagnostics; +using System.IO; +using System.IO.Ports; +using System.Net; +using System.Windows.Forms; +using System.Net.Sockets; +using PortListener.Core.Utilities; +using System.Collections.Generic; +using System.Configuration; +using System.Threading; + +namespace dgiot_dtu +{ + public enum TelnetCommand : byte + { + SE = 240, // End of subnegotiation parameters. + NOP = 241, // No operation. + DataMark = 242, // The data stream portion of a Synch. + // This should always be accompanied + // by a TCP Urgent notification. + Break = 243, // NVT character BRK. + InterruptProcess = 244, // The function IP. + AbortOutput = 245, // The function AO. + AreYouThere = 246, // The function AYT. + EraseCharacter = 247, //The function EC. + EraseLine = 248, // The function EL. + GoAhead = 249, // The GA signal. + SB = 250, // Indicates that what follows is subnegotiation of the indicated option. + WILL = 251, // Indicates the desire to begin performing, or confirmation that you are now performing, the indicated option. + WONT = 252, // Indicates the refusal to perform, or continue performing, the indicated option. + DO = 253, // Indicates the request that the other party perform, or confirmation that you are expecting + // the other party to perform, the indicated option. + DONT = 254, // Indicates the demand that the other party stop performing, or confirmation that you are no + // longer expecting the other party to perform, the indicated option. + IAC = 255, // Data Byte 255. + } + + public enum TelnetOption : byte + { + ECHO = 1, + NO_GO_AHEAD = 3, + LINEMODE = 34, + } + + public partial class MainForm : Form + { + private delegate void LogHandler(string text); + + private TcpClient _client; + private TcpListener _server; + private TcpListener ro_server; + private List ro_clientList = new List(); + + private SerialPort _port; + private NetworkStream _stream; + private readonly byte[] _tcpdata = new byte[1024]; + + private bool _bAutoReconnect; + private bool _bDisplayHex; + private bool _bIsRunning; + private bool _bTelnet; + + private Configuration config; + + enum ConnectionMode + { + CLIENT, + SERVER, + } + + private ConnectionMode _eConnectionMode = ConnectionMode.SERVER; + + public MainForm() + { + InitializeComponent(); + + Text += " v" + System.Reflection.Assembly.GetEntryAssembly().GetName().Version; + + var arrPorts = SerialPort.GetPortNames(); + comboBoxSerialPort.Items.Clear(); + foreach (var port in arrPorts) + comboBoxSerialPort.Items.Add(port); + if (arrPorts.Length > 0) + comboBoxSerialPort.SelectedIndex = 0; + + comboBoxBaudRate.SelectedIndex = 7; + comboBoxDataBits.SelectedIndex = 0; + comboBoxStopBits.SelectedIndex = 0; + + _bAutoReconnect = checkBoxReconnect.Checked; + _bDisplayHex = checkBoxDisplayHex.Checked; + + try + { + config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); + if (config.AppSettings.Settings["SerialPort"] != null) + { + var tmp = config.AppSettings.Settings["SerialPort"].Value; + comboBoxSerialPort.SelectedIndex = comboBoxSerialPort.Items.IndexOf(tmp); + + } + + if (config.AppSettings.Settings["BaudRate"] != null) + { + var tmp = config.AppSettings.Settings["BaudRate"].Value; + comboBoxBaudRate.SelectedIndex = comboBoxBaudRate.Items.IndexOf(tmp); + } + + if (config.AppSettings.Settings["tcpPort"] != null) + { + var tmp = config.AppSettings.Settings["tcpPort"].Value; + textBoxTargetPort.Text = tmp; + } + + if (config.AppSettings.Settings["tcpPortRO"] != null) + { + var tmp = config.AppSettings.Settings["tcpPortRO"].Value; + textBoxReadOnlyPort.Text = tmp; + } + + if (config.AppSettings.Settings["bTelnet"] != null) + { + var tmp = config.AppSettings.Settings["bTelnet"].Value; + checkBoxTelnet.Checked = bool.Parse(tmp); + } + + } + catch (Exception ex) + { + Log("read config exception: " + ex.Message); + } + + _bTelnet = checkBoxTelnet.Checked; + radioButtonServer_CheckedChanged_do(); + } + + private void toStop() + { + try + { + buttonStartStop.Text = @"Start"; + _bIsRunning = false; + + if (_port.IsOpen) + _port.Close(); + + if (_client != null) + { + if (_client.Connected) + _client.Close(); + _client = null; + } + foreach (var c in ro_clientList) + { + c.Close(); + } + ro_clientList.Clear(); + + if (_server != null) + { + _server.Stop(); + _server = null; + } + if (ro_server != null) + { + ro_server.Stop(); + ro_server = null; + } + } + catch (Exception e) + { + Log("stop server exception:" + e.Message); + return; + } + + } + + private StopBits strToStopBits(string s) + { + if (s == "1") + { + return StopBits.One; + } + if (s == "2") + { + return StopBits.Two; + } + if (s == "1.5") + { + return StopBits.OnePointFive; + } + return StopBits.None; + } + + private void saveAppConfig() + { + if (config.AppSettings.Settings["SerialPort"] == null) + { + config.AppSettings.Settings.Add("SerialPort", (string)comboBoxSerialPort.SelectedItem); + } else + { + config.AppSettings.Settings["SerialPort"].Value = (string)comboBoxSerialPort.SelectedItem; + } + + if (config.AppSettings.Settings["BaudRate"] == null) { + config.AppSettings.Settings.Add("BaudRate", (string)comboBoxBaudRate.SelectedItem); + } else + { + config.AppSettings.Settings["BaudRate"].Value = (string)comboBoxBaudRate.SelectedItem; + } + + if (config.AppSettings.Settings["tcpPort"] == null) + { + config.AppSettings.Settings.Add("tcpPort", textBoxTargetPort.Text); + } + else + { + config.AppSettings.Settings["tcpPort"].Value = textBoxTargetPort.Text; + } + + if (config.AppSettings.Settings["tcpPortRO"] == null) + { + config.AppSettings.Settings.Add("tcpPortRO", textBoxReadOnlyPort.Text); + } + else + { + config.AppSettings.Settings["tcpPortRO"].Value = textBoxReadOnlyPort.Text; + } + + if (config.AppSettings.Settings["login"] == null) + { + config.AppSettings.Settings.Add("login", textlogin.Text); + } + else + { + config.AppSettings.Settings["login"].Value = textlogin.Text; + } + + if (config.AppSettings.Settings["bTelnet"] == null) + { + config.AppSettings.Settings.Add("bTelnet", _bTelnet.ToString()); + } + else + { + config.AppSettings.Settings["bTelnet"].Value = _bTelnet.ToString(); + } + + config.Save(ConfigurationSaveMode.Full); + ConfigurationManager.RefreshSection("appSettings"); + } + private void ButtonStartStopClick(object sender, EventArgs e) + { + if (!_bIsRunning) + { + try + { + _port = new SerialPort((string)comboBoxSerialPort.SelectedItem, + int.Parse((string)comboBoxBaudRate.SelectedItem), + Parity.None, + int.Parse((string)comboBoxDataBits.SelectedItem), + strToStopBits((string)comboBoxStopBits.SelectedItem)); + _port.DataReceived += PortDataReceived; + _port.ReceivedBytesThreshold = 1; + _port.Open(); + } catch(Exception) + { + MessageBox.Show(@"Couldn't open port " + (string) comboBoxSerialPort.SelectedItem); + return; + } + + try + { + if (_eConnectionMode == ConnectionMode.CLIENT) + { + Log("Connecting to " + textBoxIPAddress.Text + ":" + textBoxTargetPort.Text); + + _client = new TcpClient(); + _client.BeginConnect(textBoxIPAddress.Text, int.Parse(textBoxTargetPort.Text), TcpConnectedOut, + null); + } + else + { + _server = new TcpListener(IPAddress.Any, int.Parse(textBoxTargetPort.Text)); + _server.Start(); + _server.BeginAcceptTcpClient(TcpConnectedIn, null); + + ro_server = new TcpListener(IPAddress.Any, int.Parse(textBoxReadOnlyPort.Text)); + ro_server.Start(); + ro_server.BeginAcceptTcpClient(TcpConnectedInRO, ro_server); + + Log("Server start!"); + } + } + catch (Exception ex) + { + if(_eConnectionMode == ConnectionMode.CLIENT) + Log("Couldn't connect: " + ex.Message); + else + Log("Couldn't listen: " + ex.Message); + + _port.DataReceived -= PortDataReceived; + _port.Close(); + + return; + } + buttonStartStop.Text = @"Stop"; + _bIsRunning = true; + + saveAppConfig(); + } + else + { + toStop(); + } + } + + void TcpReaderRO(IAsyncResult ar) + { + TcpClient client = (TcpClient)ar.AsyncState; + NetworkStream stream = client.GetStream(); + try + { + var numRead = stream.EndRead(ar); + if (numRead == 0) + { + Log(client.Client.LocalEndPoint + " <==> " + client.Client.RemoteEndPoint + " disconnect"); + client.Close(); + ro_clientList.Remove(client); + return; + } + byte[] data = new byte[1024]; + stream.BeginRead(data, 0, data.Length, TcpReaderRO, client); + } + catch (Exception e) + { + Log(client.Client.LocalEndPoint + " <==> " + client.Client.RemoteEndPoint + " exception:" + e.Message); + client.Close(); + ro_clientList.Remove(client); + return; + } + } + void TcpConnectedInRO(IAsyncResult result) + { + // Get the listener that handles the client request. + TcpListener listener = (TcpListener)result.AsyncState; + try + { + if (!_bIsRunning) + { + Log("TcpConnectedInRO: server shutdown"); + goto end; + } + + TcpClient tmp_client = listener.EndAcceptTcpClient(result); + NetworkStream tmp_stream = tmp_client.GetStream(); + + ro_clientList.Add(tmp_client); + + Log("Client Connected: " + tmp_client.Client.LocalEndPoint + " <==> " + tmp_client.Client.RemoteEndPoint); + + Log("dddd start!"); + if (_bTelnet) { + byte[] willEcho = new byte[] { (byte) TelnetCommand.IAC, + (byte) TelnetCommand.WILL, + (byte)TelnetOption.ECHO }; + byte[] noGoAhead = new byte[] { (byte) TelnetCommand.IAC, + (byte) TelnetCommand.WILL, + (byte)TelnetOption.NO_GO_AHEAD }; + byte[] wontLinemode = new byte[] { (byte) TelnetCommand.IAC, + (byte) TelnetCommand.WONT, + (byte)TelnetOption.LINEMODE }; + tmp_stream.Write(willEcho, 0, willEcho.Length); + tmp_stream.Write(noGoAhead, 0, noGoAhead.Length); + tmp_stream.Write(wontLinemode, 0, wontLinemode.Length); + } + + byte[] data = new byte[1024]; + tmp_stream.BeginRead(data, 0, data.Length, TcpReaderRO, tmp_client); + + } + catch (Exception e) + { + if (e is ObjectDisposedException) + Log("Connection shutdown"); + else + Log("Connection exception: " + e.Message); + } + + end: + try + { + if (_bIsRunning) + { + /* accept other connection again */ + listener.BeginAcceptTcpClient(TcpConnectedInRO, listener); + } + } + catch (Exception e) + { + Log("Server exception: " + e.Message); + toStop(); + } + } + + void TcpConnectedIn(IAsyncResult result) + { + try + { + if (!_bIsRunning) + { + Log("TcpConnectedIn: server shutdown"); + goto end; + } + TcpClient tmp_client = _server.EndAcceptTcpClient(result); + NetworkStream tmp_stream = tmp_client.GetStream(); + + if (_client != null) + { + Log("Already in use, close connected from: " + tmp_client.Client.RemoteEndPoint); + byte[] reject = System.Text.Encoding.ASCII.GetBytes( "Already in use!\r\n"); + tmp_stream.Write(reject, 0, reject.Length); + tmp_stream.Close(); + tmp_client.Close(); + goto end; + } + + _client = tmp_client; + + _stream = tmp_stream; + + Log("Client Connected: " + _client.Client.LocalEndPoint + "<==>" + _client.Client.RemoteEndPoint); + + if (_bTelnet) { + byte[] willEcho = new byte[] { (byte) TelnetCommand.IAC, + (byte) TelnetCommand.WILL, + (byte)TelnetOption.ECHO }; + byte[] noGoAhead = new byte[] { (byte) TelnetCommand.IAC, + (byte) TelnetCommand.WILL, + (byte)TelnetOption.NO_GO_AHEAD }; + byte[] wontLinemode = new byte[] { (byte) TelnetCommand.IAC, + (byte) TelnetCommand.WONT, + (byte)TelnetOption.LINEMODE }; + _stream.Write(willEcho, 0, willEcho.Length); + _stream.Write(noGoAhead, 0, noGoAhead.Length); + _stream.Write(wontLinemode, 0, wontLinemode.Length); + } + + _stream.BeginRead(_tcpdata, 0, _tcpdata.Length, TcpReader, null); + } catch(Exception e) + { + if(e is ObjectDisposedException) + Log("Connection shutdown"); + else + Log("Connection exception: " + e.Message); + } +end: + try + { + if (_bIsRunning) + { + /* accept other connection again */ + _server.BeginAcceptTcpClient(TcpConnectedIn, null); + } + } + catch (Exception e) + { + Log("Server exception: " + e.Message); + toStop(); + } + } + + void TcpConnectedOut(IAsyncResult result) + { + try + { + _client.EndConnect(result); + + _stream = _client.GetStream(); + + Log("Connected"); + + var tcpdata = new byte[1024]; + _stream.BeginRead(tcpdata, 0, tcpdata.Length, TcpReader, null); + + if (_stream.CanWrite) + { + Thread.Sleep(1000 * 1); + byte[] login = System.Text.Encoding.UTF8.GetBytes(config.AppSettings.Settings["login"].Value); + Log("S->N: login[" + config.AppSettings.Settings["login"].Value+"]"); + _stream.Write(login, 0, login.Length); + } + + } catch(Exception e) + { + Log("Couldn't connect: " + e.Message); + + if (_eConnectionMode == ConnectionMode.CLIENT) + { + if (_bAutoReconnect && _bIsRunning) + { + Log("Connecting to " + textBoxIPAddress.Text + ":" + textBoxTargetPort.Text); + _client.BeginConnect(textBoxIPAddress.Text, int.Parse(textBoxTargetPort.Text), TcpConnectedOut, + null); + } + } + } + } + + void PortDataReceived(object sender, SerialDataReceivedEventArgs e) + { + var rxlen = _port.BytesToRead; + var data = new byte[rxlen]; + _port.Read(data, 0, rxlen); + + var line = _bDisplayHex ? StringHelper.ToHexString(data, 0, rxlen) : System.Text.Encoding.ASCII.GetString(data, 0, rxlen); + if (line.EndsWith("\r\n")) + line = line.Substring(0, line.Length - 2); + + Log("S->N: " + line); + + foreach (var c in ro_clientList) + { + var stream = c.GetStream(); + if (stream.CanWrite) + { + try + { + stream.Write(data, 0, rxlen); + } + catch (Exception ex) + { + Log("Write to " + c.Client.LocalEndPoint + " exception:" + ex.Message); + c.Close(); + ro_clientList.Remove(c); + } + } + + } + if(_stream != null) + if(_stream.CanWrite) + { + try + { + _stream.Write(data, 0, rxlen); + } + catch(Exception ex) + { + Log("Can't write to TCP stream:" + ex.Message); + + try + { + _stream.Close(); + } catch{} + + _stream = null; + if (_bAutoReconnect && _bIsRunning) + { + if (_eConnectionMode == ConnectionMode.CLIENT) + { + Log("Connecting to " + textBoxIPAddress.Text + ":" + textBoxTargetPort.Text); + + _client.BeginConnect(textBoxIPAddress.Text, int.Parse(textBoxTargetPort.Text), + TcpConnectedOut, null); + } + } + } + } + } + + private void onConnectClosed() + { + try + { + _client.Close(); + _client = null; + + } catch { } + + if (_bAutoReconnect && _bIsRunning) + { + try + { + if (_eConnectionMode == ConnectionMode.CLIENT) + { + Log("Connecting to " + textBoxIPAddress.Text + ":" + textBoxTargetPort.Text); + + _client = new TcpClient(); + + _client.BeginConnect(textBoxIPAddress.Text, int.Parse(textBoxTargetPort.Text), + TcpConnectedOut, + null); + } + } + catch (Exception ex) + { + Log("Problem reconnecting:" + ex.Message); + } + } + } + + void TcpReader(IAsyncResult ar) + { + try + { + + var rxbytes = _stream.EndRead(ar); + + if (rxbytes > 0) + { + var offset = 0; + + if (_bTelnet) { + while (_tcpdata[offset] == (byte)TelnetCommand.IAC && rxbytes >= 3) { + Log("Receive IAC: " + StringHelper.ToHexString(_tcpdata, offset, 3)); + offset += 3; + } + } + + _port.Write(_tcpdata, offset, rxbytes - offset); + + var line = _bDisplayHex ? StringHelper.ToHexString(_tcpdata, offset, rxbytes - offset) + : System.Text.Encoding.ASCII.GetString(_tcpdata, offset, rxbytes - offset); + if (line.EndsWith("\r\n")) + line = line.Substring(0, line.Length - 2); + + Log("N->S: " + line); + _stream.BeginRead(_tcpdata, 0, _tcpdata.Length, TcpReader, null); + } + + if (rxbytes == 0) + { + Log("Client closed"); + onConnectClosed(); + } + } catch(Exception e) + { + if (e is ObjectDisposedException) + Log("Connection closed"); + else if(e is IOException && e.Message.Contains("closed")) + Log("Connection closed"); + else + Log("Exception: " + e.Message); + + onConnectClosed(); + } + } + + void Log(string text) + { + if(InvokeRequired) + { + Invoke(new LogHandler(Log), new object[] {text}); + return; + } + + // Truncate + if (textBoxLog.Text.Length > 4096) + textBoxLog.Text = textBoxLog.Text.Substring(textBoxLog.Text.Length - 4096); + + textBoxLog.Text += text + "\r\n"; + textBoxLog.SelectionStart = textBoxLog.Text.Length - 1; + textBoxLog.ScrollToCaret(); + } + + private void LinkLabel1LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) + { + Process.Start("http://www.dynamicdevices.co.uk"); + } + + private void CheckBoxReconnectCheckedChanged(object sender, EventArgs e) + { + _bAutoReconnect = checkBoxReconnect.Checked; + } + + private void CheckBoxDisplayHexCheckedChanged(object sender, EventArgs e) + { + _bDisplayHex = checkBoxDisplayHex.Checked; + } + + private void ButtonClearClick(object sender, EventArgs e) + { + textBoxLog.Text = ""; + } + + private void radioButtonServer_CheckedChanged_do() + { + if (radioButtonServer.Checked) + { + _eConnectionMode = ConnectionMode.SERVER; + textBoxIPAddress.Enabled = false; + checkBoxReconnect.Enabled = false; + textBoxReadOnlyPort.Enabled = true; + } + else + { + _eConnectionMode = ConnectionMode.CLIENT; + textBoxIPAddress.Enabled = true; + checkBoxReconnect.Enabled = true; + textBoxReadOnlyPort.Enabled = false; + } + } + + private void radioButtonServer_CheckedChanged(object sender, EventArgs e) + { + radioButtonServer_CheckedChanged_do(); + } + + private void linkLabel2_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) + { + Process.Start("https://github.com/YeLincoln/Serial2Net"); + } + + private void checkBoxTelnet_CheckedChanged(object sender, EventArgs e) + { + _bTelnet = checkBoxTelnet.Checked; + } + } +} diff --git a/MainForm.resx b/MainForm.resx new file mode 100644 index 0000000..2fc1c23 --- /dev/null +++ b/MainForm.resx @@ -0,0 +1,200 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + 17, 17 + + + + + AAABAAEAICAAAAEAIACoEAAAFgAAACgAAAAgAAAAQAAAAAEAIAAAAAAAABAAABILAAASCwAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAA////AP///wL///8L////Bv///wP///8o////Wf///xr///8E////Ef// + /xP///8L////Bf///wH///8C////BP///wL///8D////Cv///xD///8m////WP///xb///8AAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD///8A////JP///4z///9u////Xv///3j///+z////gP// + /07///95////ff///4n///9m////Fv///y////9W////N////0////9p////iP///27///+w////Pv// + /wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAP///wD///8x////qf///5P///9z////bP// + /3n///9v////b////47///9a////fv///33///8e////Pv///8f///9f////X////17///9t////XP// + /3f///8l////AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA////AP///xL///9a////Mf// + /yz///8O////Af///yD///8e////Hf///wP///8C////Lf///wz///8Z////Yf///yj///8B////A/// + /wP///8B////Av///wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA////AP///wP///81////Nv// + /zn///86////I////yX///8y////QP///zX///8+////Qf///y7///8o////Mf///yf///8C////H/// + /xr///8Z////Mv///yz///82////LP///zP///8C////AAAAAAAAAAAAAAAAAAAAAAD///8A////Af// + /3/////R////sv///4/////F////Yv///3n////d////sP///53////C////Vv///6H////V////pv// + /1z///+e////cf///1L////A////Yv///7X////K////Y////wP///8AAAAAAAAAAAAAAAAAAAAAAP// + /wD///8E////of///7/////A////VP///8H///8h////kP///+f///+Q////nv///9D///9L////lv// + //L///+M////fv///8z///+c////bf///9f///8v////oP///8H///8l////AAAAAAAAAAAAAAAAAAAA + AAAAAAAA////AP///wb///+P////qf///5n///92////zv///0P///+d////z////53///+N////t/// + /0T///93////7////3j///+X////oP///2v///8W////wP///2j///+S////tf///5r///8D////AAAA + AAAAAAAAAAAAAAAAAAD///8A////Af///3T////S////pv///4X///+C////dv///53////P////of// + /53////I////T////2T////a////ef///4v///+b////af///xH///+5////df///6z////U////dv// + /wb///8AAAAAAAAAAAAAAAAAAAAAAP///wD///8D////h////8z///+u////t////7v///9p////g/// + /9T///97////pP///9L///9T////YP///8v///+J////lf///4////9k////Qv///9n///+G////l/// + /8L///9e////BP///wAAAAAAAAAAAAAAAAAAAAAA////AP///wD///8U////O////yH///89////Jv// + /wT///8J////KP///wb///8X////KP///wX///8T////J////yz///8Q////H////xr///8G////LP// + /wz///8Q////I////wAAAAAAAAAAAAAAAAAAA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SuF/90rhf/9O5YP/Hp1T/pncy/6mA + Nf+3lkPzzrNb0tO5YHHPtFwI0LVcAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAADSuF8A0rhfFtK4X33SuF/b0rhf+dG3 + Xv+3j0P/p3oz/7CNPP+6l0P/wZ5Kzr6ZRRi+mUUAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAADSuF8A0rhfAtK4 + XybSuF9d0rlfls6yW6u3kUSrsY09pK+IN3Sqey0xp3QlAqh3KAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAA+AAAH/gAAB/4AAAf+AAAP+AAAAfgAAAH4AAAD+AAAAfgAAAH4AAAB+AA + AB/////////////gD///4AP//8AB///gAP//8AD///8Af/4HgH/8A4A//AHAP/wAwD/8AMA//ABgP/wQ + cD/+CDh//gA///8AD///gAf//8AH///gB/8= + + + \ No newline at end of file diff --git a/Program.cs b/Program.cs new file mode 100644 index 0000000..cfa6ca4 --- /dev/null +++ b/Program.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.Windows.Forms; + +namespace dgiot_dtu +{ + static class Program + { + /// + /// The main entry point for the application. + /// + [STAThread] + static void Main() + { + Application.EnableVisualStyles(); + Application.SetCompatibleTextRenderingDefault(false); + Application.Run(new MainForm()); + } + } +} diff --git a/Properties/AssemblyInfo.cs b/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..e493b6d --- /dev/null +++ b/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("dgiot_dtu")] +[assembly: AssemblyDescription("Serial to TCP Port Fowarder")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("dgiot Ltd")] +[assembly: AssemblyProduct("dgiot_dtu")] +[assembly: AssemblyCopyright("Copyright © dgiot Ltd 2021")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("790e8dc9-9e65-4d33-8e58-1208a764e66a")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/Properties/Resources.Designer.cs b/Properties/Resources.Designer.cs new file mode 100644 index 0000000..d71a600 --- /dev/null +++ b/Properties/Resources.Designer.cs @@ -0,0 +1,63 @@ +//------------------------------------------------------------------------------ +// +// 此代码由工具生成。 +// 运行时版本:4.0.30319.42000 +// +// 对此文件的更改可能会导致不正确的行为,并且如果 +// 重新生成代码,这些更改将会丢失。 +// +//------------------------------------------------------------------------------ + +namespace dgiot_dtu.Properties { + using System; + + + /// + /// 一个强类型的资源类,用于查找本地化的字符串等。 + /// + // 此类是由 StronglyTypedResourceBuilder + // 类通过类似于 ResGen 或 Visual Studio 的工具自动生成的。 + // 若要添加或移除成员,请编辑 .ResX 文件,然后重新运行 ResGen + // (以 /str 作为命令选项),或重新生成 VS 项目。 + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + internal class Resources { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal Resources() { + } + + /// + /// 返回此类使用的缓存的 ResourceManager 实例。 + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager { + get { + if (object.ReferenceEquals(resourceMan, null)) { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("dgiot_dtu.Properties.Resources", typeof(Resources).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// 使用此强类型资源类,为所有资源查找 + /// 重写当前线程的 CurrentUICulture 属性。 + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Globalization.CultureInfo Culture { + get { + return resourceCulture; + } + set { + resourceCulture = value; + } + } + } +} diff --git a/Properties/Resources.resx b/Properties/Resources.resx new file mode 100644 index 0000000..ffecec8 --- /dev/null +++ b/Properties/Resources.resx @@ -0,0 +1,117 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Properties/Settings.Designer.cs b/Properties/Settings.Designer.cs new file mode 100644 index 0000000..a1049be --- /dev/null +++ b/Properties/Settings.Designer.cs @@ -0,0 +1,26 @@ +//------------------------------------------------------------------------------ +// +// 此代码由工具生成。 +// 运行时版本:4.0.30319.42000 +// +// 对此文件的更改可能会导致不正确的行为,并且如果 +// 重新生成代码,这些更改将会丢失。 +// +//------------------------------------------------------------------------------ + +namespace dgiot_dtu.Properties { + + + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "14.0.0.0")] + internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase { + + private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); + + public static Settings Default { + get { + return defaultInstance; + } + } + } +} diff --git a/Properties/Settings.settings b/Properties/Settings.settings new file mode 100644 index 0000000..abf36c5 --- /dev/null +++ b/Properties/Settings.settings @@ -0,0 +1,7 @@ + + + + + + + diff --git a/StringHelper.cs b/StringHelper.cs new file mode 100644 index 0000000..90d7aba --- /dev/null +++ b/StringHelper.cs @@ -0,0 +1,59 @@ +using System.Text; +//using log4net; + +namespace PortListener.Core.Utilities +{ + public class StringHelper + { + #region Fields + + //private static readonly ILog _objLogger = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); + + #endregion + + /// + /// Converts an ASCII string to it's string representation as hex bytes + /// + /// + /// + public static string ToHexString(string s) + { + return ToHexString( Encoding.ASCII.GetBytes(s) ); + } + + public static string ToHexString(byte[] arrBytes) + { + return ToHexString(arrBytes, 0, arrBytes.Length); + } + + /// + /// Converts an array of bytes to a string of hex bytes + /// + /// + /// + /// + /// + public static string ToHexString(byte[] arrBytes, int iOffset, int iLength) + { + if (arrBytes.Length == 0) + return ""; + + var sb = new StringBuilder(""); + + var i = 0; + for (; i < iLength - 1; i++) + { + sb.AppendFormat("{0:X2} ", arrBytes[i]); + } + sb.AppendFormat("{0:X2}", arrBytes[i]); + + return sb.ToString(); + + } + + public static string ToHexString(byte data) + { + return string.Format("{0:X2}", data); + } + } +} diff --git a/app.config b/app.config new file mode 100644 index 0000000..9c3d200 --- /dev/null +++ b/app.config @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/dgiot_dtu.csproj b/dgiot_dtu.csproj new file mode 100644 index 0000000..301d3be --- /dev/null +++ b/dgiot_dtu.csproj @@ -0,0 +1,92 @@ + + + + Debug + x86 + 8.0.30703 + 2.0 + {5C46A923-4066-4CE8-89F2-3BAC47BF83ED} + WinExe + Properties + dgiot_dtu + dgiot_dtu + v2.0 + 512 + + + x86 + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + x86 + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + DD-All.ico + + + + + + + + + + + + + Form + + + MainForm.cs + + + + + + MainForm.cs + + + ResXFileCodeGenerator + Resources.Designer.cs + Designer + + + True + Resources.resx + True + + + + SettingsSingleFileGenerator + Settings.Designer.cs + + + True + Settings.settings + True + + + + + + + + \ No newline at end of file diff --git a/dgiot_dtu.sln b/dgiot_dtu.sln new file mode 100644 index 0000000..385e7af --- /dev/null +++ b/dgiot_dtu.sln @@ -0,0 +1,22 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 14 +VisualStudioVersion = 14.0.25420.1 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "dgiot_dtu", "dgiot_dtu.csproj", "{5C46A923-4066-4CE8-89F2-3BAC47BF83ED}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|x86 = Debug|x86 + Release|x86 = Release|x86 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {5C46A923-4066-4CE8-89F2-3BAC47BF83ED}.Debug|x86.ActiveCfg = Debug|x86 + {5C46A923-4066-4CE8-89F2-3BAC47BF83ED}.Debug|x86.Build.0 = Debug|x86 + {5C46A923-4066-4CE8-89F2-3BAC47BF83ED}.Release|x86.ActiveCfg = Release|x86 + {5C46A923-4066-4CE8-89F2-3BAC47BF83ED}.Release|x86.Build.0 = Release|x86 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal