修改了截取IP的逻辑,更好的适配非192.168.1频段

This commit is contained in:
zhouyunhao
2024-08-20 08:42:26 +08:00
parent 2ccd3554fa
commit d782b731ca
8 changed files with 20 additions and 7 deletions

View File

@@ -880,6 +880,7 @@
this.progressBar1.Name = "progressBar1";
this.progressBar1.Size = new System.Drawing.Size(100, 23);
this.progressBar1.TabIndex = 146;
this.progressBar1.Visible = false;
//
// button2
//
@@ -1637,7 +1638,7 @@
this.Controls.Add(this.ReceiveText);
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
this.Name = "Form1";
this.Text = "20240816";
this.Text = "20240819";
this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.Form1_FormClosing);
this.Load += new System.EventHandler(this.Form1_Load);
((System.ComponentModel.ISupportInitialize)(this.DataGridView1)).EndInit();

View File

@@ -1206,7 +1206,19 @@ namespace C_Windows_1
byte[] data = Encoding.ASCII.GetBytes("hello,udp server");
System.Net.IPAddress ip;
string localip=GetLocalIPAddress();
localip = localip.Substring(0, 10) + "255";
// 查找第三个 '.' 符号的位置
int firstDot = localip.IndexOf('.');
int secondDot = localip.IndexOf('.', firstDot + 1);
int thirdDot = localip.IndexOf('.', secondDot + 1);
// 截取到第三个 '.' 符号
localip = thirdDot != -1
? localip.Substring(0, thirdDot + 1)
: localip;
localip = localip/*.Substring(0, 10)*/ + "255";
//Code.Text = localip;
ip = System.Net.IPAddress.Parse(localip);
// 获本机IP频段广播到 .255
IPEndPoint endPoint = new IPEndPoint(ip, Port);
@@ -3133,8 +3145,8 @@ namespace C_Windows_1
station2 = Convert.ToUInt16(stationIP);
station = station2.ToString("X2");
Modbusread(360, 4, ReadData);
labelruanjian.Text = "软件版本号:" + ReadData[360].ToString("X4") + ReadData[361].ToString("X4");
labelyinjian.Text = "硬件版本号:" + ReadData[362].ToString("X4") + ReadData[363].ToString("X4");
labelruanjian.Text = "软件版本号:" + ReadData[361].ToString("X4") + ReadData[360].ToString("X4");
labelyinjian.Text = "硬件版本号:" + ReadData[363].ToString("X4") + ReadData[362].ToString("X4");
}

View File

@@ -878,7 +878,7 @@
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(712, 425);
this.ClientSize = new System.Drawing.Size(644, 425);
this.Controls.Add(this.label15);
this.Controls.Add(this.label54);
this.Controls.Add(this.TestTime2);

View File

@@ -91,13 +91,13 @@ namespace C_Windows_1
{
try
{
if (FullTime.Text == "" || BBalanTime.Text == "" || SBalanTime.Text == "" || TestTime1.Text == "" || ExhaustTime.Text == "" || BypassTime.Text == "" || DelayTime1.Text == "" || DelayTime2.Text == "" || BLeakLPre.Text == "" || BLeakTPre.Text == "" || LUnit.Text == "" || PUnit.Text == "")
if (FullTime.Text == "" || TestTime1.Text == "" || ExhaustTime.Text == "" || DelayTime1.Text == "" || DelayTime2.Text == "" || BLeakLPre.Text == "" || BLeakTPre.Text == "" || LUnit.Text == "" || PUnit.Text == "")
{
MessageBox.Show("输入参数格式不对");
}
else
{
if (FullTime.Text == "" || BBalanTime.Text == "" || SBalanTime.Text == "" || TestTime1.Text == "" || ExhaustTime.Text == "" || BypassTime.Text == "" || DelayTime1.Text == "" || DelayTime2.Text == "" || BLeakLPre.Text == "" || BLeakTPre.Text == "" || LUnit.Text == "" || PUnit.Text == "")
if (FullTime.Text == "" || TestTime1.Text == "" || ExhaustTime.Text == "" || DelayTime1.Text == "" || DelayTime2.Text == "" || BLeakLPre.Text == "" || BLeakTPre.Text == "" || LUnit.Text == "" || PUnit.Text == "")
{
MessageBox.Show("输入参数格式不对");
}

Binary file not shown.