通讯循环逻辑修改
This commit is contained in:
commit
6c6fa42544
3 files changed
+44
-10
No files matched your search
@@ -53,6 +53,7 @@
|
||||
</DataGrid.Columns>
|
||||
</DataGrid>
|
||||
<TextBlock Text="SUNLIGHT 838 b0.0.1 (master 2025/03/18)" HorizontalAlignment="Right" VerticalAlignment="Bottom" Height="30" Width="600" Margin="0,0,10,160" FontSize="22"/>
|
||||
<TextBlock x:Name="SocketIP" HorizontalAlignment="Right" VerticalAlignment="Bottom" Height="30" Width="600" Margin="0,0,10,130" FontSize="22"/>
|
||||
|
||||
<Button Content="{x:Static lang:Resources.Shutdown}" x:Name="Shutdown" FontSize="20" HorizontalAlignment="Right" Height="40" Margin="0,0,20,20"
|
||||
VerticalAlignment="Bottom" Width="200" Background="White" Click="Shutdown_Click"/>
|
||||
|
||||
@@ -3,6 +3,8 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Net.Sockets;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
@@ -40,10 +42,33 @@ namespace DyeingComputer.View
|
||||
string[] Language = { "en-US", "zh-CN", "zh -TW" };
|
||||
comboBoxLanguage.ItemsSource = Language;
|
||||
comboBoxLanguage.Text = Configini.IniReadvalue("SYS", "Language");
|
||||
|
||||
SocketIP.Text = "SocketIP:"+ GetLocalIPAddress()+"[7789][7799]";
|
||||
}
|
||||
//调用配置文件
|
||||
private UserClass.IniFile.IniFiles Configini = new UserClass.IniFile.IniFiles(Convert.ToString(System.AppDomain.CurrentDomain.BaseDirectory) + "DyeingComputer.ini");
|
||||
|
||||
public static string GetLocalIPAddress()
|
||||
{
|
||||
// 获取主机名和所有 IP 地址
|
||||
var hostEntry = Dns.GetHostEntry(Dns.GetHostName());
|
||||
|
||||
// 优先尝试获取非内部、非虚拟网卡的 IPv4 地址(如以太网、Wi-Fi)
|
||||
var ipAddress = hostEntry.AddressList
|
||||
.FirstOrDefault(ip => ip.AddressFamily == AddressFamily.InterNetwork
|
||||
&& !IPAddress.IsLoopback(ip)
|
||||
&& ip.ToString().StartsWith("192.168")); // 示例:优先 192.168 网段
|
||||
|
||||
// 如果没找到优先的,则选择第一个非环回的 IPv4 地址
|
||||
if (ipAddress == null)
|
||||
{
|
||||
ipAddress = hostEntry.AddressList
|
||||
.FirstOrDefault(ip => ip.AddressFamily == AddressFamily.InterNetwork
|
||||
&& !IPAddress.IsLoopback(ip));
|
||||
}
|
||||
// 如果还是没找到,返回环回地址或抛出异常
|
||||
return ipAddress?.ToString() ?? "127.0.0.1";
|
||||
}
|
||||
private void comboBoxCOM_SelectionChanged(object sender, SelectionChangedEventArgs e)
|
||||
{
|
||||
Configini.IniWritevalue("SYS", "COM", comboBoxCOM.SelectedValue.ToString());
|
||||
|
||||
Reference in new issue
Block a user