From d5e22d64f20d08beed6c2d7eb400a167c924c42a Mon Sep 17 00:00:00 2001 From: zqm Date: Wed, 5 Nov 2025 09:15:28 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8DCamera.cs=E5=92=8CV8.cs?= =?UTF-8?q?=E4=B8=AD=E7=9A=84=E9=97=AE=E9=A2=98=EF=BC=9A=E7=A7=BB=E9=99=A4?= =?UTF-8?q?=E5=A4=9A=E4=BD=99=E7=9A=84.Value=E8=AE=BF=E9=97=AE=E5=99=A8?= =?UTF-8?q?=E5=92=8C=E6=B7=BB=E5=8A=A0=E6=B8=A9=E8=A1=A5=E5=80=BC=E5=85=A8?= =?UTF-8?q?=E5=B1=80=E4=BF=9D=E5=AD=98=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../CS/Framework4.0/Toprie/Toprie/Camera.cs | 71 ++++++++++++------- .../CS/Framework4.0/Toprie/Toprie/README.md | 6 +- Windows/CS/Framework4.0/Toprie/Toprie/V8.cs | 13 +++- 3 files changed, 61 insertions(+), 29 deletions(-) diff --git a/Windows/CS/Framework4.0/Toprie/Toprie/Camera.cs b/Windows/CS/Framework4.0/Toprie/Toprie/Camera.cs index 1f412a1..e228bbc 100644 --- a/Windows/CS/Framework4.0/Toprie/Toprie/Camera.cs +++ b/Windows/CS/Framework4.0/Toprie/Toprie/Camera.cs @@ -168,30 +168,8 @@ namespace JoyD.Windows.CS.Toprie } } else if (isReady) - { - // 步骤3:就绪条件下,如果有温度数据,显示最高温度 - // 从DeviceManager获取最新的温度数据 - if (_deviceManager != null) - { - TemperatureData temperatureData = _deviceManager.LastTemperature; - if (temperatureData != null) - { - // 有有效温度数据,显示最高温度 - string tempText = $"最高温度: {temperatureData.MaxTemperature:F2} °C"; - Color textColor = Color.White; - - using (Font font = new Font("Arial", 24, FontStyle.Bold)) - using (SolidBrush textBrush = new SolidBrush(textColor)) - { - StringFormat format = new StringFormat() { Alignment = StringAlignment.Center }; - - // 在图像底部显示温度信息 - g.DrawString(tempText, font, textBrush, - new RectangleF(0, BUFFER_HEIGHT - 40, BUFFER_WIDTH, 40), - format); - } - } - } + { + // 就绪条件下,根据用户要求不再显示温度数据 } } @@ -785,6 +763,51 @@ namespace JoyD.Windows.CS.Toprie g.DrawString("测试信息", font, textBrush, 10, 10); } } + + // 步骤3:在就绪条件下,如果有温度数据(时间在最近3秒内),显示最高温度(居中显示) + if (!_isPaused && IsDevicePingable && _deviceManager != null && _deviceManager.ConnectionStatus == ConnectionStatus.Connected) + { + TemperatureData temperatureData = _deviceManager.LastTemperature; + if (temperatureData != null && temperatureData.Timestamp != null) + { + // 检查温度数据时间是否在最近3秒内 + TimeSpan timeDiff = DateTime.Now - temperatureData.Timestamp; + if (timeDiff.TotalSeconds <= 3) + { + // 有有效温度数据,居中显示最高温度 + string tempText = $"最高温度: {temperatureData.MaxTemperature:F2} °C"; + Color textColor = Color.White; + + using (Font font = new Font("Arial", 24, FontStyle.Bold)) + using (SolidBrush textBrush = new SolidBrush(textColor)) + { + StringFormat format = new StringFormat() { + Alignment = StringAlignment.Center, + LineAlignment = StringAlignment.Center + }; + + // 计算文本位置,确保居中显示 + RectangleF textRect = new RectangleF(0, 0, BUFFER_WIDTH, BUFFER_HEIGHT); + + // 添加半透明背景以提高可读性 + SizeF textSize = g.MeasureString(tempText, font); + RectangleF bgRect = new RectangleF( + (BUFFER_WIDTH - textSize.Width - 20) / 2, + (BUFFER_HEIGHT - textSize.Height - 20) / 2, + textSize.Width + 20, + textSize.Height + 20 + ); + using (SolidBrush bgBrush = new SolidBrush(Color.FromArgb(128, 0, 0, 0))) + { + g.FillRectangle(bgBrush, bgRect); + } + + // 居中绘制温度信息 + g.DrawString(tempText, font, textBrush, textRect, format); + } + } + } + } } // 在同一个锁内创建缓冲区的副本,避免重复锁定 diff --git a/Windows/CS/Framework4.0/Toprie/Toprie/README.md b/Windows/CS/Framework4.0/Toprie/Toprie/README.md index 410353d..d130a0e 100644 --- a/Windows/CS/Framework4.0/Toprie/Toprie/README.md +++ b/Windows/CS/Framework4.0/Toprie/Toprie/README.md @@ -13,18 +13,18 @@ 1. 暂停或恢复时,设置暂停状态,调用更新Info 2. 断开或连接时,设置连接状态,调用更新Info 3. Ping通状态变化时,修改Ping状态,调用更新Info -4. 图像更新时,保存LastImage,调用更新Info +4. 图像更新时,保存LastImage,调用更新UI 5. 2-4 只在非暂停状态下调用更新,暂停状态下不更新Info和UI ### 更新Info 1. 以透明色清空Info 2. 如果暂停,显示暂停信息,否则如果Ping不通或断开,显示重连信息 否则满足就绪条件 -3. 在就绪条件下,如果有温度数据,显示最高温度 -4. 最后调用更新UI +3. 最后调用更新UI ### 更新UI 1. 先将LastImage绘制到全局缓冲 2. 再将InfoImage绘制到缓冲 +3. 在就绪条件下,如果有温度数据(时间在最近3秒内),显示最高温度(居中显示) 3. 最后一次性绘制到图像框的bitmap ## TCP温度数据接收 diff --git a/Windows/CS/Framework4.0/Toprie/Toprie/V8.cs b/Windows/CS/Framework4.0/Toprie/Toprie/V8.cs index 9f0c0dd..9d0e516 100644 --- a/Windows/CS/Framework4.0/Toprie/Toprie/V8.cs +++ b/Windows/CS/Framework4.0/Toprie/Toprie/V8.cs @@ -2324,6 +2324,9 @@ namespace JoyD.Windows.CS.Toprie } } + // 私有字段,用于存储最后一次成功获取的温补值 + private int _lastSuccessfulCompTemp = 0; + public int Comp_temp { get @@ -2347,16 +2350,22 @@ namespace JoyD.Windows.CS.Toprie } if (int.TryParse(valueStr, out int result)) { + // 查询成功,更新并返回温补值 + _lastSuccessfulCompTemp = result; return result; } } } + // 查询失败但有上一次成功的值,则返回上一次的值 + Console.WriteLine("温补查询失败,使用上一次成功的温补值"); + return _lastSuccessfulCompTemp; } catch (Exception ex) { - Console.WriteLine($"获取补偿温度失败: {ex.Message}"); + Console.WriteLine($"获取补偿温度失败: {ex.Message},使用上一次成功的温补值"); + // 异常情况下也返回上一次成功的值 + return _lastSuccessfulCompTemp; } - return 0; } }