通讯循环逻辑修改
This commit is contained in:
commit
6c6fa42544
3 files changed
+44
-10
No files matched your search
@@ -53,6 +53,7 @@
|
|||||||
</DataGrid.Columns>
|
</DataGrid.Columns>
|
||||||
</DataGrid>
|
</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 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"
|
<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"/>
|
VerticalAlignment="Bottom" Width="200" Background="White" Click="Shutdown_Click"/>
|
||||||
|
|||||||
@@ -3,6 +3,8 @@ using System;
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Net;
|
||||||
|
using System.Net.Sockets;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using System.Windows;
|
using System.Windows;
|
||||||
@@ -40,10 +42,33 @@ namespace DyeingComputer.View
|
|||||||
string[] Language = { "en-US", "zh-CN", "zh -TW" };
|
string[] Language = { "en-US", "zh-CN", "zh -TW" };
|
||||||
comboBoxLanguage.ItemsSource = Language;
|
comboBoxLanguage.ItemsSource = Language;
|
||||||
comboBoxLanguage.Text = Configini.IniReadvalue("SYS", "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");
|
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)
|
private void comboBoxCOM_SelectionChanged(object sender, SelectionChangedEventArgs e)
|
||||||
{
|
{
|
||||||
Configini.IniWritevalue("SYS", "COM", comboBoxCOM.SelectedValue.ToString());
|
Configini.IniWritevalue("SYS", "COM", comboBoxCOM.SelectedValue.ToString());
|
||||||
|
|||||||
@@ -2474,7 +2474,7 @@ namespace DyeingComputer.ViewModel
|
|||||||
else if (WORK_RUN == 1)
|
else if (WORK_RUN == 1)
|
||||||
{
|
{
|
||||||
Status_Str = Resources.Paused;
|
Status_Str = Resources.Paused;
|
||||||
for (int i = 4; i < 128; i++)
|
for (int i = 4; i < DQ_DL; i++)
|
||||||
{
|
{
|
||||||
Updata_dtd((3000 + i).ToString(), false);
|
Updata_dtd((3000 + i).ToString(), false);
|
||||||
}
|
}
|
||||||
@@ -2485,7 +2485,7 @@ namespace DyeingComputer.ViewModel
|
|||||||
// {
|
// {
|
||||||
Updata_dtm("1004", 0);
|
Updata_dtm("1004", 0);
|
||||||
Updata_dtm("1005", Selet_dtm("1010"));
|
Updata_dtm("1005", Selet_dtm("1010"));
|
||||||
for (int i = 1; i <128; i++)
|
for (int i = 1; i < DQ_DL; i++)
|
||||||
{
|
{
|
||||||
Updata_dtd((3000+i).ToString(), false);
|
Updata_dtd((3000+i).ToString(), false);
|
||||||
}
|
}
|
||||||
@@ -3376,10 +3376,10 @@ namespace DyeingComputer.ViewModel
|
|||||||
private bool LINK_OK = false;
|
private bool LINK_OK = false;
|
||||||
private int LINK_RUN = 0;
|
private int LINK_RUN = 0;
|
||||||
private int LINK_ERR = 0;
|
private int LINK_ERR = 0;
|
||||||
bool[] DQ = new bool[63];
|
bool[] DQ = new bool[127];
|
||||||
ushort DQ_L = 63;
|
ushort DQ_L = 127;
|
||||||
bool[] DO = new bool[63];
|
bool[] DO = new bool[127];
|
||||||
ushort DO_L = 63;
|
ushort DO_L = 127;
|
||||||
//int[] MW = new int[128];
|
//int[] MW = new int[128];
|
||||||
// ushort MW_L = 128;
|
// ushort MW_L = 128;
|
||||||
ushort[] DW = new ushort[63];
|
ushort[] DW = new ushort[63];
|
||||||
@@ -3577,6 +3577,10 @@ namespace DyeingComputer.ViewModel
|
|||||||
public static object D_view = true;
|
public static object D_view = true;
|
||||||
public static object A_view = true;
|
public static object A_view = true;
|
||||||
public static bool User_Button = false;
|
public static bool User_Button = false;
|
||||||
|
public static int DO_DL = 0;
|
||||||
|
public static int DQ_DL = 0;
|
||||||
|
public static int AI_DL = 0;
|
||||||
|
public static int AO_DL = 0;
|
||||||
public static void SQL_data()//获得io表
|
public static void SQL_data()//获得io表
|
||||||
{
|
{
|
||||||
//SQLiteHelpers = new SQLiteHelper(DBAddress); //数据库连接路径
|
//SQLiteHelpers = new SQLiteHelper(DBAddress); //数据库连接路径
|
||||||
@@ -3588,6 +3592,10 @@ namespace DyeingComputer.ViewModel
|
|||||||
dt_SysSet = MainWindow.SQLiteHelpers.ExecuteDataSet("select * from System order by ParameterID asc", null).Tables[0];
|
dt_SysSet = MainWindow.SQLiteHelpers.ExecuteDataSet("select * from System order by ParameterID asc", null).Tables[0];
|
||||||
dt_TP = MainWindow.SQLiteHelpers.ExecuteDataSet("select * from RUN", null).Tables[0];
|
dt_TP = MainWindow.SQLiteHelpers.ExecuteDataSet("select * from RUN", null).Tables[0];
|
||||||
//SQLiteHelpers.Close();
|
//SQLiteHelpers.Close();
|
||||||
|
DO_DL = dt_d.Select("type='DO'").Count();
|
||||||
|
DQ_DL = dt_d.Select("type='DQ'").Count();
|
||||||
|
AI_DL = dt_a.Select("type='AI'").Count();
|
||||||
|
AO_DL = dt_a.Select("type='AO'").Count();
|
||||||
|
|
||||||
dt_d.RowChanged += new DataRowChangeEventHandler(ROW_changed_D);//添加行改变触发事件
|
dt_d.RowChanged += new DataRowChangeEventHandler(ROW_changed_D);//添加行改变触发事件
|
||||||
dt_a.RowChanged += new DataRowChangeEventHandler(ROW_changed_A);
|
dt_a.RowChanged += new DataRowChangeEventHandler(ROW_changed_A);
|
||||||
@@ -3644,10 +3652,10 @@ namespace DyeingComputer.ViewModel
|
|||||||
{
|
{
|
||||||
await Task.Run(() =>
|
await Task.Run(() =>
|
||||||
{
|
{
|
||||||
for (ushort i = 0; i < DO_L; i++) { Upplc_dtd((i + 2001).ToString(), DO[i]); }
|
for (ushort i = 0; i < DO_DL-1; i++) { Upplc_dtd((i + 2001).ToString(), DO[i]); }
|
||||||
for (ushort i = 0; i < DQ_L; i++) { DQ[i] = Seplc_dtd((i + 3001).ToString()); }
|
for (ushort i = 0; i < DQ_DL-1; i++) { DQ[i] = Seplc_dtd((i + 3001).ToString()); }
|
||||||
for (ushort i = 0; i < RW_L; i++) { Upplc_dta((i + 4001).ToString(), RW[i]); }
|
for (ushort i = 0; i < AI_DL-1; i++) { Upplc_dta((i + 4001).ToString(), RW[i]); }
|
||||||
for (ushort i = 0; i < DW_L; i++) { DW[i] = Convert.ToUInt16(Seplc_dta((i + 5001).ToString())); }
|
for (ushort i = 0; i < AO_DL-1; i++) { DW[i] =Convert.ToUInt16( Seplc_dta((i + 5001).ToString())); }
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
public void IO_view()//IO显示
|
public void IO_view()//IO显示
|
||||||
|
|||||||
Reference in new issue
Block a user