fyf преди 2 години
родител
ревизия
cbc79d432e
променени са 3 файла, в които са добавени 68 реда и са изтрити 59 реда
  1. +1
    -0
      HBLConsole.Business/HeartbeatReport.cs
  2. +66
    -58
      HBLConsole.Business/IotReport.cs
  3. +1
    -1
      HBLConsole.MainConsole/Main.cs

+ 1
- 0
HBLConsole.Business/HeartbeatReport.cs Целия файл

@@ -46,6 +46,7 @@ namespace HBLConsole.Business
MessagePackage.Timestamp = DateTime.Now;
MessagePackage.Message = deviceStatus;//GetMessage == null ? deviceStatus : GetMessage();
MqttHelper.GetInstance.MqttPublishAsync(Topic, MessagePackage.Serialize());
IotReport.GetInstance.SendTargetMessage();
Thread.Sleep(1000);
}), "设备心跳上报");



+ 66
- 58
HBLConsole.Business/IotReport.cs Целия файл

@@ -77,6 +77,58 @@ namespace HBLConsole.Business
IOTDevServer.GetInstance().IOT_Publish(IOTDevServer.PubTopic,jsonstr);
}
}

/// <summary>
/// 上报属性状态
/// 调用示例:SendTargetMessage();
/// </summary>
/// <param name="json"></param>
public void SendTargetMessage()
{
if (IOTDevServer.client != null && IOTDevServer.client.IsConnected)
{
string kzsx = string.Empty;
string jbsx = Tools.JsonConvertTools<DevSX>(new DevSX
{
data = new List<DevSXBase>
{
new DevSXBase { SXMC="设备硬件",SXLX="机器人",SXStatus=ModbusTcpHelper.GetInstance.Connected
,SXYCMS=ModbusTcpHelper.GetInstance.Connected?"":DateTime.Now+" 异常,机器人未连接,疑似未连接网络...."},
new DevSXBase { SXMC="设备软件",SXLX="上位机",SXStatus=true }
}
});
bool IsAllowRun = GetTypeValue<bool>("AllowRun");
bool TemperatureReached = GetTypeValue<bool>("TemperatureReached");
bool MissingBowl = GetTypeValue<bool>("MissingBowl");
bool MissingBowlSignal2 = GetTypeValue<bool>("MissingBowlSignal2");
bool IsNoodles = GetTypeValue<bool>("IsNoodles");//转台
bool AllowFallNoodle = GetTypeValue<bool>("AllowFallNoodle");//是否允许到面
bool[] CookNoodlesComplete = GetTypeValue<bool[]>("CookNoodlesComplete");//煮面完成上升信号
bool isCookNoodles = CookNoodlesComplete.ToList().Find(o => o);
//设置扩展属性与状态,连接上机器人后才会处罚
if (IsAllowRun)
{
kzsx = Tools.JsonConvertTools<DevSX>(new DevSX
{
data = new List<DevSXBase>
{
new DevSXBase { SXMC="设备硬件",SXLX="煮面炉",SXStatus= !TemperatureReached ,
SXYCMS=!TemperatureReached?"":DateTime.Now+" 异常,煮面炉温度不够,疑似正在加热或者未工作...."},
new DevSXBase { SXMC="设备硬件",SXLX="装小碗结构",SXStatus=MissingBowl ,
SXYCMS=MissingBowl?"":DateTime.Now+" 异常,缺小碗...."},
new DevSXBase { SXMC="设备硬件",SXLX="装大碗结构",SXStatus=MissingBowlSignal2 ,
SXYCMS=MissingBowlSignal2?"":DateTime.Now+" 异常,缺大碗...."},
new DevSXBase { SXMC="设备硬件",SXLX="取面转台",SXStatus=IsNoodles ,
SXYCMS=IsNoodles?"":DateTime.Now+" 异常,转台位置缺少物料...."},
new DevSXBase { SXMC="设备硬件",SXLX="配料机",SXStatus=!(!AllowFallNoodle && isCookNoodles) ,
SXYCMS=!((!AllowFallNoodle && isCookNoodles))?"":DateTime.Now+" 异常,配料机未配完料,疑似碗未到配料机下方或者配料机未工作...."}
}
});
}
string jsonstr = Tools.JsonConvertTools<IotModel<TargetIOT>>(new IotModel<TargetIOT> { @params = new TargetIOT { JBSX = jbsx,KZSX = kzsx } });
IOTDevServer.GetInstance().IOT_Publish(IOTDevServer.PubTopic,jsonstr);
}
}
#endregion

#region 外部关闭或初始化IOT调用
@@ -125,64 +177,6 @@ namespace HBLConsole.Business
}
#endregion

#region 废弃代码
/// <summary>
/// 设置上报基本与扩展数据
/// </summary>
public void SetData()
{
#region 基本数据
//设置基本属性与状态
iOTDevSXModel.SetJBSX(new DevSX
{
data = new List<DevSXBase>
{
new DevSXBase { SXMC="设备硬件",SXLX="机器人",SXStatus=ModbusTcpHelper.GetInstance.Connected
,SXYCMS=ModbusTcpHelper.GetInstance.Connected?"":DateTime.Now+" 异常,机器人未连接,疑似未连接网络...."},
new DevSXBase { SXMC="设备软件",SXLX="上位机",SXStatus=true }
}
});
#endregion

#region 扩展数据
bool IsAllowRun = GetTypeValue<bool>("AllowRun");
bool TemperatureReached = GetTypeValue<bool>("TemperatureReached");
bool MissingBowl = GetTypeValue<bool>("MissingBowl");
bool MissingBowlSignal2 = GetTypeValue<bool>("MissingBowlSignal2");
bool IsNoodles = GetTypeValue<bool>("IsNoodles");//转台
bool AllowFallNoodle = GetTypeValue<bool>("AllowFallNoodle");//是否允许到面
bool[] CookNoodlesComplete = GetTypeValue<bool[]>("CookNoodlesComplete");//煮面完成上升信号
bool isCookNoodles = CookNoodlesComplete.ToList().Find(o => o);
//设置扩展属性与状态,连接上机器人后才会处罚
if (IsAllowRun)
{
iOTDevSXModel.SetKZSX(new DevSX
{
data = new List<DevSXBase>
{
new DevSXBase { SXMC="设备硬件",SXLX="煮面炉",SXStatus= !TemperatureReached ,
SXYCMS=!TemperatureReached?"":DateTime.Now+" 异常,煮面炉温度不够,疑似正在加热或者未工作...."},
new DevSXBase { SXMC="设备硬件",SXLX="装小碗结构",SXStatus=MissingBowl ,
SXYCMS=MissingBowl?"":DateTime.Now+" 异常,缺小碗...."},
new DevSXBase { SXMC="设备硬件",SXLX="装大碗结构",SXStatus=MissingBowlSignal2 ,
SXYCMS=MissingBowlSignal2?"":DateTime.Now+" 异常,缺大碗...."},
new DevSXBase { SXMC="设备硬件",SXLX="取面转台",SXStatus=IsNoodles ,
SXYCMS=IsNoodles?"":DateTime.Now+" 异常,转台位置缺少物料...."},
new DevSXBase { SXMC="设备硬件",SXLX="配料机",SXStatus=!(!AllowFallNoodle && isCookNoodles) ,
SXYCMS=!((!AllowFallNoodle && isCookNoodles))?"":DateTime.Now+" 异常,配料机未配完料,疑似碗未到配料机下方或者配料机未工作...."}
}
});
}
else
{
iOTDevSXModel.SetKZSX(new DevSX { data = new List<DevSXBase> { new DevSXBase { SXMC = "",SXLX = "" } } });
}
#endregion

IOTDevServer.GetInstance().IOT_Publish(IOTDevServer.PubTopic,iOTDevSXModel.Tojson());
}
#endregion

#region 私有函数
/// <summary>
/// 获取属性状态
@@ -215,4 +209,18 @@ namespace HBLConsole.Business
{
public string NodeStatus { get; set; }
}
/// <summary>
/// 基本属性与扩展属性
/// </summary>
public class TargetIOT
{
/// <summary>
/// 基本属性
/// </summary>
public string JBSX { get; set; }
/// <summary>
/// 扩展属性
/// </summary>
public string KZSX { get; set; }
}
}

+ 1
- 1
HBLConsole.MainConsole/Main.cs Целия файл

@@ -54,7 +54,7 @@ namespace HBLConsole.MainConsole
ThreadManage.GetInstance.Start(new Action(() =>
{
InternetInfo.ConfigInit();//从 consul 获取配置数据
//IotReport.GetInstance.Initialize();
IotReport.GetInstance.Initialize();
Topics.Clear();
Topics.Add(TOPIC.GetInstance.GetOrderPushTopic(GeneralConfig.DeviceType, InternetInfo.ClientId));
Topics.Add(TOPIC.GetInstance.GetBusinessTopic(GeneralConfig.DeviceType, InternetInfo.ClientId));


Зареждане…
Отказ
Запис