更新图标
This commit is contained in:
@@ -22,6 +22,9 @@ namespace CSI_H238M
|
||||
|
||||
try
|
||||
{
|
||||
// 在應用啟動時設置 ScottPlot 的中文字體(必須最先執行)
|
||||
SetScottPlotChineseFont();
|
||||
|
||||
// 加載應用程序配置
|
||||
string configPath = AppConfig.GetDefaultConfigPath();
|
||||
_config = AppConfig.Load(configPath);
|
||||
@@ -47,6 +50,44 @@ namespace CSI_H238M
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 設置 ScottPlot 的中文字體
|
||||
/// </summary>
|
||||
private void SetScottPlotChineseFont()
|
||||
{
|
||||
try
|
||||
{
|
||||
// 使用 SkiaSharp 的字體管理器查找支持中文的字體
|
||||
var fontManager = SkiaSharp.SKFontManager.Default;
|
||||
|
||||
// 嘗試匹配一個中文字符來找到合適的字體
|
||||
var typeface = fontManager.MatchCharacter('中');
|
||||
if (typeface != null && !string.IsNullOrEmpty(typeface.FamilyName))
|
||||
{
|
||||
ScottPlot.Fonts.Default = typeface.FamilyName;
|
||||
System.Diagnostics.Debug.WriteLine($"[App] 使用系統中文字體: {typeface.FamilyName}");
|
||||
return;
|
||||
}
|
||||
|
||||
// 備選方案:嘗試常見的中文字體名稱
|
||||
var chineseFonts = new[] { "Microsoft YaHei", "SimHei", "SimSun" };
|
||||
foreach (var fontName in chineseFonts)
|
||||
{
|
||||
var tf = SkiaSharp.SKTypeface.FromFamilyName(fontName);
|
||||
if (tf != null)
|
||||
{
|
||||
ScottPlot.Fonts.Default = fontName;
|
||||
System.Diagnostics.Debug.WriteLine($"[App] 使用中文字體: {fontName}");
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
System.Diagnostics.Debug.WriteLine($"[App] 設置中文字體失敗: {ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 根據配置創建相應的數據採集服務
|
||||
/// </summary>
|
||||
|
||||
@@ -32,6 +32,8 @@ namespace COFTester.Resources
|
||||
["StartTest"] = "开始测试",
|
||||
["Stop"] = "停止",
|
||||
["ResetSystem"] = "重置系统",
|
||||
["Connect"] = "连接",
|
||||
["Disconnect"] = "断开",
|
||||
|
||||
// 左侧面板 - 测试参数
|
||||
["TestParameters"] = "测试参数",
|
||||
@@ -57,6 +59,7 @@ namespace COFTester.Resources
|
||||
// 右侧面板 - 统计信息
|
||||
["Statistics"] = "统计信息",
|
||||
["GroupStatistics"] = "成组统计",
|
||||
["CurrentTest"] = "当前测试",
|
||||
["AvgForce"] = "平均力值:",
|
||||
["TestTime"] = "测试时间:",
|
||||
["DataPoints"] = "数据点数:",
|
||||
@@ -67,6 +70,9 @@ namespace COFTester.Resources
|
||||
["Status"] = "状态:",
|
||||
["PLCConnected"] = "PLC: 已连接",
|
||||
["DataPointsCount"] = "数据点: {0}",
|
||||
["Connected"] = "已连接",
|
||||
["NotConnected"] = "未连接",
|
||||
["Connecting"] = "连接中...",
|
||||
|
||||
// 状态消息
|
||||
["SystemReady"] = "系统就绪",
|
||||
@@ -119,6 +125,8 @@ namespace COFTester.Resources
|
||||
["StartTest"] = "Start Test",
|
||||
["Stop"] = "Stop",
|
||||
["ResetSystem"] = "Reset System",
|
||||
["Connect"] = "Connect",
|
||||
["Disconnect"] = "Disconnect",
|
||||
|
||||
// Left Panel - Test Parameters
|
||||
["TestParameters"] = "Test Parameters",
|
||||
@@ -144,6 +152,7 @@ namespace COFTester.Resources
|
||||
// Right Panel - Statistics
|
||||
["Statistics"] = "Statistics",
|
||||
["GroupStatistics"] = "Group Statistics",
|
||||
["CurrentTest"] = "Current Test",
|
||||
["AvgForce"] = "Avg Force:",
|
||||
["TestTime"] = "Test Time:",
|
||||
["DataPoints"] = "Data Points:",
|
||||
@@ -154,6 +163,9 @@ namespace COFTester.Resources
|
||||
["Status"] = "Status:",
|
||||
["PLCConnected"] = "PLC: Connected",
|
||||
["DataPointsCount"] = "Data Points: {0}",
|
||||
["Connected"] = "Connected",
|
||||
["NotConnected"] = "Not Connected",
|
||||
["Connecting"] = "Connecting...",
|
||||
|
||||
// Status Messages
|
||||
["SystemReady"] = "System Ready",
|
||||
@@ -240,6 +252,12 @@ namespace COFTester.Resources
|
||||
public string Status => GetString("Status");
|
||||
public string PLCConnected => GetString("PLCConnected");
|
||||
public string DataPointsCount => GetString("DataPointsCount");
|
||||
public string Connected => GetString("Connected");
|
||||
public string NotConnected => GetString("NotConnected");
|
||||
public string Connecting => GetString("Connecting");
|
||||
public string Connect => GetString("Connect");
|
||||
public string Disconnect => GetString("Disconnect");
|
||||
public string CurrentTest => GetString("CurrentTest");
|
||||
public string SystemReady => GetString("SystemReady");
|
||||
public string Testing => GetString("Testing");
|
||||
public string TestStopped => GetString("TestStopped");
|
||||
@@ -325,6 +343,12 @@ namespace COFTester.Resources
|
||||
OnPropertyChanged(nameof(Status));
|
||||
OnPropertyChanged(nameof(PLCConnected));
|
||||
OnPropertyChanged(nameof(DataPointsCount));
|
||||
OnPropertyChanged(nameof(Connected));
|
||||
OnPropertyChanged(nameof(NotConnected));
|
||||
OnPropertyChanged(nameof(Connecting));
|
||||
OnPropertyChanged(nameof(Connect));
|
||||
OnPropertyChanged(nameof(Disconnect));
|
||||
OnPropertyChanged(nameof(CurrentTest));
|
||||
OnPropertyChanged(nameof(SystemReady));
|
||||
OnPropertyChanged(nameof(Testing));
|
||||
OnPropertyChanged(nameof(TestStopped));
|
||||
|
||||
@@ -107,7 +107,7 @@ namespace COFTester.ViewModels
|
||||
{
|
||||
_wpfPlot.Plot.Clear();
|
||||
|
||||
// 设置支持中文的字体
|
||||
// 设置支持中文的字体(必须在添加任何元素之前)
|
||||
SetChineseFont();
|
||||
|
||||
// 创建空的散点图
|
||||
@@ -116,7 +116,7 @@ namespace COFTester.ViewModels
|
||||
_scatterPlot.LineWidth = 2;
|
||||
_scatterPlot.MarkerSize = 0;
|
||||
|
||||
// 设置坐标轴标签
|
||||
// 设置坐标轴标签(使用已设置的中文字体)
|
||||
_wpfPlot.Plot.XLabel(Lang.DisplacementAxis);
|
||||
_wpfPlot.Plot.YLabel(Lang.ForceAxis);
|
||||
|
||||
@@ -138,24 +138,39 @@ namespace COFTester.ViewModels
|
||||
{
|
||||
try
|
||||
{
|
||||
// 尝试使用常见的中文字体
|
||||
// Windows 系统通常有这些字体:Microsoft YaHei, SimHei, SimSun
|
||||
var availableFonts = new[] { "Microsoft YaHei", "SimHei", "SimSun", "Arial Unicode MS" };
|
||||
// 方法1: 使用 SkiaSharp 的字体管理器查找支持中文的字体
|
||||
var fontManager = SkiaSharp.SKFontManager.Default;
|
||||
|
||||
foreach (var font in availableFonts)
|
||||
// 尝试匹配一个中文字符来找到合适的字体
|
||||
var typeface = fontManager.MatchCharacter('中');
|
||||
if (typeface != null && !string.IsNullOrEmpty(typeface.FamilyName))
|
||||
{
|
||||
try
|
||||
ScottPlot.Fonts.Default = typeface.FamilyName;
|
||||
System.Diagnostics.Debug.WriteLine($"使用系统中文字体: {typeface.FamilyName}");
|
||||
return;
|
||||
}
|
||||
|
||||
// 方法2: 尝试常见的中文字体名称
|
||||
var chineseFonts = new[]
|
||||
{
|
||||
"Microsoft YaHei", // 微软雅黑
|
||||
"SimHei", // 黑体
|
||||
"SimSun", // 宋体
|
||||
"Microsoft YaHei UI", // 微软雅黑 UI
|
||||
"DengXian", // 等线
|
||||
};
|
||||
|
||||
foreach (var fontName in chineseFonts)
|
||||
{
|
||||
var tf = SkiaSharp.SKTypeface.FromFamilyName(fontName);
|
||||
if (tf != null && tf.FamilyName == fontName)
|
||||
{
|
||||
_wpfPlot.Plot.Font.Set(font);
|
||||
return; // 成功设置字体后退出
|
||||
}
|
||||
catch
|
||||
{
|
||||
continue; // 尝试下一个字体
|
||||
ScottPlot.Fonts.Default = fontName;
|
||||
System.Diagnostics.Debug.WriteLine($"成功设置中文字体: {fontName}");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// 如果所有字体都失败,使用默认字体(可能显示方框)
|
||||
System.Diagnostics.Debug.WriteLine("警告:无法找到支持中文的字体");
|
||||
}
|
||||
catch (Exception ex)
|
||||
@@ -844,13 +859,16 @@ namespace COFTester.ViewModels
|
||||
}
|
||||
}
|
||||
|
||||
public event EventHandler? CanExecuteChanged;
|
||||
public event EventHandler? CanExecuteChanged
|
||||
{
|
||||
add { CommandManager.RequerySuggested += value; }
|
||||
remove { CommandManager.RequerySuggested -= value; }
|
||||
}
|
||||
|
||||
private void RaiseCanExecuteChanged()
|
||||
{
|
||||
Application.Current?.Dispatcher.InvokeAsync(() =>
|
||||
{
|
||||
CanExecuteChanged?.Invoke(this, EventArgs.Empty);
|
||||
CommandManager.InvalidateRequerySuggested();
|
||||
});
|
||||
}
|
||||
|
||||
@@ -151,7 +151,7 @@
|
||||
<ColumnDefinition Width="*"/>
|
||||
<ColumnDefinition Width="*"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<Button Grid.Column="0" Content="連接" Command="{Binding ConnectCommand}" Height="36" Foreground="White" FontSize="12" Margin="0,0,3,0">
|
||||
<Button Grid.Column="0" Content="{Binding Lang.Connect}" Command="{Binding ConnectCommand}" Height="36" Foreground="White" FontSize="12" Margin="0,0,3,0">
|
||||
<Button.Style>
|
||||
<Style TargetType="Button">
|
||||
<Setter Property="Background" Value="#27AE60"/>
|
||||
@@ -160,7 +160,7 @@
|
||||
</Style>
|
||||
</Button.Style>
|
||||
</Button>
|
||||
<Button Grid.Column="1" Content="斷開" Command="{Binding DisconnectCommand}" Height="36" Foreground="White" FontSize="12" Margin="3,0,0,0">
|
||||
<Button Grid.Column="1" Content="{Binding Lang.Disconnect}" Command="{Binding DisconnectCommand}" Height="36" Foreground="White" FontSize="12" Margin="3,0,0,0">
|
||||
<Button.Style>
|
||||
<Style TargetType="Button">
|
||||
<Setter Property="Background" Value="#95A5A6"/>
|
||||
@@ -308,7 +308,7 @@
|
||||
<!-- 标签页控件 -->
|
||||
<TabControl Background="Transparent" BorderThickness="0">
|
||||
<!-- 当前测试统计 -->
|
||||
<TabItem Header="当前测试">
|
||||
<TabItem Header="{Binding Lang.CurrentTest}">
|
||||
<Grid Margin="0,10,0,0">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto"/>
|
||||
@@ -379,15 +379,15 @@
|
||||
<TextBlock>
|
||||
<TextBlock.Style>
|
||||
<Style TargetType="TextBlock">
|
||||
<Setter Property="Text" Value="未連接"/>
|
||||
<Setter Property="Text" Value="{Binding Lang.NotConnected}"/>
|
||||
<Setter Property="Foreground" Value="#E74C3C"/>
|
||||
<Style.Triggers>
|
||||
<DataTrigger Binding="{Binding IsConnected}" Value="True">
|
||||
<Setter Property="Text" Value="已連接"/>
|
||||
<Setter Property="Text" Value="{Binding Lang.Connected}"/>
|
||||
<Setter Property="Foreground" Value="#27AE60"/>
|
||||
</DataTrigger>
|
||||
<DataTrigger Binding="{Binding IsConnecting}" Value="True">
|
||||
<Setter Property="Text" Value="連接中..."/>
|
||||
<Setter Property="Text" Value="{Binding Lang.Connecting}"/>
|
||||
<Setter Property="Foreground" Value="#F39C12"/>
|
||||
</DataTrigger>
|
||||
</Style.Triggers>
|
||||
|
||||
@@ -5,16 +5,42 @@
|
||||
"Port": 502,
|
||||
"SlaveId": 1,
|
||||
"Timeout": 3000,
|
||||
"ConnectTimeout": 5000,
|
||||
"ForceRegister": 0,
|
||||
"DisplacementRegister": 2,
|
||||
"ControlRegister": 10
|
||||
"ControlRegister": 10,
|
||||
"StatusRegister": 12,
|
||||
"RetryCount": 3,
|
||||
"RetryDelay": 500
|
||||
},
|
||||
"ModbusRtu": {
|
||||
"PortName": "COM1",
|
||||
"BaudRate": 9600,
|
||||
"DataBits": 8,
|
||||
"Parity": "None",
|
||||
"StopBits": "One",
|
||||
"SlaveId": 1,
|
||||
"Timeout": 3000,
|
||||
"ReadTimeout": 1000,
|
||||
"WriteTimeout": 1000,
|
||||
"ForceRegister": 0,
|
||||
"DisplacementRegister": 2,
|
||||
"ControlRegister": 10,
|
||||
"StatusRegister": 12,
|
||||
"RetryCount": 3,
|
||||
"RetryDelay": 500
|
||||
},
|
||||
"SerialPort": {
|
||||
"PortName": "COM1",
|
||||
"BaudRate": 9600,
|
||||
"DataBits": 8,
|
||||
"Parity": "None",
|
||||
"StopBits": "One"
|
||||
"StopBits": "One",
|
||||
"ReadTimeout": 1000,
|
||||
"WriteTimeout": 1000,
|
||||
"Handshake": "None",
|
||||
"DtrEnable": false,
|
||||
"RtsEnable": false
|
||||
},
|
||||
"DataStoragePath": "C:\\Users\\YourName\\Documents\\CSI-H238M\\TestData",
|
||||
"Language": "zh-TW",
|
||||
@@ -27,5 +53,12 @@
|
||||
"SamplingRate": 100.0,
|
||||
"MaterialType": "Plastic Film",
|
||||
"Operator": "Default"
|
||||
},
|
||||
"_comments": {
|
||||
"CommunicationMode": "可選值: Simulated, ModbusTCP, ModbusRTU, ModbusASCII, SerialPort",
|
||||
"ModbusTCP": "用於以太網連接的 PLC 或工業控制器",
|
||||
"ModbusRTU": "用於 RS485/RS232 串口 Modbus RTU 設備",
|
||||
"ModbusASCII": "用於 RS485/RS232 串口 Modbus ASCII 設備",
|
||||
"SerialPort": "用於直接串口通信(非 Modbus 協議)"
|
||||
}
|
||||
}
|
||||
|
||||
106
README.md
Normal file
106
README.md
Normal file
@@ -0,0 +1,106 @@
|
||||
# CSI-H238M 高精度摩擦係數測試儀上位機系統
|
||||
|
||||
## 項目簡介
|
||||
|
||||
CSI-H238M 是一款基於 **C# WPF** 技術開發的專業摩擦係數測試儀上位機系統,符合 **ASTM D1894**、**ISO 8295** 和 **GB 10006** 國際標準。系統採用 **MVVM** 設計模式,提供高精度、高響應性的測試界面。
|
||||
|
||||
## 主要特性
|
||||
|
||||
### ✨ 核心功能
|
||||
- 🎯 **實時數據採集**:支持最高 1000 Hz 採樣率
|
||||
- 📊 **動態曲線繪製**:基於 LiveCharts 的流暢圖表
|
||||
- 🧮 **自動計算**:靜摩擦係數(μs)和動摩擦係數(μk)
|
||||
- 💾 **數據存儲**:JSON 格式保存,支持 CSV 導出
|
||||
- 🔧 **多種通信**:支持模擬、Modbus TCP、串口通信
|
||||
|
||||
### 🎨 用戶界面
|
||||
- 🖥️ **12 吋觸控屏優化**:大按鈕、清晰顯示
|
||||
- 🇨🇳 **中文界面**:繁體中文本地化
|
||||
- 🎨 **工業風格**:專業、簡潔的設計
|
||||
- ⚡ **實時監控**:力值、位移、狀態實時更新
|
||||
|
||||
### 🔬 數據處理
|
||||
- 📈 **滑動平均濾波**:減少傳感器噪聲
|
||||
- 📉 **中值濾波**:抑制脈衝干擾
|
||||
- 🔍 **異常值檢測**:3-sigma 原則
|
||||
- 📐 **標準符合**:ASTM D1894、ISO 8295、GB 10006
|
||||
|
||||
## 快速開始
|
||||
|
||||
### 環境要求
|
||||
- Windows 10/11
|
||||
- .NET 8.0 SDK
|
||||
- Visual Studio 2022(可選)
|
||||
|
||||
### 安裝步驟
|
||||
|
||||
1. **克隆項目**
|
||||
```bash
|
||||
git clone https://github.com/your-repo/CSI-H238M.git
|
||||
cd CSI-H238M
|
||||
```
|
||||
|
||||
2. **還原依賴**
|
||||
```bash
|
||||
dotnet restore
|
||||
```
|
||||
|
||||
3. **編譯項目**
|
||||
```bash
|
||||
dotnet build
|
||||
```
|
||||
|
||||
4. **運行程序**
|
||||
```bash
|
||||
dotnet run --project CSI-H238M/CSI-H238M.csproj
|
||||
```
|
||||
|
||||
## 使用指南
|
||||
|
||||
詳細使用說明請參閱:[使用說明.md](CSI-H238M/使用說明.md)
|
||||
|
||||
## 項目結構
|
||||
|
||||
```
|
||||
CSI-H238M/
|
||||
├── Models/ # 數據模型
|
||||
│ ├── Model.cs # 核心數據結構
|
||||
│ └── AppConfig.cs # 配置管理
|
||||
├── Services/ # 業務服務
|
||||
│ ├── Services.cs # 數據處理和模擬
|
||||
│ ├── ModbusService.cs # Modbus 通信
|
||||
│ └── DataStorageService.cs # 數據存儲
|
||||
├── ViewModels/ # 視圖模型
|
||||
│ └── ViewModel.cs # 主視圖模型
|
||||
├── Views/ # 用戶界面
|
||||
│ ├── MainWindow.xaml # 主窗口 XAML
|
||||
│ └── MainWindow.xaml.cs # 主窗口代碼
|
||||
└── App.xaml.cs # 應用程序入口
|
||||
```
|
||||
|
||||
## 技術棧
|
||||
|
||||
- **框架**:.NET 8.0 + WPF
|
||||
- **設計模式**:MVVM
|
||||
- **圖表庫**:LiveCharts.Wpf 0.9.7
|
||||
- **數據格式**:JSON (System.Text.Json)
|
||||
- **通信協議**:Modbus TCP(可擴展)
|
||||
|
||||
## 更新日誌
|
||||
|
||||
### v1.0.0 (2026-01-13)
|
||||
- ✅ 初始版本發布
|
||||
- ✅ 支持模擬和 Modbus TCP 通信
|
||||
- ✅ 實現 ASTM D1894 和 ISO 8295 標準
|
||||
- ✅ 數據存儲和 CSV 導出
|
||||
- ✅ 中文界面
|
||||
|
||||
## 許可證
|
||||
|
||||
版權所有 © 2026 CSI Instruments. 保留所有權利。
|
||||
|
||||
## 聯繫方式
|
||||
|
||||
- 📧 技術支持:support@csi-instruments.com
|
||||
- 📚 文檔:https://docs.csi-instruments.com
|
||||
- 🌐 官網:https://www.csi-instruments.com
|
||||
Reference in New Issue
Block a user