This commit is contained in:
xyy
2026-05-11 19:06:26 +08:00
parent 3dece416fa
commit 7780b4758b
26 changed files with 428 additions and 93 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"
Title="{DynamicResource WindowTitle}"
Height="768" Width="1024" Loaded="Window_Loaded" WindowStartupLocation="CenterScreen">
WindowState="Maximized" Height="768" Width="1024" Loaded="Window_Loaded" WindowStartupLocation="CenterScreen">

View File

@@ -1,7 +1,7 @@
<Window x:Class="ShanghaiEnvironmentalTechnology.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="" Height="768" Width="1024" Loaded="Window_Loaded" WindowStartupLocation="CenterScreen"
Title="" WindowState="Maximized" Height="768" Width="1024" Loaded="Window_Loaded" WindowStartupLocation="CenterScreen"
>
<Grid Margin="20" Cursor="">
<Grid.RowDefinitions>

View File

@@ -1,7 +1,7 @@
<Window x:Class="ShanghaiEnvironmentalTechnology.ReportWindow1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="{DynamicResource FlowReport}" Height="768" Width="1024" Loaded="Window_Loaded" WindowStartupLocation="CenterScreen">
Title="{DynamicResource FlowReport}" WindowState="Maximized" Height="768" Width="1024" Loaded="Window_Loaded" WindowStartupLocation="CenterScreen">
<Window.Resources>
<Style x:Key="MyButtonStyle" TargetType="Button">

View File

@@ -1,7 +1,7 @@
<Window x:Class="ShanghaiEnvironmentalTechnology.ReportWindow2"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="{DynamicResource TestReport}" Height="768" Width="1024" Loaded="Window_Loaded" WindowStartupLocation="CenterScreen">
Title="{DynamicResource TestReport}" WindowState="Maximized" Height="768" Width="1024" Loaded="Window_Loaded" WindowStartupLocation="CenterScreen">
<Window.Resources>
<Style x:Key="MyButtonStyle" TargetType="Button">

View File

@@ -1,7 +1,7 @@
<Window x:Class="ShanghaiEnvironmentalTechnology.ReportWindow3"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="{DynamicResource FxReport}" Height="768" Width="1024" Loaded="Window_Loaded" WindowStartupLocation="CenterScreen">
Title="{DynamicResource FxReport}" WindowState="Maximized" Height="768" Width="1024" Loaded="Window_Loaded" WindowStartupLocation="CenterScreen">
<Window.Resources>
<Style x:Key="MyButtonStyle" TargetType="Button">

View File

@@ -1,7 +1,7 @@
<Window x:Class="ShanghaiEnvironmentalTechnology.ReportWindow4"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="{DynamicResource FxNReport}" Height="768" Width="1024" Loaded="Window_Loaded" WindowStartupLocation="CenterScreen">
Title="{DynamicResource FxNReport}" WindowState="Maximized" Height="768" Width="1024" Loaded="Window_Loaded" WindowStartupLocation="CenterScreen">
<Window.Resources>
<Style x:Key="MyButtonStyle" TargetType="Button">

View File

@@ -1,7 +1,7 @@
<Window x:Class="ShanghaiEnvironmentalTechnology.ReportWindow5"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="{DynamicResource testReport}" Height="768" Width="1024" Loaded="Window_Loaded" WindowStartupLocation="CenterScreen">
Title="{DynamicResource testReport}" WindowState="Maximized" Height="768" Width="1024" Loaded="Window_Loaded" WindowStartupLocation="CenterScreen">
<Window.Resources>
<Style x:Key="MyButtonStyle" TargetType="Button">

View File

@@ -42,10 +42,10 @@ namespace ShanghaiEnvironmentalTechnology
using (SQLiteConnection conn = new SQLiteConnection(CSConstant.DbConnectionString))
{
conn.Open();
string query = "SELECT Id, Flow, Pressure, BeginCO2, EndCO2, CO2Added, RecordTime FROM CO2";
string query = "SELECT Id, Flow, Pressure, BeginCO2, EndCO2, CO2Added, RecordTime,IsEnd FROM CO2 where 1=1 and isEnd=1 ";
if (!string.IsNullOrEmpty(startDate) && !string.IsNullOrEmpty(endDate))
{
query += " WHERE RecordTime BETWEEN @startDate AND @endDate";
query += " And RecordTime BETWEEN @startDate AND @endDate";
}
query += " LIMIT @offset, @limit";
@@ -259,7 +259,7 @@ namespace ShanghaiEnvironmentalTechnology
MessageBox.Show("CO2表中无数据无法导出", "提示", MessageBoxButton.OK, MessageBoxImage.Warning);
return;
}
records = records.Where(s => s.isEnd ?? false).ToList();
bool success = ExportCO2RecordsToExcel(records);
if (success)
{
@@ -288,7 +288,7 @@ namespace ShanghaiEnvironmentalTechnology
using (SQLiteConnection conn = new SQLiteConnection(CSConstant.DbConnectionString))
{
conn.Open();
string query = "SELECT BeginCO2, EndCO2, CO2Added, RecordTime FROM CO2 WHERE 1=1";
string query = "SELECT BeginCO2, EndCO2, CO2Added, RecordTime,isEnd FROM CO2 WHERE 1=1 ";
if (startDate != null) query += " AND RecordTime >= @StartDate";
if (endDate != null) query += " AND RecordTime <= @EndDate";
@@ -308,7 +308,8 @@ namespace ShanghaiEnvironmentalTechnology
BeginCO2 = reader.GetDouble(0),
EndCO2 = reader.GetDouble(1),
CO2Added = reader.GetDouble(2),
RecordTime = reader.GetDateTime(3)
RecordTime = reader.GetDateTime(3),
isEnd = reader.GetBoolean(4)
});
}
}

View File

@@ -1,7 +1,7 @@
<Window x:Class="ShanghaiEnvironmentalTechnology.ReportWindow6"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="{DynamicResource testReport}" Height="768" Width="1024" Loaded="Window_Loaded" WindowStartupLocation="CenterScreen">
Title="{DynamicResource testReport}" WindowState="Maximized" Height="768" Width="1024" Loaded="Window_Loaded" WindowStartupLocation="CenterScreen">
<Window.Resources>
<Style x:Key="MyButtonStyle" TargetType="Button">

View File

@@ -98,7 +98,7 @@
<system:String x:Key="test6">Test auxiliary parameters</system:String>
<system:String x:Key="test7">Breathing rate</system:String>
<system:String x:Key="test77">Respiratory timing</system:String>
<system:String x:Key="test8">time/min</system:String>
<system:String x:Key="test8">times</system:String>
<system:String x:Key="test9">divide</system:String>
<system:String x:Key="test10">Second</system:String>
<system:String x:Key="test11">Real-time monitoring data</system:String>
@@ -280,6 +280,6 @@
<system:String x:Key="9# Maximum Force Value (N)">9# Maximum Force Value (N)</system:String>
<system:String x:Key="10# Maximum Force Value (N)">10# Maximum Force Value (N)</system:String>
<system:String x:Key="Peak test (peak force)">Peak test (peak force)</system:String>
<system:String x:Key="customize">customize</system:String>
</ResourceDictionary>

View File

@@ -99,7 +99,7 @@
<system:String x:Key="test6">测试辅助参数</system:String>
<system:String x:Key="test7">呼吸次数</system:String>
<system:String x:Key="test77">呼吸计时</system:String>
<system:String x:Key="test8">次/min</system:String>
<system:String x:Key="test8">次</system:String>
<system:String x:Key="test9">分</system:String>
<system:String x:Key="test10">秒</system:String>
<system:String x:Key="test11">实时监测数据</system:String>
@@ -287,6 +287,6 @@
<system:String x:Key="Peak test (peak force)">峰值测试(峰值力)</system:String>
<system:String x:Key="customize">自定义</system:String>
</ResourceDictionary>

View File

@@ -3,7 +3,7 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:av="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="av" x:Class="ShanghaiEnvironmentalTechnology.Window1"
Title="{DynamicResource WindowTitle1}"
Height="768" Width="1024" Loaded="Window_Loaded" WindowStartupLocation="CenterScreen">
WindowState="Maximized" Height="768" Width="1024" Loaded="Window_Loaded" WindowStartupLocation="CenterScreen">
<Window.Resources>
<Style x:Key="MyButtonStyle" TargetType="{x:Type Button}">

View File

@@ -1,7 +1,7 @@
<Window x:Class="ShanghaiEnvironmentalTechnology.Window2"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="{DynamicResource Next}" Height="768" Width="1024"
Title="{DynamicResource Next}" WindowState="Maximized" Height="768" Width="1024"
Loaded="Window_Loaded" WindowStartupLocation="CenterScreen">
<Window.Resources>

View File

@@ -1,7 +1,7 @@
<Window x:Class="ShanghaiEnvironmentalTechnology.Window3"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="{DynamicResource Deformation10}" Height="768" Width="1024"
Title="{DynamicResource Deformation10}" WindowState="Maximized" Height="768" Width="1024"
Loaded="Window_Loaded" WindowStartupLocation="CenterScreen">
<Window.Resources>
@@ -182,8 +182,8 @@
</StackPanel>
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center" Margin="0,10">
<Button Content="{DynamicResource SetPressure}" Style="{StaticResource MyButtonStyle}" Width="220" Margin="10" Click="Button_Click_3"/>
<Button Content="{DynamicResource ResetDistance}" Style="{StaticResource MyButtonStyle}" Width="220" Margin="10" Click="Button_Click_9"/>
<Button Content="{DynamicResource SetPressure}" Style="{StaticResource MyButtonStyle}" Width="220" Margin="10" Click="Button_Click_3" Visibility="Hidden"/>
<Button Content="{DynamicResource ResetDistance}" Style="{StaticResource MyButtonStyle}" Width="220" Margin="10" Click="Button_Click_9" Visibility="Hidden"/>
</StackPanel>
<StackPanel Margin="0,10,0,0">

View File

@@ -39,6 +39,9 @@ namespace ShanghaiEnvironmentalTechnology
private readonly ushort _testStartAddress = 0x0014; // 防窒息压力测试启动M20
private readonly ushort _testStopAddress = 0x001E; // 防窒息压力测试停止M30
private readonly ushort _calibrationCoilAddress = 0x0048; // 校准线圈M72
private bool _lastTestRunningState = false; // 记录上一次的测试运行状态
private bool _isDelayedButtonClickPending = false;
#endregion
#region
@@ -81,7 +84,7 @@ namespace ShanghaiEnvironmentalTechnology
_pressureReadTimer = CreateTimer(1000, OnPressureTimerElapsed);
_settingReadTimer = CreateTimer(1000, OnSettingReadTimerTimerElapsed);
_settingReadTimer2 = CreateTimer(1000, OnSettingReadTimerTimerElapsed2);
startTimer = CreateTimer(1000, OnStartTimerElapsed);
startTimer = CreateTimer(200, OnStartTimerElapsed);
fc = new Function(_modbusMaster);
@@ -111,6 +114,109 @@ namespace ShanghaiEnvironmentalTechnology
/// <summary>
/// 实时流量读取定时器修正跨线程访问UI问题
/// </summary>
//private void OnStartTimerElapsed(object sender, ElapsedEventArgs e)
//{
// try
// {
// bool[] result = _modbusMaster?.ReadCoils(0x01, 21, 1);
// bool isTestRunning = result != null && result.Length > 0 && result[0];
// string testStartButtonText = "";
// string ButtonStatus = "";
// string currentLanguage = ConfigurationManager.AppSettings["Language"] ?? "zh-CN";
// if (currentLanguage == "en-US")
// {
// testStartButtonText = "Test Start Success";
// ButtonStatus = "Test initiation";
// }
// else if (currentLanguage == "zh-CN")
// {
// testStartButtonText = "测试启动成功";
// ButtonStatus = "测试启动";
// }
// TestStartButton.Dispatcher.Invoke(() =>
// {
// if (isTestRunning)
// {
// btnsetting.IsEnabled = false;
// btnjiaozhun.IsEnabled = false;
// btnsetting2.IsEnabled = false;
// TestStartButton.Content = testStartButtonText;
// TestStartButton.Foreground = Brushes.LightGreen;
// }
// else
// {
// btnsetting.IsEnabled = true;
// btnjiaozhun.IsEnabled = true;
// btnsetting2.IsEnabled = true;
// TestStartButton.Content = ButtonStatus;
// TestStartButton.Foreground = Brushes.White;
// Button_Click_3(sender, new RoutedEventArgs { });
// // 测试结束延迟1秒调用 Button_Click_3只调用一次
// lock (this) // 简单锁防止多线程竞争
// {
// if (!_isDelayedButtonClickPending)
// {
// _isDelayedButtonClickPending = true;
// // 延迟1秒执行避免阻塞定时器线程
// Task.Delay(1000).ContinueWith(_ =>
// {
// // 回到 UI 线程执行 Button_Click_3
// TestStartButton.Dispatcher.Invoke(() =>
// {
// try
// {
// Button_Click_3(sender, new RoutedEventArgs());
// }
// finally
// {
// // 执行完毕后重置标志
// lock (this)
// {
// _isDelayedButtonClickPending = false;
// }
// }
// });
// });
// }
// }
// }
// });
// }
// catch (Exception ex)
// {
// Console.WriteLine($"读取线圈或更新UI失败{ex.Message}");
// }
//}
private void OnStartTimerElapsed(object sender, ElapsedEventArgs e)
{
try
@@ -118,7 +224,6 @@ namespace ShanghaiEnvironmentalTechnology
bool[] result = _modbusMaster?.ReadCoils(0x01, 21, 1);
bool isTestRunning = result != null && result.Length > 0 && result[0];
string testStartButtonText = "";
string ButtonStatus = "";
string currentLanguage = ConfigurationManager.AppSettings["Language"] ?? "zh-CN";
@@ -133,18 +238,20 @@ namespace ShanghaiEnvironmentalTechnology
ButtonStatus = "测试启动";
}
TestStartButton.Dispatcher.Invoke(() =>
{
if (isTestRunning)
{
btnsetting.IsEnabled = false;
btnjiaozhun.IsEnabled = false;
btnsetting2.IsEnabled = false;
TestStartButton.Content = testStartButtonText;
TestStartButton.Foreground = Brushes.LightGreen;
// 测试开始:重置下降沿标志,并更新上次状态
_lastTestRunningState = true;
// 注意:不重置 _isDelayedButtonClickPending因为尚未调度或已调度完成不影响
}
else
{
@@ -154,6 +261,33 @@ namespace ShanghaiEnvironmentalTechnology
TestStartButton.Content = ButtonStatus;
TestStartButton.Foreground = Brushes.White;
// 检测下降沿:上一次为 true当前为 false
bool isFallingEdge = _lastTestRunningState == true && isTestRunning == false;
// 更新上一次状态
_lastTestRunningState = isTestRunning;
// 仅在下降沿且未调度延迟任务时,调度一次
if (isFallingEdge && !_isDelayedButtonClickPending)
{
_isDelayedButtonClickPending = true;
Task.Delay(0).ContinueWith(_ =>
{
TestStartButton.Dispatcher.Invoke(() =>
{
try
{
Button_Click_3(sender, new RoutedEventArgs());
}
finally
{
_isDelayedButtonClickPending = false;
}
});
});
}
}
});
}
@@ -245,6 +379,13 @@ namespace ShanghaiEnvironmentalTechnology
ushort b = data[1]; // 低位寄存器值
float floatValue = c.UshortToFloat(b, a);
floatValue = (float)Math.Round(floatValue, 2);
//if (address == 202)
//{
// floatValue = 0;
//}
updateAction?.Invoke(floatValue);
}
else
@@ -784,6 +925,8 @@ namespace ShanghaiEnvironmentalTechnology
var content = selectedItem.Content?.ToString();
if (string.IsNullOrEmpty(content)) return;
if (_modbusMaster == null)
return;
// 获取当前语言
string currentLanguage = ConfigurationManager.AppSettings["Language"] ?? "zh-CN";
string stopMsg = currentLanguage == "en-US" ? "Stop" : "停止";
@@ -793,12 +936,12 @@ namespace ShanghaiEnvironmentalTechnology
{
case "开阀捕捉":
case "Open the valve to capture":
await WriteCoilWithCheck(0, true, null, stopMsg, "开关阀选择");
await _modbusMaster.WriteSingleCoilAsync(0x01, 67, false);
break;
case "关阀捕捉":
case "Closing the valve to capture":
await WriteCoilWithCheck(1, true, null, stopMsg, "开关阀选择");
await _modbusMaster.WriteSingleCoilAsync(0x01, 67, true);
break;
default:
return;
@@ -1035,8 +1178,8 @@ namespace ShanghaiEnvironmentalTechnology
return;
}
fc.BtnClickFunctionForNew(Function.ButtonType., 170);
fc.BtnClickFunctionForNew(Function.ButtonType., 170);
//fc.BtnClickFunctionForNew(Function.ButtonType.切换型, 170);
//fc.BtnClickFunctionForNew(Function.ButtonType.切换型, 170);
ReadAndUpdateRegister(_openRegisterAddress, true, value => UpdateFlowFlowUI(value.ToString()));
ReadAndUpdateRegister(_closeRegisterAddress, true, value => UpdateCloseFlowUI(value.ToString()));
@@ -1058,15 +1201,15 @@ namespace ShanghaiEnvironmentalTechnology
return;
}
bool exportSuccessFlag = ExportCO2RecordsToExcel(co2Records);
if (exportSuccessFlag)
{
MessageBox.Show(exportSuccess, currentLanguage == "en-US" ? "Success" : "成功", MessageBoxButton.OK, MessageBoxImage.Information);
}
else
{
//MessageBox.Show(exportFail, currentLanguage == "en-US" ? "Error" : "错误", MessageBoxButton.OK, MessageBoxImage.Error);
}
//bool exportSuccessFlag = ExportCO2RecordsToExcel(co2Records);
//if (exportSuccessFlag)
//{
// MessageBox.Show(exportSuccess, currentLanguage == "en-US" ? "Success" : "成功", MessageBoxButton.OK, MessageBoxImage.Information);
//}
//else
//{
// //MessageBox.Show(exportFail, currentLanguage == "en-US" ? "Error" : "错误", MessageBoxButton.OK, MessageBoxImage.Error);
//}
}

View File

@@ -1,7 +1,7 @@
<Window x:Class="ShanghaiEnvironmentalTechnology.Window4"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="{DynamicResource setFlow2}" Height="768" Width="1024"
Title="{DynamicResource setFlow2}" WindowState="Maximized" Height="768" Width="1024"
Loaded="Window_Loaded"
WindowStartupLocation="CenterScreen">
<Window.Resources>
@@ -287,20 +287,14 @@
<Button Grid.Row="3" Grid.Column="2"
Content="{DynamicResource setFlow10}"
Style="{StaticResource MyButtonStyle}"
Click="Button_Click_5"
Click="Button_Click_6"
Width="NaN"
Margin="42,10,42,10"/>
</Grid>
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center" Margin="0,10">
<!-- 减少边距原20→10 -->
<Button Content="{DynamicResource Deformation}" Style="{StaticResource MyButtonStyle}" Click="Button_Click_2"/>
<Button Name="TestStartButton" Content="{DynamicResource Maximumforcevaluetestresult(N)}" Style="{StaticResource MyButtonStyle}" Click="Button_Click_4"/>
<Button Content="{DynamicResource Deformation test results}" Style="{StaticResource MyButtonStyle}" Click="Button_Click_3"/>
<Button Content="{DynamicResource ViewReport}" Style="{StaticResource MyButtonStyle}" Click="Button_Click_7" Width="201"/>
</StackPanel>
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center" Margin="0,10">
<TextBlock Text="{DynamicResource setFlow112}" VerticalAlignment="Center" FontWeight="Bold" FontSize="16" Margin="20 0 50 0"/>
@@ -311,6 +305,13 @@
<TextBlock Text="pa" VerticalAlignment="Center" Margin="10,0,0,0"/>
</StackPanel>
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center" Margin="0,10">
<!-- 减少边距原20→10 -->
<Button Content="{DynamicResource Deformation}" Style="{StaticResource MyButtonStyle}" Click="Button_Click_2"/>
<Button Name="TestStartButton" Content="{DynamicResource Maximumforcevaluetestresult(N)}" Style="{StaticResource MyButtonStyle}" Click="Button_Click_4"/>
<Button Content="{DynamicResource Deformation test results}" Style="{StaticResource MyButtonStyle}" Click="Button_Click_3"/>
<Button Content="{DynamicResource ViewReport}" Style="{StaticResource MyButtonStyle}" Click="Button_Click_7" Width="201"/>
</StackPanel>
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center" Margin="0,10,0,20">
<!-- 增加底部边距,避免被窗口边缘遮挡 -->
<!--<Button Content="记录呼气阻力" Style="{StaticResource MyButtonStyle}" Click="Button_Click_5"/>

View File

@@ -458,12 +458,11 @@ namespace ShanghaiEnvironmentalTechnology
fc.BtnClickFunctionForNew(Function.ButtonType., 192);
ReadAndUpdateRegister(_BreathOutRegisterAddress, true, value => UpdateFlowFlowUI(value.ToString()));
ReadAndUpdateRegister(_BreathInRegisterAddress, true, value => UpdateCloseFlowUI2(value.ToString()));
//ReadAndUpdateRegister(_BreathInRegisterAddress, true, value => UpdateCloseFlowUI2(value.ToString()));
if (float.TryParse(saveFlowOutTxt.Text, out float flowValue) &&
float.TryParse(saveFlowInTxt.Text, out float pressureValue))
if (float.TryParse(saveFlowOutTxt.Text, out float flowValue))
{
SaveRecordToDatabase(flowValue, pressureValue);
SaveRecordToDatabase(flowValue, 0);
}
else
{
@@ -486,12 +485,61 @@ namespace ShanghaiEnvironmentalTechnology
}
else
{
string msg = lang == "en-US" ? "Export failed" : "Excel导出失败请检查文件是否被占用";
MessageBox.Show(msg, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
//string msg = lang == "en-US" ? "Export failed" : "Excel导出失败请检查文件是否被占用";
//MessageBox.Show(msg, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
}
}
private async void Button_Click_6(object sender, RoutedEventArgs e)
{
string lang = ConfigurationManager.AppSettings["Language"] ?? "zh-CN";
if (!IsModbusConnected())
{
saveFlowOutTxt.Text = lang == "en-US" ? "Disconnected" : "连接断开";
ShowError(lang == "en-US" ? "Modbus TCP not connected" : "Modbus TCP 未连接");
return;
}
fc.BtnClickFunctionForNew(Function.ButtonType., 193);
fc.BtnClickFunctionForNew(Function.ButtonType., 193);
//ReadAndUpdateRegister(_BreathOutRegisterAddress, true, value => UpdateFlowFlowUI(value.ToString()));
ReadAndUpdateRegister(_BreathInRegisterAddress, true, value => UpdateCloseFlowUI2(value.ToString()));
if (
float.TryParse(saveFlowInTxt.Text, out float pressureValue))
{
SaveRecordToDatabase(0, pressureValue);
}
else
{
ShowError(lang == "en-US" ? "Invalid data format" : "流量或压力值格式不正确,请检查输入");
}
List<CO2Record> records = ReadCO2RecordsFromDatabase();
if (records == null || records.Count == 0)
{
string msg = lang == "en-US" ? "No data to export" : "单一故障气阻表中无数据,无法导出";
MessageBox.Show(msg, "Info", MessageBoxButton.OK, MessageBoxImage.Warning);
return;
}
bool exportSuccess = ExportCO2RecordsToExcel(records);
if (exportSuccess)
{
string msg = lang == "en-US" ? "Export successful" : "数据已成功导出到Excel";
MessageBox.Show(msg, "Success", MessageBoxButton.OK, MessageBoxImage.Information);
}
else
{
//string msg = lang == "en-US" ? "Export failed" : "Excel导出失败请检查文件是否被占用";
//MessageBox.Show(msg, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
}
}
private bool ExportCO2RecordsToExcel(List<CO2Record> records)
{
try
@@ -865,7 +913,7 @@ namespace ShanghaiEnvironmentalTechnology
/// <summary>
/// 加载窗口背景
/// </summary>
private void Window_Loaded(object sender, RoutedEventArgs e)
private async void Window_Loaded(object sender, RoutedEventArgs e)
{
try
{
@@ -881,6 +929,11 @@ namespace ShanghaiEnvironmentalTechnology
{
Console.WriteLine($"背景图片不存在: {imgPath}");
}
await LoadBreathTypeSelection();
}
catch (Exception ex)
{
@@ -889,6 +942,44 @@ namespace ShanghaiEnvironmentalTechnology
}
private async Task LoadBreathTypeSelection()
{
try
{
// 读取线圈 36假设 36 为呼吸类型true=吸气/Inhalefalse=呼气/Exhale
bool[] result = await _modbusMaster?.ReadCoilsAsync(1, 36, 1);
bool isInhale = result != null && result.Length > 0 && result[0];
// 获取当前语言
string currentLanguage = ConfigurationManager.AppSettings["Language"] ?? "zh-CN";
string expectedContent;
if (currentLanguage == "en-US")
{
expectedContent = isInhale ? "Inhale" : "Exhale";
}
else
{
expectedContent = isInhale ? "吸气" : "呼气";
}
// 查找并设置选中项
foreach (ComboBoxItem item in CaptureModeComboBox.Items)
{
if (item.Content?.ToString() == expectedContent)
{
CaptureModeComboBox.SelectedItem = item;
break;
}
}
}
catch (Exception ex)
{
// 记录错误,可选用日志或 Console
Console.WriteLine($"加载呼吸类型失败: {ex.Message}");
}
}
/// <summary>
/// clostTxt输入验证仅允许数字和小数点
/// </summary>

View File

@@ -1,7 +1,7 @@
<Window x:Class="ShanghaiEnvironmentalTechnology.Window5"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="{DynamicResource test}" Height="768" Width="1024"
Title="{DynamicResource test}" WindowState="Maximized" Height="768" Width="1024"
Loaded="Window_Loaded"
Background="#F5F7FA" WindowStartupLocation="CenterScreen">
<Window.Resources>
@@ -106,15 +106,51 @@
<!-- 主布局DockPanel分区避免元素重叠 -->
<DockPanel Margin="15">
<!-- 1. 顶部标题区(突出显示) -->
<Border DockPanel.Dock="Top" Height="60" Background="#4A90E2" CornerRadius="8" Margin="0,0,0,15">
<!--<Border DockPanel.Dock="Top" Height="60" Background="#4A90E2" CornerRadius="8" Margin="0,0,0,15">
<TextBlock Text="{DynamicResource test}"
HorizontalAlignment="Center"
VerticalAlignment="Center"
FontSize="24"
Foreground="White"
FontWeight="Medium"/>
</Border>
</Border>-->
<!-- 1. 顶部标题区(突出显示 + 左上角下拉框) -->
<Border DockPanel.Dock="Top" Height="60" Background="#4A90E2" CornerRadius="8" Margin="0,0,0,15">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<!-- 下拉框 -->
<ColumnDefinition Width="*"/>
<!-- 居中标题 -->
<ColumnDefinition Width="Auto"/>
<!-- 右侧留白占位,保持对称 -->
</Grid.ColumnDefinitions>
<!-- 左上角下拉框 -->
<ComboBox Grid.Column="0"
Width="120"
Height="30"
VerticalAlignment="Center"
Margin="15,0,0,0"
Background="White" SelectionChanged="CaptureModeComboBox_SelectionChanged">
<ComboBoxItem Content="YY0671" IsSelected="True"/>
<ComboBoxItem Content="{DynamicResource customize}" />
</ComboBox>
<!-- 标题依然居中 -->
<TextBlock Grid.Column="1"
Text="{DynamicResource test}"
HorizontalAlignment="Center"
VerticalAlignment="Center"
FontSize="24"
Foreground="White"
FontWeight="Medium"/>
<!-- 右侧留空(保证标题居中视觉效果) -->
<Rectangle Grid.Column="2" Width="120" Visibility="Hidden"/>
</Grid>
</Border>
<!-- 2. 底部操作与导航区(聚合功能按钮) -->
<Border DockPanel.Dock="Bottom" Height="120" Background="White"
BorderBrush="#E0E0E0" BorderThickness="1"

View File

@@ -1,11 +1,12 @@
using Microsoft.Win32;
using Modbus.Device;
using Modbus;
using Modbus.Device;
using OfficeOpenXml;
using System;
using System.Configuration;
using System.Data.SQLite;
using System.IO;
using System.Net.Mail;
using System.Net.Sockets;
using System.Runtime.Intrinsics;
using System.Threading.Tasks;
@@ -17,6 +18,7 @@ using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Media.Imaging;
using ;
using static OfficeOpenXml.ExcelErrorValue;
namespace ShanghaiEnvironmentalTechnology
{
@@ -164,7 +166,7 @@ namespace ShanghaiEnvironmentalTechnology
if (!_isEditingFrequency)
{
ReadAndUpdateSingleRegister(
368,
3680,
isFloat: true,
value => UpdatePressureUI5(value.ToString())
);
@@ -389,7 +391,8 @@ namespace ShanghaiEnvironmentalTechnology
BeginCO2 REAL NOT NULL,
EndCO2 REAL NOT NULL,
CO2Added REAL NOT NULL,
RecordTime DATETIME NOT NULL
RecordTime DATETIME NOT NULL,
IsEnd BOOLEAN DEFAULT 0
);";
using (var command = new SQLiteCommand(createTableSql, connection))
{
@@ -947,12 +950,13 @@ namespace ShanghaiEnvironmentalTechnology
}
try
{
await Task.Run(() => _modbusMaster.WriteSingleCoil(0x01, 38, false));
UpdateResetButtonStatus(_lang == "en-US" ? "Resetting..." : "正在复位...", Brushes.LightGreen);
await Task.Run(() => _modbusMaster.WriteSingleCoil(0x01, _resetAddress, true));
fc.BtnClickFunctionForNew(Function.ButtonType., _resetAddress);
//await Task.Run(() => _modbusMaster.WriteSingleCoil(0x01, _resetAddress, true));
fc.BtnClickFunctionForNew(Function.ButtonType., 2);
await Task.Delay(100);
await Task.Run(() => _modbusMaster.WriteSingleCoil(0x01, _resetAddress, false));
fc.BtnClickFunctionForNew(Function.ButtonType., _resetAddress);
//fc.BtnClickFunctionForNew(Function.ButtonType.复位型, _resetAddress);
UpdateResetButtonStatus(_lang == "en-US" ? "Reset Success" : "复位成功", Brushes.LightGreen);
}
catch (Exception ex)
@@ -1054,6 +1058,25 @@ namespace ShanghaiEnvironmentalTechnology
return;
}
float flowData = ReadAndUpdateSingleRegisterWithNoUI(_co2Address, true);
float pressureData = ReadAndUpdateSingleRegisterWithNoUI(_breathOutAddress, true);
float beginCo2Data = ReadAndUpdateSingleRegisterWithNoUI(_co2BeginAddress, true);
float endCo2Data = ReadAndUpdateSingleRegisterWithNoUI(_co2EndAddress, true);
float addCo2Data = ReadAndUpdateSingleRegisterWithNoUI(_co2AddAddress, true);
// 保存到数据库
SaveRecordToDatabase(
flowData,
pressureData,
beginCo2Data,
endCo2Data,
addCo2Data,
true
);
var records = ReadCO2RecordsFromDatabase();
if (records == null || !records.Any())
{
@@ -1078,7 +1101,7 @@ namespace ShanghaiEnvironmentalTechnology
{
conn.Open();
// 查询CO2表所有记录按时间排序
string query = "SELECT Flow, Pressure, BeginCO2, EndCO2, CO2Added, RecordTime FROM CO2 ORDER BY RecordTime desc limit 1 ";
string query = "SELECT Flow, Pressure, BeginCO2, EndCO2, CO2Added, RecordTime,isEnd FROM CO2 ORDER BY RecordTime desc limit 1 ";
using (SQLiteCommand cmd = new SQLiteCommand(query, conn))
{
using (SQLiteDataReader reader = cmd.ExecuteReader())
@@ -1162,6 +1185,8 @@ namespace ShanghaiEnvironmentalTechnology
public double EndCO2 { get; set; } // 终CO2浓度%
public double CO2Added { get; set; } // CO2浓度相对增加%
public DateTime RecordTime { get; set; } // 时间
public bool? isEnd { get; set; }
}
private void Button_Click_15(object sender, RoutedEventArgs e) { }
@@ -1221,7 +1246,7 @@ namespace ShanghaiEnvironmentalTechnology
/// <summary>
/// 保存记录到数据库
/// </summary>
private void SaveRecordToDatabase(double flow, double pressure, double beginCo2, double endCo2, double co2Added)
private void SaveRecordToDatabase(double flow, double pressure, double beginCo2, double endCo2, double co2Added, bool isEnd = false)
{
try
{
@@ -1230,12 +1255,15 @@ namespace ShanghaiEnvironmentalTechnology
beginCo2 = Math.Round(beginCo2, 2);
endCo2 = Math.Round(endCo2, 2);
co2Added = Math.Round(co2Added, 2);
int isEnded= isEnd ? 1 : 0;
using (var conn = new SQLiteConnection(CSConstant.DbConnectionString))
{
conn.Open();
string insertSql = @"
INSERT INTO CO2(Flow, Pressure, BeginCO2, EndCO2, CO2Added, RecordTime)
VALUES (@Flow, @Pressure, @BeginCO2, @EndCO2, @CO2Added, @RecordTime);";
INSERT INTO CO2(Flow, Pressure, BeginCO2, EndCO2, CO2Added, RecordTime,isEnd)
VALUES (@Flow, @Pressure, @BeginCO2, @EndCO2, @CO2Added, @RecordTime,"+ isEnded + ");";
using (var cmd = new SQLiteCommand(insertSql, conn))
{
cmd.Parameters.AddWithValue("@Flow", flow);
@@ -1514,5 +1542,30 @@ namespace ShanghaiEnvironmentalTechnology
{
}
}
private async void CaptureModeComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
if (sender == null) return;
var comboBox = sender as ComboBox;
if (comboBox == null) return;
var selectedItem = comboBox.SelectedItem as ComboBoxItem;
if (selectedItem == null) return;
var content = selectedItem.Content?.ToString();
if (string.IsNullOrEmpty(content)) return;
if (_modbusMaster == null) return;
switch (content)
{
case "自定义":
case "customize":
await _modbusMaster?.WriteSingleRegisterAsync(0x01, 30, 1);
break;
case "YY0671":
await _modbusMaster?.WriteSingleRegisterAsync(0x01, 30, 0);
break;
default:
return;
}
}
}
}

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:oxy="http://oxyplot.org/wpf"
Title="{DynamicResource Manual}" Height="768" Width="1024"
Title="{DynamicResource Manual}" WindowState="Maximized" Height="768" Width="1024"
WindowStartupLocation="CenterScreen" Loaded="Window_Loaded"
Background="#F5F7FA" >
<Window.Resources>

View File

@@ -763,8 +763,18 @@ namespace ShanghaiEnvironmentalTechnology
private async void Button_Click_5(object sender, RoutedEventArgs e) => await WriteSingleRegisterWithOutUI(_OutBreathDownAddress, v => $"Exhale Down: {v}");
private async void Button_Click_6(object sender, RoutedEventArgs e) => await WriteSingleRegisterWithOutUI(_InBreathUpAddress, v => $"Inhale Up: {v}");
private async void Button_Click_7(object sender, RoutedEventArgs e) => await WriteSingleRegisterWithOutUI(_InBreathDownAddress, v => $"Inhale Down: {v}");
private async void Button_Click_8(object sender, RoutedEventArgs e) => await WriteSingleRegisterWithOutUI(_HandInBreathUpAddress, v => $"Manual Inhale: {v}");
private async void Button_Click_9(object sender, RoutedEventArgs e) => await WriteSingleRegisterWithOutUI(_HandInBreathDownAddress, v => $"Manual Exhale: {v}");
//private async void Button_Click_8(object sender, RoutedEventArgs e) => await WriteSingleRegisterWithOutUI(_HandInBreathUpAddress, v => $"Manual Inhale: {v}");
private bool _isManualInhaleOn;
private async void Button_Click_8(object sender, RoutedEventArgs e)
=> fc.BtnClickFunctionForNew(Function.ButtonType., _HandInBreathUpAddress);
private async void Button_Click_9(object sender, RoutedEventArgs e)
=>fc.BtnClickFunctionForNew(Function.ButtonType., _HandInBreathDownAddress);
private async void Button_Click_10(object sender, RoutedEventArgs e)
{

View File

@@ -1,7 +1,7 @@
<Window x:Class="ShanghaiEnvironmentalTechnology.ParameterConfigWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="参数配置界面" Height="768" Width="1024"
Title="参数配置界面" WindowState="Maximized" Height="768" Width="1024"
WindowStartupLocation="CenterScreen"
Loaded="Window_Loaded"
Background="#F5F7FA">

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:oxy="http://oxyplot.org/wpf"
Title="{DynamicResource WatchData}" Height="768" Width="1204"
Title="{DynamicResource WatchData}" WindowState="Maximized" Height="768" Width="1024"
Loaded="Window_Loaded"
Background="#F0F2F5">

View File

@@ -5,7 +5,7 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:睡眠多功能"
mc:Ignorable="d"
Title="Window9" Height="450" Width="800">
Title="Window9" WindowState="Maximized" Height="768" Width="1024">
<Grid>
</Grid>

View File

@@ -2,7 +2,7 @@
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net8.0-windows8.0</TargetFramework>
<TargetFramework>net8.0-windows</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<UseWPF>true</UseWPF>

Binary file not shown.