关闭程序关闭灯条

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:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:头罩视野"
StartupUri="MainWindow.xaml">
StartupUri="MainWindow.xaml" Exit="MainForm_FormClosing">
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>

View File

@@ -1,14 +1,27 @@
using System.Configuration;
using Modbus.Device;
using System.Configuration;
using System.Data;
using System.Windows;
using .Services.Data;
namespace
{
/// <summary>
/// Interaction logic for App.xaml
/// </summary>
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:头罩视野"
mc:Ignorable="d"
Background="#FFE6F2FF"
Title="MainWindow" Height="768" Width="1024">
Title="MainWindow" Height="768" Width="1024" >
<Window.Resources>
<Style x:Key="TabButtonStyle" TargetType="Button">
<Setter Property="Background" Value="#3498DB"/>

View File

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

View File

@@ -326,7 +326,7 @@ namespace 头罩视野.Views
if (_modbusMaster == null)
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[0])
@@ -841,6 +841,9 @@ namespace 头罩视野.Views
_cts?.Cancel();
_cts = null;
_modbusMaster.WriteSingleCoil(1, 1, false);
_modbusMaster.WriteSingleCoil(1, 0, false);
}