You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

265 lines
21 KiB

  1. using BPA.Message.IOT;
  2. using HBLConsole.Communication;
  3. using HBLConsole.GVL;
  4. using HBLConsole.Interface;
  5. using HBLConsole.Service;
  6. using System;
  7. using System.Collections.Generic;
  8. using System.Linq;
  9. using System.Reflection;
  10. using System.Text;
  11. using System.Threading;
  12. using System.Threading.Tasks;
  13. using HBLConsole.Factory;
  14. using BPA.Message.API请求;
  15. namespace HBLConsole.Business
  16. {
  17. public class IotReport
  18. {
  19. #region 单例模式
  20. private volatile static IotReport _Instance;
  21. public static IotReport GetInstance => _Instance ?? (_Instance = new IotReport());
  22. #endregion
  23. #region 变量
  24. /// <summary>
  25. /// 查询出当前设备信息
  26. /// </summary>
  27. public DeviceTable device;
  28. /// <summary>
  29. /// 大屏上报Model
  30. /// </summary>
  31. public IOTDevSXModel iOTDevSXModel = new IOTDevSXModel() { };
  32. /// <summary>
  33. /// 属性状态
  34. /// </summary>
  35. public string NodeStatus = "{\"data\":[{\"Id\":0,\"VarName\":\"InitComplete\",\"PLCAddress\":\"M100.0\",\"Notes\":\"初始化完成\",\"ModbusTcpAddress\":\"1120\",\"CurrentValue\":\"False\"},{\"Id\":1,\"VarName\":\"TurntableInPlace\",\"PLCAddress\":\"M100.1\",\"Notes\":\"转台到位\",\"ModbusTcpAddress\":\"1121\",\"CurrentValue\":\"False\"},{\"Id\":2,\"VarName\":\"RBTakeNoodleComplete\",\"PLCAddress\":\"M100.2\",\"Notes\":\"机器人取面完成\",\"ModbusTcpAddress\":\"1122\",\"CurrentValue\":\"False\"},{\"Id\":3,\"VarName\":\"AxisIdle_1\",\"PLCAddress\":\"M100.3\",\"Notes\":\"轴空闲_1\",\"ModbusTcpAddress\":\"1123\",\"CurrentValue\":\"False\"},{\"Id\":4,\"VarName\":\"AxisIdle_2\",\"PLCAddress\":\"M100.4\",\"Notes\":\"轴空闲_2\",\"ModbusTcpAddress\":\"1124\",\"CurrentValue\":\"False\"},{\"Id\":5,\"VarName\":\"AxisAllowInvertedNoodle_1\",\"PLCAddress\":\"M100.5\",\"Notes\":\"轴允许倒面_1\",\"ModbusTcpAddress\":\"1125\",\"CurrentValue\":\"False\"},{\"Id\":6,\"VarName\":\"AxisAllowInvertedNoodle_2\",\"PLCAddress\":\"M100.6\",\"Notes\":\"轴允许倒面_2\",\"ModbusTcpAddress\":\"1126\",\"CurrentValue\":\"False\"},{\"Id\":7,\"VarName\":\"AxisAllowInvertedSoup_1\",\"PLCAddress\":\"M101.0\",\"Notes\":\"轴允许倒浇头_1\",\"ModbusTcpAddress\":\"1127\",\"CurrentValue\":\"False\"},{\"Id\":8,\"VarName\":\"AxisAllowInvertedSoup_2\",\"PLCAddress\":\"M101.0\",\"Notes\":\"轴允许倒浇头_2\",\"ModbusTcpAddress\":\"1128\",\"CurrentValue\":\"False\"},{\"Id\":9,\"VarName\":\"SoupHeatComplete_1\",\"PLCAddress\":\"M101.1\",\"Notes\":\"浇头加热完成_1\",\"ModbusTcpAddress\":\"1129\",\"CurrentValue\":\"False\"},{\"Id\":10,\"VarName\":\"SoupHeatComplete_2\",\"PLCAddress\":\"M101.2\",\"Notes\":\"浇头加热完成_2\",\"ModbusTcpAddress\":\"1130\",\"CurrentValue\":\"False\"},{\"Id\":11,\"VarName\":\"CookNoodleBasketIdle_1\",\"PLCAddress\":\"M101.3\",\"Notes\":\"煮面篮空闲_1\",\"ModbusTcpAddress\":\"1131\",\"CurrentValue\":\"False\"},{\"Id\":12,\"VarName\":\"CookNoodleBasketIdle_2\",\"PLCAddress\":\"M101.4\",\"Notes\":\"煮面篮空闲_2\",\"ModbusTcpAddress\":\"1132\",\"CurrentValue\":\"False\"},{\"Id\":13,\"VarName\":\"CookNoodleBasketIdle_3\",\"PLCAddress\":\"M101.5\",\"Notes\":\"煮面篮空闲_3\",\"ModbusTcpAddress\":\"1133\",\"CurrentValue\":\"False\"},{\"Id\":14,\"VarName\":\"CookNoodleBasketIdle_4\",\"PLCAddress\":\"M101.6\",\"Notes\":\"煮面篮空闲_4\",\"ModbusTcpAddress\":\"1134\",\"CurrentValue\":\"False\"},{\"Id\":15,\"VarName\":\"CookNoodleBasketIdle_5\",\"PLCAddress\":\"M101.7\",\"Notes\":\"煮面篮空闲_5\",\"ModbusTcpAddress\":\"1135\",\"CurrentValue\":\"False\"},{\"Id\":16,\"VarName\":\"CookNoodleBasketIdle_6\",\"PLCAddress\":\"M101.8\",\"Notes\":\"煮面篮空闲_6\",\"ModbusTcpAddress\":\"1136\",\"CurrentValue\":\"False\"},{\"Id\":17,\"VarName\":\"CookNoodleComplete_1\",\"PLCAddress\":\"M102.1\",\"Notes\":\"煮面完成_1\",\"ModbusTcpAddress\":\"1137\",\"CurrentValue\":\"False\"},{\"Id\":18,\"VarName\":\"CookNoodleComplete_2\",\"PLCAddress\":\"M102.2\",\"Notes\":\"煮面完成_2\",\"ModbusTcpAddress\":\"1138\",\"CurrentValue\":\"False\"},{\"Id\":19,\"VarName\":\"CookNoodleComplete_3\",\"PLCAddress\":\"M102.3\",\"Notes\":\"煮面完成_3\",\"ModbusTcpAddress\":\"1139\",\"CurrentValue\":\"False\"},{\"Id\":20,\"VarName\":\"CookNoodleComplete_4\",\"PLCAddress\":\"M102.4\",\"Notes\":\"煮面完成_4\",\"ModbusTcpAddress\":\"1140\",\"CurrentValue\":\"False\"},{\"Id\":21,\"VarName\":\"CookNoodleComplete_5\",\"PLCAddress\":\"M102.5\",\"Notes\":\"煮面完成_5\",\"ModbusTcpAddress\":\"1141\",\"CurrentValue\":\"False\"},{\"Id\":22,\"VarName\":\"CookNoodleComplete_6\",\"PLCAddress\":\"M102.6\",\"Notes\":\"煮面完成_6\",\"ModbusTcpAddress\":\"1142\",\"CurrentValue\":\"False\"},{\"Id\":23,\"VarName\":\"TakeNoodleRobotIdle\",\"PLCAddress\":\"M102.7\",\"Notes\":\"取面机器人空闲状态\",\"ModbusTcpAddress\":\"1143\",\"CurrentValue\":\"False\"},{\"Id\":24,\"VarName\":\"TakeSoupRobotIdle\",\"PLCAddress\":\"M103.0\",\"Notes\":\"取浇头机器人空闲状态\",\"ModbusTcpAddress\":\"1144\",\"CurrentValue\":\"False\"},{\"Id\":25,\"VarName\":\"BreakMechanismIdle_1\",\"PLCAddress\":\"M103.1\",\"Notes\":\"破口机构空闲_1\",\"ModbusTcpAddress\":\"1145\",\"CurrentValue\":\"False\"},{\"Id\":26,\"VarName\":\"BreakMechanismIdle_2\",\"PLCAddress\":\"M103.2\",\"Notes\":\"破口机构空闲_2\",\"ModbusTcpAddress\":\"1146\",\"CurrentValue\":\"False\"},{\"Id\":27,\"VarName\":\"TakeSoupComplete\",\"PLCAddress\":\"M103.3\",\"Notes\":\"取浇头完成\",\"ModbusTcpAddress\":\"1147\",\"CurrentValue\":\"False\"},{\"Id\":28,\"VarName\":\"PutNoodleTakeMealComplete\",\"PLCAddress\":\"M103.4\",\"Notes\":\"放面至取餐口完成\",\"ModbusTcpAddress\":\"1148\",\"CurrentValue\":\"False\"},{\"Id\":29,\"VarName\":\"Initing\",\"PLCAddress\":\"M103.5\",\"Notes\":\"设备初始化中\",\"ModbusTcpAddress\":\"1149\",\"CurrentValue\":\"False\"},{\"Id\":30,\"VarName\":\"TurntableFeedbackloc\",\"PLCAddress\":\"VW1240\",\"Notes\":\"转台反馈位置\",\"ModbusTcpAddress\":\"720\",\"CurrentValue\":\"0\"},{\"Id\":31,\"VarName\":\"TurntableLowerLimit\",\"PLCAddress\":\"M120.0\",\"Notes\":\"转台下限位\",\"ModbusTcpAddress\":\"1280\",\"CurrentValue\":\"False\"},{\"Id\":32,\"VarName\":\"TurntableUpLimit\",\"PLCAddress\":\"M120.1\",\"Notes\":\"转台上限位\",\"ModbusTcpAddress\":\"1281\",\"CurrentValue\":\"False\"},{\"Id\":33,\"VarName\":\"SoupMaterialShortage_1\",\"PLCAddress\":\"M120.2\",\"Notes\":\"浇头缺料_1\",\"ModbusTcpAddress\":\"1282\",\"CurrentValue\":\"False\"},{\"Id\":34,\"VarName\":\"SoupMaterialShortage_2\",\"PLCAddress\":\"M120.3\",\"Notes\":\"浇头缺料_2\",\"ModbusTcpAddress\":\"1283\",\"CurrentValue\":\"False\"},{\"Id\":35,\"VarName\":\"SoupMaterialShortage_3\",\"PLCAddress\":\"M120.4\",\"Notes\":\"浇头缺料_3\",\"ModbusTcpAddress\":\"1284\",\"CurrentValue\":\"False\"},{\"Id\":36,\"VarName\":\"SoupMaterialShortage_4\",\"PLCAddress\":\"M120.5\",\"Notes\":\"浇头缺料_4\",\"ModbusTcpAddress\":\"1285\",\"CurrentValue\":\"False\"},{\"Id\":37,\"VarName\":\"SoupMaterialShortage_5\",\"PLCAddress\":\"M120.6\",\"Notes\":\"浇头缺料_5\",\"ModbusTcpAddress\":\"1286\",\"CurrentValue\":\"False\"},{\"Id\":38,\"VarName\":\"OutMealDetect_1\",\"PLCAddress\":\"M121.0\",\"Notes\":\"出餐口检测_1\",\"ModbusTcpAddress\":\"1287\",\"CurrentValue\":\"False\"},{\"Id\":39,\"VarName\":\"OutMealDetect_2\",\"PLCAddress\":\"M121.0\",\"Notes\":\"出餐口检测_2\",\"ModbusTcpAddress\":\"1288\",\"CurrentValue\":\"False\"},{\"Id\":40,\"VarName\":\"OutMealDetect_3\",\"PLCAddress\":\"M121.0\",\"Notes\":\"出餐口检测_3\",\"ModbusTcpAddress\":\"1289\",\"CurrentValue\":\"False\"},{\"Id\":41,\"VarName\":\"TemperatureReached\",\"PLCAddress\":\"M121.2\",\"Notes\":\"温度到达\",\"ModbusTcpAddress\":\"1290\",\"CurrentValue\":\"False\"},{\"Id\":42,\"VarName\":\"AllowPutSoup\",\"PLCAddress\":\"\",\"Notes\":\"允许倒浇头\",\"ModbusTcpAddress\":\"\",\"CurrentValue\":\"False\"},{\"Id\":43,\"VarName\":\"AllowTakeSoup\",\"PLCAddress\":\"\",\"Notes\":\"允许取浇头\",\"ModbusTcpAddress\":\"\",\"CurrentValue\":\"False\"},{\"Id\":44,\"VarName\":\"PutNoodleLoc\",\"PLCAddress\":\"\",\"Notes\":\"放面位置\",\"ModbusTcpAddress\":\"\",\"CurrentValue\":\"0\"},{\"Id\":45,\"VarName\":\"AxisIdleIndex\",\"PLCAddress\":\"\",\"Notes\":\"轴空闲位置\",\"ModbusTcpAddress\":\"\",\"CurrentValue\":\"-1\"},{\"Id\":46,\"VarName\":\"AxisIdleLockIndex\",\"PLCAddress\":\"\",\"Notes\":\"轴空闲互锁位置\",\"ModbusTcpAddress\":\"\",\"CurrentValue\":\"0\"},{\"Id\":47,\"VarName\":\"TurntableLoc\",\"PLCAddress\":\"\",\"Notes\":\"转台位置\",\"ModbusTcpAddress\":\"\",\"CurrentValue\":\"0\"},{\"Id\":48,\"VarName\":\"RobotTaskInterlock\",\"PLCAddress\":\"\",\"Notes\":\"机器人任务互锁信号\",\"ModbusTcpAddress\":\"\",\"CurrentValue\":\"False\"},{\"Id\":49,\"VarName\":\"TakeBowlInterlock\",\"PLCAddress\":\"\",\"Notes\":\"取碗互锁信号\",\"ModbusTcpAddress\":\"\",\"CurrentValue\":\"False\"},{\"Id\":50,\"VarName\":\"TakeNoodleInterlock\",\"PLCAddress\":\"\",\"Notes\":\"取面互锁信号\",\"ModbusTcpAddress\":\"\",\"CurrentValue\":\"False\"},{\"Id\":51,\"VarName\":\"OutNoodleing\",\"PLCAddress\":\"\",\"Notes\":\"出面中\",\"ModbusTcpAddress\":\"\",\"CurrentValue\":\"False\"},{\"Id\":52,\"VarName\":\"AllowTakeNoodle\",\"PLCAddress\":\"\",\"Notes\":\"允许取面\",\"ModbusTcpAddress\":\"\",\"CurrentValue\":\"False\"},{\"Id\":53,\"VarName\":\"TurntableInterlock\",\"PLCAddress\":\"\",\"Notes\":\"转台互锁信号\",\"ModbusTcpAddress\":\"\",\"CurrentValue\":\"False\"},{\"Id\":54,\"VarName\":\"CookNodeState_1\",\"PLCAddress\":null,\"Notes\":\"煮面炉互锁_1\",\"ModbusTcpAddress\":null,\"CurrentValue\":\"False\"},{\"Id\":55,\"VarName\":\"CookNodeState_2\",\"PLCAddress\":null,\"Notes\":\"煮面炉互锁_2\",\"ModbusTcpAddress\":null,\"CurrentValue\":\"False\"},{\"Id\":56,\"VarName\":\"CookNodeState_3\",\"PLCAddress\":null,\"Notes\":\"煮面炉互锁_3\",\"ModbusTcpAddress\":null,\"CurrentValue\":\"False\"},{\"Id\":57,\"VarName\":\"CookNodeState_4\",\"PLCAddress\":null,\"Notes\":\"煮面炉互锁_4\",\"ModbusTcpAddress\":null,\"CurrentValue\":\"False\"},{\"Id\":58,\"VarName\":\"CookNodeState_5\",\"PLCAddress\":null,\"Notes\":\"煮面炉互锁_5\",\"ModbusTcpAddress\":null,\"CurrentValue\":\"False\"},{\"Id\":59,\"VarName\":\"CookNodeState_6\",\"PLCAddress\":null,\"Notes\":\"煮面炉互锁_6\",\"ModbusTcpAddress\":null,\"CurrentValue\":\"False\"},{\"Id\":60,\"VarName\":\"AxisIdleLock_1\",\"PLCAddress\":null,\"Notes\":\"轴空闲互锁_1\",\"ModbusTcpAddress\":null,\"CurrentValue\":\"False\"},{\"Id\":61,\"VarName\":\"AxisIdleLock_2\",\"PLCAddress\":null,\"Notes\":\"轴空闲互锁_2\",\"ModbusTcpAddress\":null,\"CurrentValue\":\"False\"},{\"Id\":62,\"VarName\":\"AllowRun\",\"PLCAddress\":\"\",\"Notes\":\"允许运行\",\"ModbusTcpAddress\":\"\",\"CurrentValue\":\"False\"}]}";
  36. #endregion
  37. #region IOT上报公共调用
  38. /// <summary>
  39. /// 上报告警消息
  40. /// 调用示例: SendAlarmMessage(new AlarmTable { AlarmTime = DateTime.Now,AlarmType = "1",AlarmMessage = "煮面机异常",AlarmVla = "煮面机" });
  41. /// </summary>
  42. /// <param name="alarmTable"></param>
  43. public void SendAlarmMessage(AlarmTable alarmTable)
  44. {
  45. if (IOTDevServer.client != null && IOTDevServer.client.IsConnected && device!=null)
  46. {
  47. alarmTable.ClientId = InternetInfo.ClientId.ToString();
  48. alarmTable.devicename = device.devicename;
  49. string json = Tools.JsonConvertTools<IotModel<AlarmIOT>>(new IotModel<AlarmIOT> { @params = new AlarmIOT { GJXX = Tools.JsonConvertTools(alarmTable) } });
  50. IOTDevServer.GetInstance().IOT_Publish(IOTDevServer.PubTopic,json);
  51. }
  52. }
  53. /// <summary>
  54. /// 上报日志消息
  55. /// 调用示例:SendLogMessage(new LogTable { LogTime = DateTime.Now,LogType = "1",LogMessage = "程序异常",LogVla = "程序" });
  56. /// </summary>
  57. /// <param name="logTable"></param>
  58. public void SendLogMessage(LogTable logTable)
  59. {
  60. if (IOTDevServer.client != null && IOTDevServer.client.IsConnected && device != null)
  61. {
  62. logTable.devicename = device.devicename;
  63. logTable.ClientId = InternetInfo.ClientId.ToString();
  64. string json = Tools.JsonConvertTools<IotModel<LogIOT>>(new IotModel<LogIOT> { @params = new LogIOT { SZXX = Tools.JsonConvertTools(logTable) } });
  65. IOTDevServer.GetInstance().IOT_Publish(IOTDevServer.PubTopic,json);
  66. }
  67. }
  68. /// <summary>
  69. /// 上报节点状态消息
  70. /// 调用示例:SendNodeStatusMessage("json字符串");
  71. /// </summary>
  72. /// <param name="json"></param>
  73. public void SendNodeStatusMessage(string json)
  74. {
  75. //if (IOTDevServer.client!=null && IOTDevServer.client.IsConnected && device != null)
  76. //{
  77. // string jsonstr = Tools.JsonConvertTools<IotModel<NodeStatusIOT>>(new IotModel<NodeStatusIOT> { @params = new NodeStatusIOT { NodeStatus = Tools.JsonConvertTools(json) } });
  78. // IOTDevServer.GetInstance().IOT_Publish(IOTDevServer.PubTopic,jsonstr);
  79. //}
  80. NodeStatus = json;
  81. }
  82. /// <summary>
  83. /// 上报属性状态
  84. /// 调用示例:SendTargetMessage();
  85. /// </summary>
  86. /// <param name="json"></param>
  87. public void SendTargetMessage()
  88. {
  89. if (IOTDevServer.client != null && IOTDevServer.client.IsConnected && device != null)
  90. {
  91. #region 私有变量
  92. bool IsAllowRun = false;
  93. bool TemperatureReached = false;
  94. #endregion
  95. string kzsx = Tools.JsonConvertTools<DevSX>(new DevSX{ data = new List<DevSXBase> { new DevSXBase { SXMC="", SXLX="" } }});
  96. string jbsx = Tools.JsonConvertTools<DevSX>(new DevSX
  97. {
  98. data = new List<DevSXBase>
  99. {
  100. new DevSXBase { SXMC="设备硬件",SXLX="机器人",SXStatus=ModbusTcpHelper.GetInstance.Connected
  101. ,SXYCMS=ModbusTcpHelper.GetInstance.Connected?"":DateTime.Now+" 异常,机器人未连接,疑似未连接网络...."},
  102. new DevSXBase { SXMC="设备软件",SXLX="上位机",SXStatus=true }
  103. }
  104. });
  105. switch (GeneralConfig.DeviceType)
  106. {
  107. case BPA.Message.Enum.DeviceClientType.MORKD:
  108. break;
  109. case BPA.Message.Enum.DeviceClientType.MORKS:
  110. IsAllowRun = GetTypeValue<bool>("AllowRun");
  111. TemperatureReached = GetTypeValue<bool>("TemperatureReached");
  112. bool MissingBowl = GetTypeValue<bool>("MissingBowl");
  113. bool MissingBowlSignal2 = GetTypeValue<bool>("MissingBowlSignal2");
  114. bool IsNoodles = GetTypeValue<bool>("IsNoodles");//转台
  115. bool AllowFallNoodle = GetTypeValue<bool>("AllowFallNoodle");//是否允许到面
  116. bool[] CookNoodlesComplete = GetTypeValue<bool[]>("CookNoodlesComplete");//煮面完成上升信号
  117. bool isCookNoodles = CookNoodlesComplete.ToList().Find(o => o);
  118. //设置扩展属性与状态,连接上机器人后才会处罚
  119. if (IsAllowRun)
  120. {
  121. kzsx = Tools.JsonConvertTools<DevSX>(new DevSX
  122. {
  123. data = new List<DevSXBase>
  124. {
  125. new DevSXBase { SXMC="设备硬件",SXLX="煮面炉",SXStatus= !TemperatureReached ,
  126. SXYCMS=!TemperatureReached?"":DateTime.Now+" 异常,煮面炉温度不够,疑似正在加热或者未工作...."},
  127. new DevSXBase { SXMC="设备硬件",SXLX="装小碗结构",SXStatus=MissingBowl ,
  128. SXYCMS=MissingBowl?"":DateTime.Now+" 异常,缺小碗...."},
  129. new DevSXBase { SXMC="设备硬件",SXLX="装大碗结构",SXStatus=MissingBowlSignal2 ,
  130. SXYCMS=MissingBowlSignal2?"":DateTime.Now+" 异常,缺大碗...."},
  131. new DevSXBase { SXMC="设备硬件",SXLX="取面转台",SXStatus=IsNoodles ,
  132. SXYCMS=IsNoodles?"":DateTime.Now+" 异常,转台位置缺少物料...."},
  133. new DevSXBase { SXMC="设备硬件",SXLX="配料机",SXStatus=!(!AllowFallNoodle && isCookNoodles) ,
  134. SXYCMS=!((!AllowFallNoodle && isCookNoodles))?"":DateTime.Now+" 异常,配料机未配完料,疑似碗未到配料机下方或者配料机未工作...."}
  135. }
  136. });
  137. }
  138. break;
  139. case BPA.Message.Enum.DeviceClientType.MORKI:
  140. break;
  141. case BPA.Message.Enum.DeviceClientType.MORKC:
  142. break;
  143. case BPA.Message.Enum.DeviceClientType.MORKIC:
  144. break;
  145. default:
  146. break;
  147. }
  148. string jsonstr = Tools.JsonConvertTools<IotModel<TargetIOT>>(new IotModel<TargetIOT> { @params = new TargetIOT { JBSX = jbsx,KZSX = kzsx,NodeStatus= NodeStatus } });
  149. IOTDevServer.GetInstance().IOT_Publish(IOTDevServer.PubTopic,jsonstr);
  150. }
  151. }
  152. #endregion
  153. #region 外部关闭或初始化IOT调用
  154. /// <summary>
  155. /// 初始化IOT连接
  156. /// </summary>
  157. public bool Initialize()
  158. {
  159. if (!IOTDevServer.GetInstance().CreateLinks(InternetInfo.ClientId,out device))
  160. {
  161. MessageLog.GetInstance.Show($"设备{InternetInfo.ClientId}阿里云上没有该设备。");
  162. return false;
  163. }
  164. IOTDevServer.GetInstance().IOT_Subscribe(IOTDevServer.BroadcastTopic);//订阅广播主题
  165. IOTDevServer.DevIOTAction += DevIOTActionHandler;
  166. IOTDevServer.UNConnectMqtt += new Action<string>((o) => { MessageLog.GetInstance.Show(o); });//断网自动重连接与打印
  167. if (IOTDevServer.client.IsConnected) MessageLog.GetInstance.Show($"设备{device.devicename} {device.remark}阿里云连接成功.");
  168. else MessageLog.GetInstance.Show($"设备{device.devicename} {device.remark}阿里云连接失败.不能上报业务信息");
  169. return IOTDevServer.client.IsConnected;
  170. }
  171. /// <summary>
  172. /// 关闭IOT连接
  173. /// </summary>
  174. public static void Close()
  175. {
  176. if (IOTDevServer.client != null)
  177. IOTDevServer.GetInstance().Disconnect();
  178. }
  179. #endregion
  180. #region 云端订阅主题消息接收
  181. /// <summary>
  182. /// 接收云端消息
  183. /// </summary>
  184. /// <param name="topic"></param>
  185. /// <param name="message"></param>
  186. private void DevIOTActionHandler(string topic, string message)
  187. {
  188. if (IOTDevServer.BroadcastTopic == topic && !string.IsNullOrEmpty(message))//广播主题消息,将广播消息发送到相应客户端
  189. {
  190. IOTCommandModel iOTCommand = Tools.JsonToObjectTools<IOTCommandModel>(message);
  191. if (iOTCommand.deviceName == device.devicename)
  192. ActionManage.GetInstance.Send("IotBroadcast", iOTCommand);
  193. }
  194. }
  195. #endregion
  196. #region 私有函数
  197. /// <summary>
  198. /// 获取属性状态
  199. /// </summary>
  200. private T GetTypeValue<T>(string str)
  201. {
  202. return (T)SimpleFactory.GetInstance.GVL?.GetType().GetProperty(str)?.GetValue(SimpleFactory.GetInstance.GVL,null);
  203. }
  204. #endregion
  205. }
  206. /// <summary>
  207. /// 日志上报
  208. /// </summary>
  209. public class LogIOT
  210. {
  211. public string SZXX { get; set; }
  212. }
  213. /// <summary>
  214. /// 告警上报
  215. /// </summary>
  216. public class AlarmIOT
  217. {
  218. public string GJXX { get; set; }
  219. }
  220. /// <summary>
  221. /// 节点状态上报
  222. /// </summary>
  223. public class NodeStatusIOT
  224. {
  225. public string NodeStatus { get; set; }
  226. }
  227. /// <summary>
  228. /// 基本属性与扩展属性
  229. /// </summary>
  230. public class TargetIOT
  231. {
  232. /// <summary>
  233. /// 基本属性
  234. /// </summary>
  235. public string JBSX { get; set; }
  236. /// <summary>
  237. /// 扩展属性
  238. /// </summary>
  239. public string KZSX { get; set; }
  240. /// <summary>
  241. /// 属性状态
  242. /// </summary>
  243. public string NodeStatus { get; set; }
  244. }
  245. }