XiChang/DM_Weight/Common/Temperature.cs

48 lines
1.3 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using DM_Weight.Port;
using log4net;
namespace DM_Weight.Common
{
public class Temperature
{
private readonly static ILog logger = LogManager.GetLogger(typeof(Temperature));
/// <summary>
/// 将收到的返回转换成具体温度数值
/// </summary>
/// <param name="receiveData"></param>
/// <returns></returns>
public static string GetResultWD(string receiveData)
{
try
{
string newStrWD = receiveData.Substring(10, 4);
logger.Info($"截取后数据newStrWD{newStrWD}");
int iWD = Convert.ToInt32(newStrWD, 16);
logger.Info($"截取后数据iWD{iWD}");
float fWD = 0;
if (iWD != 0)
{
fWD = iWD * 1.0f / 10;
}
logger.Info($"截取后数据fWD{fWD}");
string strRet = $"冰箱抽屉当前温度:{fWD}℃;";
return strRet;
}
catch (Exception ex)
{
logger.Info("GetResultWD异常", new Exception($"{ex.ToString()}"));
}
return "数据异常";
}
}
}