diff --git a/Windows/CS/Framework4.0/Toprie/Toprie/Camera.Designer.cs b/Windows/CS/Framework4.0/Toprie/Toprie/Camera.Designer.cs
index c515207..72e2791 100644
--- a/Windows/CS/Framework4.0/Toprie/Toprie/Camera.Designer.cs
+++ b/Windows/CS/Framework4.0/Toprie/Toprie/Camera.Designer.cs
@@ -21,11 +21,6 @@ namespace JoyD.Windows.CS.Toprie
this.imageModeToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.thermalModeToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.visibleModeToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
- this.fusionMode1ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
- this.fusionMode2ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
- this.fusionMode3ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
- this.fusionMode4ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
- this.fusionMode5ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.colorModeToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.whiteHotToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.blackHotToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
@@ -44,6 +39,12 @@ namespace JoyD.Windows.CS.Toprie
this.toolStripSeparator1 = new System.Windows.Forms.ToolStripSeparator();
this.saveTemperatureToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.pauseDetectionToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
+ this.saveLogToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
+ this.fusionMode1ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
+ this.fusionMode2ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
+ this.fusionMode3ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
+ this.fusionMode4ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
+ this.fusionMode5ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
((System.ComponentModel.ISupportInitialize)(this.imageBox)).BeginInit();
this.contextMenuStrip1.SuspendLayout();
this.SuspendLayout();
@@ -58,12 +59,11 @@ namespace JoyD.Windows.CS.Toprie
this.imageBox.SizeMode = System.Windows.Forms.PictureBoxSizeMode.Zoom;
this.imageBox.TabIndex = 0;
this.imageBox.TabStop = false;
+ this.imageBox.DoubleClick += new System.EventHandler(this.ImageBox_DoubleClick);
//
// contextMenuStrip1
//
- // 初始化保存日志菜单项
- this.saveLogToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
-
+ this.contextMenuStrip1.ImageScalingSize = new System.Drawing.Size(20, 20);
this.contextMenuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.imageModeToolStripMenuItem,
this.colorModeToolStripMenuItem,
@@ -73,7 +73,7 @@ namespace JoyD.Windows.CS.Toprie
this.pauseDetectionToolStripMenuItem,
this.saveLogToolStripMenuItem});
this.contextMenuStrip1.Name = "contextMenuStrip1";
- this.contextMenuStrip1.Size = new System.Drawing.Size(161, 100);
+ this.contextMenuStrip1.Size = new System.Drawing.Size(139, 154);
//
// imageModeToolStripMenuItem
//
@@ -81,75 +81,23 @@ namespace JoyD.Windows.CS.Toprie
this.thermalModeToolStripMenuItem,
this.visibleModeToolStripMenuItem});
this.imageModeToolStripMenuItem.Name = "imageModeToolStripMenuItem";
- this.imageModeToolStripMenuItem.Size = new System.Drawing.Size(152, 22);
+ this.imageModeToolStripMenuItem.Size = new System.Drawing.Size(138, 24);
this.imageModeToolStripMenuItem.Text = "图像模式";
//
// thermalModeToolStripMenuItem
//
this.thermalModeToolStripMenuItem.Name = "thermalModeToolStripMenuItem";
- this.thermalModeToolStripMenuItem.Size = new System.Drawing.Size(152, 22);
+ this.thermalModeToolStripMenuItem.Size = new System.Drawing.Size(144, 26);
this.thermalModeToolStripMenuItem.Text = "红外模式";
this.thermalModeToolStripMenuItem.Click += new System.EventHandler(this.ThermalModeToolStripMenuItem_Click);
//
// visibleModeToolStripMenuItem
//
this.visibleModeToolStripMenuItem.Name = "visibleModeToolStripMenuItem";
- this.visibleModeToolStripMenuItem.Size = new System.Drawing.Size(152, 22);
+ this.visibleModeToolStripMenuItem.Size = new System.Drawing.Size(144, 26);
this.visibleModeToolStripMenuItem.Text = "自然模式";
this.visibleModeToolStripMenuItem.Click += new System.EventHandler(this.VisibleModeToolStripMenuItem_Click);
//
- // temperatureDisplayToolStripMenuItem
- //
- this.temperatureDisplayToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
- this.globalTemperatureToolStripMenuItem,
- this.areaTemperatureToolStripMenuItem,
- this.maxTemperatureToolStripMenuItem,
- this.avgTemperatureToolStripMenuItem,
- this.minTemperatureToolStripMenuItem});
- this.temperatureDisplayToolStripMenuItem.Name = "temperatureDisplayToolStripMenuItem";
- this.temperatureDisplayToolStripMenuItem.Size = new System.Drawing.Size(160, 22);
- this.temperatureDisplayToolStripMenuItem.Text = "温度显示";
- //
- // globalTemperatureToolStripMenuItem
- //
- this.globalTemperatureToolStripMenuItem.CheckOnClick = true;
- this.globalTemperatureToolStripMenuItem.Name = "globalTemperatureToolStripMenuItem";
- this.globalTemperatureToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
- this.globalTemperatureToolStripMenuItem.Text = "全局温度";
- this.globalTemperatureToolStripMenuItem.Click += new System.EventHandler(this.GlobalTemperatureToolStripMenuItem_Click);
- //
- // areaTemperatureToolStripMenuItem
- //
- this.areaTemperatureToolStripMenuItem.CheckOnClick = true;
- this.areaTemperatureToolStripMenuItem.Name = "areaTemperatureToolStripMenuItem";
- this.areaTemperatureToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
- this.areaTemperatureToolStripMenuItem.Text = "区域温度";
- this.areaTemperatureToolStripMenuItem.Click += new System.EventHandler(this.AreaTemperatureToolStripMenuItem_Click);
- //
- // maxTemperatureToolStripMenuItem
- //
- this.maxTemperatureToolStripMenuItem.CheckOnClick = true;
- this.maxTemperatureToolStripMenuItem.Name = "maxTemperatureToolStripMenuItem";
- this.maxTemperatureToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
- this.maxTemperatureToolStripMenuItem.Text = "最高温度";
- this.maxTemperatureToolStripMenuItem.Click += new System.EventHandler(this.MaxTemperatureToolStripMenuItem_Click);
- //
- // avgTemperatureToolStripMenuItem
- //
- this.avgTemperatureToolStripMenuItem.CheckOnClick = true;
- this.avgTemperatureToolStripMenuItem.Name = "avgTemperatureToolStripMenuItem";
- this.avgTemperatureToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
- this.avgTemperatureToolStripMenuItem.Text = "平均温度";
- this.avgTemperatureToolStripMenuItem.Click += new System.EventHandler(this.AvgTemperatureToolStripMenuItem_Click);
- //
- // minTemperatureToolStripMenuItem
- //
- this.minTemperatureToolStripMenuItem.CheckOnClick = true;
- this.minTemperatureToolStripMenuItem.Name = "minTemperatureToolStripMenuItem";
- this.minTemperatureToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
- this.minTemperatureToolStripMenuItem.Text = "最低温度";
- this.minTemperatureToolStripMenuItem.Click += new System.EventHandler(this.MinTemperatureToolStripMenuItem_Click);
- //
// colorModeToolStripMenuItem
//
this.colorModeToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
@@ -161,100 +109,174 @@ namespace JoyD.Windows.CS.Toprie
this.ironGrayToolStripMenuItem,
this.redHotToolStripMenuItem,
this.rainbow2ToolStripMenuItem});
- //
- // toolStripSeparator1
- //
- this.toolStripSeparator1.Name = "toolStripSeparator1";
- this.toolStripSeparator1.Size = new System.Drawing.Size(157, 6);
- //
- // saveTemperatureToolStripMenuItem
- //
- this.saveTemperatureToolStripMenuItem.Name = "saveTemperatureToolStripMenuItem";
- this.saveTemperatureToolStripMenuItem.Size = new System.Drawing.Size(160, 22);
- this.saveTemperatureToolStripMenuItem.Text = "保存温度";
- this.saveTemperatureToolStripMenuItem.Click += new System.EventHandler(this.SaveTemperatureToolStripMenuItem_Click);
- //
- // saveLogToolStripMenuItem
- //
- this.saveLogToolStripMenuItem.CheckOnClick = true;
- this.saveLogToolStripMenuItem.Name = "saveLogToolStripMenuItem";
- this.saveLogToolStripMenuItem.Size = new System.Drawing.Size(160, 22);
- this.saveLogToolStripMenuItem.Text = "保存日志";
- this.saveLogToolStripMenuItem.Click += new System.EventHandler(this.SaveLogToolStripMenuItem_Click);
- //
- // pauseDetectionToolStripMenuItem
- //
- this.pauseDetectionToolStripMenuItem.Name = "pauseDetectionToolStripMenuItem";
- this.pauseDetectionToolStripMenuItem.Size = new System.Drawing.Size(160, 22);
- this.pauseDetectionToolStripMenuItem.Text = "暂停检测";
- this.pauseDetectionToolStripMenuItem.Click += new System.EventHandler(this.PauseDetectionToolStripMenuItem_Click);
this.colorModeToolStripMenuItem.Name = "colorModeToolStripMenuItem";
- this.colorModeToolStripMenuItem.Size = new System.Drawing.Size(160, 22);
+ this.colorModeToolStripMenuItem.Size = new System.Drawing.Size(138, 24);
this.colorModeToolStripMenuItem.Text = "色彩模式";
//
- // rainbowToolStripMenuItem
- //
- this.rainbowToolStripMenuItem.Name = "rainbowToolStripMenuItem";
- this.rainbowToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
- this.rainbowToolStripMenuItem.Text = "彩虹";
- this.rainbowToolStripMenuItem.Click += new System.EventHandler(this.RainbowToolStripMenuItem_Click);
- //
- // ironRedToolStripMenuItem
- //
- this.ironRedToolStripMenuItem.Name = "ironRedToolStripMenuItem";
- this.ironRedToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
- this.ironRedToolStripMenuItem.Text = "铁红";
- this.ironRedToolStripMenuItem.Click += new System.EventHandler(this.IronRedToolStripMenuItem_Click);
- //
- // lavaToolStripMenuItem
- //
- this.lavaToolStripMenuItem.Name = "lavaToolStripMenuItem";
- this.lavaToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
- this.lavaToolStripMenuItem.Text = "熔岩";
- this.lavaToolStripMenuItem.Click += new System.EventHandler(this.LavaToolStripMenuItem_Click);
- //
- // ironGrayToolStripMenuItem
- //
- this.ironGrayToolStripMenuItem.Name = "ironGrayToolStripMenuItem";
- this.ironGrayToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
- this.ironGrayToolStripMenuItem.Text = "铁灰";
- this.ironGrayToolStripMenuItem.Click += new System.EventHandler(this.IronGrayToolStripMenuItem_Click);
- //
- // redHotToolStripMenuItem
- //
- this.redHotToolStripMenuItem.Name = "redHotToolStripMenuItem";
- this.redHotToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
- this.redHotToolStripMenuItem.Text = "红热";
- this.redHotToolStripMenuItem.Click += new System.EventHandler(this.RedHotToolStripMenuItem_Click);
- //
- // rainbow2ToolStripMenuItem
- //
- this.rainbow2ToolStripMenuItem.Name = "rainbow2ToolStripMenuItem";
- this.rainbow2ToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
- this.rainbow2ToolStripMenuItem.Text = "彩虹2";
- this.rainbow2ToolStripMenuItem.Click += new System.EventHandler(this.Rainbow2ToolStripMenuItem_Click);
- //
// whiteHotToolStripMenuItem
//
this.whiteHotToolStripMenuItem.Name = "whiteHotToolStripMenuItem";
- this.whiteHotToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
+ this.whiteHotToolStripMenuItem.Size = new System.Drawing.Size(123, 26);
this.whiteHotToolStripMenuItem.Text = "白热";
this.whiteHotToolStripMenuItem.Click += new System.EventHandler(this.WhiteHotToolStripMenuItem_Click);
//
// blackHotToolStripMenuItem
//
this.blackHotToolStripMenuItem.Name = "blackHotToolStripMenuItem";
- this.blackHotToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
+ this.blackHotToolStripMenuItem.Size = new System.Drawing.Size(123, 26);
this.blackHotToolStripMenuItem.Text = "黑热";
this.blackHotToolStripMenuItem.Click += new System.EventHandler(this.BlackHotToolStripMenuItem_Click);
//
- // 已移除蓝红菜单项(不在SDK的8种标准色板中)
+ // ironRedToolStripMenuItem
+ //
+ this.ironRedToolStripMenuItem.Name = "ironRedToolStripMenuItem";
+ this.ironRedToolStripMenuItem.Size = new System.Drawing.Size(123, 26);
+ this.ironRedToolStripMenuItem.Text = "铁红";
+ this.ironRedToolStripMenuItem.Click += new System.EventHandler(this.IronRedToolStripMenuItem_Click);
+ //
+ // lavaToolStripMenuItem
+ //
+ this.lavaToolStripMenuItem.Name = "lavaToolStripMenuItem";
+ this.lavaToolStripMenuItem.Size = new System.Drawing.Size(123, 26);
+ this.lavaToolStripMenuItem.Text = "熔岩";
+ this.lavaToolStripMenuItem.Click += new System.EventHandler(this.LavaToolStripMenuItem_Click);
+ //
+ // rainbowToolStripMenuItem
+ //
+ this.rainbowToolStripMenuItem.Name = "rainbowToolStripMenuItem";
+ this.rainbowToolStripMenuItem.Size = new System.Drawing.Size(123, 26);
+ this.rainbowToolStripMenuItem.Text = "彩虹";
+ this.rainbowToolStripMenuItem.Click += new System.EventHandler(this.RainbowToolStripMenuItem_Click);
+ //
+ // ironGrayToolStripMenuItem
+ //
+ this.ironGrayToolStripMenuItem.Name = "ironGrayToolStripMenuItem";
+ this.ironGrayToolStripMenuItem.Size = new System.Drawing.Size(123, 26);
+ this.ironGrayToolStripMenuItem.Text = "铁灰";
+ this.ironGrayToolStripMenuItem.Click += new System.EventHandler(this.IronGrayToolStripMenuItem_Click);
+ //
+ // redHotToolStripMenuItem
+ //
+ this.redHotToolStripMenuItem.Name = "redHotToolStripMenuItem";
+ this.redHotToolStripMenuItem.Size = new System.Drawing.Size(123, 26);
+ this.redHotToolStripMenuItem.Text = "红热";
+ this.redHotToolStripMenuItem.Click += new System.EventHandler(this.RedHotToolStripMenuItem_Click);
+ //
+ // rainbow2ToolStripMenuItem
+ //
+ this.rainbow2ToolStripMenuItem.Name = "rainbow2ToolStripMenuItem";
+ this.rainbow2ToolStripMenuItem.Size = new System.Drawing.Size(123, 26);
+ this.rainbow2ToolStripMenuItem.Text = "彩虹2";
+ this.rainbow2ToolStripMenuItem.Click += new System.EventHandler(this.Rainbow2ToolStripMenuItem_Click);
+ //
+ // temperatureDisplayToolStripMenuItem
+ //
+ this.temperatureDisplayToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
+ this.globalTemperatureToolStripMenuItem,
+ this.areaTemperatureToolStripMenuItem,
+ this.maxTemperatureToolStripMenuItem,
+ this.avgTemperatureToolStripMenuItem,
+ this.minTemperatureToolStripMenuItem});
+ this.temperatureDisplayToolStripMenuItem.Name = "temperatureDisplayToolStripMenuItem";
+ this.temperatureDisplayToolStripMenuItem.Size = new System.Drawing.Size(138, 24);
+ this.temperatureDisplayToolStripMenuItem.Text = "温度显示";
+ //
+ // globalTemperatureToolStripMenuItem
+ //
+ this.globalTemperatureToolStripMenuItem.CheckOnClick = true;
+ this.globalTemperatureToolStripMenuItem.Name = "globalTemperatureToolStripMenuItem";
+ this.globalTemperatureToolStripMenuItem.Size = new System.Drawing.Size(144, 26);
+ this.globalTemperatureToolStripMenuItem.Text = "全局温度";
+ this.globalTemperatureToolStripMenuItem.Click += new System.EventHandler(this.GlobalTemperatureToolStripMenuItem_Click);
+ //
+ // areaTemperatureToolStripMenuItem
+ //
+ this.areaTemperatureToolStripMenuItem.CheckOnClick = true;
+ this.areaTemperatureToolStripMenuItem.Name = "areaTemperatureToolStripMenuItem";
+ this.areaTemperatureToolStripMenuItem.Size = new System.Drawing.Size(144, 26);
+ this.areaTemperatureToolStripMenuItem.Text = "区域温度";
+ this.areaTemperatureToolStripMenuItem.Click += new System.EventHandler(this.AreaTemperatureToolStripMenuItem_Click);
+ //
+ // maxTemperatureToolStripMenuItem
+ //
+ this.maxTemperatureToolStripMenuItem.CheckOnClick = true;
+ this.maxTemperatureToolStripMenuItem.Name = "maxTemperatureToolStripMenuItem";
+ this.maxTemperatureToolStripMenuItem.Size = new System.Drawing.Size(144, 26);
+ this.maxTemperatureToolStripMenuItem.Text = "最高温度";
+ this.maxTemperatureToolStripMenuItem.Click += new System.EventHandler(this.MaxTemperatureToolStripMenuItem_Click);
+ //
+ // avgTemperatureToolStripMenuItem
+ //
+ this.avgTemperatureToolStripMenuItem.CheckOnClick = true;
+ this.avgTemperatureToolStripMenuItem.Name = "avgTemperatureToolStripMenuItem";
+ this.avgTemperatureToolStripMenuItem.Size = new System.Drawing.Size(144, 26);
+ this.avgTemperatureToolStripMenuItem.Text = "平均温度";
+ this.avgTemperatureToolStripMenuItem.Click += new System.EventHandler(this.AvgTemperatureToolStripMenuItem_Click);
+ //
+ // minTemperatureToolStripMenuItem
+ //
+ this.minTemperatureToolStripMenuItem.CheckOnClick = true;
+ this.minTemperatureToolStripMenuItem.Name = "minTemperatureToolStripMenuItem";
+ this.minTemperatureToolStripMenuItem.Size = new System.Drawing.Size(144, 26);
+ this.minTemperatureToolStripMenuItem.Text = "最低温度";
+ this.minTemperatureToolStripMenuItem.Click += new System.EventHandler(this.MinTemperatureToolStripMenuItem_Click);
+ //
+ // toolStripSeparator1
+ //
+ this.toolStripSeparator1.Name = "toolStripSeparator1";
+ this.toolStripSeparator1.Size = new System.Drawing.Size(135, 6);
+ //
+ // saveTemperatureToolStripMenuItem
+ //
+ this.saveTemperatureToolStripMenuItem.Name = "saveTemperatureToolStripMenuItem";
+ this.saveTemperatureToolStripMenuItem.Size = new System.Drawing.Size(138, 24);
+ this.saveTemperatureToolStripMenuItem.Text = "保存温度";
+ this.saveTemperatureToolStripMenuItem.Click += new System.EventHandler(this.SaveTemperatureToolStripMenuItem_Click);
+ //
+ // pauseDetectionToolStripMenuItem
+ //
+ this.pauseDetectionToolStripMenuItem.Name = "pauseDetectionToolStripMenuItem";
+ this.pauseDetectionToolStripMenuItem.Size = new System.Drawing.Size(138, 24);
+ this.pauseDetectionToolStripMenuItem.Text = "暂停检测";
+ this.pauseDetectionToolStripMenuItem.Click += new System.EventHandler(this.PauseDetectionToolStripMenuItem_Click);
+ //
+ // saveLogToolStripMenuItem
+ //
+ this.saveLogToolStripMenuItem.CheckOnClick = true;
+ this.saveLogToolStripMenuItem.Name = "saveLogToolStripMenuItem";
+ this.saveLogToolStripMenuItem.Size = new System.Drawing.Size(138, 24);
+ this.saveLogToolStripMenuItem.Text = "保存日志";
+ this.saveLogToolStripMenuItem.Click += new System.EventHandler(this.SaveLogToolStripMenuItem_Click);
+ //
+ // fusionMode1ToolStripMenuItem
+ //
+ this.fusionMode1ToolStripMenuItem.Name = "fusionMode1ToolStripMenuItem";
+ this.fusionMode1ToolStripMenuItem.Size = new System.Drawing.Size(32, 19);
+ //
+ // fusionMode2ToolStripMenuItem
+ //
+ this.fusionMode2ToolStripMenuItem.Name = "fusionMode2ToolStripMenuItem";
+ this.fusionMode2ToolStripMenuItem.Size = new System.Drawing.Size(32, 19);
+ //
+ // fusionMode3ToolStripMenuItem
+ //
+ this.fusionMode3ToolStripMenuItem.Name = "fusionMode3ToolStripMenuItem";
+ this.fusionMode3ToolStripMenuItem.Size = new System.Drawing.Size(32, 19);
+ //
+ // fusionMode4ToolStripMenuItem
+ //
+ this.fusionMode4ToolStripMenuItem.Name = "fusionMode4ToolStripMenuItem";
+ this.fusionMode4ToolStripMenuItem.Size = new System.Drawing.Size(32, 19);
+ //
+ // fusionMode5ToolStripMenuItem
+ //
+ this.fusionMode5ToolStripMenuItem.Name = "fusionMode5ToolStripMenuItem";
+ this.fusionMode5ToolStripMenuItem.Size = new System.Drawing.Size(32, 19);
//
// Camera
//
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 15F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
- // 添加imageBox
this.Controls.Add(this.imageBox);
this.Name = "Camera";
this.Size = new System.Drawing.Size(512, 384);
diff --git a/Windows/CS/Framework4.0/Toprie/Toprie/Camera.cs b/Windows/CS/Framework4.0/Toprie/Toprie/Camera.cs
index 607d9d7..88ce5e9 100644
--- a/Windows/CS/Framework4.0/Toprie/Toprie/Camera.cs
+++ b/Windows/CS/Framework4.0/Toprie/Toprie/Camera.cs
@@ -16,52 +16,52 @@ namespace JoyD.Windows.CS.Toprie
{
// 设备管理器实例
private DeviceManager _deviceManager;
-
+
// 是否正在接收图像
private bool _isReceivingImage = false;
-
+
// 全局图像缓冲区bitmap,用于在其上绘制图像和mask信息
private Bitmap _imageBuffer = null;
private const int BUFFER_WIDTH = 512;
private const int BUFFER_HEIGHT = 384;
-
+
// 最后接收的图像
private Image _lastImage = null;
-
+
// 信息图像,用于显示额外信息
private Image _infoImage = null;
-
+
// 实时信息图像,用于显示温度等实时数据
private Image _displayImage = null;
private readonly object _displayImageLock = new object();
-
+
// 最近一次获取到的温度数据
-
+
// 温度显示状态标志
private bool _showGlobalTemperature = false; // 是否显示全局温度
private bool _showAreaTemperature = false; // 是否显示区域温度
private bool _showMaxTemperature = false; // 是否显示最高温度(默认为false)
private bool _showAverageTemperature = false; // 是否显示平均温度
private bool _showMinTemperature = false; // 是否显示最低温度
-
+
// 日志保存状态标志
// 不再需要_saveLogEnabled字段,直接使用DeviceManager.LogToFile静态属性控制日志记录
-
+
// 用于保护_lastImage的线程锁
private readonly object _lastImageLock = new object();
-
+
// 用于保护_infoImage的线程锁
private readonly object _infoImageLock = new object();
-
+
// 是否显示信息图像
private bool _isDisplayingInfo = false;
-
+
// 是否暂停检测
private bool _isPaused = false;
-
+
// 项目路径,用于数据文件的存取
private string _projectPath = "";
-
+
///
/// 获取或设置项目路径,控件所需的数据文件将在此目录中进行存取
///
@@ -69,28 +69,28 @@ namespace JoyD.Windows.CS.Toprie
[Description("设置项目路径,控件所需的数据文件将在此目录中进行存取")]
[DefaultValue("")]
public string ProjectPath
- {
- get { return _projectPath; }
- set
- {
+ {
+ get { return _projectPath; }
+ set
+ {
// 只有当值发生变化时才进行同步
if (_projectPath != value)
- {
- _projectPath = value;
+ {
+ _projectPath = value;
// 如果DeviceManager已经初始化,则同步更新其ProjectPath属性
- if (_deviceManager != null)
- {
- _deviceManager.ProjectPath = _projectPath;
+ if (_deviceManager != null)
+ {
+ _deviceManager.ProjectPath = _projectPath;
}
}
}
}
-
+
///
/// 更新设计模式状态到DeviceManager
///
private void UpdateDesignModeStatus()
- {
+ {
DeviceManager.IsDesignMode = DesignMode;
Console.WriteLine($"相机控件设计模式状态已更新: {DesignMode}");
}
@@ -184,7 +184,7 @@ namespace JoyD.Windows.CS.Toprie
// 设置显示标志
_isDisplayingInfo = (isPaused || isDisconnected || isReconnecting || _showGlobalTemperature || _showAreaTemperature);
-
+
// 步骤3:无论就绪状态如何,都调用更新UI以显示状态信息
UpdateImageOnUI();
}
@@ -194,111 +194,111 @@ namespace JoyD.Windows.CS.Toprie
Console.WriteLine($"更新Info显示时出错: {ex.Message}");
}
}
-
+
///
/// 暂停/恢复检测菜单项点击事件处理
/// 1、暂停或恢复时,设置暂停状态,调用更新Info
///
private void PauseDetectionToolStripMenuItem_Click(object sender, EventArgs e)
- {
+ {
if (DesignMode) return;
-
+
try
- {
+ {
// 记录操作前的暂停状态
Console.WriteLine($"[PauseDetection] 操作前状态: _isPaused = {_isPaused}");
-
+
// 切换暂停状态
_isPaused = !_isPaused;
-
+
// 记录操作后的暂停状态
Console.WriteLine($"[PauseDetection] 操作后状态: _isPaused = {_isPaused}");
-
+
if (_isPaused)
- {
+ {
// 设置暂停状态
pauseDetectionToolStripMenuItem.Text = "恢复检测";
-
+
// 暂停时停止图像接收并更新DeviceManager的暂停检测状态
if (_deviceManager != null)
- {
+ {
_deviceManager.IsDetectionPaused = true;
-
+
if (_isReceivingImage)
- {
+ {
_deviceManager.StopImageReceiving();
_deviceManager.PauseTemperatureDataReceiving();
_isReceivingImage = false;
}
}
-
+
Console.WriteLine($"[PauseDetection] 检测已暂停 - DeviceManager状态更新完成,当前时间: {DateTime.Now.ToString("HH:mm:ss.fff")}");
}
else
- {
+ {
// 设置恢复状态
pauseDetectionToolStripMenuItem.Text = "暂停检测";
-
+
// 恢复时更新DeviceManager的暂停检测状态并重新开始图像接收
if (_deviceManager != null)
- {
+ {
_deviceManager.IsDetectionPaused = false;
-
+
if (_deviceManager.ConnectionStatus == ConnectionStatus.Connected)
- {
+ {
_deviceManager.StopImageReceiving();
_deviceManager.StartImageReceiving();
_deviceManager.ResumeTemperatureDataReceiving();
_isReceivingImage = true;
-
+
// 恢复检测后,启动连接检查以确保连接正常
_deviceManager.StartConnectionCheck();
}
// 如果当前是断开状态但启用了自动重连,尝试启动重连
else if (_deviceManager.AutoReconnectEnabled)
- {
+ {
_deviceManager.StartAutoReconnect();
}
}
-
+
Console.WriteLine($"[PauseDetection] 检测已恢复 - DeviceManager状态更新完成,连接状态: {_deviceManager?.ConnectionStatus}, 当前时间: {DateTime.Now.ToString("HH:mm:ss.fff")}");
}
-
+
// 修改流程第1点和第5点:暂停或恢复时,设置暂停状态,调用更新Info(在暂停状态下会显示暂停信息)
UpdateInfo();
-
+
// 保存菜单状态
SaveMenuConfig();
}
catch (Exception ex)
- {
+ {
Console.WriteLine($"处理暂停/恢复检测时出错: {ex.Message}");
}
}
-
+
public Camera()
- {
+ {
InitializeComponent();
-
+
// 为右键菜单添加Opening事件,用于在菜单显示前更新色彩模式的选中状态
this.contextMenuStrip1.Opening += ContextMenuStrip1_Opening;
-
+
// 初始化日志保存状态,确保与菜单项状态同步
// 直接使用DeviceManager.LogToFile静态属性控制日志记录,无需额外的_saveLogEnabled字段
saveLogToolStripMenuItem.Checked = DeviceManager.LogToFile;
-
+
// 将设计模式状态传递给DeviceManager
UpdateDesignModeStatus();
-
+
// 初始化图像缓冲区
InitializeImageBuffer();
-
+
// 加载保存的菜单配置
LoadMenuConfig();
-
+
// 初始化Ping定时器
_pingTimer = new System.Threading.Timer(PingTimer_Tick, null, Timeout.Infinite, Timeout.Infinite);
-
+
// 只有在非设计模式下才初始化设备管理器和错误定时器
if (!DesignMode)
{
@@ -322,7 +322,7 @@ namespace JoyD.Windows.CS.Toprie
InitializeDeviceManager();
}
}
-
+
///
/// Camera控件加载事件
/// 在控件加载时自动启动相机显示热图
@@ -349,103 +349,103 @@ namespace JoyD.Windows.CS.Toprie
/// 初始化设备管理器
///
private void InitializeDeviceManager()
- {
+ {
// 只有在非设计模式下才初始化设备管理器
if (!DesignMode)
- {
+ {
_deviceManager = new DeviceManager
- {
+ {
AutoReconnectEnabled = true,
ReconnectInterval = 2000, // 2秒
ProjectPath = !string.IsNullOrEmpty(ProjectPath) ? ProjectPath : Application.StartupPath
};
-
+
// 设置静态属性
DeviceManager.MaxReconnectAttempts = 5;
-
+
// 注册图像接收事件
_deviceManager.ImageReceived += DeviceManager_ImageReceived;
-
+
// 注册连接状态变更事件
_deviceManager.ConnectionStatusChanged += DeviceManager_ConnectionStatusChanged;
-
+
// 注册连接异常事件
_deviceManager.ConnectionException += DeviceManager_ConnectionException;
-
+
// 不再需要温度数据实时通知,移除事件订阅
}
}
-
+
///
/// 初始化图像缓冲区和相关图像资源
///
private void InitializeImageBuffer()
- {
+ {
try
- {
+ {
// 创建512*384大小的透明bitmap作为图像缓冲区
_imageBuffer = new Bitmap(BUFFER_WIDTH, BUFFER_HEIGHT);
Console.WriteLine($"图像缓冲区已初始化: {BUFFER_WIDTH}x{BUFFER_HEIGHT}");
-
+
// 初始化缓冲区为黑色背景
using (Graphics g = Graphics.FromImage(_imageBuffer))
- {
+ {
g.Clear(Color.Black);
}
-
+
// 初始化InfoImage为透明bitmap
lock (_infoImageLock)
- {
+ {
_infoImage = new Bitmap(BUFFER_WIDTH, BUFFER_HEIGHT);
using (Graphics g = Graphics.FromImage(_infoImage))
- {
+ {
g.Clear(Color.Transparent);
}
Console.WriteLine("InfoImage已初始化为透明bitmap");
}
-
+
// 初始化DisplayImage为透明bitmap
lock (_displayImageLock)
- {
+ {
_displayImage = new Bitmap(BUFFER_WIDTH, BUFFER_HEIGHT);
using (Graphics g = Graphics.FromImage(_displayImage))
- {
+ {
g.Clear(Color.Transparent);
}
Console.WriteLine("DisplayImage已初始化为透明bitmap");
}
-
+
// 初始化图像框的bitmap为透明
if (imageBox != null && !imageBox.IsDisposed)
- {
+ {
imageBox.Image = new Bitmap(BUFFER_WIDTH, BUFFER_HEIGHT);
using (Graphics g = Graphics.FromImage(imageBox.Image))
- {
+ {
g.Clear(Color.Transparent);
}
Console.WriteLine("图像框bitmap已初始化为透明");
}
}
catch (Exception ex)
- {
+ {
Console.WriteLine($"初始化图像资源失败: {ex.Message}");
// 发生异常时释放已创建的资源
if (_imageBuffer != null)
- {
+ {
_imageBuffer.Dispose();
_imageBuffer = null;
}
lock (_infoImageLock)
- {
+ {
if (_infoImage != null)
- {
+ {
_infoImage.Dispose();
_infoImage = null;
}
}
}
}
-
+
@@ -453,7 +453,7 @@ namespace JoyD.Windows.CS.Toprie
/// 启动相机
///
public void StartCamera()
- {
+ {
// 启动设备Ping
StartDevicePing();
if (DesignMode) return;
@@ -464,7 +464,7 @@ namespace JoyD.Windows.CS.Toprie
{
// 清理错误显示
ShowError(string.Empty);
-
+
// 使用异步方式连接设备和设置模式,避免UI线程阻塞
ThreadPool.QueueUserWorkItem(delegate
{
@@ -472,15 +472,15 @@ namespace JoyD.Windows.CS.Toprie
{
// 设置为热图模式
bool modeSet = false;
-
+
// 启用自动重连
_deviceManager.AutoReconnectEnabled = true;
-
+
// 尝试连接设备
if (_deviceManager.ConnectDevice())
{
Console.WriteLine("设备连接成功");
-
+
// 如果热图模式未成功设置,在连接成功后再次尝试
if (!modeSet)
{
@@ -494,7 +494,7 @@ namespace JoyD.Windows.CS.Toprie
Console.WriteLine($"连接后设置热图模式失败: {ex.Message}");
}
}
-
+
// 在连接成功后开始接收图像
this.Invoke(new Action(() =>
{
@@ -522,7 +522,7 @@ namespace JoyD.Windows.CS.Toprie
Console.WriteLine(ex.StackTrace);
}
});
-
+
Console.WriteLine("相机启动流程已开始");
}
else
@@ -553,7 +553,7 @@ namespace JoyD.Windows.CS.Toprie
WriteLog("开始使用HTTP方式接收图像");
// 直接调用HTTP方式的图像接收
_deviceManager.StartImageReceiving();
-
+
// 不再需要温度数据实时通知机制,移除相关代码
_isReceivingImage = true;
WriteLog("图像接收已启动");
@@ -570,7 +570,7 @@ namespace JoyD.Windows.CS.Toprie
/// 停止接收图像
///
public void StopCamera()
- {
+ {
// 停止设备Ping
StopDevicePing();
if (DesignMode) return;
@@ -589,22 +589,22 @@ namespace JoyD.Windows.CS.Toprie
}
// 温度数据相关变量已移除,不再需要温度数据实时通知机制
-
+
// Ping相关字段
private System.Threading.Timer _pingTimer;
private bool _isDevicePingable = false;
private const int _pingInterval = 500; // 0.5秒Ping一次
-
+
///
/// 获取设备是否可Ping通
///
public bool IsDevicePingable
- {
+ {
get { return _isDevicePingable; }
private set
- {
+ {
if (_isDevicePingable != value)
- {
+ {
_isDevicePingable = value;
Console.WriteLine($"设备Ping状态变更: {(_isDevicePingable ? "可Ping通" : "不可Ping通")}");
// 按照README中要求的修改流程第3点和第6点:Ping通状态变化时,只在非暂停状态下调用更新Info
@@ -615,65 +615,65 @@ namespace JoyD.Windows.CS.Toprie
}
}
}
-
+
///
/// 设备管理器图像接收事件处理
///
private void DeviceManager_ImageReceived(object sender, ImageReceivedEventArgs e)
- {
+ {
if (DesignMode) return;
-
+
try
- {
+ {
if (e.ImageData != null && e.ImageData.Length > 0)
- {
+ {
// 创建内存流并从流中创建图像
using (MemoryStream ms = new MemoryStream(e.ImageData))
- {
+ {
// 检查流是否可读且有效
if (ms.CanRead && ms.Length > 0)
- {
+ {
// 从流中创建图像
using (Image newImage = System.Drawing.Image.FromStream(ms))
{
// 立即验证新创建的图像是否有效
try
- {
+ {
// 访问Width和Height属性来验证图像是否有效
int width = newImage.Width;
int height = newImage.Height;
if (width <= 0 || height <= 0)
- {
+ {
Console.WriteLine("创建的图像尺寸无效");
return;
}
if (_lastImage == null) _lastImage = new Bitmap(newImage);
else
{
- using(Graphics g= Graphics.FromImage(_lastImage))
+ using (Graphics g = Graphics.FromImage(_lastImage))
{
- g.DrawImage(newImage,Point.Empty);
+ g.DrawImage(newImage, Point.Empty);
}
}
}
catch (Exception)
- {
+ {
Console.WriteLine("创建的图像无效");
return;
}
-
+
// 按照README中要求:图像更新时,保存LastImage,调用更新UI,不调用更新Info
this.BeginInvoke(new Action(() =>
- {
+ {
try
- {
+ {
if (!_isPaused)
- {
+ {
UpdateImageOnUI(); // 只调用更新UI,不调用更新Info
}
}
catch (Exception ex)
- {
+ {
Console.WriteLine($"更新UI图像失败: {ex.Message}");
}
}));
@@ -683,13 +683,13 @@ namespace JoyD.Windows.CS.Toprie
}
}
catch (Exception ex)
- {
+ {
Console.WriteLine($"处理接收到的图像时出错: {ex.Message}");
}
}
-
+
///
/// 在UI线程上更新图像 - 新实现,按照用户要求:
/// 1. 先将LastImage绘制到全局缓冲
@@ -697,30 +697,30 @@ namespace JoyD.Windows.CS.Toprie
/// 3. 最后一次性绘制到图像框的bitmap
///
private void UpdateImageOnUI()
- {
+ {
if (DesignMode) return;
-
+
// 线程安全检查 - 确保在UI线程上执行
if (this.InvokeRequired)
- {
+ {
try
- {
+ {
this.BeginInvoke(new Action(UpdateImageOnUI));
}
catch (ObjectDisposedException)
- {
+ {
Console.WriteLine("控件已释放,跳过UI更新");
}
return;
}
-
+
// 一次性控件有效性检查,避免重复检查
if (this.IsDisposed || imageBox == null || imageBox.IsDisposed)
- {
+ {
Console.WriteLine("控件已释放,无法更新图像");
return;
}
-
+
// 调用温度显示更新方法
// 在就绪条件下,调用更新实时信息
bool isReady = !_isPaused && IsDevicePingable && _deviceManager != null && _deviceManager.ConnectionStatus == ConnectionStatus.Connected;
@@ -728,83 +728,83 @@ namespace JoyD.Windows.CS.Toprie
{
UpdateRealTimeInfoOnUI();
}
-
+
Image lastImage = null;
Image infoImage = null;
Image oldImage = null;
Bitmap tempImage = null;
-
+
try
- {
+ {
// 检查图像缓冲区是否有效
if (_imageBuffer == null)
- {
+ {
Console.WriteLine("图像缓冲区未初始化,尝试重新初始化");
InitializeImageBuffer();
if (_imageBuffer == null)
- {
+ {
Console.WriteLine("重新初始化图像缓冲区失败");
return;
}
}
-
+
// 保存旧图像引用,以便在设置新图像后释放
oldImage = imageBox.Image;
-
+
// 获取当前的LastImage引用
lock (_lastImageLock)
- {
+ {
if (_lastImage != null)
- {
+ {
lastImage = (Image)_lastImage.Clone();
}
}
-
+
// 获取当前的InfoImage引用
lock (_infoImageLock)
- {
+ {
if (_infoImage != null)
- {
+ {
infoImage = (Image)_infoImage.Clone();
}
}
-
+
// 合并锁定,减少锁的数量,提高性能
lock (_imageBuffer)
- {
+ {
using (Graphics g = Graphics.FromImage(_imageBuffer))
- {
+ {
// 清除缓冲区背景为黑色
g.Clear(Color.Black);
-
+
// 步骤1:先将LastImage绘制到全局缓冲
if (lastImage != null)
- {
+ {
// 保持原始图像比例,居中显示
float scale = Math.Min((float)BUFFER_WIDTH / lastImage.Width, (float)BUFFER_HEIGHT / lastImage.Height);
int scaledWidth = (int)(lastImage.Width * scale);
int scaledHeight = (int)(lastImage.Height * scale);
int x = (BUFFER_WIDTH - scaledWidth) / 2;
int y = (BUFFER_HEIGHT - scaledHeight) / 2;
-
+
g.DrawImage(lastImage, x, y, scaledWidth, scaledHeight);
}
-
+
// 步骤2:再将InfoImage绘制到缓冲
if (infoImage != null)
- {
+ {
g.DrawImage(infoImage, 0, 0);
}
else if (_isDisplayingInfo)
- {
+ {
// 如果没有InfoImage但需要显示信息,则绘制默认信息
using (Font font = new Font("微软雅黑", 12, FontStyle.Bold))
using (Brush textBrush = new SolidBrush(Color.Red))
- {
+ {
g.DrawString("测试信息", font, textBrush, 10, 10);
}
}
-
+
// 步骤2.1:绘制DisplayImage(实时温度信息等) - 仅在就绪条件下执行
if (isReady)
{
@@ -816,18 +816,18 @@ namespace JoyD.Windows.CS.Toprie
}
}
}
-
+
// 注意:温度信息不再直接在这里绘制
// 而是在UpdateRealTimeInfoOnUI方法中绘制到_displayImage,然后在这里绘制到_imageBuffer
}
-
+
// 在同一个锁内创建缓冲区的副本,避免重复锁定
tempImage = (Bitmap)_imageBuffer.Clone();
}
-
+
// 将全局缓冲一次性绘制到图像框的bitmap
imageBox.Image = tempImage;
-
+
// 步骤5:同步更新检测配置窗口的实时图像属性
// 创建LastImage的副本并通过UpdateRealTimeImage方法传递给Setting窗口
lock (_lastImageLock)
@@ -840,55 +840,55 @@ namespace JoyD.Windows.CS.Toprie
Setting.Form.UpdateRealTimeImage(lastImageCopy);
}
}
-
+
if (lastImage != null)
- {
+ {
Console.WriteLine($"图像更新成功: {lastImage.Width}x{lastImage.Height}");
}
}
catch (ArgumentException ex) when (ex.Message.Contains("参数无效"))
- {
+ {
// 特别处理"参数无效"异常
Console.WriteLine($"图像参数无效异常: {ex.Message}");
-
+
// 尝试设置旧图像回来,不需要再次检查控件状态(已在方法开始处检查)
if (oldImage != null)
- {
+ {
try
- {
+ {
imageBox.Image = oldImage;
}
catch
- {
+ {
// 如果设置旧图像也失败,释放它
DisposeImage(oldImage);
}
}
}
catch (Exception ex)
- {
+ {
Console.WriteLine($"更新图像UI异常: {ex.Message}");
}
finally
- {
+ {
// 确保在任何情况下都释放资源
DisposeImage(lastImage);
DisposeImage(infoImage);
// 只有当旧图像不再被使用时才释放
if (oldImage != null && oldImage != imageBox.Image)
- {
+ {
DisposeImage(oldImage);
}
}
}
-
+
///
/// 安全释放图像资源的辅助方法
///
private void DisposeImage(Image image)
- {
+ {
if (image != null)
- {
+ {
try { image.Dispose(); } catch { }
}
}
@@ -901,68 +901,68 @@ namespace JoyD.Windows.CS.Toprie
if (DesignMode) return;
// 参数验证
if (e == null)
- {
+ {
Console.WriteLine($"[{DateTime.Now:HH:mm:ss.fff}] 警告: 接收到空的连接状态变更事件参数");
return;
}
-
+
Console.WriteLine($"[{DateTime.Now:HH:mm:ss.fff}] [线程:{Thread.CurrentThread.ManagedThreadId}] 接收连接状态变更事件: {e.Status}");
-
+
// 捕获所有可能的异常,确保事件处理器不会崩溃
try
- {
+ {
// 首先检查控件状态
if (this.IsDisposed || this.Disposing)
- {
+ {
Console.WriteLine($"[{DateTime.Now:HH:mm:ss.fff}] 控件已释放或正在释放,跳过UI更新");
return;
}
-
+
// 检查事件参数中的状态信息
string statusMessage = $"连接状态变更为: {e.Status}";
if (!string.IsNullOrEmpty(e.DeviceInfo))
- {
- statusMessage += $" (设备信息: {e.DeviceInfo})";
+ {
+ statusMessage += $" (设备信息: {e.DeviceInfo})";
}
-
+
// 线程安全处理 - 确保在UI线程上更新
if (this.InvokeRequired)
- {
+ {
try
- {
+ {
// 使用BeginInvoke代替Invoke,避免可能的死锁问题
- this.BeginInvoke(new Action(args =>
- {
+ this.BeginInvoke(new Action(args =>
+ {
// 再次检查控件状态,防止在异步调用期间控件被释放
if (!this.IsDisposed && !this.Disposing)
- {
+ {
HandleConnectionStatusChanged(args);
}
else
- {
+ {
Console.WriteLine($"[{DateTime.Now:HH:mm:ss.fff}] 异步调用期间控件已释放,跳过处理");
}
}), e);
}
catch (ObjectDisposedException ode)
- {
+ {
// 捕获控件已释放异常,避免程序崩溃
Console.WriteLine($"[{DateTime.Now:HH:mm:ss.fff}] 控件已释放,无法进行UI线程调用: {ode.Message}");
}
catch (InvalidOperationException ioe)
- {
+ {
// 捕获无效操作异常,通常发生在控件状态异常时
Console.WriteLine($"[{DateTime.Now:HH:mm:ss.fff}] UI线程调用无效: {ioe.Message}");
}
}
else
- {
+ {
// 直接在UI线程上处理
HandleConnectionStatusChanged(e);
}
}
catch (Exception ex)
- {
+ {
// 捕获所有其他异常,记录并继续
Console.WriteLine($"[{DateTime.Now:HH:mm:ss.fff}] 处理连接状态变更事件异常: {ex.Message}\n{ex.StackTrace}");
}
@@ -986,7 +986,7 @@ namespace JoyD.Windows.CS.Toprie
// 更新UI状态
UpdateUIState(e.Status == ConnectionStatus.Connected);
-
+
// 检查_deviceManager是否为空
if (_deviceManager == null)
{
@@ -994,64 +994,64 @@ namespace JoyD.Windows.CS.Toprie
WriteLog("设备管理器未初始化");
return;
}
-
+
// 记录连接状态变化
WriteLog($"连接状态变化: {e.Status} {(!string.IsNullOrEmpty(e.DeviceInfo) ? "- " + e.DeviceInfo : "")}");
-
+
switch (e.Status)
{
case ConnectionStatus.Connected:
Console.WriteLine("设备已连接");
WriteLog("设备已连接成功");
-
+
// 仅在首次连接时设置为热图模式,重连时保留之前的模式
if (!_isReceivingImage) // 首次连接时_isReceivingImage为false
- {
+ {
try
- {
+ {
_deviceManager.SetImageMode(ImageMode.Infrared);
Console.WriteLine("首次连接,设置热图模式");
WriteLog("首次连接,设置热图模式");
}
catch (Exception ex)
- {
+ {
Console.WriteLine($"设置热图模式失败: {ex.Message}");
WriteLog($"设置热图模式失败: {ex.Message}");
}
}
else
- {
+ {
Console.WriteLine("重连成功,保留当前图像模式");
WriteLog("重连成功,保留当前图像模式");
}
-
+
// 注意:色彩模式同步现在在DeviceManager内部的连接成功处理中自动完成
// 无需在此处重复调用
-
+
// 开始接收图像(包含在try-catch中)
if (!_isReceivingImage)
- {
+ {
try
- {
+ {
StartReceiveImage();
}
catch (Exception ex)
- {
+ {
Console.WriteLine($"开始接收图像失败: {ex.Message}");
WriteLog($"开始接收图像失败: {ex.Message}");
}
}
-
+
// 按照README中要求的修改流程第2点和第5点:断开或连接时,设置连接状态,只在非暂停状态下调用更新Info
if (!_isPaused)
- {
+ {
UpdateInfo();
}
break;
case ConnectionStatus.Disconnected:
Console.WriteLine("设备已断开连接");
WriteLog("设备连接已断开");
-
+
// 停止接收图像(添加空检查和异常处理)
if (_isReceivingImage)
{
@@ -1067,21 +1067,21 @@ namespace JoyD.Windows.CS.Toprie
_isReceivingImage = false; // 确保状态更新
}
}
-
-
+
+
// 按照README中要求的修改流程第2点和第5点:断开或连接时,设置连接状态,只在非暂停状态下调用更新Info
if (!_isPaused)
- {
+ {
UpdateInfo();
}
-
+
if (!string.IsNullOrEmpty(e.DeviceInfo))
{
ShowError(e.DeviceInfo);
WriteLog($"断开原因: {e.DeviceInfo}");
- }
- else
+ }
+ else
{
ShowError("设备连接已断开");
WriteLog("设备连接已断开");
@@ -1096,10 +1096,10 @@ namespace JoyD.Windows.CS.Toprie
Console.WriteLine($"正在重新连接设备...{(!string.IsNullOrEmpty(e.DeviceInfo) ? " " + e.DeviceInfo : "")}");
WriteLog($"正在重新连接设备...{(!string.IsNullOrEmpty(e.DeviceInfo) ? " " + e.DeviceInfo : "")}");
ShowError(string.Empty); // 清除之前的错误信息
-
+
// 按照README中要求的修改流程第2点和第6点:连接状态变化时,只在非暂停状态下调用更新Info
if (!_isPaused)
- {
+ {
UpdateInfo();
}
break;
@@ -1114,10 +1114,10 @@ namespace JoyD.Windows.CS.Toprie
ShowError($"连接状态处理错误: {ex.Message}");
}
catch
- {}
+ { }
}
}
-
+
///
/// 更新UI状态
///
@@ -1139,7 +1139,7 @@ namespace JoyD.Windows.CS.Toprie
imageBox.BorderStyle = BorderStyle.Fixed3D;
}
}
-
+
// 更新图像框的边框颜色,提供视觉反馈
if (imageBox != null)
{
@@ -1154,7 +1154,7 @@ namespace JoyD.Windows.CS.Toprie
imageBox.BackColor = Color.LightGray;
}
}
-
+
Console.WriteLine($"UI状态已更新为: {(isConnected ? "已连接" : "未连接")}");
}
catch (Exception ex)
@@ -1171,88 +1171,88 @@ namespace JoyD.Windows.CS.Toprie
if (DesignMode) return;
// 参数验证
if (e == null)
- {
+ {
Console.WriteLine($"[{DateTime.Now:HH:mm:ss.fff}] 警告: 接收到空的连接异常事件参数");
return;
}
-
+
// 记录详细的异常信息,但避免在UI线程上执行耗时操作
string exceptionMessage = e.Exception != null ? e.Exception.Message : "无详细异常信息";
string stackTrace = e.Exception != null ? e.Exception.StackTrace : "无堆栈信息";
Console.WriteLine($"[{DateTime.Now:HH:mm:ss.fff}] [线程:{Thread.CurrentThread.ManagedThreadId}] 接收连接异常事件: {e.Message}\n{exceptionMessage}\n{stackTrace}");
-
+
// 捕获所有可能的异常,确保异常处理不会导致程序崩溃
try
- {
+ {
// 首先检查控件状态
if (this.IsDisposed || this.Disposing)
- {
+ {
Console.WriteLine($"[{DateTime.Now:HH:mm:ss.fff}] 控件已释放或正在释放,跳过异常显示");
return;
}
-
+
// 创建用于UI显示的错误消息
string uiErrorMessage = $"连接异常: {e.Message}";
if (string.IsNullOrEmpty(e.Message) && e.Exception != null)
- {
+ {
uiErrorMessage = $"连接异常: {exceptionMessage}";
}
-
+
// 线程安全处理 - 确保在UI线程上更新
if (this.InvokeRequired)
- {
+ {
try
- {
+ {
// 创建局部变量保存错误消息,避免闭包问题
string errorMsg = uiErrorMessage;
-
+
// 使用BeginInvoke代替Invoke,避免可能的死锁问题
- this.BeginInvoke(new Action(() =>
+ this.BeginInvoke(new Action(() =>
{
// 再次检查控件状态,防止在异步调用期间控件被释放
if (!this.IsDisposed && !this.Disposing)
- {
+ {
try
- {
+ {
ShowError(errorMsg);
}
catch (Exception showEx)
- {
+ {
Console.WriteLine($"[{DateTime.Now:HH:mm:ss.fff}] 显示错误消息异常: {showEx.Message}");
}
}
else
- {
+ {
Console.WriteLine($"[{DateTime.Now:HH:mm:ss.fff}] 异步调用期间控件已释放,跳过错误显示");
}
}));
}
catch (ObjectDisposedException ode)
- {
+ {
// 捕获控件已释放异常,避免程序崩溃
Console.WriteLine($"[{DateTime.Now:HH:mm:ss.fff}] 控件已释放,无法进行UI线程调用: {ode.Message}");
}
catch (InvalidOperationException ioe)
- {
+ {
// 捕获无效操作异常,通常发生在控件状态异常时
Console.WriteLine($"[{DateTime.Now:HH:mm:ss.fff}] UI线程调用无效: {ioe.Message}");
}
}
else
- {
+ {
// 直接在UI线程上处理
try
- {
+ {
ShowError(uiErrorMessage);
}
catch (Exception showEx)
- {
+ {
Console.WriteLine($"[{DateTime.Now:HH:mm:ss.fff}] 显示错误消息异常: {showEx.Message}");
}
}
}
catch (Exception ex)
- {
+ {
// 捕获所有其他异常,记录并继续
Console.WriteLine($"[{DateTime.Now:HH:mm:ss.fff}] 处理连接异常事件异常: {ex.Message}\n{ex.StackTrace}");
}
@@ -1290,7 +1290,7 @@ namespace JoyD.Windows.CS.Toprie
{
// 检查是否处于暂停状态
bool isPaused = pauseDetectionToolStripMenuItem.Text == "恢复检测";
-
+
// 检查设备是否已连接
bool isConnected = _deviceManager != null && _deviceManager.ConnectionStatus == ConnectionStatus.Connected;
@@ -1305,11 +1305,11 @@ namespace JoyD.Windows.CS.Toprie
// 隐藏图像模式根菜单
if (imageModeToolStripMenuItem != null)
imageModeToolStripMenuItem.Visible = false;
-
+
// 隐藏色彩模式菜单
colorModeToolStripMenuItem.Visible = false;
saveTemperatureToolStripMenuItem.Visible = false;
-
+
// 在暂停状态下隐藏温度显示根菜单
temperatureDisplayToolStripMenuItem.Visible = false;
@@ -1320,15 +1320,15 @@ namespace JoyD.Windows.CS.Toprie
{
// 在非暂停状态且已连接状态下,显示图像模式根菜单
// 注意:根菜单显示后,其所有子菜单会自动显示,不需要单独设置
-
+
// 只在红外模式下显示温度显示根菜单
temperatureDisplayToolStripMenuItem.Visible = isInfraredMode;
if (imageModeToolStripMenuItem != null)
imageModeToolStripMenuItem.Visible = true;
-
+
// 在非暂停状态且已连接状态下,显示分隔符
toolStripSeparator1.Visible = true;
-
+
// 根据当前图像模式控制色彩模式菜单的可见性
// 只有在红外模式下才显示色彩模式菜单和保存温度菜单
// 清除视频模式菜单项的选中状态
@@ -1339,7 +1339,7 @@ namespace JoyD.Windows.CS.Toprie
fusionMode3ToolStripMenuItem.Checked = false;
fusionMode4ToolStripMenuItem.Checked = false;
fusionMode5ToolStripMenuItem.Checked = false;
-
+
// 清除色彩模式菜单项的选中状态
whiteHotToolStripMenuItem.Checked = false;
blackHotToolStripMenuItem.Checked = false;
@@ -1349,7 +1349,7 @@ namespace JoyD.Windows.CS.Toprie
ironGrayToolStripMenuItem.Checked = false;
redHotToolStripMenuItem.Checked = false;
rainbow2ToolStripMenuItem.Checked = false;
-
+
// 尝试获取当前色彩模式并更新对应菜单项的选中状态
if (_deviceManager != null && _deviceManager.ConnectionStatus == ConnectionStatus.Connected)
{
@@ -1357,7 +1357,7 @@ namespace JoyD.Windows.CS.Toprie
{
// 获取当前色彩模式
PaletteType currentPalette = _deviceManager.CurrentPaletteType;
-
+
// 根据当前色彩模式设置对应菜单项的选中状态
switch (currentPalette)
{
@@ -1391,7 +1391,7 @@ namespace JoyD.Windows.CS.Toprie
{
Console.WriteLine($"获取当前色彩模式失败: {ex.Message}");
}
-
+
// 更新视频模式菜单项的选中状态
try
{
@@ -1612,109 +1612,109 @@ namespace JoyD.Windows.CS.Toprie
#endregion
#region 设备Ping相关方法
-
+
///
/// Ping定时器的回调方法
///
/// 状态对象
private void PingTimer_Tick(object state)
- {
+ {
if (_deviceManager != null && !string.IsNullOrEmpty(_deviceManager.IPAddress))
- {
- Task.Factory.StartNew(() =>
- {
+ {
+ Task.Factory.StartNew(() =>
+ {
bool pingResult = PingDevice(_deviceManager.IPAddress);
try
- {
+ {
// 在线程安全的方式下更新状态
if (this.InvokeRequired)
- {
+ {
this.Invoke(new Action(UpdatePingState), pingResult);
}
else
- {
+ {
UpdatePingState(pingResult);
}
}
catch (ObjectDisposedException)
- {
+ {
// 控件可能已被释放,忽略此更新
}
});
}
}
-
+
///
/// 执行Ping操作
///
/// 要Ping的IP地址
/// 是否Ping通
private bool PingDevice(string ipAddress)
- {
+ {
try
- {
+ {
using (var ping = new System.Net.NetworkInformation.Ping())
- {
+ {
var reply = ping.Send(ipAddress, 2000); // 2秒超时
return reply != null && reply.Status == System.Net.NetworkInformation.IPStatus.Success;
}
}
catch (Exception ex)
- {
+ {
Console.WriteLine($"Ping设备失败: {ex.Message}");
return false;
}
}
-
+
///
/// 更新Ping状态
///
/// 是否可Ping通
private void UpdatePingState(bool isPingable)
- {
+ {
// 按照README中要求的修改流程第3点:Ping通状态变化时,修改Ping状态
// 注意:UpdateInfo的调用已在IsDevicePingable的setter中实现(只在非暂停状态下)
IsDevicePingable = isPingable;
}
-
+
///
/// 开始设备Ping
///
private void StartDevicePing()
- {
+ {
try
- {
+ {
if (_pingTimer != null)
- {
+ {
_pingTimer.Change(0, _pingInterval); // 立即开始,然后按间隔执行
Console.WriteLine("设备Ping已启动");
}
}
catch (Exception ex)
- {
+ {
Console.WriteLine($"启动设备Ping失败: {ex.Message}");
}
}
-
+
///
/// 停止设备Ping
///
private void StopDevicePing()
- {
+ {
try
- {
+ {
if (_pingTimer != null)
- {
+ {
_pingTimer.Change(Timeout.Infinite, Timeout.Infinite);
Console.WriteLine("设备Ping已停止");
}
}
catch (Exception ex)
- {
+ {
Console.WriteLine($"停止设备Ping失败: {ex.Message}");
}
}
-
+
#endregion
///
@@ -1751,92 +1751,92 @@ namespace JoyD.Windows.CS.Toprie
_deviceManager.Dispose();
_deviceManager = null;
}
-
-
+
+
// 无论是否在设计模式下,都需要释放图像资源
-
+
// 释放Ping定时器
if (_pingTimer != null)
- {
+ {
_pingTimer.Dispose();
_pingTimer = null;
}
if (imageBox != null && !imageBox.IsDisposed && imageBox.Image != null)
- {
+ {
imageBox.Image.Dispose();
imageBox.Image = null;
}
-
+
// 释放图像缓冲区资源
if (_imageBuffer != null)
- {
+ {
try
- {
+ {
_imageBuffer.Dispose();
_imageBuffer = null;
Console.WriteLine("图像缓冲区资源已释放");
}
catch (Exception ex)
- {
+ {
Console.WriteLine($"清理ImageBuffer资源异常: {ex.Message}");
}
}
-
+
// 释放LastImage资源
lock (_lastImageLock)
- {
+ {
if (_lastImage != null)
- {
+ {
try
- {
+ {
_lastImage.Dispose();
_lastImage = null;
Console.WriteLine("LastImage资源已释放");
}
catch (Exception ex)
- {
+ {
Console.WriteLine($"清理LastImage资源异常: {ex.Message}");
}
}
}
-
+
// 释放InfoImage资源
lock (_infoImageLock)
- {
+ {
if (_infoImage != null)
- {
+ {
try
- {
+ {
_infoImage.Dispose();
_infoImage = null;
Console.WriteLine("InfoImage资源已释放");
}
catch (Exception ex)
- {
+ {
Console.WriteLine($"清理InfoImage资源异常: {ex.Message}");
}
}
}
-
+
// 释放DisplayImage资源
lock (_displayImageLock)
- {
+ {
if (_displayImage != null)
- {
+ {
try
- {
+ {
_displayImage.Dispose();
_displayImage = null;
Console.WriteLine("DisplayImage资源已释放");
}
catch (Exception ex)
- {
+ {
Console.WriteLine($"清理DisplayImage资源异常: {ex.Message}");
}
}
}
-
+
// 释放组件资源
if (components != null)
{
@@ -1859,22 +1859,22 @@ namespace JoyD.Windows.CS.Toprie
{
// 更新全局温度显示状态标志
_showGlobalTemperature = globalTemperatureToolStripMenuItem.Checked;
-
+
// 当全局温度被勾选时,自动取消区域温度的勾选
if (_showGlobalTemperature)
{
_showAreaTemperature = false;
areaTemperatureToolStripMenuItem.Checked = false;
}
-
+
// 修改流程第6点:数据显示菜单勾选变化时,只在非暂停状态下调用更新实时信息
- if (!_isPaused)
- {
- UpdateRealTimeInfoOnUI();
- }
-
- // 菜单状态变更时自动静默保存配置
- SaveMenuConfig();
+ if (!_isPaused)
+ {
+ UpdateRealTimeInfoOnUI();
+ }
+
+ // 菜单状态变更时自动静默保存配置
+ SaveMenuConfig();
}
///
@@ -1885,24 +1885,24 @@ namespace JoyD.Windows.CS.Toprie
{
// 更新区域温度显示状态标志
_showAreaTemperature = areaTemperatureToolStripMenuItem.Checked;
-
+
// 当区域温度被勾选时,自动取消全局温度的勾选
if (_showAreaTemperature)
{
_showGlobalTemperature = false;
globalTemperatureToolStripMenuItem.Checked = false;
}
-
+
// 修改流程第6点:数据显示菜单勾选变化时,只在非暂停状态下调用更新实时信息
if (!_isPaused)
{
UpdateRealTimeInfoOnUI();
}
-
+
// 菜单状态变更时自动静默保存配置
SaveMenuConfig();
}
-
+
///
/// 最高温度菜单项点击事件处理
///
@@ -1910,17 +1910,17 @@ namespace JoyD.Windows.CS.Toprie
{
// 更新最高温度显示状态标志
_showMaxTemperature = maxTemperatureToolStripMenuItem.Checked;
-
+
// 修改流程第6点:数据显示菜单勾选变化时,只在非暂停状态下调用更新实时信息
if (!_isPaused)
{
UpdateRealTimeInfoOnUI();
}
-
+
// 菜单状态变更时自动静默保存配置
SaveMenuConfig();
}
-
+
///
/// 平均温度菜单项点击事件处理
///
@@ -1928,17 +1928,17 @@ namespace JoyD.Windows.CS.Toprie
{
// 更新平均温度显示状态标志
_showAverageTemperature = avgTemperatureToolStripMenuItem.Checked;
-
+
// 修改流程第6点:数据显示菜单勾选变化时,只在非暂停状态下调用更新实时信息
if (!_isPaused)
{
UpdateRealTimeInfoOnUI();
}
-
+
// 菜单状态变更时自动静默保存配置
SaveMenuConfig();
}
-
+
///
/// 最低温度菜单项点击事件处理
///
@@ -1946,17 +1946,17 @@ namespace JoyD.Windows.CS.Toprie
{
// 更新最低温度显示状态标志
_showMinTemperature = minTemperatureToolStripMenuItem.Checked;
-
+
// 修改流程第6点:数据显示菜单勾选变化时,只在非暂停状态下调用更新实时信息
if (!_isPaused)
{
UpdateRealTimeInfoOnUI();
}
-
+
// 菜单状态变更时自动静默保存配置
SaveMenuConfig();
}
-
+
///
/// 保存日志菜单项点击事件处理
///
@@ -1964,7 +1964,7 @@ namespace JoyD.Windows.CS.Toprie
{
// 更新DeviceManager.LogToFile静态属性,这是控制所有日志记录的单一来源
DeviceManager.LogToFile = saveLogToolStripMenuItem.Checked;
-
+
// 可以在这里添加日志记录的初始化或清理逻辑
if (DeviceManager.LogToFile)
{
@@ -1976,11 +1976,11 @@ namespace JoyD.Windows.CS.Toprie
// 日志禁用时的清理(如果需要)
WriteLog("日志保存功能已禁用");
}
-
+
// 菜单状态变更时自动静默保存配置
SaveMenuConfig();
}
-
+
///
/// 保存菜单配置到CSV文件
///
@@ -1989,9 +1989,9 @@ namespace JoyD.Windows.CS.Toprie
try
{
WriteLog("开始保存菜单配置");
-
+
string configFilePath;
-
+
// 如果项目路径存在,使用项目路径下的Config目录
if (!string.IsNullOrEmpty(_projectPath) && Directory.Exists(_projectPath))
{
@@ -2000,7 +2000,7 @@ namespace JoyD.Windows.CS.Toprie
// 创建Config目录(如果不存在)
string configDir = Path.Combine(_projectPath, "Config");
Directory.CreateDirectory(configDir);
-
+
// 配置文件路径
configFilePath = Path.Combine(configDir, "menu_config.csv");
WriteLog($"使用项目路径保存配置: {configFilePath}");
@@ -2024,12 +2024,12 @@ namespace JoyD.Windows.CS.Toprie
configFilePath = Path.Combine(configDir, "menu_config.csv");
WriteLog($"使用应用程序目录保存配置: {configFilePath}");
}
-
+
// 创建CSV内容
StringBuilder csvContent = new StringBuilder();
// 添加标题行
csvContent.AppendLine("MenuName,Status,Checked");
-
+
try
{
// 保存暂停检测菜单状态
@@ -2041,7 +2041,7 @@ namespace JoyD.Windows.CS.Toprie
{
WriteLog("警告: pauseDetectionToolStripMenuItem未初始化");
}
-
+
// 保存日志保存菜单状态
if (saveLogToolStripMenuItem != null)
{
@@ -2051,7 +2051,7 @@ namespace JoyD.Windows.CS.Toprie
{
WriteLog("警告: saveLogToolStripMenuItem未初始化");
}
-
+
// 保存温度显示菜单状态
if (globalTemperatureToolStripMenuItem != null)
csvContent.AppendLine($"globalTemperature,{globalTemperatureToolStripMenuItem.Text},{globalTemperatureToolStripMenuItem.Checked}");
@@ -2063,7 +2063,7 @@ namespace JoyD.Windows.CS.Toprie
csvContent.AppendLine($"avgTemperature,{avgTemperatureToolStripMenuItem.Text},{avgTemperatureToolStripMenuItem.Checked}");
if (minTemperatureToolStripMenuItem != null)
csvContent.AppendLine($"minTemperature,{minTemperatureToolStripMenuItem.Text},{minTemperatureToolStripMenuItem.Checked}");
-
+
// 保存色彩模式菜单状态
if (whiteHotToolStripMenuItem != null)
csvContent.AppendLine($"whiteHot,{whiteHotToolStripMenuItem.Text},{whiteHotToolStripMenuItem.Checked}");
@@ -2081,7 +2081,7 @@ namespace JoyD.Windows.CS.Toprie
csvContent.AppendLine($"redHot,{redHotToolStripMenuItem.Text},{redHotToolStripMenuItem.Checked}");
if (rainbow2ToolStripMenuItem != null)
csvContent.AppendLine($"rainbow2,{rainbow2ToolStripMenuItem.Text},{rainbow2ToolStripMenuItem.Checked}");
-
+
// 保存图像模式菜单状态
if (thermalModeToolStripMenuItem != null)
csvContent.AppendLine($"thermalMode,{thermalModeToolStripMenuItem.Text},{thermalModeToolStripMenuItem.Checked}");
@@ -2096,7 +2096,7 @@ namespace JoyD.Windows.CS.Toprie
Console.WriteLine(errorMsg);
throw;
}
-
+
// 写入文件
try
{
@@ -2132,18 +2132,18 @@ namespace JoyD.Windows.CS.Toprie
WriteLog("菜单配置保存操作完成");
}
}
-
+
///
/// 从CSV文件加载菜单配置
///
private void LoadMenuConfig()
{
WriteLog("开始加载菜单配置");
-
+
try
{
string configFilePath = null;
-
+
// 检查项目路径下的配置文件
if (!string.IsNullOrEmpty(_projectPath) && Directory.Exists(_projectPath))
{
@@ -2151,7 +2151,7 @@ namespace JoyD.Windows.CS.Toprie
{
configFilePath = Path.Combine(_projectPath, "Config", "menu_config.csv");
WriteLog($"检查项目路径配置文件: {configFilePath}");
-
+
// 如果项目路径下没有配置文件,检查应用程序目录
if (!File.Exists(configFilePath))
{
@@ -2175,7 +2175,7 @@ namespace JoyD.Windows.CS.Toprie
configFilePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Config", "menu_config.csv");
WriteLog($"检查应用程序目录配置文件: {configFilePath}");
}
-
+
// 如果配置文件不存在,直接返回
if (!File.Exists(configFilePath))
{
@@ -2184,7 +2184,7 @@ namespace JoyD.Windows.CS.Toprie
WriteLog(infoMsg);
return;
}
-
+
// 读取CSV文件内容
string[] lines = null;
try
@@ -2206,22 +2206,22 @@ namespace JoyD.Windows.CS.Toprie
Console.WriteLine(errorMsg);
return;
}
-
+
// 创建菜单状态字典
Dictionary> menuStates = new Dictionary>();
-
+
// 解析CSV内容
try
{
for (int i = 1; i < lines.Length; i++) // 跳过标题行
{
string line = lines[i];
- if (string.IsNullOrWhiteSpace(line))
+ if (string.IsNullOrWhiteSpace(line))
{
- WriteLog($"警告: 配置文件第{i+1}行为空,已跳过");
+ WriteLog($"警告: 配置文件第{i + 1}行为空,已跳过");
continue;
}
-
+
try
{
// 简单的CSV解析,这里假设没有包含逗号的字段
@@ -2231,7 +2231,7 @@ namespace JoyD.Windows.CS.Toprie
string menuName = parts[0];
string status = parts[1];
string isChecked = parts[2];
-
+
menuStates[menuName] = new Dictionary
{
{ "status", status },
@@ -2240,16 +2240,16 @@ namespace JoyD.Windows.CS.Toprie
}
else
{
- WriteLog($"警告: 配置文件第{i+1}行格式不正确,字段数量不足: {line}");
+ WriteLog($"警告: 配置文件第{i + 1}行格式不正确,字段数量不足: {line}");
}
}
catch (Exception ex)
{
- WriteLog($"解析配置文件第{i+1}行时出错: {ex.Message} - {ex.StackTrace}");
+ WriteLog($"解析配置文件第{i + 1}行时出错: {ex.Message} - {ex.StackTrace}");
// 继续处理下一行,不中断整个解析过程
}
}
-
+
WriteLog($"成功解析配置文件,共加载{menuStates.Count}个菜单状态");
}
catch (Exception ex)
@@ -2259,7 +2259,7 @@ namespace JoyD.Windows.CS.Toprie
Console.WriteLine(errorMsg);
return;
}
-
+
// 应用菜单状态
try
{
@@ -2277,7 +2277,7 @@ namespace JoyD.Windows.CS.Toprie
WriteLog($"暂停检测菜单状态格式错误: {ex.Message}");
}
}
-
+
// 日志保存菜单
if (menuStates.ContainsKey("saveLog") && saveLogToolStripMenuItem != null)
{
@@ -2298,7 +2298,7 @@ namespace JoyD.Windows.CS.Toprie
WriteLog($"日志保存菜单状态格式错误: {ex.Message}");
}
}
-
+
// 温度显示菜单 - 添加空值检查
if (globalTemperatureToolStripMenuItem != null)
ApplyMenuState(menuStates, "globalTemperature", globalTemperatureToolStripMenuItem);
@@ -2310,7 +2310,7 @@ namespace JoyD.Windows.CS.Toprie
ApplyMenuState(menuStates, "avgTemperature", avgTemperatureToolStripMenuItem);
if (minTemperatureToolStripMenuItem != null)
ApplyMenuState(menuStates, "minTemperature", minTemperatureToolStripMenuItem);
-
+
// 色彩模式菜单 - 添加空值检查
if (whiteHotToolStripMenuItem != null)
ApplyMenuState(menuStates, "whiteHot", whiteHotToolStripMenuItem);
@@ -2328,13 +2328,13 @@ namespace JoyD.Windows.CS.Toprie
ApplyMenuState(menuStates, "redHot", redHotToolStripMenuItem);
if (rainbow2ToolStripMenuItem != null)
ApplyMenuState(menuStates, "rainbow2", rainbow2ToolStripMenuItem);
-
+
// 图像模式菜单 - 添加空值检查
if (thermalModeToolStripMenuItem != null)
ApplyMenuState(menuStates, "thermalMode", thermalModeToolStripMenuItem);
if (visibleModeToolStripMenuItem != null)
ApplyMenuState(menuStates, "visibleMode", visibleModeToolStripMenuItem);
-
+
string successMsg = "菜单配置已从CSV文件成功加载并应用";
Console.WriteLine(successMsg);
WriteLog(successMsg);
@@ -2358,7 +2358,7 @@ namespace JoyD.Windows.CS.Toprie
WriteLog("菜单配置加载操作完成");
}
}
-
+
///
/// 应用菜单状态的辅助方法
///
@@ -2375,24 +2375,24 @@ namespace JoyD.Windows.CS.Toprie
WriteLog($"警告: 应用菜单状态时,menuStates参数为null,菜单名称: {menuName}");
return;
}
-
+
if (string.IsNullOrEmpty(menuName))
{
WriteLog("警告: 应用菜单状态时,menuName参数为空");
return;
}
-
+
if (menuItem == null)
{
WriteLog($"警告: 应用菜单状态时,菜单项为null,菜单名称: {menuName}");
return;
}
-
+
// 检查菜单状态字典中是否包含该菜单
if (menuStates.ContainsKey(menuName))
{
WriteLog($"应用菜单状态: {menuName}");
-
+
try
{
// 尝试解析和应用Checked状态
@@ -2407,7 +2407,7 @@ namespace JoyD.Windows.CS.Toprie
WriteLog(errorMsg);
// 保留默认值,不抛出异常以允许其他菜单状态继续应用
}
-
+
try
{
// 尝试设置菜单项文本
@@ -2437,7 +2437,7 @@ namespace JoyD.Windows.CS.Toprie
// 不重新抛出异常,避免影响其他菜单状态的应用
}
}
-
+
///
/// 写入日志信息到文件
/// 只有在DeviceManager.LogToFile为true时才会保存
@@ -2452,14 +2452,14 @@ namespace JoyD.Windows.CS.Toprie
try
{
string logFilePath;
-
+
// 如果项目路径存在,使用项目路径下的Logs目录
if (!string.IsNullOrEmpty(_projectPath) && Directory.Exists(_projectPath))
{
// 创建Logs目录(如果不存在)
string logDir = Path.Combine(_projectPath, "Logs");
Directory.CreateDirectory(logDir);
-
+
// 生成日志文件名(按日期)
string logFileName = $"Log_{DateTime.Now:yyyyMMdd}.txt";
logFilePath = Path.Combine(logDir, logFileName);
@@ -2471,7 +2471,7 @@ namespace JoyD.Windows.CS.Toprie
// 确保目录存在
Directory.CreateDirectory(Path.GetDirectoryName(logFilePath));
}
-
+
// 写入日志(带时间戳)
string logEntry = $"[{DateTime.Now:yyyy-MM-dd HH:mm:ss.fff}] {logMessage}";
File.AppendAllText(logFilePath, logEntry + Environment.NewLine);
@@ -2502,7 +2502,7 @@ namespace JoyD.Windows.CS.Toprie
{
// 清除DisplayImage为透明色
g.Clear(Color.Transparent);
-
+
// 2. 如果没有温度数据或温度数据的时间3秒之前,返回
TemperatureData temperatureData = _deviceManager.LastTemperature;
if (temperatureData == null || temperatureData.Timestamp == null)
@@ -2548,7 +2548,7 @@ namespace JoyD.Windows.CS.Toprie
{
temperatureTexts.Add($"最高: {temperatureData.MaxTemperature:F2} °C");
}
-
+
// 记录温度数据日志
if (temperatureTexts.Count > 0)
{
@@ -2620,11 +2620,11 @@ namespace JoyD.Windows.CS.Toprie
brush.Dispose();
format.Dispose();
}
-
+
// 设置显示状态标志
_isDisplayingInfo = true;
}
-
+
// 标记信息正在显示
_isDisplayingInfo = true;
}
@@ -2680,14 +2680,14 @@ namespace JoyD.Windows.CS.Toprie
// 获取已有的温度数据(从DeviceManager缓存中获取)
TemperatureData temperatureData = _deviceManager.LastTemperature;
if (temperatureData == null)
- {
+ {
MessageBox.Show("获取温度数据失败,请确保设备已连接且正在接收数据。", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
// 使用DeviceManager的新重载方法,直接传入已获取的温度数据
bool saveResult = _deviceManager.SaveTemperatureDataToCsv(saveFileDialog.FileName, temperatureData);
-
+
if (saveResult)
{
// 显示保存成功消息
@@ -2707,7 +2707,7 @@ namespace JoyD.Windows.CS.Toprie
Console.WriteLine($"保存温度数据异常: {ex.Message}\n{ex.StackTrace}");
}
}
-
+
///
/// 验证菜单功能是否正常工作 - 用于测试
/// 可以在调试时手动调用此方法来测试菜单配置的保存和加载
@@ -2717,22 +2717,22 @@ namespace JoyD.Windows.CS.Toprie
try
{
WriteLog("开始验证菜单功能");
-
+
// 1. 保存当前菜单配置
SaveMenuConfig();
WriteLog("菜单配置已保存");
-
+
// 2. 模拟菜单状态更改并再次保存
if (globalTemperatureToolStripMenuItem != null)
{
globalTemperatureToolStripMenuItem.Checked = !globalTemperatureToolStripMenuItem.Checked;
WriteLog($"临时更改全局温度菜单状态为: {globalTemperatureToolStripMenuItem.Checked}");
}
-
+
// 3. 重新加载配置
LoadMenuConfig();
WriteLog("菜单配置已重新加载");
-
+
// 4. 输出验证信息
WriteLog("菜单功能验证完成");
Console.WriteLine("菜单功能验证完成: 保存和加载配置正常工作");
@@ -2743,23 +2743,24 @@ namespace JoyD.Windows.CS.Toprie
Console.WriteLine($"验证菜单功能失败: {ex.Message}");
}
}
- }
- }
-
- ///
- /// imageBox双击事件处理方法
- /// 双击后弹出检测配置窗口
- ///
- private void ImageBox_DoubleClick(object sender, EventArgs e)
+
+ ///
+ ///
+ /// imageBox双击事件处理方法
+ /// 双击后弹出检测配置窗口
+ ///
+ private void ImageBox_DoubleClick(object sender, EventArgs e)
+ {
+ try
{
- try
- {
- // 显示配置窗口,使用完整命名空间引用Setting类
- JoyD.Windows.CS.Setting.Form.ShowDialog();
- }
- catch (Exception ex)
- {
- Console.WriteLine($"打开配置窗口时出错: {ex.Message}");
- MessageBox.Show($"打开配置窗口时出错: {ex.Message}", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
- }
- }
\ No newline at end of file
+ // 显示配置窗口,使用完整命名空间引用Setting类
+ JoyD.Windows.CS.Setting.Form.ShowDialog();
+ }
+ catch (Exception ex)
+ {
+ Console.WriteLine($"打开配置窗口时出错: {ex.Message}");
+ MessageBox.Show($"打开配置窗口时出错: {ex.Message}", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ }
+ }
+}
+}
\ No newline at end of file
diff --git a/Windows/CS/Framework4.0/Toprie/Toprie/Camera.resx b/Windows/CS/Framework4.0/Toprie/Toprie/Camera.resx
index 1af7de1..ad53752 100644
--- a/Windows/CS/Framework4.0/Toprie/Toprie/Camera.resx
+++ b/Windows/CS/Framework4.0/Toprie/Toprie/Camera.resx
@@ -117,4 +117,7 @@
System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+ 17, 17
+
\ No newline at end of file