diff --git a/ConvertMoels/StatexmlConvert.cs b/ConvertMoels/StatexmlConvert.cs index 3318486..0c46eaf 100644 --- a/ConvertMoels/StatexmlConvert.cs +++ b/ConvertMoels/StatexmlConvert.cs @@ -29,7 +29,8 @@ namespace SunlightCentralizedControlManagement_SCCM_.ConvertMoels else if (i == "800") Staten = "LinkOff";//未连接 else if (i == "801") Staten = "Link";//连接成功 else if (i == "899") Staten = "LinkOff";//关闭连接 - else if (i == "True") Staten = "Lock";//锁 + else if (i == "True") Staten = "Visible";// + else if (i == "False") Staten = "Collapsed";// return Staten; } diff --git a/ERR/ERR2025-08-28.txt b/ERR/ERR2025-08-28.txt new file mode 100644 index 0000000..c7a25c3 --- /dev/null +++ b/ERR/ERR2025-08-28.txt @@ -0,0 +1,20 @@ +[2025-08-28 17:45:02];[Error] || + +[2025-08-28 17:45:02];[Error source] ||.Net SqlClient Data Provider + +[2025-08-28 17:45:02];[Error message] ||在与 SQL Server 建立连接时出现与网络相关的或特定于实例的错误。未找到或无法访问服务器。请验证实例名称是否正确并且 SQL Server 已配置为允许远程连接。 (provider: Named Pipes Provider, error: 40 - 无法打开到 SQL Server 的连接) + +[2025-08-28 17:45:02];[Error area] || 在 System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, SqlCredential credential, Object providerInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString userConnectionOptions, SessionData reconnectSessionData, DbConnectionPool pool, String accessToken, Boolean applyTransientFaultHandling, SqlAuthenticationProviderManager sqlAuthProviderManager) + 在 System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection, DbConnectionOptions userOptions) + 在 System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnectionPool pool, DbConnection owningObject, DbConnectionOptions options, DbConnectionPoolKey poolKey, DbConnectionOptions userOptions) + 在 System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection) + 在 System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection) + 在 System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, UInt32 waitForMultipleObjectsTimeout, Boolean allowCreate, Boolean onlyOneCheckConnection, DbConnectionOptions userOptions, DbConnectionInternal& connection) + 在 System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal& connection) + 在 System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal oldConnection, DbConnectionInternal& connection) + 在 System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions) + 在 System.Data.ProviderBase.DbConnectionClosed.TryOpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions) + 在 System.Data.SqlClient.SqlConnection.TryOpenInner(TaskCompletionSource`1 retry) + 在 System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource`1 retry) + 在 System.Data.SqlClient.SqlConnection.Open() + 在 SunlightCentralizedControlManagement_SCCM_.ViewModel.ManualDyelotModel..ctor() 位置 C:\Users\Administrator\source\repos\SunlightCentralizedControlManagement(SCCM)\ViewModel\ManualDyelotModel.cs:行号 35 diff --git a/Properties/Resources.Designer.cs b/Properties/Resources.Designer.cs index 689ef94..268e3e6 100644 --- a/Properties/Resources.Designer.cs +++ b/Properties/Resources.Designer.cs @@ -60,6 +60,15 @@ namespace SunlightCentralizedControlManagement_SCCM_.Properties { } } + /// + /// 查找类似 Manual/Automatic 的本地化字符串。 + /// + public static string _Auto { + get { + return ResourceManager.GetString("_Auto", resourceCulture); + } + } + /// /// 查找类似 continue 的本地化字符串。 /// diff --git a/Properties/Resources.en-US.resx b/Properties/Resources.en-US.resx index cdeda62..b771253 100644 --- a/Properties/Resources.en-US.resx +++ b/Properties/Resources.en-US.resx @@ -1077,4 +1077,7 @@ Dispense Exception + + Manual/Automatic + \ No newline at end of file diff --git a/Properties/Resources.resx b/Properties/Resources.resx index 5808cb1..0889381 100644 --- a/Properties/Resources.resx +++ b/Properties/Resources.resx @@ -1077,4 +1077,7 @@ DispenseException + + Manual/Automatic + \ No newline at end of file diff --git a/Properties/Resources.zh-CN.resx b/Properties/Resources.zh-CN.resx index bb8b9f2..ef47a64 100644 --- a/Properties/Resources.zh-CN.resx +++ b/Properties/Resources.zh-CN.resx @@ -1077,4 +1077,7 @@ 输送异常 + + 手/自动 + \ No newline at end of file diff --git a/Properties/Resources.zh-TW.resx b/Properties/Resources.zh-TW.resx index 62621bf..29ed59e 100644 --- a/Properties/Resources.zh-TW.resx +++ b/Properties/Resources.zh-TW.resx @@ -1077,4 +1077,7 @@ 輸送異常 + + + \ No newline at end of file diff --git a/UserClass/AsyncTcpClient.cs b/UserClass/AsyncTcpClient.cs index 0dc1d0a..e62c2ac 100644 --- a/UserClass/AsyncTcpClient.cs +++ b/UserClass/AsyncTcpClient.cs @@ -387,8 +387,12 @@ namespace SunlightCentralizedControlManagement_SCCM_.UserClass .SetMinBufferSize(1024*64) .SetRemoteIPHost(ip + ":" + port) .ConfigurePlugins(a => - { - // a.UseTcpReconnection();//触发型重连 + { + //触发型重连 + // a.UseTcpReconnection(); + //使用Polling轮询连接插件 + a.UseTcpReconnection() + .UsePolling(TimeSpan.FromSeconds(5)); }) .ConfigureContainer(a => { @@ -396,7 +400,7 @@ namespace SunlightCentralizedControlManagement_SCCM_.UserClass })); // Result result = await - _ = tcpClient.TryConnectAsync(); + await tcpClient.TryConnectAsync(); // return result.IsSuccess; /* try { diff --git a/UserControls/info.xaml b/UserControls/info.xaml index 0426d80..462aafe 100644 --- a/UserControls/info.xaml +++ b/UserControls/info.xaml @@ -5,20 +5,25 @@ xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:local="clr-namespace:SunlightCentralizedControlManagement_SCCM_.UserControls" xmlns:lang="clr-namespace:SunlightCentralizedControlManagement_SCCM_.Properties" - mc:Ignorable="d" + xmlns:lvc="clr-namespace:LiveChartsCore.SkiaSharpView.WPF;assembly=LiveChartsCore.SkiaSharpView.WPF" + mc:Ignorable="d" + Loaded="UserControl_Loaded" d:DesignHeight="400" d:DesignWidth="300" Background="White"> - - - - - - - - - - - - - + + + + + + + + + + + + + + + diff --git a/UserControls/info.xaml.cs b/UserControls/info.xaml.cs index 9095011..183d7fe 100644 --- a/UserControls/info.xaml.cs +++ b/UserControls/info.xaml.cs @@ -1,8 +1,18 @@ -using ScottPlot.Plottables; +using LiveChartsCore; +using LiveChartsCore.Defaults; +using LiveChartsCore.Kernel.Sketches; +using LiveChartsCore.SkiaSharpView; +using LiveChartsCore.SkiaSharpView.Painting; +using Newtonsoft.Json.Linq; +using ScottPlot.Plottables; +using SkiaSharp; +using SunlightCentralizedControlManagement_SCCM_.ViewModel; using System; using System.Collections.Generic; +using System.Collections.ObjectModel; using System.ComponentModel; using System.Linq; +using System.Runtime.Serialization; using System.Text; using System.Threading.Tasks; using System.Windows; @@ -28,10 +38,75 @@ namespace SunlightCentralizedControlManagement_SCCM_.UserControls public info() { InitializeComponent(); - + DataContext = this; //new infoModel(); } - + public void DataAdd() + { + } + private readonly Random _random = new Random(); + private readonly List _values = new List(); + private readonly DateTimeAxis _customAxis; + public ObservableCollection Series { get; set; } + public static ObservableCollection ObservableValues { get; set; } + + //x轴时间格式 + public Axis[] XAxes { get; set; } = + { + new DateTimeAxis(TimeSpan.FromSeconds(5) , date => date.ToString("HH:mm")) + { + MinLimit = DateTime.Now.AddHours(-6).Ticks, + MaxLimit = DateTime.Now.AddHours(0.5).Ticks, + CrosshairLabelsBackground = SKColors.DarkGray.AsLvcColor(), + CrosshairLabelsPaint = new SolidColorPaint(SKColors.DarkSlateBlue, 1), + CrosshairPaint = new SolidColorPaint(SKColors.DarkSlateGray, 1), + }, + }; + //颜色 + private static readonly SKColor s_blue = new SKColor(25, 118, 210); + private static readonly SKColor s_red = new SKColor(229, 57, 53); + public ICartesianAxis[] YAxes { get; set; } ={ + new Axis //y在此轴上缩放 + { + MinLimit =0, + MaxLimit =160, + NamePadding = new LiveChartsCore.Drawing.Padding(0, 20), + Padding = new LiveChartsCore.Drawing.Padding(0, 0, 20, 0), + TextSize = 12, + LabelsPaint = new SolidColorPaint(s_blue), + TicksPaint = new SolidColorPaint(s_blue), + SubticksPaint = new SolidColorPaint(s_blue), + DrawTicksPath = true, + CrosshairSnapEnabled = true, + Position = LiveChartsCore.Measure.AxisPosition.Start + },//温度轴 + + }; + + private static ObservableCollection MTH_values; + private void UserControl_Loaded(object sender, RoutedEventArgs e) + { + var MTH_items = new List(); + MTH_values = new ObservableCollection(MTH_items); + + Series = new ObservableCollection + { + new LineSeries + { + Name = Properties.Resources.Temperature, + Values = MTH_values, + Stroke = new SolidColorPaint(s_red, 2), + GeometrySize = 0, + GeometryStroke = new SolidColorPaint(s_red, 2), + Fill = null, + LineSmoothness = 0, + ScalesYAt = 2, + } + }; + + + + } } } diff --git a/View/MonitorView.xaml b/View/MonitorView.xaml index b2da9fb..0065645 100644 --- a/View/MonitorView.xaml +++ b/View/MonitorView.xaml @@ -19,6 +19,7 @@ + @@ -112,9 +113,12 @@ - + diff --git a/View/MonitorView.xaml.cs b/View/MonitorView.xaml.cs index b144c29..0e845ef 100644 --- a/View/MonitorView.xaml.cs +++ b/View/MonitorView.xaml.cs @@ -227,19 +227,21 @@ namespace SunlightCentralizedControlManagement_SCCM_.View }//单据 private void MenuItem_LOCK_XML(object sender, RoutedEventArgs e) { - string mode = MainWindowViewModel.Machines.Select("NAME='" + machine + "'").First().Field("LOCK"); + bool mode = MainWindowViewModel.Machines.Select("NAME='" + machine + "'").First().Field("LOCK"); - Dictionary dat_821 = new Dictionary(); - dat_821.Clear(); + Dictionary dat_ = new Dictionary(); + dat_.Clear(); - if (mode != "True") + if (!mode) { - dat_821.Add("LOCK", "True"); - MainWindowViewModel.Updata_Machines(MainWindowViewModel.Machines, "LOCK", "Name='" + machine + "'", "True"); - } + dat_.Add("NAME", "LOCK"); + dat_.Add("VALUE", "True"); + MainWindowViewModel.Updata_Machines(MainWindowViewModel.Machines, "LOCK", "Name='" + machine + "'", "True"); + } else { - dat_821.Add("LOCK", "FALSE"); + dat_.Add("NAME", "LOCK"); + dat_.Add("VALUE", "False"); MainWindowViewModel.Updata_Machines(MainWindowViewModel.Machines, "LOCK", "Name='" + machine + "'", "False"); } @@ -248,14 +250,43 @@ namespace SunlightCentralizedControlManagement_SCCM_.View MainWindowViewModel.stringQueue.Enqueue(new MainWindowViewModel.QueueString { ID = index, - DAT = "SC829" + MainWindowViewModel.Selet_Machines(MainWindowViewModel.Machines, "SYSKEY", "ID='" + index + "'") + dat_821.ToJsonString() + DAT = "SC829" + MainWindowViewModel.Selet_Machines(MainWindowViewModel.Machines, "SYSKEY", "ID='" + index + "'") + dat_.ToJsonString() }); - if (mode != "True") { MessageBox.Show(machine + Properties.Resources.user_lock, "800", MessageBoxButton.OK, MessageBoxImage.Information); + if (!mode) { MessageBox.Show(machine + Properties.Resources.user_lock, "800", MessageBoxButton.OK, MessageBoxImage.Information); } else { MessageBox.Show(machine + Properties.Resources.user_unlock, "800", MessageBoxButton.OK, MessageBoxImage.Information); } }//锁定 + private void MenuItem_AUTO_XML(object sender, RoutedEventArgs e) + { + bool mode = MainWindowViewModel.Machines.Select("NAME='" + machine + "'").First().Field("AUTO"); + + Dictionary dat_ = new Dictionary(); + dat_.Clear(); + + if (!mode) + { + dat_.Add("NAME", "AUTO"); + dat_.Add("VALUE", "True"); + MainWindowViewModel.Updata_Machines(MainWindowViewModel.Machines, "AUTO", "Name='" + machine + "'", "True"); + } + else + { + dat_.Add("NAME", "AUTO"); + dat_.Add("VALUE", "FALSE"); + MainWindowViewModel.Updata_Machines(MainWindowViewModel.Machines, "AUTO", "Name='" + machine + "'", "False"); + } + + DataRow drEmployee = MainWindowViewModel.Machines.Select("NAME='" + machine + "'").First(); + int index = Convert.ToInt16(drEmployee.Field("ID")); + MainWindowViewModel.stringQueue.Enqueue(new MainWindowViewModel.QueueString + { + ID = index, + DAT = "SC829" + MainWindowViewModel.Selet_Machines(MainWindowViewModel.Machines, "SYSKEY", "ID='" + index + "'") + dat_.ToJsonString() + }); + + }//手自动 private void ListViewItem_Curve(object sender, MouseButtonEventArgs e) { log.Visibility = Visibility.Collapsed; @@ -658,7 +689,8 @@ namespace SunlightCentralizedControlManagement_SCCM_.View public string Step { get; set; } public string Message { get; set; } public string State { get; set; } - public string LOCK { get; set; } + public bool LOCK { get; set; } + public bool AUTO { get; set; } } public class TechnologicalP diff --git a/View/Whole.xaml.cs b/View/Whole.xaml.cs index 01a45c1..a0eafa8 100644 --- a/View/Whole.xaml.cs +++ b/View/Whole.xaml.cs @@ -105,10 +105,9 @@ namespace SunlightCentralizedControlManagement_SCCM_.View else if (State_ == "201") { inf[i].name.Background = new SolidColorBrush(Color.FromRgb(0, 255, 0)); } else if (State_ == "202") - { inf[i].name.Background = new SolidColorBrush(Color.FromRgb(255, 255, 0)); } + { inf[i].name.Background = new SolidColorBrush(Color.FromRgb(0, 255, 0)); } else { inf[i].name.Background = new SolidColorBrush(Color.FromRgb(255, 0, 0)); } - inf[i].temp.Text = Selet_Machines(MainWindowViewModel.Machines, "Temperature", i).ToString() + "°C"; inf[i].Process.Text = (string)Selet_Machines(MainWindowViewModel.Machines, "Process", i); inf[i].Step.Text = (string)Selet_Machines(MainWindowViewModel.Machines, "Step", i); diff --git a/ViewModel/MainWindowViewModel.cs b/ViewModel/MainWindowViewModel.cs index b8180e2..b1b31d8 100644 --- a/ViewModel/MainWindowViewModel.cs +++ b/ViewModel/MainWindowViewModel.cs @@ -258,18 +258,18 @@ namespace SunlightCentralizedControlManagement_SCCM_.ViewModel DAT = "SC830" + Selet_Machines(Machines, "SYSKEY", "ID='" + i + "'").ToString() });//信息插入队列 - string mode = Machines.Select("ID='" + i + "'").First().Field("LOCK");//发送锁定状态 - if (mode == "True") + bool mode = Machines.Select("ID='" + i + "'").First().Field("LOCK");//发送锁定状态 + if (mode) { - Dictionary dat_821 = new Dictionary(); - dat_821.Clear(); - dat_821.Add("LOCK", "True"); + Dictionary dat_829 = new Dictionary(); + dat_829.Clear(); + dat_829.Add("LOCK", "True"); DataRow drEmployee = Machines.Select("ID='" + i + "'").First(); int index = Convert.ToInt16(drEmployee.Field("ID")); stringQueue.Enqueue(new QueueString { ID = index, - DAT = "SC829" + Selet_Machines(Machines, "SYSKEY", "ID='" + index + "'") + dat_821.ToJsonString() + DAT = "SC829" + Selet_Machines(Machines, "SYSKEY", "ID='" + index + "'") + dat_829.ToJsonString() }); } @@ -315,7 +315,7 @@ namespace SunlightCentralizedControlManagement_SCCM_.ViewModel else { Time5++; } if (Time60 > 60) { - Tick_Event_60S(); + // Tick_Event_60S(); Time60 = 0; } else { Time60++; } @@ -607,7 +607,7 @@ namespace SunlightCentralizedControlManagement_SCCM_.ViewModel } } - void Tick_Event_60S() + async void Tick_Event_60S() { for (int i = 0; i < Machinesdata_Count; i++) { @@ -615,7 +615,7 @@ namespace SunlightCentralizedControlManagement_SCCM_.ViewModel { MachiensTcpClient[i] = new TcpClient(); DataRow dt = machinesdata[i]; - _ = AsyncTcpClient.TcpClient(MachiensTcpClient[i] //建立tcp连接 + await AsyncTcpClient.TcpClient(MachiensTcpClient[i] //建立tcp连接 , Selet_Machines(Machines, "IP", "ID='" + Convert.ToInt16(dt["ID"]) + "'" ).ToString() , Selet_Machines(Machines, "PORT", "ID='" + Convert.ToInt16(dt["ID"]) + "'").ToString()); } @@ -631,19 +631,23 @@ namespace SunlightCentralizedControlManagement_SCCM_.ViewModel machinesdata = Machines.Select("PORT>0 AND IP<>''", "id asc");//获取连接有效的组 Machinesdata_Count = machinesdata.Count(); - for (int i = 0; i < Machinesdata_Count; i++) + foreach (DataRow dataRow in Machines.Rows) { - MachiensTcpClient[i] = new TcpClient(); - DataRow dt = machinesdata[i]; - Updata_Machines(Machines, "State", "ID='" + Convert.ToInt16(dt["ID"]) + "'", "800"); - Updata_Machines(Machines, "Temperature", "ID='" + Convert.ToInt16(dt["ID"]) + "'", "0.0"); - Updata_Machines(Machines, "WaterLevel", "ID='" + Convert.ToInt16(dt["ID"]) + "'", "0"); - Updata_Machines(Machines, "WORK_RUN", "ID='" + Convert.ToInt16(dt["ID"]) + "'", "-1"); - Updata_Machines(Machines, "ERR", "ID='" + Convert.ToInt16(dt["ID"]) + "'", "False"); - Updata_Machines(Machines, "UserInfoStart", "ID='" + Convert.ToInt16(dt["ID"]) + "'", "900"); - _ = AsyncTcpClient.TcpClient(MachiensTcpClient[i] //建立tcp连接 - , Selet_Machines(Machines, "IP", "ID='" + Convert.ToInt16(dt["ID"]) + "'").ToString() - , Selet_Machines(Machines, "PORT", "ID='" + Convert.ToInt16(dt["ID"]) + "'").ToString()); + dataRow.BeginEdit(); + dataRow["State"] = 800; + dataRow["Temperature"] = 0; + dataRow["WaterLevel"] = 0; + dataRow["WORK_RUN"] = -1; + dataRow["ERR"] = false; + dataRow["LOCK"] = false; + dataRow["AUTO"] = false; + dataRow["UserInfoStart"] = 900; + dataRow.EndEdit(); + dataRow.AcceptChanges(); + + MachiensTcpClient[Convert.ToInt16(dataRow["ID"])]= new TcpClient(); + _ = AsyncTcpClient.TcpClient(MachiensTcpClient[Convert.ToInt16(dataRow["ID"])] //建立tcp连接 + , dataRow["IP"].ToString(), dataRow["PORT"].ToString()); } }