Commit e31bcddb 张东亮

温度后台配置修改

1 个父辈 61eae5e4
......@@ -5,7 +5,7 @@ using System.Collections.Generic;
using System.IO.Ports;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Text;
namespace OnlineStore.DeviceLibrary
{
......@@ -15,16 +15,16 @@ namespace OnlineStore.DeviceLibrary
public class HumitureController
{
//public static readonly ILog LOGGER = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
private static int bautRate = 4800;//波特率
private static Parity parity = Parity.None;//校验位
private static int dataBits = 8;//数据位
private static StopBits stopBits = StopBits.One; //停止位
private static string LogName = "";
private static Dictionary<string, AcSerialBean> serialBeanMap = new Dictionary<string, AcSerialBean>();
public static int HumitureControllerType = ConfigAppSettings.GetIntValue(Setting_Init.HumitureControllerType);
public static int HumitureControllerType = ConfigAppSettings.GetIntValue(Setting_Init.HumitureControllerType);
public static bool Init(string port)
{
if (serialBeanMap.ContainsKey(port))
......@@ -32,31 +32,31 @@ namespace OnlineStore.DeviceLibrary
return true;
}
LogName = "温湿度传感器[" + port + "]";
LogName = "温湿度传感器[" + port + "]";
AcSerialBean sb = null;
if (HumitureControllerType.Equals(1))
{
bautRate = 9600;//波特率
}
sb = new AcSerialBean(port, bautRate, parity, dataBits, stopBits);
sb = new AcSerialBean(port, bautRate, parity, dataBits, stopBits);
try
{
if (sb.openPort())
{
serialBeanMap.Add(port, sb);
var ht = HumitureController.QueryData(port);
LogUtil.info(LogName + "串口" + port + "打开成功!温度:"+ ht.Temperate+",湿度:"+ht.Humidity);
LogUtil.info(LogName + "串口" + port + "打开成功!温度:" + ht.Temperate + ",湿度:" + ht.Humidity);
return true;
}
else
{
LogUtil.error( LogName + "串口" + port + "打开失败!");
LogUtil.error(LogName + "串口" + port + "打开失败!");
return false;
}
}
catch (Exception ex)
{
LogUtil.error("串口" + port + "打开失败:" + ex.ToString());
LogUtil.error("串口" + port + "打开失败:" + ex.ToString());
}
return true;
}
......@@ -98,12 +98,12 @@ namespace OnlineStore.DeviceLibrary
}
return null;
}
// public static ASTemperateParam LastData = new ASTemperateParam(0, 0);
// public static ASTemperateParam LastData = new ASTemperateParam(0, 0);
public static HumitureParam QueryData(string port)
{
HumitureParam param = new HumitureParam(0, 0,100);
HumitureParam param = new HumitureParam(0, 0, 100);
param.DeviceAddress = port;
List<double> data = queryData(port );
List<double> data = queryData(port);
if (data.Count.Equals(3))
{
//double humidityadjust = (double)ConfigAppSettings.GetNumValue(Setting_Init.Device_HumidityAdjust);
......@@ -129,9 +129,12 @@ namespace OnlineStore.DeviceLibrary
// else
// data[1] += tempadjust;
//}
data[1] = ProcessTemp(data[1]);
data[1] = ProcessTemp(port, data[1]);
param = new HumitureParam(data[1], data[0], data[2]);
}
}
//校准温湿度
return param;
}
/// <summary>
......@@ -139,7 +142,7 @@ namespace OnlineStore.DeviceLibrary
/// </summary>
/// <param name="nowTemp"></param>
/// <returns></returns>
private static double ProcessTemp(double nowTemp)
private static double ProcessTemp(string port, double nowTemp)
{
double temp = nowTemp;
double minVal = 5;//ConfigHelper.Config.Get("TempThreshold_Min", 5);
......@@ -158,7 +161,12 @@ namespace OnlineStore.DeviceLibrary
{
temp = (nowTemp - 11) * (nowTemp - 10) / 10 + 11;
}
else
{
var calib = ConfigHelper.Config.Get($"TemptureCalib_{port}", 0);
nowTemp += calib;
return nowTemp;
}
return Math.Round(temp, 1);
}
/// <summary>
......@@ -204,7 +212,7 @@ namespace OnlineStore.DeviceLibrary
sendData[0] = 0x01;
if (HumitureControllerType.Equals(1))
{
sendData[1] = 0x04;
sendData[1] = 0x04;
}
else
{
......@@ -225,14 +233,14 @@ namespace OnlineStore.DeviceLibrary
return getReviceData(reviceData);
}
public static int QueryHistoryCount(string port)
{
AcSerialBean sb = GetSerialBean(port);
if (sb == null|| HumitureControllerType.Equals(2).Equals(false))
if (sb == null || HumitureControllerType.Equals(2).Equals(false))
{
return -1;
}
}
byte[] sendData = new byte[8];
sendData[0] = 0x01;
sendData[1] = 0x04;
......@@ -255,7 +263,7 @@ namespace OnlineStore.DeviceLibrary
sendData[7] = 0x00;
sendData = buildCheckData(sendData, sendData.Length - 2);
string str = AcSerialBean.byteToHexStr(sendData);
// LogUtil.debug("温湿度控制器发送数据:" + str);
// LogUtil.debug("温湿度控制器发送数据:" + str);
byte[] reviceData = new byte[9];
bool isOk = false;
sb.SendCommand(sendData, ref reviceData, 100, out isOk);
......@@ -339,7 +347,7 @@ namespace OnlineStore.DeviceLibrary
return list;
}
private static byte[] buildCheckData(byte[] sendData, int length)
{
ushort pChecksum = 0;
......@@ -356,7 +364,7 @@ namespace OnlineStore.DeviceLibrary
{
sendData[length + 1] = checkByte[0];
sendData[length] = checkByte[1];
}
}
return sendData;
}
......@@ -371,7 +379,7 @@ namespace OnlineStore.DeviceLibrary
}
if (dataArray.Length >= 9)
{
string data = String.Format("{0:X2}", dataArray[5]) + String.Format("{0:X2}", dataArray[6]+String.Format("{0:X2}", dataArray[3]) + String.Format("{0:X2}", dataArray[4]) );
string data = String.Format("{0:X2}", dataArray[5]) + String.Format("{0:X2}", dataArray[6] + String.Format("{0:X2}", dataArray[3]) + String.Format("{0:X2}", dataArray[4]));
int tempV = Convert.ToInt32(data, 16);
return tempV;
}
......@@ -385,7 +393,7 @@ namespace OnlineStore.DeviceLibrary
private static List<double> getReviceData(byte[] dataArray)
{
List<double> list = new List<double>();
List<double> list = new List<double>();
try
{
if (dataArray == null)
......@@ -411,6 +419,6 @@ namespace OnlineStore.DeviceLibrary
}
return list;
}
}
}
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!