diff --git a/App.xaml.cs b/App.xaml.cs index 11c0fce..1f92128 100644 --- a/App.xaml.cs +++ b/App.xaml.cs @@ -4,8 +4,10 @@ using System.Collections.Generic; using System.ComponentModel; using System.Configuration; using System.Data; +using System.Globalization; using System.IO; using System.Linq; +using System.Reflection; using System.Runtime.InteropServices; using System.Threading; using System.Threading.Tasks; @@ -18,6 +20,43 @@ namespace DyeingComputer /// public partial class App : Application { + private static Assembly OnResolveAssembly(object sender, ResolveEventArgs args) + { + Assembly executingAssembly = Assembly.GetExecutingAssembly(); + var executingAssemblyName = executingAssembly.GetName(); + var resName = executingAssemblyName.Name + ".resources"; + + AssemblyName assemblyName = new AssemblyName(args.Name); string path = ""; + if (resName == assemblyName.Name) + { + path = executingAssemblyName.Name + ".g.resources"; ; + } + else + { + path = assemblyName.Name + ".dll"; + if (assemblyName.CultureInfo.Equals(CultureInfo.InvariantCulture) == false) + { + path = String.Format(@"{0}\{1}", assemblyName.CultureInfo, path); + } + } + + using (Stream stream = executingAssembly.GetManifestResourceStream(path)) + { + if (stream == null) + return null; + + byte[] assemblyRawBytes = new byte[stream.Length]; + stream.Read(assemblyRawBytes, 0, assemblyRawBytes.Length); + return Assembly.Load(assemblyRawBytes); + } + } + protected override void OnStartup(StartupEventArgs e) + { + base.OnStartup(e); + AppDomain.CurrentDomain.AssemblyResolve += OnResolveAssembly; + this.DispatcherUnhandledException += App_DispatcherUnhandledException; + } + private UserClass.IniFile.IniFiles Configini = new UserClass.IniFile.IniFiles(Convert.ToString(System.AppDomain.CurrentDomain.BaseDirectory) + "DyeingComputer.ini"); public App() @@ -46,12 +85,12 @@ namespace DyeingComputer //return Container.Resolve(); } - protected override void OnStartup(StartupEventArgs e) //跟踪报错信息 - { - base.OnStartup(e); - //UI线程的异常捕捉 - this.DispatcherUnhandledException += App_DispatcherUnhandledException; - } + // protected override void OnStartup(StartupEventArgs e) //跟踪报错信息 + // { + // base.OnStartup(e); + // //UI线程的异常捕捉 + // this.DispatcherUnhandledException += App_DispatcherUnhandledException; + // } private void App_DispatcherUnhandledException(object sender, System.Windows.Threading.DispatcherUnhandledExceptionEventArgs e) { diff --git a/DyeingComputer.csproj b/DyeingComputer.csproj index 3dc9925..595e462 100644 --- a/DyeingComputer.csproj +++ b/DyeingComputer.csproj @@ -61,6 +61,25 @@ LOGO\sunlight_logo.ico + + true + bin\x64\Debug\ + DEBUG;TRACE + full + x64 + 7.3 + prompt + + + bin\x64\Release\ + TRACE + true + pdbonly + x64 + 7.3 + prompt + true + @@ -387,4 +406,11 @@ + + + + %(ReferenceCopyLocalPaths.DestinationSubDirectory)%(ReferenceCopyLocalPaths.Filename)%(ReferenceCopyLocalPaths.Extension) + + + \ No newline at end of file diff --git a/View/CurveDiagramView.xaml b/View/CurveDiagramView.xaml index 2afbcfd..e0ed3af 100644 --- a/View/CurveDiagramView.xaml +++ b/View/CurveDiagramView.xaml @@ -6,5 +6,7 @@ xmlns:local="clr-namespace:DyeingComputer.View" mc:Ignorable="d" d:DesignHeight="630" d:DesignWidth="1280" VerticalAlignment="Top"> - + + + diff --git a/View/HistoryRecordsView.xaml b/View/HistoryRecordsView.xaml index 0fa74ba..160e2c8 100644 --- a/View/HistoryRecordsView.xaml +++ b/View/HistoryRecordsView.xaml @@ -6,5 +6,8 @@ xmlns:local="clr-namespace:DyeingComputer.View" mc:Ignorable="d" d:DesignHeight="630" d:DesignWidth="1280" VerticalAlignment="Top"> - + + + + diff --git a/ViewModel/MainWindowViewModel.cs b/ViewModel/MainWindowViewModel.cs index 467a443..db84631 100644 --- a/ViewModel/MainWindowViewModel.cs +++ b/ViewModel/MainWindowViewModel.cs @@ -233,8 +233,7 @@ namespace DyeingComputer.ViewModel if (!string.IsNullOrEmpty(Name_err.ToString())) Status_Str = Name_err.ToString(); } void Tick_Event_5S(object sender, EventArgs e)//Tick_Event周期执行事件5S - { - Name_err = ""; + { if (!LINK_OK) Modbus_link(); if (string.IsNullOrEmpty(Name_err.ToString()) && ((Selet_dtm("1010") < 10) || (Selet_dtm("1010") > 160))) @@ -988,6 +987,7 @@ namespace DyeingComputer.ViewModel { LogGing.LogGingDATA("800_SerialPort_Not"); LogGing.LogGingDATA(e.Message); + Name_err = "800_SerialPort_Not"; } } @@ -1007,24 +1007,29 @@ namespace DyeingComputer.ViewModel readonly byte slaveId = 1; private async void Modbus_link() { - await Task.Run(() => + if (Name_err.ToString() != "800_SerialPort_Not") { - LINK_RUN++; - try + await Task.Run(() => { - master.WriteMultipleCoils(slaveId, 00000, DQ); //写入线圈 - master.WriteMultipleRegisters(slaveId, 07000, DW); //写入寄存器 - DO = master.ReadCoils(slaveId, 01000, DO_L); //读取线圈 - RW = master.ReadHoldingRegisters(slaveId, 06000, RW_L); //读取寄存器 - LINK_OK = true; - } - catch (Exception ex) - { - LINK_OK = false; - LINK_ERR++; - Name_err = "PLC" + Properties.Resources.Connectionlost + "(" + ex.Message + ")"; - } - }); + LINK_RUN++; + try + { + master.WriteMultipleCoils(slaveId, 00000, DQ); //写入线圈 + master.WriteMultipleRegisters(slaveId, 07000, DW); //写入寄存器 + DO = master.ReadCoils(slaveId, 01000, DO_L); //读取线圈 + RW = master.ReadHoldingRegisters(slaveId, 06000, RW_L); //读取寄存器 + LINK_OK = true; + Name_err = ""; + } + catch (Exception ex) + { + LINK_OK = false; + LINK_ERR++; + Name_err = "PLC" + Properties.Resources.Connectionlost + "(" + ex.Message + ")"; + } + + }); + } } void LOG_view()//细节页面 {