修改了截取IP的逻辑,更好的适配非192.168.1频段
This commit is contained in:
@@ -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");
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user