关闭程序关闭灯条

This commit is contained in:
2026-05-13 16:03:35 +08:00
parent b4e45a519b
commit b6c8582678
6 changed files with 26 additions and 6 deletions

View File

@@ -2,7 +2,7 @@
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:头罩视野" xmlns:local="clr-namespace:头罩视野"
StartupUri="MainWindow.xaml"> StartupUri="MainWindow.xaml" Exit="MainForm_FormClosing">
<Application.Resources> <Application.Resources>
<ResourceDictionary> <ResourceDictionary>
<ResourceDictionary.MergedDictionaries> <ResourceDictionary.MergedDictionaries>

View File

@@ -1,14 +1,27 @@
using System.Configuration; using Modbus.Device;
using System.Configuration;
using System.Data; using System.Data;
using System.Windows; using System.Windows;
using .Services.Data;
namespace namespace
{ {
/// <summary> /// <summary>
/// Interaction logic for App.xaml /// Interaction logic for App.xaml
/// </summary> /// </summary>
public partial class App : Application public partial class App : Application
{ {
private IModbusMaster _modbusMaster => ModbusResourceManager.Instance.ModbusMaster;
private void MainForm_FormClosing(object sender, ExitEventArgs e)
{
_modbusMaster.WriteSingleCoil(1, 1, false);
_modbusMaster.WriteSingleCoil(1, 0, false);
// 最后退出程序
System.Windows.Application.Current.Shutdown();
}
} }
} }

View File

@@ -7,7 +7,7 @@
xmlns:local="clr-namespace:头罩视野" xmlns:local="clr-namespace:头罩视野"
mc:Ignorable="d" mc:Ignorable="d"
Background="#FFE6F2FF" Background="#FFE6F2FF"
Title="MainWindow" Height="768" Width="1024"> Title="MainWindow" Height="768" Width="1024" >
<Window.Resources> <Window.Resources>
<Style x:Key="TabButtonStyle" TargetType="Button"> <Style x:Key="TabButtonStyle" TargetType="Button">
<Setter Property="Background" Value="#3498DB"/> <Setter Property="Background" Value="#3498DB"/>

View File

@@ -6,6 +6,7 @@ using System.Windows;
using System.Windows.Controls; using System.Windows.Controls;
using System.Windows.Data; using System.Windows.Data;
using System.Windows.Documents; using System.Windows.Documents;
using System.Windows.Forms;
using System.Windows.Input; using System.Windows.Input;
using System.Windows.Media; using System.Windows.Media;
using System.Windows.Media.Imaging; using System.Windows.Media.Imaging;
@@ -21,11 +22,12 @@ namespace 头罩视野
public partial class MainWindow : Window public partial class MainWindow : Window
{ {
public MainWindow() public MainWindow()
{ {
InitializeComponent(); InitializeComponent();
ModbusHelper.Connect("192.168.1.10", 502); // 连接一次,全局生效 ModbusHelper.Connect("192.168.1.10", 502); // 连接一次,全局生效
} }
// 程序退出 // 程序退出
@@ -46,5 +48,7 @@ namespace 头罩视野
//NavigationService.Navigate(new Views.RecordDate()); 页面相互跳转 //NavigationService.Navigate(new Views.RecordDate()); 页面相互跳转
//private void ShowError(string msg) => MessageBox.Show(msg, "错误", MessageBoxButton.OK, MessageBoxImage.Error); //private void ShowError(string msg) => MessageBox.Show(msg, "错误", MessageBoxButton.OK, MessageBoxImage.Error);
} }
} }

View File

@@ -8,7 +8,7 @@
mc:Ignorable="d" mc:Ignorable="d"
Background="#F5F7FA" Background="#F5F7FA"
d:DesignHeight="768" d:DesignWidth="1024" d:DesignHeight="768" d:DesignWidth="1024"
Title="PageTest" Loaded="Page_Loaded" Unloaded="Page_Unloaded" > Title="PageTest" Loaded="Page_Loaded" Unloaded="Page_Unloaded" >
<Page.Resources> <Page.Resources>
<!-- 标题样式 --> <!-- 标题样式 -->
<Style x:Key="MainTitleStyle" TargetType="TextBlock"> <Style x:Key="MainTitleStyle" TargetType="TextBlock">

View File

@@ -326,7 +326,7 @@ namespace 头罩视野.Views
if (_modbusMaster == null) if (_modbusMaster == null)
return; return;
var ret = await _modbusMaster.ReadCoilsAsync(1, 1, 2); var ret = await _modbusMaster.ReadCoilsAsync(1, 0, 2);
if (ret != null && ret.Length > 0) if (ret != null && ret.Length > 0)
{ //左眼开 { //左眼开
if (ret[0]) if (ret[0])
@@ -841,6 +841,9 @@ namespace 头罩视野.Views
_cts?.Cancel(); _cts?.Cancel();
_cts = null; _cts = null;
_modbusMaster.WriteSingleCoil(1, 1, false);
_modbusMaster.WriteSingleCoil(1, 0, false);
} }