sc 1 year ago
parent
commit
9ddcbb99fa
  1. 51
      App.xaml.cs
  2. 26
      DyeingComputer.csproj
  3. 4
      View/CurveDiagramView.xaml
  4. 5
      View/HistoryRecordsView.xaml
  5. 7
      ViewModel/MainWindowViewModel.cs

51
App.xaml.cs

@ -4,8 +4,10 @@ using System.Collections.Generic;
using System.ComponentModel; using System.ComponentModel;
using System.Configuration; using System.Configuration;
using System.Data; using System.Data;
using System.Globalization;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Reflection;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
@ -18,6 +20,43 @@ namespace DyeingComputer
/// </summary> /// </summary>
public partial class App : Application 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"); private UserClass.IniFile.IniFiles Configini = new UserClass.IniFile.IniFiles(Convert.ToString(System.AppDomain.CurrentDomain.BaseDirectory) + "DyeingComputer.ini");
public App() public App()
@ -46,12 +85,12 @@ namespace DyeingComputer
//return Container.Resolve<MainWindow>(); //return Container.Resolve<MainWindow>();
} }
protected override void OnStartup(StartupEventArgs e) //跟踪报错信息 // protected override void OnStartup(StartupEventArgs e) //跟踪报错信息
{ // {
base.OnStartup(e); // base.OnStartup(e);
//UI线程的异常捕捉 // //UI线程的异常捕捉
this.DispatcherUnhandledException += App_DispatcherUnhandledException; // this.DispatcherUnhandledException += App_DispatcherUnhandledException;
} // }
private void App_DispatcherUnhandledException(object sender, System.Windows.Threading.DispatcherUnhandledExceptionEventArgs e) private void App_DispatcherUnhandledException(object sender, System.Windows.Threading.DispatcherUnhandledExceptionEventArgs e)
{ {

26
DyeingComputer.csproj

@ -61,6 +61,25 @@
<PropertyGroup> <PropertyGroup>
<ApplicationIcon>LOGO\sunlight_logo.ico</ApplicationIcon> <ApplicationIcon>LOGO\sunlight_logo.ico</ApplicationIcon>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'">
<DebugSymbols>true</DebugSymbols>
<OutputPath>bin\x64\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<DebugType>full</DebugType>
<PlatformTarget>x64</PlatformTarget>
<LangVersion>7.3</LangVersion>
<ErrorReport>prompt</ErrorReport>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'">
<OutputPath>bin\x64\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<Optimize>true</Optimize>
<DebugType>pdbonly</DebugType>
<PlatformTarget>x64</PlatformTarget>
<LangVersion>7.3</LangVersion>
<ErrorReport>prompt</ErrorReport>
<Prefer32Bit>true</Prefer32Bit>
</PropertyGroup>
<ItemGroup> <ItemGroup>
<Reference Include="System" /> <Reference Include="System" />
<Reference Include="System.ComponentModel.DataAnnotations" /> <Reference Include="System.ComponentModel.DataAnnotations" />
@ -387,4 +406,11 @@
</BootstrapperPackage> </BootstrapperPackage>
</ItemGroup> </ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Target Name="AfterResolveReferences">
<ItemGroup>
<EmbeddedResource Include="@(ReferenceCopyLocalPaths)" Condition="'%(ReferenceCopyLocalPaths.Extension)' == '.dll'">
<LogicalName>%(ReferenceCopyLocalPaths.DestinationSubDirectory)%(ReferenceCopyLocalPaths.Filename)%(ReferenceCopyLocalPaths.Extension)</LogicalName>
</EmbeddedResource>
</ItemGroup>
</Target>
</Project> </Project>

4
View/CurveDiagramView.xaml

@ -6,5 +6,7 @@
xmlns:local="clr-namespace:DyeingComputer.View" xmlns:local="clr-namespace:DyeingComputer.View"
mc:Ignorable="d" mc:Ignorable="d"
d:DesignHeight="630" d:DesignWidth="1280" VerticalAlignment="Top"> d:DesignHeight="630" d:DesignWidth="1280" VerticalAlignment="Top">
<Grid/> <Grid>
<DataGrid HorizontalAlignment="Left" Height="152" Margin="69,315,0,0" VerticalAlignment="Top" Width="282" d:ItemsSource="{d:SampleData ItemCount=5}"/>
</Grid>
</UserControl> </UserControl>

5
View/HistoryRecordsView.xaml

@ -6,5 +6,8 @@
xmlns:local="clr-namespace:DyeingComputer.View" xmlns:local="clr-namespace:DyeingComputer.View"
mc:Ignorable="d" mc:Ignorable="d"
d:DesignHeight="630" d:DesignWidth="1280" VerticalAlignment="Top"> d:DesignHeight="630" d:DesignWidth="1280" VerticalAlignment="Top">
<Grid/> <Grid>
<DataGrid HorizontalAlignment="Left" Height="264" Margin="783,195,0,0" VerticalAlignment="Top" Width="394" d:ItemsSource="{d:SampleData ItemCount=5}"/>
</Grid>
</UserControl> </UserControl>

7
ViewModel/MainWindowViewModel.cs

@ -234,7 +234,6 @@ namespace DyeingComputer.ViewModel
} }
void Tick_Event_5S(object sender, EventArgs e)//Tick_Event周期执行事件5S void Tick_Event_5S(object sender, EventArgs e)//Tick_Event周期执行事件5S
{ {
Name_err = "";
if (!LINK_OK) Modbus_link(); if (!LINK_OK) Modbus_link();
if (string.IsNullOrEmpty(Name_err.ToString()) && ((Selet_dtm("1010") < 10) || (Selet_dtm("1010") > 160))) 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("800_SerialPort_Not");
LogGing.LogGingDATA(e.Message); LogGing.LogGingDATA(e.Message);
Name_err = "800_SerialPort_Not";
} }
} }
@ -1006,6 +1006,8 @@ namespace DyeingComputer.ViewModel
ushort RW_L = 63; ushort RW_L = 63;
readonly byte slaveId = 1; readonly byte slaveId = 1;
private async void Modbus_link() private async void Modbus_link()
{
if (Name_err.ToString() != "800_SerialPort_Not")
{ {
await Task.Run(() => await Task.Run(() =>
{ {
@ -1017,6 +1019,7 @@ namespace DyeingComputer.ViewModel
DO = master.ReadCoils(slaveId, 01000, DO_L); //读取线圈 DO = master.ReadCoils(slaveId, 01000, DO_L); //读取线圈
RW = master.ReadHoldingRegisters(slaveId, 06000, RW_L); //读取寄存器 RW = master.ReadHoldingRegisters(slaveId, 06000, RW_L); //读取寄存器
LINK_OK = true; LINK_OK = true;
Name_err = "";
} }
catch (Exception ex) catch (Exception ex)
{ {
@ -1024,8 +1027,10 @@ namespace DyeingComputer.ViewModel
LINK_ERR++; LINK_ERR++;
Name_err = "PLC" + Properties.Resources.Connectionlost + "(" + ex.Message + ")"; Name_err = "PLC" + Properties.Resources.Connectionlost + "(" + ex.Message + ")";
} }
}); });
} }
}
void LOG_view()//细节页面 void LOG_view()//细节页面
{ {
Sys_log = Resources.Target + Resources.Temperature + " : " + string.Format(" {0:###.#}", TEMP_tar) + "°C";//显示目标温度 Sys_log = Resources.Target + Resources.Temperature + " : " + string.Format(" {0:###.#}", TEMP_tar) + "°C";//显示目标温度

Loading…
Cancel
Save