Commit 88993a4a 张东亮

温湿度读取失败1,不更新数据

1 个父辈 f3609f30
...@@ -29,21 +29,21 @@ namespace OnlineStore.DeviceLibrary ...@@ -29,21 +29,21 @@ namespace OnlineStore.DeviceLibrary
} }
public HumitureParam QueryData() public HumitureParam QueryData()
{ {
HumitureParam param = HumitureController.QueryData(PortName); bool rtn = HumitureController.QueryData(PortName, out HumitureParam param);
updateData(PortName, param); return updateData(PortName, rtn, param);
return param;
} }
static void updateData(string port, HumitureParam param) static HumitureParam updateData(string port,bool ok, HumitureParam param)
{ {
var find = LastData.Find(s => port.Equals(s.DeviceAddress)); var find = LastData.Find(s => port.Equals(s.DeviceAddress));
if (find != null) if (ok && find != null)
{ {
find.Temperate = param.Temperate; find.Temperate = param.Temperate;
find.UpdateTime = param.UpdateTime; find.UpdateTime = param.UpdateTime;
find.Humidity = param.Humidity; find.Humidity = param.Humidity;
find.OxygenV = param.OxygenV; find.OxygenV = param.OxygenV;
return find;
} }
return param;
} }
public static double GetMinOxygenV() public static double GetMinOxygenV()
{ {
......
...@@ -44,8 +44,8 @@ namespace OnlineStore.DeviceLibrary ...@@ -44,8 +44,8 @@ namespace OnlineStore.DeviceLibrary
if (sb.openPort()) if (sb.openPort())
{ {
serialBeanMap.Add(port, sb); serialBeanMap.Add(port, sb);
var ht = HumitureController.QueryData(port); var rtn = HumitureController.QueryData(port, out HumitureParam ht);
LogUtil.info(LogName + "串口" + port + "打开成功!温度:" + ht.Temperate + ",湿度:" + ht.Humidity); LogUtil.info(LogName + "串口" + port + $"打开成功!{rtn} 温度:" + ht.Temperate + ",湿度:" + ht.Humidity);
return true; return true;
} }
else else
...@@ -99,9 +99,9 @@ namespace OnlineStore.DeviceLibrary ...@@ -99,9 +99,9 @@ namespace OnlineStore.DeviceLibrary
return null; return null;
} }
// public static ASTemperateParam LastData = new ASTemperateParam(0, 0); // public static ASTemperateParam LastData = new ASTemperateParam(0, 0);
public static HumitureParam QueryData(string port) public static bool QueryData(string port, out HumitureParam param)
{ {
HumitureParam param = new HumitureParam(0, 0, 100); param = new HumitureParam(0, 0, 100);
param.DeviceAddress = port; param.DeviceAddress = port;
List<double> data = queryData(port); List<double> data = queryData(port);
if (data.Count.Equals(3)) if (data.Count.Equals(3))
...@@ -117,7 +117,7 @@ namespace OnlineStore.DeviceLibrary ...@@ -117,7 +117,7 @@ namespace OnlineStore.DeviceLibrary
// else // else
// data[0] += humidityadjust; // data[0] += humidityadjust;
//} //}
data[0] = ProcessHumity(port,data[0]); data[0] = ProcessHumity(port, data[0]);
//double tempadjust = (double)ConfigAppSettings.GetNumValue(Setting_Init.Device_TemptureAdjust); //double tempadjust = (double)ConfigAppSettings.GetNumValue(Setting_Init.Device_TemptureAdjust);
//double templimited = (double)ConfigAppSettings.GetNumValue(Setting_Init.Device_TemptureLimited); //double templimited = (double)ConfigAppSettings.GetNumValue(Setting_Init.Device_TemptureLimited);
//if (tempadjust != 0 && templimited != 0) //if (tempadjust != 0 && templimited != 0)
...@@ -129,21 +129,26 @@ namespace OnlineStore.DeviceLibrary ...@@ -129,21 +129,26 @@ namespace OnlineStore.DeviceLibrary
// else // else
// data[1] += tempadjust; // data[1] += tempadjust;
//} //}
if (data[1]>80) data[1] = ProcessTemp(port, data[1]);
var maxTemp = ConfigHelper.Config.Get("MaxTempThreshold", 60);
var minTemp = ConfigHelper.Config.Get("MinTempThreshold", 0);
if (data[1] >= maxTemp || data[1] <= minTemp)//温度
{ {
data[1] = 0; return false;
} }
if (data[0] > 100) var maxHum = ConfigHelper.Config.Get("MaxHumidityThreshold", 100);
var minHum = ConfigHelper.Config.Get("MinHumidityThreshold", 0);
if (data[0] >= maxHum || data[0] <= minHum)//湿度
{ {
data[0] = 0; return false;
} }
data[1] = ProcessTemp(port, data[1]);
param = new HumitureParam(data[1], data[0], data[2]); param = new HumitureParam(data[1], data[0], data[2]);
return true;
} }
//校准温湿度 //校准温湿度
return param; return false;
} }
/// <summary> /// <summary>
/// 温度数据处理 /// 温度数据处理
...@@ -182,7 +187,7 @@ namespace OnlineStore.DeviceLibrary ...@@ -182,7 +187,7 @@ namespace OnlineStore.DeviceLibrary
/// </summary> /// </summary>
/// <param name="nowHumity"></param> /// <param name="nowHumity"></param>
/// <returns></returns> /// <returns></returns>
private static double ProcessHumity(string port,double nowHumity) private static double ProcessHumity(string port, double nowHumity)
{ {
double temp = nowHumity; double temp = nowHumity;
double minVal = ConfigHelper.Config.Get("HumidityThreshold_Min", 5); double minVal = ConfigHelper.Config.Get("HumidityThreshold_Min", 5);
...@@ -242,123 +247,124 @@ namespace OnlineStore.DeviceLibrary ...@@ -242,123 +247,124 @@ namespace OnlineStore.DeviceLibrary
//LogUtil.debug("温湿度控制器发送数据:" + str); //LogUtil.debug("温湿度控制器发送数据:" + str);
byte[] reviceData = new byte[9]; byte[] reviceData = new byte[9];
bool isOk = false; bool isOk = false;
sb.SendCommand(sendData, ref reviceData, 100, out isOk); sb.SendCommand(sendData, ref reviceData, 200, out isOk);
LogUtil.debug($"{port}({isOk}):【{AcSerialBean.byteToHexStr(sendData)}】【{AcSerialBean.byteToHexStr(reviceData)}】");
return getReviceData(reviceData); return getReviceData(reviceData);
} }
public static int QueryHistoryCount(string port) //public static int QueryHistoryCount(string port)
{ //{
AcSerialBean sb = GetSerialBean(port); // AcSerialBean sb = GetSerialBean(port);
if (sb == null || HumitureControllerType.Equals(2).Equals(false)) // if (sb == null || HumitureControllerType.Equals(2).Equals(false))
{ // {
return -1; // return -1;
} // }
byte[] sendData = new byte[8]; // byte[] sendData = new byte[8];
sendData[0] = 0x01; // sendData[0] = 0x01;
sendData[1] = 0x04; // sendData[1] = 0x04;
sendData[2] = 0x20; // sendData[2] = 0x20;
sendData[3] = 0x00; // sendData[3] = 0x00;
byte[] addrByte = AcSerialBean.StringToByte("2000"); // byte[] addrByte = AcSerialBean.StringToByte("2000");
if (addrByte.Length == 1) // if (addrByte.Length == 1)
{ // {
sendData[2] = 0x00; // sendData[2] = 0x00;
sendData[3] = addrByte[0]; // sendData[3] = addrByte[0];
} // }
else if (addrByte.Length == 2) // else if (addrByte.Length == 2)
{ // {
sendData[3] = addrByte[1]; // sendData[3] = addrByte[1];
sendData[2] = addrByte[0]; // sendData[2] = addrByte[0];
} // }
sendData[4] = 0x00; // sendData[4] = 0x00;
sendData[5] = 0x02; // sendData[5] = 0x02;
sendData[6] = 0x00; // sendData[6] = 0x00;
sendData[7] = 0x00; // sendData[7] = 0x00;
sendData = buildCheckData(sendData, sendData.Length - 2); // sendData = buildCheckData(sendData, sendData.Length - 2);
string str = AcSerialBean.byteToHexStr(sendData); // string str = AcSerialBean.byteToHexStr(sendData);
// LogUtil.debug("温湿度控制器发送数据:" + str); // // LogUtil.debug("温湿度控制器发送数据:" + str);
byte[] reviceData = new byte[9]; // byte[] reviceData = new byte[9];
bool isOk = false; // bool isOk = false;
sb.SendCommand(sendData, ref reviceData, 100, out isOk); // sb.SendCommand(sendData, ref reviceData, 100, out isOk);
return getReviceIntData(reviceData); // return getReviceIntData(reviceData);
} //}
public static int QueryCurrCount(string port) //public static int QueryCurrCount(string port)
{ //{
AcSerialBean sb = GetSerialBean(port); // AcSerialBean sb = GetSerialBean(port);
if (sb == null || HumitureControllerType.Equals(2).Equals(false)) // if (sb == null || HumitureControllerType.Equals(2).Equals(false))
{ // {
return -1; // return -1;
} // }
byte[] sendData = new byte[8]; // byte[] sendData = new byte[8];
sendData[0] = 0x01; // sendData[0] = 0x01;
sendData[1] = 0x04; // sendData[1] = 0x04;
sendData[2] = 0x20; // sendData[2] = 0x20;
sendData[3] = 0x02; // sendData[3] = 0x02;
sendData[4] = 0x00; // sendData[4] = 0x00;
sendData[5] = 0x02; // sendData[5] = 0x02;
sendData[6] = 0x00; // sendData[6] = 0x00;
sendData[7] = 0x00; // sendData[7] = 0x00;
sendData = buildCheckData(sendData, sendData.Length - 2); // sendData = buildCheckData(sendData, sendData.Length - 2);
string str = AcSerialBean.byteToHexStr(sendData); // string str = AcSerialBean.byteToHexStr(sendData);
//LogUtil.debug("温湿度控制器发送数据:" + str); // //LogUtil.debug("温湿度控制器发送数据:" + str);
byte[] reviceData = new byte[9]; // byte[] reviceData = new byte[9];
bool isOk = false; // bool isOk = false;
sb.SendCommand(sendData, ref reviceData, 100, out isOk); // sb.SendCommand(sendData, ref reviceData, 100, out isOk);
return getReviceIntData(reviceData); // return getReviceIntData(reviceData);
} //}
public static List<object> QueryHistory(string port) //public static List<object> QueryHistory(string port)
{ //{
List<object> list = new List<object>(); // List<object> list = new List<object>();
AcSerialBean sb = GetSerialBean(port); // AcSerialBean sb = GetSerialBean(port);
if (sb == null || HumitureControllerType.Equals(2).Equals(false)) // if (sb == null || HumitureControllerType.Equals(2).Equals(false))
{ // {
return list; // return list;
} // }
byte[] sendData = new byte[8]; // byte[] sendData = new byte[8];
sendData[0] = 0x01; // sendData[0] = 0x01;
sendData[1] = 0x04; // sendData[1] = 0x04;
sendData[2] = 0x20; // sendData[2] = 0x20;
sendData[3] = 0x04; // sendData[3] = 0x04;
sendData[4] = 0x00; // sendData[4] = 0x00;
sendData[5] = 0x05; // sendData[5] = 0x05;
sendData[6] = 0x00; // sendData[6] = 0x00;
sendData[7] = 0x00; // sendData[7] = 0x00;
sendData = buildCheckData(sendData, sendData.Length - 2); // sendData = buildCheckData(sendData, sendData.Length - 2);
string str = AcSerialBean.byteToHexStr(sendData); // string str = AcSerialBean.byteToHexStr(sendData);
//LogUtil.debug("温湿度控制器发送数据:" + str); // //LogUtil.debug("温湿度控制器发送数据:" + str);
byte[] reviceData = new byte[15]; // byte[] reviceData = new byte[15];
bool isOk = false; // bool isOk = false;
sb.SendCommand(sendData, ref reviceData, 100, out isOk); // sb.SendCommand(sendData, ref reviceData, 100, out isOk);
try // try
{ // {
if (reviceData != null && reviceData.Length >= 9) // if (reviceData != null && reviceData.Length >= 9)
{ // {
string temp = String.Format("{0:X2}", reviceData[3]) + String.Format("{0:X2}", reviceData[4]); // string temp = String.Format("{0:X2}", reviceData[3]) + String.Format("{0:X2}", reviceData[4]);
string hum = String.Format("{0:X2}", reviceData[5]) + String.Format("{0:X2}", reviceData[6]); // string hum = String.Format("{0:X2}", reviceData[5]) + String.Format("{0:X2}", reviceData[6]);
double tempV = (double)Convert.ToInt32(temp, 16) / 10; // double tempV = (double)Convert.ToInt32(temp, 16) / 10;
double humV = (double)Convert.ToInt32(hum, 16) / 10; // double humV = (double)Convert.ToInt32(hum, 16) / 10;
int year = Convert.ToInt32(String.Format("{0:X2}", reviceData[7]), 16); // int year = Convert.ToInt32(String.Format("{0:X2}", reviceData[7]), 16);
int mouth = Convert.ToInt32(String.Format("{0:X2}", reviceData[8]), 16); // int mouth = Convert.ToInt32(String.Format("{0:X2}", reviceData[8]), 16);
int day = Convert.ToInt32(String.Format("{0:X2}", reviceData[9]), 16); // int day = Convert.ToInt32(String.Format("{0:X2}", reviceData[9]), 16);
int hour = Convert.ToInt32(String.Format("{0:X2}", reviceData[10]), 16); // int hour = Convert.ToInt32(String.Format("{0:X2}", reviceData[10]), 16);
int minute = Convert.ToInt32(String.Format("{0:X2}", reviceData[11]), 16); // int minute = Convert.ToInt32(String.Format("{0:X2}", reviceData[11]), 16);
int second = Convert.ToInt32(String.Format("{0:X2}", reviceData[12]), 16); // int second = Convert.ToInt32(String.Format("{0:X2}", reviceData[12]), 16);
DateTime time = new DateTime(year, mouth, day, hour, minute, second); // DateTime time = new DateTime(year, mouth, day, hour, minute, second);
list.Add(tempV); // list.Add(tempV);
list.Add(humV); // list.Add(humV);
list.Add(time); // list.Add(time);
} // }
} // }
catch (Exception ex) // catch (Exception ex)
{ // {
LogUtil.info(LogName + "转换出错:" + ex.ToString()); // LogUtil.info(LogName + "转换出错:" + ex.ToString());
} // }
return list; // return list;
} //}
private static byte[] buildCheckData(byte[] sendData, int length) private static byte[] buildCheckData(byte[] sendData, int length)
......
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!