修改Comp_temp属性支持+RET:和+RSP:两种响应格式

This commit is contained in:
zqm
2025-11-04 17:19:20 +08:00
parent 92da615022
commit cab535004c
3 changed files with 23 additions and 23 deletions

View File

@@ -178,7 +178,7 @@ namespace JoyD.Windows.CS.Toprie
/// <summary> /// <summary>
/// 最近检查到的温度 /// 最近检查到的温度
/// </summary> /// </summary>
public TemperatureData LastTemperature = null; public volatile TemperatureData LastTemperature = null;
// 项目路径,用于数据文件的存取 // 项目路径,用于数据文件的存取
private string _projectPath = ""; private string _projectPath = "";
@@ -763,10 +763,10 @@ namespace JoyD.Windows.CS.Toprie
// 记录处理开始时间 // 记录处理开始时间
System.Diagnostics.Stopwatch stopwatch = new System.Diagnostics.Stopwatch(); System.Diagnostics.Stopwatch stopwatch = new System.Diagnostics.Stopwatch();
stopwatch.Start(); stopwatch.Start();
// 调用温度帧处理方法 // 调用温度帧处理方法
ProcessTemperatureFrame(frameToProcess, WIDTH, HEIGHT); ProcessTemperatureFrame(frameToProcess, WIDTH, HEIGHT);
// 停止计时并记录处理时间 // 停止计时并记录处理时间
stopwatch.Stop(); stopwatch.Stop();
Log($"温度数据处理完成,耗时: {stopwatch.ElapsedMilliseconds}ms"); Log($"温度数据处理完成,耗时: {stopwatch.ElapsedMilliseconds}ms");
@@ -978,6 +978,7 @@ namespace JoyD.Windows.CS.Toprie
{ {
if (_connectionStatus == ConnectionStatus.Connected && _a8Sdk != null) if (_connectionStatus == ConnectionStatus.Connected && _a8Sdk != null)
{ {
// 使用SDK提供的Comp_temp属性获取温度补偿值
float compensationValue = _a8Sdk.Comp_temp; float compensationValue = _a8Sdk.Comp_temp;
Log($"获取温度补偿值: {compensationValue}"); Log($"获取温度补偿值: {compensationValue}");
return compensationValue; return compensationValue;

View File

@@ -13,9 +13,8 @@
1. 暂停或恢复时设置暂停状态调用更新Info 1. 暂停或恢复时设置暂停状态调用更新Info
2. 断开或连接时设置连接状态调用更新Info 2. 断开或连接时设置连接状态调用更新Info
3. Ping通状态变化时修改Ping状态调用更新Info 3. Ping通状态变化时修改Ping状态调用更新Info
4. 温度数据更新时调用更新Info 4. 图像更新时保存LastImage调用更新Info
5. 图像更新时保存LastImage调用更新到UI 5. 2-4 只在非暂停状态下调用更新暂停状态下不更新Info和UI
6. 2-5 只在非暂停状态下调用更新暂停状态下不更新Info和UI
### 更新Info ### 更新Info
1. 以透明色清空Info 1. 以透明色清空Info

View File

@@ -2166,7 +2166,7 @@ namespace JoyD.Windows.CS.Toprie
{ {
// 解析响应中的设备名称 // 解析响应中的设备名称
// 格式: +RET:1:设备名称$ 或 +RET:设备名称$ // 格式: +RET:1:设备名称$ 或 +RET:设备名称$
if (response != null && response.StartsWith("+RET:")) if (response != null && (response.StartsWith("+RET:") || response.StartsWith("+RSP:")))
{ {
int paramTypeEndPos = response.IndexOf(':', 5); int paramTypeEndPos = response.IndexOf(':', 5);
int nameStartPos = (paramTypeEndPos > 0) ? paramTypeEndPos + 1 : 5; int nameStartPos = (paramTypeEndPos > 0) ? paramTypeEndPos + 1 : 5;
@@ -2198,7 +2198,7 @@ namespace JoyD.Windows.CS.Toprie
{ {
// 解析响应,返回检测编号数据 // 解析响应,返回检测编号数据
// 响应格式: +RET:0:数据内容$ 或 +RET:数据内容$ // 响应格式: +RET:0:数据内容$ 或 +RET:数据内容$
if (response != null && response.StartsWith("+RET:")) if (response != null && (response.StartsWith("+RET:") || response.StartsWith("+RSP:")))
{ {
// 解析响应中的数据部分 // 解析响应中的数据部分
int startPos = response.IndexOf(':', 5) + 1; int startPos = response.IndexOf(':', 5) + 1;
@@ -2248,7 +2248,7 @@ namespace JoyD.Windows.CS.Toprie
if (SendCommand(command, out string response)) if (SendCommand(command, out string response))
{ {
// 解析响应中的温度帧值 // 解析响应中的温度帧值
if (response != null && response.StartsWith("+RET:")) if (response != null && (response.StartsWith("+RET:") || response.StartsWith("+RSP:")))
{ {
int valueStartPos = response.IndexOf(':', 5) + 1; int valueStartPos = response.IndexOf(':', 5) + 1;
int endPos = response.IndexOf('$', valueStartPos); int endPos = response.IndexOf('$', valueStartPos);
@@ -2330,24 +2330,24 @@ namespace JoyD.Windows.CS.Toprie
{ {
try try
{ {
// 使用GET_COMP_TEMP命令获取补偿温度 - SDK格式 // 与C++ SDK保持一致使用GET_PARAMETER命令并指定COMP_TEMP参数类型
string command = $"{deviceIp}:{(int)CMD_TYPE.GET_COMP_TEMP}$"; string command = $"{CMD_HEAD}:{(int)CMD_TYPE.GET_PARAMETER},{(int)PARAM_TYPE.COMP_TEMP}$";
if (SendCommand(command, out string response)) if (SendCommand(command, out string response))
{ {
// 解析响应中的补偿温度值 // 解析响应中的补偿温度值 - 支持+RET:和+RSP:两种格式
if (response != null && response.StartsWith("+RET:")) if (response != null && (response.StartsWith("+RET:") || response.StartsWith("+RSP:")))
{ {
int valueStartPos = response.IndexOf(':', 5) + 1; // 与C++ SDK一致从缓冲区+5位置解析值
int endPos = response.IndexOf('$', valueStartPos); string valueStr = response.Substring(5);
// 移除末尾的$符号
if (endPos > valueStartPos) if (valueStr.EndsWith("$"))
{ {
string valueStr = response.Substring(valueStartPos, endPos - valueStartPos); valueStr = valueStr.Substring(0, valueStr.Length - 1);
if (int.TryParse(valueStr, out int result)) }
{ if (int.TryParse(valueStr, out int result))
return result; {
} return result;
} }
} }
} }
@@ -2356,7 +2356,7 @@ namespace JoyD.Windows.CS.Toprie
{ {
Console.WriteLine($"获取补偿温度失败: {ex.Message}"); Console.WriteLine($"获取补偿温度失败: {ex.Message}");
} }
return 2500; return 0;
} }
} }