Basic config functions
This commit is contained in:
@@ -3,24 +3,30 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace Lora_Wsen_Configtool
|
||||
{
|
||||
public class CommandButton : System.Windows.Forms.Button
|
||||
public class CommandButton : Button
|
||||
{
|
||||
//public CommandButton()
|
||||
//{
|
||||
// InitializeComponent();
|
||||
//}
|
||||
public CommandButton()
|
||||
{
|
||||
// InitializeComponent();
|
||||
this.Enabled = false;
|
||||
}
|
||||
|
||||
public void SetVisbleState(object sender, bool state)
|
||||
{
|
||||
this.Enabled = state;
|
||||
}
|
||||
|
||||
|
||||
public char SerialCommand { get; set; }
|
||||
|
||||
public string CommandDesciption { get; set; }
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
469
Lora-Wsen-Configtool/Form1.Designer.cs
generated
469
Lora-Wsen-Configtool/Form1.Designer.cs
generated
@@ -31,33 +31,33 @@
|
||||
this.groupBox1 = new System.Windows.Forms.GroupBox();
|
||||
this.SerialConsole = new System.Windows.Forms.TextBox();
|
||||
this.OpenSerialPort = new System.Windows.Forms.Button();
|
||||
this.DevEUI = new System.Windows.Forms.TextBox();
|
||||
this.DevUEIGroupBox = new System.Windows.Forms.GroupBox();
|
||||
this.DevEUISet = new Lora_Wsen_Configtool.CommandButton();
|
||||
this.DevEUIGet = new Lora_Wsen_Configtool.CommandButton();
|
||||
this.AppEUIGroupBox = new System.Windows.Forms.GroupBox();
|
||||
this.AppEUISet = new Lora_Wsen_Configtool.CommandButton();
|
||||
this.AppEUIGet = new Lora_Wsen_Configtool.CommandButton();
|
||||
this.AppEUI = new System.Windows.Forms.TextBox();
|
||||
this.AppKeyGroupBox = new System.Windows.Forms.GroupBox();
|
||||
this.AppKeySet = new Lora_Wsen_Configtool.CommandButton();
|
||||
this.AppKeyGet = new Lora_Wsen_Configtool.CommandButton();
|
||||
this.AppKey = new System.Windows.Forms.TextBox();
|
||||
this.DevAddrGroupBox = new System.Windows.Forms.GroupBox();
|
||||
this.DevAddrSet = new Lora_Wsen_Configtool.CommandButton();
|
||||
this.DevAddrGet = new Lora_Wsen_Configtool.CommandButton();
|
||||
this.DevAddr = new System.Windows.Forms.TextBox();
|
||||
this.NwsKeyGroupBox = new System.Windows.Forms.GroupBox();
|
||||
this.NwsKeySet = new Lora_Wsen_Configtool.CommandButton();
|
||||
this.NwsKeyGet = new Lora_Wsen_Configtool.CommandButton();
|
||||
this.NwsKey = new System.Windows.Forms.TextBox();
|
||||
this.AppsKeyGroupBox = new System.Windows.Forms.GroupBox();
|
||||
this.AppsKeySet = new Lora_Wsen_Configtool.CommandButton();
|
||||
this.AppsKeyGet = new Lora_Wsen_Configtool.CommandButton();
|
||||
this.AppsKey = new System.Windows.Forms.TextBox();
|
||||
this.OTAAGroupBox = new System.Windows.Forms.GroupBox();
|
||||
this.ABPGroupBox = new System.Windows.Forms.GroupBox();
|
||||
this.ComPortSelection = new System.Windows.Forms.ComboBox();
|
||||
this.DevAddrSet = new Lora_Wsen_Configtool.CommandButton();
|
||||
this.DevAddrGet = new Lora_Wsen_Configtool.CommandButton();
|
||||
this.DevAddr = new Lora_Wsen_Configtool.HexValueTextbox();
|
||||
this.NwsKeySet = new Lora_Wsen_Configtool.CommandButton();
|
||||
this.NwsKeyGet = new Lora_Wsen_Configtool.CommandButton();
|
||||
this.NwsKey = new Lora_Wsen_Configtool.HexValueTextbox();
|
||||
this.AppsKeySet = new Lora_Wsen_Configtool.CommandButton();
|
||||
this.AppsKeyGet = new Lora_Wsen_Configtool.CommandButton();
|
||||
this.AppsKey = new Lora_Wsen_Configtool.HexValueTextbox();
|
||||
this.DevEUISet = new Lora_Wsen_Configtool.CommandButton();
|
||||
this.DevEUIGet = new Lora_Wsen_Configtool.CommandButton();
|
||||
this.DevEUI = new Lora_Wsen_Configtool.HexValueTextbox();
|
||||
this.AppKeySet = new Lora_Wsen_Configtool.CommandButton();
|
||||
this.AppKeyGet = new Lora_Wsen_Configtool.CommandButton();
|
||||
this.AppKey = new Lora_Wsen_Configtool.HexValueTextbox();
|
||||
this.AppEUISet = new Lora_Wsen_Configtool.CommandButton();
|
||||
this.AppEUIGet = new Lora_Wsen_Configtool.CommandButton();
|
||||
this.AppEUI = new Lora_Wsen_Configtool.HexValueTextbox();
|
||||
this.groupBox1.SuspendLayout();
|
||||
this.DevUEIGroupBox.SuspendLayout();
|
||||
this.AppEUIGroupBox.SuspendLayout();
|
||||
@@ -100,15 +100,6 @@
|
||||
this.OpenSerialPort.UseVisualStyleBackColor = true;
|
||||
this.OpenSerialPort.Click += new System.EventHandler(this.OpenSerialPort_Click);
|
||||
//
|
||||
// DevEUI
|
||||
//
|
||||
this.DevEUI.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
|
||||
this.DevEUI.Location = new System.Drawing.Point(6, 19);
|
||||
this.DevEUI.Name = "DevEUI";
|
||||
this.DevEUI.Size = new System.Drawing.Size(666, 26);
|
||||
this.DevEUI.TabIndex = 3;
|
||||
this.DevEUI.TextChanged += new System.EventHandler(this.DevEUI_TextChanged);
|
||||
//
|
||||
// DevUEIGroupBox
|
||||
//
|
||||
this.DevUEIGroupBox.Controls.Add(this.DevEUISet);
|
||||
@@ -119,29 +110,7 @@
|
||||
this.DevUEIGroupBox.Size = new System.Drawing.Size(844, 56);
|
||||
this.DevUEIGroupBox.TabIndex = 4;
|
||||
this.DevUEIGroupBox.TabStop = false;
|
||||
this.DevUEIGroupBox.Text = "DevEUI";
|
||||
//
|
||||
// DevEUISet
|
||||
//
|
||||
this.DevEUISet.Location = new System.Drawing.Point(759, 19);
|
||||
this.DevEUISet.Name = "DevEUISet";
|
||||
this.DevEUISet.SerialCommand = 'A';
|
||||
this.DevEUISet.Size = new System.Drawing.Size(75, 26);
|
||||
this.DevEUISet.TabIndex = 4;
|
||||
this.DevEUISet.Text = "Set";
|
||||
this.DevEUISet.UseVisualStyleBackColor = true;
|
||||
this.DevEUISet.Click += new System.EventHandler(this.CommandButtonSet_Click);
|
||||
//
|
||||
// DevEUIGet
|
||||
//
|
||||
this.DevEUIGet.Location = new System.Drawing.Point(678, 19);
|
||||
this.DevEUIGet.Name = "DevEUIGet";
|
||||
this.DevEUIGet.SerialCommand = 'a';
|
||||
this.DevEUIGet.Size = new System.Drawing.Size(75, 26);
|
||||
this.DevEUIGet.TabIndex = 4;
|
||||
this.DevEUIGet.Text = "Get";
|
||||
this.DevEUIGet.UseVisualStyleBackColor = true;
|
||||
this.DevEUIGet.Click += new System.EventHandler(this.CommandButtonGet_Click);
|
||||
this.DevUEIGroupBox.Text = "Device EUI (ttn lsb)";
|
||||
//
|
||||
// AppEUIGroupBox
|
||||
//
|
||||
@@ -153,37 +122,7 @@
|
||||
this.AppEUIGroupBox.Size = new System.Drawing.Size(844, 56);
|
||||
this.AppEUIGroupBox.TabIndex = 4;
|
||||
this.AppEUIGroupBox.TabStop = false;
|
||||
this.AppEUIGroupBox.Text = "AppEUI";
|
||||
//
|
||||
// AppEUISet
|
||||
//
|
||||
this.AppEUISet.Location = new System.Drawing.Point(759, 19);
|
||||
this.AppEUISet.Name = "AppEUISet";
|
||||
this.AppEUISet.SerialCommand = 'B';
|
||||
this.AppEUISet.Size = new System.Drawing.Size(75, 26);
|
||||
this.AppEUISet.TabIndex = 4;
|
||||
this.AppEUISet.Text = "Set";
|
||||
this.AppEUISet.UseVisualStyleBackColor = true;
|
||||
this.AppEUISet.Click += new System.EventHandler(this.CommandButtonSet_Click);
|
||||
//
|
||||
// AppEUIGet
|
||||
//
|
||||
this.AppEUIGet.Location = new System.Drawing.Point(678, 19);
|
||||
this.AppEUIGet.Name = "AppEUIGet";
|
||||
this.AppEUIGet.SerialCommand = 'b';
|
||||
this.AppEUIGet.Size = new System.Drawing.Size(75, 26);
|
||||
this.AppEUIGet.TabIndex = 4;
|
||||
this.AppEUIGet.Text = "Get";
|
||||
this.AppEUIGet.UseVisualStyleBackColor = true;
|
||||
this.AppEUIGet.Click += new System.EventHandler(this.CommandButtonGet_Click);
|
||||
//
|
||||
// AppEUI
|
||||
//
|
||||
this.AppEUI.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
|
||||
this.AppEUI.Location = new System.Drawing.Point(6, 19);
|
||||
this.AppEUI.Name = "AppEUI";
|
||||
this.AppEUI.Size = new System.Drawing.Size(666, 26);
|
||||
this.AppEUI.TabIndex = 3;
|
||||
this.AppEUIGroupBox.Text = "Application EUI (ttn lsb)";
|
||||
//
|
||||
// AppKeyGroupBox
|
||||
//
|
||||
@@ -195,37 +134,7 @@
|
||||
this.AppKeyGroupBox.Size = new System.Drawing.Size(844, 56);
|
||||
this.AppKeyGroupBox.TabIndex = 4;
|
||||
this.AppKeyGroupBox.TabStop = false;
|
||||
this.AppKeyGroupBox.Text = "AppKey";
|
||||
//
|
||||
// AppKeySet
|
||||
//
|
||||
this.AppKeySet.Location = new System.Drawing.Point(759, 19);
|
||||
this.AppKeySet.Name = "AppKeySet";
|
||||
this.AppKeySet.SerialCommand = 'C';
|
||||
this.AppKeySet.Size = new System.Drawing.Size(75, 26);
|
||||
this.AppKeySet.TabIndex = 4;
|
||||
this.AppKeySet.Text = "Set";
|
||||
this.AppKeySet.UseVisualStyleBackColor = true;
|
||||
this.AppKeySet.Click += new System.EventHandler(this.CommandButtonSet_Click);
|
||||
//
|
||||
// AppKeyGet
|
||||
//
|
||||
this.AppKeyGet.Location = new System.Drawing.Point(678, 19);
|
||||
this.AppKeyGet.Name = "AppKeyGet";
|
||||
this.AppKeyGet.SerialCommand = 'c';
|
||||
this.AppKeyGet.Size = new System.Drawing.Size(75, 26);
|
||||
this.AppKeyGet.TabIndex = 4;
|
||||
this.AppKeyGet.Text = "Get";
|
||||
this.AppKeyGet.UseVisualStyleBackColor = true;
|
||||
this.AppKeyGet.Click += new System.EventHandler(this.CommandButtonGet_Click);
|
||||
//
|
||||
// AppKey
|
||||
//
|
||||
this.AppKey.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
|
||||
this.AppKey.Location = new System.Drawing.Point(6, 19);
|
||||
this.AppKey.Name = "AppKey";
|
||||
this.AppKey.Size = new System.Drawing.Size(666, 26);
|
||||
this.AppKey.TabIndex = 3;
|
||||
this.AppKeyGroupBox.Text = "App Key (ttn lsb or msb)";
|
||||
//
|
||||
// DevAddrGroupBox
|
||||
//
|
||||
@@ -237,37 +146,7 @@
|
||||
this.DevAddrGroupBox.Size = new System.Drawing.Size(844, 56);
|
||||
this.DevAddrGroupBox.TabIndex = 4;
|
||||
this.DevAddrGroupBox.TabStop = false;
|
||||
this.DevAddrGroupBox.Text = "DevAddr";
|
||||
//
|
||||
// DevAddrSet
|
||||
//
|
||||
this.DevAddrSet.Location = new System.Drawing.Point(759, 19);
|
||||
this.DevAddrSet.Name = "DevAddrSet";
|
||||
this.DevAddrSet.SerialCommand = 'D';
|
||||
this.DevAddrSet.Size = new System.Drawing.Size(75, 26);
|
||||
this.DevAddrSet.TabIndex = 4;
|
||||
this.DevAddrSet.Text = "Set";
|
||||
this.DevAddrSet.UseVisualStyleBackColor = true;
|
||||
this.DevAddrSet.Click += new System.EventHandler(this.CommandButtonSet_Click);
|
||||
//
|
||||
// DevAddrGet
|
||||
//
|
||||
this.DevAddrGet.Location = new System.Drawing.Point(678, 19);
|
||||
this.DevAddrGet.Name = "DevAddrGet";
|
||||
this.DevAddrGet.SerialCommand = 'd';
|
||||
this.DevAddrGet.Size = new System.Drawing.Size(75, 26);
|
||||
this.DevAddrGet.TabIndex = 4;
|
||||
this.DevAddrGet.Text = "Get";
|
||||
this.DevAddrGet.UseVisualStyleBackColor = true;
|
||||
this.DevAddrGet.Click += new System.EventHandler(this.CommandButtonGet_Click);
|
||||
//
|
||||
// DevAddr
|
||||
//
|
||||
this.DevAddr.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
|
||||
this.DevAddr.Location = new System.Drawing.Point(6, 19);
|
||||
this.DevAddr.Name = "DevAddr";
|
||||
this.DevAddr.Size = new System.Drawing.Size(666, 26);
|
||||
this.DevAddr.TabIndex = 3;
|
||||
this.DevAddrGroupBox.Text = "Device Address";
|
||||
//
|
||||
// NwsKeyGroupBox
|
||||
//
|
||||
@@ -279,37 +158,7 @@
|
||||
this.NwsKeyGroupBox.Size = new System.Drawing.Size(844, 56);
|
||||
this.NwsKeyGroupBox.TabIndex = 4;
|
||||
this.NwsKeyGroupBox.TabStop = false;
|
||||
this.NwsKeyGroupBox.Text = "NwsKey";
|
||||
//
|
||||
// NwsKeySet
|
||||
//
|
||||
this.NwsKeySet.Location = new System.Drawing.Point(759, 19);
|
||||
this.NwsKeySet.Name = "NwsKeySet";
|
||||
this.NwsKeySet.SerialCommand = 'E';
|
||||
this.NwsKeySet.Size = new System.Drawing.Size(75, 26);
|
||||
this.NwsKeySet.TabIndex = 4;
|
||||
this.NwsKeySet.Text = "Set";
|
||||
this.NwsKeySet.UseVisualStyleBackColor = true;
|
||||
this.NwsKeySet.Click += new System.EventHandler(this.CommandButtonSet_Click);
|
||||
//
|
||||
// NwsKeyGet
|
||||
//
|
||||
this.NwsKeyGet.Location = new System.Drawing.Point(678, 19);
|
||||
this.NwsKeyGet.Name = "NwsKeyGet";
|
||||
this.NwsKeyGet.SerialCommand = 'e';
|
||||
this.NwsKeyGet.Size = new System.Drawing.Size(75, 26);
|
||||
this.NwsKeyGet.TabIndex = 4;
|
||||
this.NwsKeyGet.Text = "Get";
|
||||
this.NwsKeyGet.UseVisualStyleBackColor = true;
|
||||
this.NwsKeyGet.Click += new System.EventHandler(this.CommandButtonGet_Click);
|
||||
//
|
||||
// NwsKey
|
||||
//
|
||||
this.NwsKey.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
|
||||
this.NwsKey.Location = new System.Drawing.Point(6, 19);
|
||||
this.NwsKey.Name = "NwsKey";
|
||||
this.NwsKey.Size = new System.Drawing.Size(666, 26);
|
||||
this.NwsKey.TabIndex = 3;
|
||||
this.NwsKeyGroupBox.Text = "Network Session Key";
|
||||
//
|
||||
// AppsKeyGroupBox
|
||||
//
|
||||
@@ -321,37 +170,7 @@
|
||||
this.AppsKeyGroupBox.Size = new System.Drawing.Size(844, 56);
|
||||
this.AppsKeyGroupBox.TabIndex = 4;
|
||||
this.AppsKeyGroupBox.TabStop = false;
|
||||
this.AppsKeyGroupBox.Text = "AppsKey";
|
||||
//
|
||||
// AppsKeySet
|
||||
//
|
||||
this.AppsKeySet.Location = new System.Drawing.Point(759, 19);
|
||||
this.AppsKeySet.Name = "AppsKeySet";
|
||||
this.AppsKeySet.SerialCommand = 'F';
|
||||
this.AppsKeySet.Size = new System.Drawing.Size(75, 26);
|
||||
this.AppsKeySet.TabIndex = 4;
|
||||
this.AppsKeySet.Text = "Set";
|
||||
this.AppsKeySet.UseVisualStyleBackColor = true;
|
||||
this.AppsKeySet.Click += new System.EventHandler(this.CommandButtonSet_Click);
|
||||
//
|
||||
// AppsKeyGet
|
||||
//
|
||||
this.AppsKeyGet.Location = new System.Drawing.Point(678, 19);
|
||||
this.AppsKeyGet.Name = "AppsKeyGet";
|
||||
this.AppsKeyGet.SerialCommand = 'f';
|
||||
this.AppsKeyGet.Size = new System.Drawing.Size(75, 26);
|
||||
this.AppsKeyGet.TabIndex = 4;
|
||||
this.AppsKeyGet.Text = "Get";
|
||||
this.AppsKeyGet.UseVisualStyleBackColor = true;
|
||||
this.AppsKeyGet.Click += new System.EventHandler(this.CommandButtonGet_Click);
|
||||
//
|
||||
// AppsKey
|
||||
//
|
||||
this.AppsKey.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
|
||||
this.AppsKey.Location = new System.Drawing.Point(6, 19);
|
||||
this.AppsKey.Name = "AppsKey";
|
||||
this.AppsKey.Size = new System.Drawing.Size(666, 26);
|
||||
this.AppsKey.TabIndex = 3;
|
||||
this.AppsKeyGroupBox.Text = "App Session Key";
|
||||
//
|
||||
// OTAAGroupBox
|
||||
//
|
||||
@@ -385,6 +204,234 @@
|
||||
this.ComPortSelection.Size = new System.Drawing.Size(121, 21);
|
||||
this.ComPortSelection.TabIndex = 8;
|
||||
//
|
||||
// DevAddrSet
|
||||
//
|
||||
this.DevAddrSet.CommandDesciption = "Set DevAddr";
|
||||
this.DevAddrSet.Enabled = false;
|
||||
this.DevAddrSet.Location = new System.Drawing.Point(759, 19);
|
||||
this.DevAddrSet.Name = "DevAddrSet";
|
||||
this.DevAddrSet.SerialCommand = 'D';
|
||||
this.DevAddrSet.Size = new System.Drawing.Size(75, 26);
|
||||
this.DevAddrSet.TabIndex = 4;
|
||||
this.DevAddrSet.Text = "Set";
|
||||
this.DevAddrSet.UseVisualStyleBackColor = true;
|
||||
this.DevAddrSet.Click += new System.EventHandler(this.CommandButtonSet_Click);
|
||||
//
|
||||
// DevAddrGet
|
||||
//
|
||||
this.DevAddrGet.CommandDesciption = "Get DevAddr";
|
||||
this.DevAddrGet.Enabled = false;
|
||||
this.DevAddrGet.Location = new System.Drawing.Point(678, 19);
|
||||
this.DevAddrGet.Name = "DevAddrGet";
|
||||
this.DevAddrGet.SerialCommand = 'd';
|
||||
this.DevAddrGet.Size = new System.Drawing.Size(75, 26);
|
||||
this.DevAddrGet.TabIndex = 4;
|
||||
this.DevAddrGet.Text = "Get";
|
||||
this.DevAddrGet.UseVisualStyleBackColor = true;
|
||||
this.DevAddrGet.Click += new System.EventHandler(this.CommandButtonGet_Click);
|
||||
//
|
||||
// DevAddr
|
||||
//
|
||||
this.DevAddr.DataLength = 0;
|
||||
this.DevAddr.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
|
||||
this.DevAddr.Location = new System.Drawing.Point(6, 19);
|
||||
this.DevAddr.MaxLength = 0;
|
||||
this.DevAddr.Name = "DevAddr";
|
||||
this.DevAddr.SerialCommandGet = 'd';
|
||||
this.DevAddr.SerialCommandSet = 'D';
|
||||
this.DevAddr.Size = new System.Drawing.Size(666, 26);
|
||||
this.DevAddr.TabIndex = 3;
|
||||
//
|
||||
// NwsKeySet
|
||||
//
|
||||
this.NwsKeySet.CommandDesciption = "Set NwsKey";
|
||||
this.NwsKeySet.Enabled = false;
|
||||
this.NwsKeySet.Location = new System.Drawing.Point(759, 19);
|
||||
this.NwsKeySet.Name = "NwsKeySet";
|
||||
this.NwsKeySet.SerialCommand = 'E';
|
||||
this.NwsKeySet.Size = new System.Drawing.Size(75, 26);
|
||||
this.NwsKeySet.TabIndex = 4;
|
||||
this.NwsKeySet.Text = "Set";
|
||||
this.NwsKeySet.UseVisualStyleBackColor = true;
|
||||
this.NwsKeySet.Click += new System.EventHandler(this.CommandButtonSet_Click);
|
||||
//
|
||||
// NwsKeyGet
|
||||
//
|
||||
this.NwsKeyGet.CommandDesciption = "Get NwsKey";
|
||||
this.NwsKeyGet.Enabled = false;
|
||||
this.NwsKeyGet.Location = new System.Drawing.Point(678, 19);
|
||||
this.NwsKeyGet.Name = "NwsKeyGet";
|
||||
this.NwsKeyGet.SerialCommand = 'e';
|
||||
this.NwsKeyGet.Size = new System.Drawing.Size(75, 26);
|
||||
this.NwsKeyGet.TabIndex = 4;
|
||||
this.NwsKeyGet.Text = "Get";
|
||||
this.NwsKeyGet.UseVisualStyleBackColor = true;
|
||||
this.NwsKeyGet.Click += new System.EventHandler(this.CommandButtonGet_Click);
|
||||
//
|
||||
// NwsKey
|
||||
//
|
||||
this.NwsKey.DataLength = 32;
|
||||
this.NwsKey.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
|
||||
this.NwsKey.Location = new System.Drawing.Point(6, 19);
|
||||
this.NwsKey.MaxLength = 0;
|
||||
this.NwsKey.Name = "NwsKey";
|
||||
this.NwsKey.SerialCommandGet = 'e';
|
||||
this.NwsKey.SerialCommandSet = 'E';
|
||||
this.NwsKey.Size = new System.Drawing.Size(666, 26);
|
||||
this.NwsKey.TabIndex = 3;
|
||||
//
|
||||
// AppsKeySet
|
||||
//
|
||||
this.AppsKeySet.CommandDesciption = "Set AppsKey";
|
||||
this.AppsKeySet.Enabled = false;
|
||||
this.AppsKeySet.Location = new System.Drawing.Point(759, 19);
|
||||
this.AppsKeySet.Name = "AppsKeySet";
|
||||
this.AppsKeySet.SerialCommand = 'F';
|
||||
this.AppsKeySet.Size = new System.Drawing.Size(75, 26);
|
||||
this.AppsKeySet.TabIndex = 4;
|
||||
this.AppsKeySet.Text = "Set";
|
||||
this.AppsKeySet.UseVisualStyleBackColor = true;
|
||||
this.AppsKeySet.Click += new System.EventHandler(this.CommandButtonSet_Click);
|
||||
//
|
||||
// AppsKeyGet
|
||||
//
|
||||
this.AppsKeyGet.CommandDesciption = "Get AppsKey";
|
||||
this.AppsKeyGet.Enabled = false;
|
||||
this.AppsKeyGet.Location = new System.Drawing.Point(678, 19);
|
||||
this.AppsKeyGet.Name = "AppsKeyGet";
|
||||
this.AppsKeyGet.SerialCommand = 'f';
|
||||
this.AppsKeyGet.Size = new System.Drawing.Size(75, 26);
|
||||
this.AppsKeyGet.TabIndex = 4;
|
||||
this.AppsKeyGet.Text = "Get";
|
||||
this.AppsKeyGet.UseVisualStyleBackColor = true;
|
||||
this.AppsKeyGet.Click += new System.EventHandler(this.CommandButtonGet_Click);
|
||||
//
|
||||
// AppsKey
|
||||
//
|
||||
this.AppsKey.DataLength = 32;
|
||||
this.AppsKey.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
|
||||
this.AppsKey.Location = new System.Drawing.Point(6, 19);
|
||||
this.AppsKey.MaxLength = 0;
|
||||
this.AppsKey.Name = "AppsKey";
|
||||
this.AppsKey.SerialCommandGet = 'f';
|
||||
this.AppsKey.SerialCommandSet = 'F';
|
||||
this.AppsKey.Size = new System.Drawing.Size(666, 26);
|
||||
this.AppsKey.TabIndex = 3;
|
||||
//
|
||||
// DevEUISet
|
||||
//
|
||||
this.DevEUISet.CommandDesciption = "Set DevEUI";
|
||||
this.DevEUISet.Enabled = false;
|
||||
this.DevEUISet.Location = new System.Drawing.Point(759, 19);
|
||||
this.DevEUISet.Name = "DevEUISet";
|
||||
this.DevEUISet.SerialCommand = 'A';
|
||||
this.DevEUISet.Size = new System.Drawing.Size(75, 26);
|
||||
this.DevEUISet.TabIndex = 4;
|
||||
this.DevEUISet.Text = "Set";
|
||||
this.DevEUISet.UseVisualStyleBackColor = true;
|
||||
this.DevEUISet.Click += new System.EventHandler(this.CommandButtonSet_Click);
|
||||
//
|
||||
// DevEUIGet
|
||||
//
|
||||
this.DevEUIGet.CommandDesciption = "Get DevEUI";
|
||||
this.DevEUIGet.Enabled = false;
|
||||
this.DevEUIGet.Location = new System.Drawing.Point(678, 19);
|
||||
this.DevEUIGet.Name = "DevEUIGet";
|
||||
this.DevEUIGet.SerialCommand = 'a';
|
||||
this.DevEUIGet.Size = new System.Drawing.Size(75, 26);
|
||||
this.DevEUIGet.TabIndex = 4;
|
||||
this.DevEUIGet.Text = "Get";
|
||||
this.DevEUIGet.UseVisualStyleBackColor = true;
|
||||
this.DevEUIGet.Click += new System.EventHandler(this.CommandButtonGet_Click);
|
||||
//
|
||||
// DevEUI
|
||||
//
|
||||
this.DevEUI.DataLength = 16;
|
||||
this.DevEUI.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
|
||||
this.DevEUI.Location = new System.Drawing.Point(6, 19);
|
||||
this.DevEUI.MaxLength = 0;
|
||||
this.DevEUI.Name = "DevEUI";
|
||||
this.DevEUI.SerialCommandGet = 'a';
|
||||
this.DevEUI.SerialCommandSet = 'A';
|
||||
this.DevEUI.Size = new System.Drawing.Size(666, 26);
|
||||
this.DevEUI.TabIndex = 3;
|
||||
//
|
||||
// AppKeySet
|
||||
//
|
||||
this.AppKeySet.CommandDesciption = "Set AppKey";
|
||||
this.AppKeySet.Enabled = false;
|
||||
this.AppKeySet.Location = new System.Drawing.Point(759, 19);
|
||||
this.AppKeySet.Name = "AppKeySet";
|
||||
this.AppKeySet.SerialCommand = 'C';
|
||||
this.AppKeySet.Size = new System.Drawing.Size(75, 26);
|
||||
this.AppKeySet.TabIndex = 4;
|
||||
this.AppKeySet.Text = "Set";
|
||||
this.AppKeySet.UseVisualStyleBackColor = true;
|
||||
this.AppKeySet.Click += new System.EventHandler(this.CommandButtonSet_Click);
|
||||
//
|
||||
// AppKeyGet
|
||||
//
|
||||
this.AppKeyGet.CommandDesciption = "Get AppKey";
|
||||
this.AppKeyGet.Enabled = false;
|
||||
this.AppKeyGet.Location = new System.Drawing.Point(678, 19);
|
||||
this.AppKeyGet.Name = "AppKeyGet";
|
||||
this.AppKeyGet.SerialCommand = 'c';
|
||||
this.AppKeyGet.Size = new System.Drawing.Size(75, 26);
|
||||
this.AppKeyGet.TabIndex = 4;
|
||||
this.AppKeyGet.Text = "Get";
|
||||
this.AppKeyGet.UseVisualStyleBackColor = true;
|
||||
this.AppKeyGet.Click += new System.EventHandler(this.CommandButtonGet_Click);
|
||||
//
|
||||
// AppKey
|
||||
//
|
||||
this.AppKey.DataLength = 32;
|
||||
this.AppKey.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
|
||||
this.AppKey.Location = new System.Drawing.Point(6, 19);
|
||||
this.AppKey.MaxLength = 0;
|
||||
this.AppKey.Name = "AppKey";
|
||||
this.AppKey.SerialCommandGet = 'c';
|
||||
this.AppKey.SerialCommandSet = 'C';
|
||||
this.AppKey.Size = new System.Drawing.Size(666, 26);
|
||||
this.AppKey.TabIndex = 3;
|
||||
//
|
||||
// AppEUISet
|
||||
//
|
||||
this.AppEUISet.CommandDesciption = "Set AppEUI";
|
||||
this.AppEUISet.Enabled = false;
|
||||
this.AppEUISet.Location = new System.Drawing.Point(759, 19);
|
||||
this.AppEUISet.Name = "AppEUISet";
|
||||
this.AppEUISet.SerialCommand = 'B';
|
||||
this.AppEUISet.Size = new System.Drawing.Size(75, 26);
|
||||
this.AppEUISet.TabIndex = 4;
|
||||
this.AppEUISet.Text = "Set";
|
||||
this.AppEUISet.UseVisualStyleBackColor = true;
|
||||
this.AppEUISet.Click += new System.EventHandler(this.CommandButtonSet_Click);
|
||||
//
|
||||
// AppEUIGet
|
||||
//
|
||||
this.AppEUIGet.CommandDesciption = "Get AppEUI";
|
||||
this.AppEUIGet.Enabled = false;
|
||||
this.AppEUIGet.Location = new System.Drawing.Point(678, 19);
|
||||
this.AppEUIGet.Name = "AppEUIGet";
|
||||
this.AppEUIGet.SerialCommand = 'b';
|
||||
this.AppEUIGet.Size = new System.Drawing.Size(75, 26);
|
||||
this.AppEUIGet.TabIndex = 4;
|
||||
this.AppEUIGet.Text = "Get";
|
||||
this.AppEUIGet.UseVisualStyleBackColor = true;
|
||||
this.AppEUIGet.Click += new System.EventHandler(this.CommandButtonGet_Click);
|
||||
//
|
||||
// AppEUI
|
||||
//
|
||||
this.AppEUI.DataLength = 16;
|
||||
this.AppEUI.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
|
||||
this.AppEUI.Location = new System.Drawing.Point(6, 19);
|
||||
this.AppEUI.MaxLength = 0;
|
||||
this.AppEUI.Name = "AppEUI";
|
||||
this.AppEUI.SerialCommandGet = 'b';
|
||||
this.AppEUI.SerialCommandSet = 'B';
|
||||
this.AppEUI.Size = new System.Drawing.Size(666, 26);
|
||||
this.AppEUI.TabIndex = 3;
|
||||
//
|
||||
// Form1
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
|
||||
@@ -423,18 +470,12 @@
|
||||
private System.Windows.Forms.GroupBox groupBox1;
|
||||
private System.Windows.Forms.TextBox SerialConsole;
|
||||
private System.Windows.Forms.Button OpenSerialPort;
|
||||
private System.Windows.Forms.TextBox DevEUI;
|
||||
private System.Windows.Forms.GroupBox DevUEIGroupBox;
|
||||
private System.Windows.Forms.GroupBox AppEUIGroupBox;
|
||||
private System.Windows.Forms.TextBox AppEUI;
|
||||
private System.Windows.Forms.GroupBox AppKeyGroupBox;
|
||||
private System.Windows.Forms.TextBox AppKey;
|
||||
private System.Windows.Forms.GroupBox DevAddrGroupBox;
|
||||
private System.Windows.Forms.TextBox DevAddr;
|
||||
private System.Windows.Forms.GroupBox NwsKeyGroupBox;
|
||||
private System.Windows.Forms.TextBox NwsKey;
|
||||
private System.Windows.Forms.GroupBox AppsKeyGroupBox;
|
||||
private System.Windows.Forms.TextBox AppsKey;
|
||||
private System.Windows.Forms.GroupBox OTAAGroupBox;
|
||||
private System.Windows.Forms.GroupBox ABPGroupBox;
|
||||
private CommandButton DevEUISet;
|
||||
@@ -450,6 +491,12 @@
|
||||
private CommandButton AppsKeySet;
|
||||
private CommandButton AppsKeyGet;
|
||||
private System.Windows.Forms.ComboBox ComPortSelection;
|
||||
private HexValueTextbox DevEUI;
|
||||
private HexValueTextbox AppEUI;
|
||||
private HexValueTextbox AppKey;
|
||||
private HexValueTextbox DevAddr;
|
||||
private HexValueTextbox NwsKey;
|
||||
private HexValueTextbox AppsKey;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -20,22 +20,31 @@ namespace Lora_Wsen_Configtool
|
||||
InitializeComponent();
|
||||
SerialPortOpenEvent += OpenSerialPort_Color;
|
||||
|
||||
DevEUI.Validating += DevEUI_Validating;
|
||||
DevEUI.KeyUp += DevEUI_KeyUp;
|
||||
|
||||
|
||||
SerialPortOpenEvent += DevEUIGet.SetVisbleState;
|
||||
SerialPortOpenEvent += DevEUISet.SetVisbleState;
|
||||
SerialPortOpenEvent += DevEUI.SetSerialState;
|
||||
DevEUI.InputIsValid += DevEUISet.SetVisbleState;
|
||||
|
||||
SerialPortOpenEvent += AppEUIGet.SetVisbleState;
|
||||
SerialPortOpenEvent += AppEUISet.SetVisbleState;
|
||||
SerialPortOpenEvent += AppEUI.SetSerialState;
|
||||
AppEUI.InputIsValid += AppEUISet.SetVisbleState;
|
||||
|
||||
SerialPortOpenEvent += AppKeyGet.SetVisbleState;
|
||||
SerialPortOpenEvent += AppKeySet.SetVisbleState;
|
||||
SerialPortOpenEvent += AppKey.SetSerialState;
|
||||
AppKey.InputIsValid += AppKeySet.SetVisbleState;
|
||||
|
||||
SerialPortOpenEvent += DevAddrGet.SetVisbleState;
|
||||
SerialPortOpenEvent += DevAddrSet.SetVisbleState;
|
||||
SerialPortOpenEvent += DevAddr.SetSerialState;
|
||||
DevAddr.InputIsValid += DevAddrSet.SetVisbleState;
|
||||
|
||||
SerialPortOpenEvent += NwsKeyGet.SetVisbleState;
|
||||
SerialPortOpenEvent += NwsKeySet.SetVisbleState;
|
||||
SerialPortOpenEvent += NwsKey.SetSerialState;
|
||||
NwsKey.InputIsValid += NwsKeySet.SetVisbleState;
|
||||
|
||||
SerialPortOpenEvent += AppsKeyGet.SetVisbleState;
|
||||
SerialPortOpenEvent += AppsKeySet.SetVisbleState;
|
||||
SerialPortOpenEvent += AppsKey.SetSerialState;
|
||||
AppsKey.InputIsValid += AppsKeySet.SetVisbleState;
|
||||
|
||||
SerialPortOpenEvent += this.QueryAuthenication;
|
||||
|
||||
SerialPortOpenEvent?.Invoke(this, false);
|
||||
|
||||
@@ -43,9 +52,9 @@ namespace Lora_Wsen_Configtool
|
||||
}
|
||||
|
||||
private SerialPort _SerialPort;
|
||||
|
||||
private const int BaudRate = 9600;
|
||||
|
||||
|
||||
private void Form1_Load(object sender, EventArgs e)
|
||||
{
|
||||
}
|
||||
@@ -54,20 +63,30 @@ namespace Lora_Wsen_Configtool
|
||||
_SerialPort.Close();
|
||||
}
|
||||
|
||||
public void QueryAuthenication(object sender, bool IsOpen)
|
||||
{
|
||||
if (IsOpen)
|
||||
{
|
||||
_SerialPort.DiscardOutBuffer();
|
||||
_SerialPort.Write(new byte[] { STX }, 0, 1);
|
||||
_SerialPort.Write(new byte[] { (byte)'?' }, 0, 1);
|
||||
_SerialPort.Write(new byte[] { ETX }, 0, 1);
|
||||
}
|
||||
}
|
||||
|
||||
public string ByteArrayToString(byte[] ba)
|
||||
{
|
||||
return BitConverter.ToString(ba, 0).Replace("-", "");
|
||||
}
|
||||
public string ByteArrayToStringSpaces(byte[] ba)
|
||||
{
|
||||
return BitConverter.ToString(ba, 0).Replace("-", " ");
|
||||
}
|
||||
public string ByteArrayToString(string str)
|
||||
public string ByteArrayToStringSpaces(string str)
|
||||
{
|
||||
return BitConverter.ToString(Encoding.ASCII.GetBytes(str), 0).Replace("-", " ");
|
||||
}
|
||||
|
||||
//public delegate void InvokeTreatment(byte[] buffer);
|
||||
|
||||
char[] SerialBuffer = new char[256];
|
||||
int idx = 0;
|
||||
|
||||
private void SerialPort_DataReceived(object sender, SerialDataReceivedEventArgs e)
|
||||
{
|
||||
@@ -75,92 +94,81 @@ namespace Lora_Wsen_Configtool
|
||||
byte[] buffer = new byte[byteCount];
|
||||
_SerialPort.Read(buffer, 0, byteCount);
|
||||
|
||||
//Console.WriteLine("SerialPort_DataReceived");
|
||||
//Console.WriteLine(ByteArrayToString(buffer));
|
||||
|
||||
if (InvokeRequired)
|
||||
{
|
||||
this.Invoke((MethodInvoker)delegate
|
||||
{
|
||||
SerialConsole.AppendText(Encoding.ASCII.GetString(buffer));
|
||||
SerialConsole.AppendText(Environment.NewLine);
|
||||
//SerialConsole.AppendText("RX - " + Encoding.ASCII.GetString(buffer) + Environment.NewLine);
|
||||
SerialConsole.AppendText("RX - " + ByteArrayToStringSpaces(buffer) + Environment.NewLine);
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
SerialConsole.AppendText(Encoding.ASCII.GetString(buffer));
|
||||
SerialConsole.AppendText(Environment.NewLine);
|
||||
//SerialConsole.AppendText("RX - " + Encoding.ASCII.GetString(buffer) + Environment.NewLine);
|
||||
SerialConsole.AppendText("RX - " + ByteArrayToStringSpaces(buffer) + Environment.NewLine);
|
||||
}
|
||||
|
||||
//Console.WriteLine("BYtesCount = " + byteCount);
|
||||
|
||||
if (buffer[0] == STX[0] && buffer[byteCount - 1] == ETX[0])
|
||||
if (buffer[0] == STX && buffer[byteCount - 1] == ETX)
|
||||
{
|
||||
switch (buffer[1])
|
||||
{
|
||||
case 0x61: //get DevEUI
|
||||
case 0x3F: //'?' answer QueryAuthentication
|
||||
if (buffer[2] == 'A')
|
||||
{
|
||||
this.Invoke((MethodInvoker)delegate
|
||||
{
|
||||
ABPGroupBox.Enabled = true;
|
||||
OTAAGroupBox.Enabled = false;
|
||||
});
|
||||
}
|
||||
if (buffer[2] == 'O')
|
||||
{
|
||||
this.Invoke((MethodInvoker)delegate
|
||||
{
|
||||
ABPGroupBox.Enabled = false;
|
||||
OTAAGroupBox.Enabled = true;
|
||||
});
|
||||
}
|
||||
break;
|
||||
case 0x61: //'a' answer get DevEUI
|
||||
this.Invoke((MethodInvoker)delegate
|
||||
{
|
||||
DevEUI.Text = ByteArrayToString(buffer.Skip(2).Take(8).ToArray());
|
||||
});
|
||||
break;
|
||||
case 0x62: //get appEUI
|
||||
case 0x62: //'b' answer get appEUI
|
||||
this.Invoke((MethodInvoker)delegate
|
||||
{
|
||||
AppEUI.Text = ByteArrayToString(buffer.Skip(2).Take(8).ToArray());
|
||||
});
|
||||
break;
|
||||
case 0x63: //get appkey
|
||||
case 0x63: //'c' answer answer get appkey
|
||||
this.Invoke((MethodInvoker)delegate
|
||||
{
|
||||
AppKey.Text = ByteArrayToString(buffer.Skip(2).Take(16).ToArray());
|
||||
});
|
||||
break;
|
||||
case 0x64: //get devaddr
|
||||
case 0x64: //'d' answer get devaddr
|
||||
this.Invoke((MethodInvoker)delegate
|
||||
{
|
||||
DevAddr.Text = ByteArrayToString(buffer.Skip(2).Take(8).ToArray());
|
||||
});
|
||||
break;
|
||||
case 0x65: //get nwkskey
|
||||
case 0x65: //'e' answer get nwkskey
|
||||
this.Invoke((MethodInvoker)delegate
|
||||
{
|
||||
NwsKey.Text = ByteArrayToString(buffer.Skip(2).Take(16).ToArray());
|
||||
});
|
||||
break;
|
||||
case 0x66: //get appskey
|
||||
case 0x66: //'f' answer get appskey
|
||||
this.Invoke((MethodInvoker)delegate
|
||||
{
|
||||
AppsKey.Text = ByteArrayToString(buffer.Skip(2).Take(16).ToArray());
|
||||
});
|
||||
break;
|
||||
|
||||
case 0x41: //Set DevEUI
|
||||
//Serial.println(F("set deveui"));
|
||||
// Serial.println(&cmdline[1]);
|
||||
// memcpy(configuration.DEVEUI, &cmdline[1], 8);
|
||||
break;
|
||||
case 0x42: //Set appEUI
|
||||
//Serial.println(F("set appeui"));
|
||||
// Serial.println(&cmdline[1]);
|
||||
// memcpy(configuration.APPEUI, &cmdline[1], 8);
|
||||
break;
|
||||
case 0x43: //Set APPKEY
|
||||
//Serial.println(F("set appkey"));
|
||||
// Serial.println(&cmdline[1]);
|
||||
// memcpy(configuration.APPKEY, &cmdline[1], 16);
|
||||
break;
|
||||
case 0x44: //Set devaddr
|
||||
//Serial.println(F("set devaddr"));
|
||||
// Serial.println(&cmdline[1]);
|
||||
break;
|
||||
case 0x45: //Set NwkSKey
|
||||
//Serial.println(F("set nwkskey"));
|
||||
// Serial.println(&cmdline[1]);
|
||||
break;
|
||||
case 0x46: //Set appskey
|
||||
//Serial.println(F("set appskey"));
|
||||
// Serial.println(&cmdline[1]);
|
||||
break;
|
||||
default:
|
||||
Console.WriteLine("Unknown command = " + buffer[1]);
|
||||
break;
|
||||
@@ -181,9 +189,18 @@ namespace Lora_Wsen_Configtool
|
||||
SerialPortOpenEvent?.Invoke(this, false);
|
||||
return;
|
||||
}
|
||||
_SerialPort = new SerialPort(ComPortSelection.SelectedItem.ToString(), BaudRate, Parity.None, 8, StopBits.One);
|
||||
_SerialPort.DataReceived += SerialPort_DataReceived;
|
||||
_SerialPort.Open();
|
||||
try
|
||||
{
|
||||
_SerialPort = new SerialPort(ComPortSelection.SelectedItem.ToString(), BaudRate, Parity.None, 8, StopBits.One);
|
||||
_SerialPort.DataReceived += SerialPort_DataReceived;
|
||||
_SerialPort.Open();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
SerialConsole.AppendText("Error - " + ex.Message);
|
||||
//throw;
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -209,250 +226,118 @@ namespace Lora_Wsen_Configtool
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
private byte[] STX = new byte[] { 0x02 };
|
||||
private byte[] ETX = new byte[] { 0x03 };
|
||||
|
||||
private void SendSerial(String str)
|
||||
{
|
||||
_SerialPort.DiscardOutBuffer();
|
||||
byte[] bytes = Encoding.ASCII.GetBytes(str);
|
||||
_SerialPort.Write(STX, 0, 1);
|
||||
_SerialPort.Write(bytes, 0, bytes.Length);
|
||||
_SerialPort.Write(ETX, 0, 1);
|
||||
}
|
||||
private byte STX = 0x02;
|
||||
private byte ETX = 0x03;
|
||||
|
||||
private void CommandButtonGet_Click(object sender, EventArgs e)
|
||||
{
|
||||
CommandButton cmdbutton = (CommandButton)sender;
|
||||
|
||||
Console.WriteLine("Get = " + cmdbutton.SerialCommand);
|
||||
|
||||
SendSerial(cmdbutton.SerialCommand.ToString());
|
||||
SerialConsole.AppendText("TX - " + cmdbutton.CommandDesciption + Environment.NewLine);
|
||||
_SerialPort.DiscardOutBuffer();
|
||||
_SerialPort.Write(new byte[] { STX }, 0, 1);
|
||||
_SerialPort.Write(new byte[] { (byte)cmdbutton.SerialCommand }, 0, 1);
|
||||
_SerialPort.Write(new byte[] { ETX }, 0, 1);
|
||||
}
|
||||
|
||||
|
||||
|
||||
private void CommandButtonSet_Click(object sender, EventArgs e)
|
||||
{
|
||||
CommandButton cmdbutton = (CommandButton)sender;
|
||||
SerialConsole.AppendText("TX " + cmdbutton.CommandDesciption + Environment.NewLine);
|
||||
|
||||
Console.WriteLine("Set = " + cmdbutton.SerialCommand);
|
||||
|
||||
byte[] bytes = new byte[17];
|
||||
byte[] bytes = new byte[1];
|
||||
|
||||
switch (cmdbutton.SerialCommand)
|
||||
{
|
||||
case 'A':
|
||||
if (string.IsNullOrEmpty(DevEUI.Text) == false && string.IsNullOrWhiteSpace(DevEUI.Text) == false)
|
||||
{
|
||||
Console.WriteLine("-" + DevEUI.Text + "-");
|
||||
bytes = DevEUI.Text.Split(' ').Select(h => byte.Parse(h, NumberStyles.AllowHexSpecifier)).ToArray();
|
||||
bytes = new byte[(DevEUI.DataLength / 2) + 3];
|
||||
bytes[0] = STX;
|
||||
//Console.WriteLine("-" + DevEUI.Text + "-");
|
||||
bytes[1] = (byte)'A';
|
||||
byte[] data = DevEUI.GetByteArray();
|
||||
Buffer.BlockCopy(data, 0, bytes, 2, data.Length);
|
||||
bytes[data.Length + 2] = ETX;
|
||||
}
|
||||
break;
|
||||
case 'B':
|
||||
if (string.IsNullOrEmpty(AppEUI.Text) == false && string.IsNullOrWhiteSpace(AppEUI.Text) == false)
|
||||
{
|
||||
Console.WriteLine("-" + AppEUI.Text + "-");
|
||||
bytes = AppEUI.Text.Split(' ').Select(h => byte.Parse(h, NumberStyles.AllowHexSpecifier)).ToArray();
|
||||
bytes = new byte[(AppEUI.DataLength / 2) + 3];
|
||||
bytes[0] = STX;
|
||||
|
||||
//Console.WriteLine("-" + AppEUI.Text + "-");
|
||||
bytes[1] = (byte)'B';
|
||||
byte[] data = AppEUI.GetByteArray();
|
||||
Buffer.BlockCopy(data, 0, bytes, 2, data.Length);
|
||||
bytes[data.Length + 2] = ETX;
|
||||
}
|
||||
break;
|
||||
case 'C':
|
||||
if (string.IsNullOrEmpty(AppKey.Text) == false && string.IsNullOrWhiteSpace(AppKey.Text) == false)
|
||||
{
|
||||
Console.WriteLine("-" + AppKey.Text + "-");
|
||||
bytes = AppKey.Text.Split(' ').Select(h => byte.Parse(h, NumberStyles.AllowHexSpecifier)).ToArray();
|
||||
bytes = new byte[(AppKey.DataLength / 2) + 3];
|
||||
bytes[0] = STX;
|
||||
|
||||
//Console.WriteLine("-" + AppKey.Text + "-");
|
||||
bytes[1] = (byte)'C';
|
||||
byte[] data = AppKey.GetByteArray();
|
||||
Buffer.BlockCopy(data, 0, bytes, 2, data.Length);
|
||||
bytes[data.Length + 2] = ETX;
|
||||
}
|
||||
break;
|
||||
case 'D':
|
||||
if (string.IsNullOrEmpty(DevAddr.Text) == false && string.IsNullOrWhiteSpace(DevAddr.Text) == false)
|
||||
{
|
||||
Console.WriteLine("-" + DevAddr.Text + "-");
|
||||
bytes = DevAddr.Text.Split(' ').Select(h => byte.Parse(h, NumberStyles.AllowHexSpecifier)).ToArray();
|
||||
bytes = new byte[(DevAddr.DataLength / 2) + 3];
|
||||
bytes[0] = STX;
|
||||
|
||||
//Console.WriteLine("-" + DevAddr.Text + "-");
|
||||
bytes[1] = (byte)'D';
|
||||
byte[] data = DevAddr.GetByteArray();
|
||||
Buffer.BlockCopy(data, 0, bytes, 2, data.Length);
|
||||
bytes[data.Length + 2] = ETX;
|
||||
}
|
||||
break;
|
||||
case 'E':
|
||||
if (string.IsNullOrEmpty(NwsKey.Text) == false && string.IsNullOrWhiteSpace(NwsKey.Text) == false)
|
||||
{
|
||||
Console.WriteLine("-" + NwsKey.Text + "-");
|
||||
bytes = NwsKey.Text.Split(' ').Select(h => byte.Parse(h, NumberStyles.AllowHexSpecifier)).ToArray();
|
||||
bytes = new byte[(NwsKey.DataLength / 2) + 3];
|
||||
bytes[0] = STX;
|
||||
|
||||
//Console.WriteLine("-" + NwsKey.Text + "-");
|
||||
bytes[1] = (byte)'E';
|
||||
byte[] data = NwsKey.GetByteArray();
|
||||
Buffer.BlockCopy(data, 0, bytes, 2, data.Length);
|
||||
bytes[data.Length + 2] = ETX;
|
||||
}
|
||||
break;
|
||||
case 'F':
|
||||
if (string.IsNullOrEmpty(AppsKey.Text) == false && string.IsNullOrWhiteSpace(AppsKey.Text) == false)
|
||||
{
|
||||
Console.WriteLine("-" + AppsKey.Text + "-");
|
||||
bytes = AppsKey.Text.Split(' ').Select(h => byte.Parse(h, NumberStyles.AllowHexSpecifier)).ToArray();
|
||||
bytes = new byte[(AppsKey.DataLength / 2) + 3];
|
||||
bytes[0] = STX;
|
||||
|
||||
//Console.WriteLine("-" + AppsKey.Text + "-");
|
||||
bytes[1] = (byte)'F';
|
||||
byte[] data = AppsKey.GetByteArray();
|
||||
Buffer.BlockCopy(data, 0, bytes, 2, data.Length);
|
||||
bytes[data.Length + 2] = ETX;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
SerialConsole.AppendText("TX - " + ByteArrayToString(bytes) + Environment.NewLine);
|
||||
|
||||
Console.WriteLine(ByteArrayToString(bytes));
|
||||
//Console.WriteLine("CommandButtonSet_Click");
|
||||
//Console.WriteLine(ByteArrayToString(bytes));
|
||||
|
||||
|
||||
|
||||
//SendSerial(cmdbutton.SerialCommand.ToString());
|
||||
_SerialPort.DiscardOutBuffer();
|
||||
_SerialPort.Write(bytes, 0, bytes.Length);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
private void DevEUI_Validating(object sender, CancelEventArgs e)
|
||||
{
|
||||
Console.WriteLine("Validating");
|
||||
|
||||
//string HexValue = DevEUI.Text.ToUpper();
|
||||
|
||||
//char[] allowedChars = new char[] { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };
|
||||
|
||||
//string newhexvalue = string.Empty;
|
||||
|
||||
//foreach (char character in HexValue)
|
||||
//{
|
||||
// if (allowedChars.Contains(character))
|
||||
// {
|
||||
// Console.WriteLine(character + " Allowed");
|
||||
|
||||
// newhexvalue.Append(character);
|
||||
|
||||
// // //MessageBox.Show(string.Format("'{0}' is not a hexadecimal character", character));
|
||||
// // //e.Cancel = true;
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// Console.WriteLine(character + " Not Allowed");
|
||||
|
||||
// // HexValue.Remove(character);
|
||||
// }
|
||||
//}
|
||||
|
||||
|
||||
|
||||
// char[] allowedChars = new char[] { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };
|
||||
|
||||
// foreach (char character in DevEUI.Text.ToUpper().ToArray())
|
||||
// {
|
||||
// if (!allowedChars.Contains(character))
|
||||
// {
|
||||
// MessageBox.Show(string.Format("'{0}' is not a hexadecimal character", character));
|
||||
// e.Cancel = true;
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
|
||||
private void DevEUI_KeyUp(object sender, EventArgs e)
|
||||
{
|
||||
Console.WriteLine("keyup");
|
||||
|
||||
string HexValue = DevEUI.Text.ToUpper();
|
||||
|
||||
char[] allowedChars = new char[] { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };
|
||||
|
||||
string newhexvalue = string.Empty;
|
||||
|
||||
foreach (char character in HexValue)
|
||||
{
|
||||
if (allowedChars.Contains(character))
|
||||
{
|
||||
Console.WriteLine(character + " Allowed");
|
||||
|
||||
newhexvalue.Append(character);
|
||||
|
||||
// //MessageBox.Show(string.Format("'{0}' is not a hexadecimal character", character));
|
||||
// //e.Cancel = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine(character + " Not Allowed");
|
||||
|
||||
// HexValue.Remove(character);
|
||||
}
|
||||
}
|
||||
|
||||
DevEUI.Text = newhexvalue;
|
||||
|
||||
//DevEUI.Select();
|
||||
//DevEUI.Select(DevEUI.Text.Length, 0);
|
||||
}
|
||||
|
||||
private void DevEUI_TextChanged(object sender, EventArgs e)
|
||||
{
|
||||
Console.WriteLine("textchanged");
|
||||
|
||||
//string HexValue = DevEUI.Text.ToUpper();
|
||||
|
||||
//char[] allowedChars = new char[] { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };
|
||||
|
||||
|
||||
////HexValue = Regex.Replace(HexValue, @"^[A-F][a-f][0-9]*$", string.Empty);
|
||||
|
||||
////string str = new string((from c in HexValue
|
||||
//// where char.IsWhiteSpace(c) || char.IsLetterOrDigit(c)
|
||||
//// select c
|
||||
//// ).ToArray());
|
||||
|
||||
//string newhexvalue = string.Empty; // = new string() ;
|
||||
|
||||
//foreach (char character in HexValue)
|
||||
//{
|
||||
// if (allowedChars.Contains(character))
|
||||
// {
|
||||
// Console.WriteLine(character + " Allowed");
|
||||
|
||||
// newhexvalue.Append(character);
|
||||
|
||||
// // //MessageBox.Show(string.Format("'{0}' is not a hexadecimal character", character));
|
||||
// // //e.Cancel = true;
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// Console.WriteLine(character + " Not Allowed");
|
||||
|
||||
// // HexValue.Remove(character);
|
||||
// }
|
||||
//}
|
||||
|
||||
|
||||
//DevEUI.Text = newhexvalue;
|
||||
|
||||
//DevEUI.Select();
|
||||
//DevEUI.Select(DevEUI.Text.Length, 0);
|
||||
|
||||
|
||||
|
||||
|
||||
//if (!int.TryParse(item, NumberStyles.HexNumber, NumberFormatInfo.CurrentInfo, out _) && item != String.Empty)
|
||||
//{
|
||||
// Console.WriteLine("1");
|
||||
|
||||
// //DevEUI.Text = item.Remove(item.Length - 1, 1);
|
||||
// //DevEUI.SelectionStart = DevEUI.Text.Length;
|
||||
//}
|
||||
//else
|
||||
//{
|
||||
// Console.WriteLine("Else");
|
||||
//}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
//private void DevEUI_TextChanged(object sender, EventArgs e)
|
||||
//{
|
||||
|
||||
// string item = DevEUI.Text;
|
||||
// if (!int.TryParse(item, System.Globalization.NumberStyles.HexNumber, System.Globalization.NumberFormatInfo.CurrentInfo, out int n) && item != String.Empty)
|
||||
// {
|
||||
// DevEUI.Text = item.Remove(item.Length - 1, 1);
|
||||
// DevEUI.SelectionStart = DevEUI.Text.Length;
|
||||
// }
|
||||
//}
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
115
Lora-Wsen-Configtool/HexValueTextbox.cs
Normal file
115
Lora-Wsen-Configtool/HexValueTextbox.cs
Normal file
@@ -0,0 +1,115 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace Lora_Wsen_Configtool
|
||||
{
|
||||
public class HexValueTextbox : TextBox
|
||||
{
|
||||
public int DataLength { get; set; }
|
||||
public char SerialCommandGet { get; set; }
|
||||
public char SerialCommandSet { get; set; }
|
||||
|
||||
|
||||
public EventHandler<Boolean> InputIsValid;
|
||||
|
||||
|
||||
public HexValueTextbox()
|
||||
{
|
||||
this.MaxLength = DataLength;
|
||||
|
||||
// InitializeComponent();
|
||||
//this.Enabled = false;
|
||||
}
|
||||
|
||||
private char[] allowedChars = new char[] { ' ', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };
|
||||
|
||||
private string CheckHexText(string text)
|
||||
{
|
||||
text = text.ToUpper();
|
||||
foreach (char character in text)
|
||||
{
|
||||
if (!allowedChars.Contains(character))
|
||||
{
|
||||
if (text.Length > 0)
|
||||
{
|
||||
text = text.Remove(text.Length - 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
return text;
|
||||
}
|
||||
|
||||
private bool IsSerialOpen;
|
||||
|
||||
public void SetSerialState(object sender, bool state)
|
||||
{
|
||||
IsSerialOpen = state;
|
||||
CheckTextLength();
|
||||
}
|
||||
|
||||
private void CheckTextLength()
|
||||
{
|
||||
if (this.Text.Length == DataLength)
|
||||
{
|
||||
InputIsValid?.Invoke(this, IsSerialOpen);
|
||||
}
|
||||
else
|
||||
{
|
||||
InputIsValid?.Invoke(this, false);
|
||||
}
|
||||
}
|
||||
|
||||
//protected override void OnKeyUp(KeyEventArgs e)
|
||||
//{
|
||||
// this.Text = CheckHexText(this.Text);
|
||||
|
||||
// this.SelectionStart = this.Text.Length;
|
||||
// this.SelectionLength = 0;
|
||||
|
||||
// CheckTextLength();
|
||||
|
||||
// //base.OnKeyUp(e);
|
||||
//}
|
||||
|
||||
protected override void OnTextChanged(EventArgs e)
|
||||
{
|
||||
this.Text = CheckHexText(this.Text);
|
||||
|
||||
if (this.Text.Length > DataLength)
|
||||
{
|
||||
this.Text = this.Text.Substring(0, DataLength);
|
||||
}
|
||||
|
||||
this.SelectionStart = this.Text.Length;
|
||||
this.SelectionLength = 0;
|
||||
|
||||
CheckTextLength();
|
||||
|
||||
|
||||
//base.OnTextChanged(e);
|
||||
}
|
||||
|
||||
//private byte STX = 0x02;
|
||||
//private byte ETX = 0x03;
|
||||
|
||||
public byte[] GetByteArray()
|
||||
{
|
||||
return Enumerable.Range(0, this.Text.Length)
|
||||
.Where(x => x % 2 == 0)
|
||||
.Select(x => Convert.ToByte(this.Text.Substring(x, 2), 16))
|
||||
.ToArray();
|
||||
}
|
||||
|
||||
//public void SetByteArray(byte[] bytes)
|
||||
//{
|
||||
|
||||
//}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -58,6 +58,9 @@
|
||||
<Compile Include="Form1.Designer.cs">
|
||||
<DependentUpon>Form1.cs</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="HexValueTextbox.cs">
|
||||
<SubType>Component</SubType>
|
||||
</Compile>
|
||||
<Compile Include="Program.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<EmbeddedResource Include="Form1.resx">
|
||||
|
||||
Reference in New Issue
Block a user