修改Comp_temp属性支持+RET:和+RSP:两种响应格式
This commit is contained in:
@@ -178,7 +178,7 @@ namespace JoyD.Windows.CS.Toprie
|
||||
/// <summary>
|
||||
/// 最近检查到的温度
|
||||
/// </summary>
|
||||
public TemperatureData LastTemperature = null;
|
||||
public volatile TemperatureData LastTemperature = null;
|
||||
// 项目路径,用于数据文件的存取
|
||||
private string _projectPath = "";
|
||||
|
||||
@@ -978,6 +978,7 @@ namespace JoyD.Windows.CS.Toprie
|
||||
{
|
||||
if (_connectionStatus == ConnectionStatus.Connected && _a8Sdk != null)
|
||||
{
|
||||
// 使用SDK提供的Comp_temp属性获取温度补偿值
|
||||
float compensationValue = _a8Sdk.Comp_temp;
|
||||
Log($"获取温度补偿值: {compensationValue}");
|
||||
return compensationValue;
|
||||
|
||||
@@ -13,9 +13,8 @@
|
||||
1. 暂停或恢复时,设置暂停状态,调用更新Info
|
||||
2. 断开或连接时,设置连接状态,调用更新Info
|
||||
3. Ping通状态变化时,修改Ping状态,调用更新Info
|
||||
4. 温度数据更新时,调用更新Info
|
||||
5. 图像更新时,保存LastImage,调用更新到UI
|
||||
6. 2-5 只在非暂停状态下调用更新,暂停状态下不更新Info和UI
|
||||
4. 图像更新时,保存LastImage,调用更新Info
|
||||
5. 2-4 只在非暂停状态下调用更新,暂停状态下不更新Info和UI
|
||||
|
||||
### 更新Info
|
||||
1. 以透明色清空Info
|
||||
|
||||
@@ -2166,7 +2166,7 @@ namespace JoyD.Windows.CS.Toprie
|
||||
{
|
||||
// 解析响应中的设备名称
|
||||
// 格式: +RET:1:设备名称$ 或 +RET:设备名称$
|
||||
if (response != null && response.StartsWith("+RET:"))
|
||||
if (response != null && (response.StartsWith("+RET:") || response.StartsWith("+RSP:")))
|
||||
{
|
||||
int paramTypeEndPos = response.IndexOf(':', 5);
|
||||
int nameStartPos = (paramTypeEndPos > 0) ? paramTypeEndPos + 1 : 5;
|
||||
@@ -2198,7 +2198,7 @@ namespace JoyD.Windows.CS.Toprie
|
||||
{
|
||||
// 解析响应,返回检测编号数据
|
||||
// 响应格式: +RET:0:数据内容$ 或 +RET:数据内容$
|
||||
if (response != null && response.StartsWith("+RET:"))
|
||||
if (response != null && (response.StartsWith("+RET:") || response.StartsWith("+RSP:")))
|
||||
{
|
||||
// 解析响应中的数据部分
|
||||
int startPos = response.IndexOf(':', 5) + 1;
|
||||
@@ -2248,7 +2248,7 @@ namespace JoyD.Windows.CS.Toprie
|
||||
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 endPos = response.IndexOf('$', valueStartPos);
|
||||
@@ -2330,24 +2330,24 @@ namespace JoyD.Windows.CS.Toprie
|
||||
{
|
||||
try
|
||||
{
|
||||
// 使用GET_COMP_TEMP命令获取补偿温度 - SDK格式
|
||||
string command = $"{deviceIp}:{(int)CMD_TYPE.GET_COMP_TEMP}$";
|
||||
// 与C++ SDK保持一致,使用GET_PARAMETER命令并指定COMP_TEMP参数类型
|
||||
string command = $"{CMD_HEAD}:{(int)CMD_TYPE.GET_PARAMETER},{(int)PARAM_TYPE.COMP_TEMP}$";
|
||||
|
||||
if (SendCommand(command, out string response))
|
||||
{
|
||||
// 解析响应中的补偿温度值
|
||||
if (response != null && response.StartsWith("+RET:"))
|
||||
// 解析响应中的补偿温度值 - 支持+RET:和+RSP:两种格式
|
||||
if (response != null && (response.StartsWith("+RET:") || response.StartsWith("+RSP:")))
|
||||
{
|
||||
int valueStartPos = response.IndexOf(':', 5) + 1;
|
||||
int endPos = response.IndexOf('$', valueStartPos);
|
||||
|
||||
if (endPos > valueStartPos)
|
||||
// 与C++ SDK一致,从缓冲区+5位置解析值
|
||||
string valueStr = response.Substring(5);
|
||||
// 移除末尾的$符号
|
||||
if (valueStr.EndsWith("$"))
|
||||
{
|
||||
string valueStr = response.Substring(valueStartPos, endPos - valueStartPos);
|
||||
if (int.TryParse(valueStr, out int result))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
valueStr = valueStr.Substring(0, valueStr.Length - 1);
|
||||
}
|
||||
if (int.TryParse(valueStr, out int result))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2356,7 +2356,7 @@ namespace JoyD.Windows.CS.Toprie
|
||||
{
|
||||
Console.WriteLine($"获取补偿温度失败: {ex.Message}");
|
||||
}
|
||||
return 2500;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user