From ff9994163dfbaaadd9725fb73189709f0d3458aa Mon Sep 17 00:00:00 2001 From: Thomas Blenkers Date: Mon, 15 Jun 2020 11:13:47 +0200 Subject: [PATCH 1/2] Corrected hexadecimal input readout for data length --- CommonControls/DataTab.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CommonControls/DataTab.cs b/CommonControls/DataTab.cs index 1844d55..dd66fa1 100644 --- a/CommonControls/DataTab.cs +++ b/CommonControls/DataTab.cs @@ -61,7 +61,8 @@ namespace Modbus.Common string str = txtSize.Text.Replace("0x", ""); rVal = Convert.ToUInt16(str, 16); } - rVal = Convert.ToUInt16(txtSize.Text); + else + rVal = Convert.ToUInt16(txtSize.Text); } catch (Exception) { From 480412ec27862ae7461f3d3b1085722e34a2e223 Mon Sep 17 00:00:00 2001 From: Thomas Blenkers Date: Mon, 15 Jun 2020 16:02:31 +0200 Subject: [PATCH 2/2] Fixes issue #17 --- CommonControls/DataTab.Designer.cs | 2 +- CommonControls/DataTab.cs | 10 ++++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/CommonControls/DataTab.Designer.cs b/CommonControls/DataTab.Designer.cs index aba5b64..0db2ce7 100644 --- a/CommonControls/DataTab.Designer.cs +++ b/CommonControls/DataTab.Designer.cs @@ -74,7 +74,7 @@ // txtSize // this.txtSize.Location = new System.Drawing.Point(211, 16); - this.txtSize.MaxLength = 3; + this.txtSize.MaxLength = 5; this.txtSize.Name = "txtSize"; this.txtSize.Size = new System.Drawing.Size(40, 20); this.txtSize.TabIndex = 34; diff --git a/CommonControls/DataTab.cs b/CommonControls/DataTab.cs index dd66fa1..eebd027 100644 --- a/CommonControls/DataTab.cs +++ b/CommonControls/DataTab.cs @@ -56,7 +56,7 @@ namespace Modbus.Common ushort rVal = 64; try { - if (txtSize.Text.IndexOf("0x", 0, txtSize.Text.Length) == 0) + if (txtSize.Text.StartsWith("0x", StringComparison.InvariantCultureIgnoreCase)) { string str = txtSize.Text.Replace("0x", ""); rVal = Convert.ToUInt16(str, 16); @@ -72,7 +72,13 @@ namespace Modbus.Common } set { - txtSize.Text = Convert.ToString(value); + if (txtSize.Text.StartsWith("0x", StringComparison.InvariantCultureIgnoreCase)) + { + // obey hex input + txtSize.Text = "0x"+Convert.ToString(value, 16); + } + else + txtSize.Text = Convert.ToString(value); } }