|
|
@@ -28,6 +28,7 @@ using System.Collections; |
|
|
|
using static Microsoft.EntityFrameworkCore.DbLoggerCategory; |
|
|
|
using System.Windows.Navigation; |
|
|
|
using System.Text.RegularExpressions; |
|
|
|
using static System.Resources.ResXFileRef; |
|
|
|
|
|
|
|
namespace BPASmartClient.DosingSystem |
|
|
|
{ |
|
|
@@ -101,6 +102,7 @@ namespace BPASmartClient.DosingSystem |
|
|
|
RecipeRun(); |
|
|
|
BusinessExcute(); |
|
|
|
ConveyerPropertyReport(); |
|
|
|
AliyunMqConnectCheck(); |
|
|
|
#if Debug |
|
|
|
Task.Run(() => { |
|
|
|
while (true) |
|
|
@@ -137,6 +139,14 @@ namespace BPASmartClient.DosingSystem |
|
|
|
#endif |
|
|
|
|
|
|
|
} |
|
|
|
/// <summary> |
|
|
|
/// 阿里云连接检查 |
|
|
|
/// </summary> |
|
|
|
private void AliyunMqConnectCheck() |
|
|
|
{ |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
public void MqttDisConnect() |
|
|
|
{ |
|
|
|
ThreadManage.GetInstance.Dispose(); |
|
|
@@ -278,6 +288,13 @@ namespace BPASmartClient.DosingSystem |
|
|
|
if (mqttCollection.Count == count + 1) |
|
|
|
{ |
|
|
|
AliyunIsConnect = true; |
|
|
|
AliyunSystemPropertyReportModel m1 = new AliyunSystemPropertyReportModel(); |
|
|
|
m1.RecipeCollection = new string[Json<LocalRecipe>.Data.Recipes.Count]; |
|
|
|
for (int i = 0; i < Json<LocalRecipe>.Data.Recipes.Count; i++) |
|
|
|
{ |
|
|
|
m1.RecipeCollection[i] = Json<LocalRecipe>.Data.Recipes[i].RecipeName; |
|
|
|
} |
|
|
|
SystemPropertyReport(m1); |
|
|
|
} |
|
|
|
#endregion |
|
|
|
|
|
|
@@ -304,17 +321,25 @@ namespace BPASmartClient.DosingSystem |
|
|
|
var topicReply = $"/sys/{produtInfo.Get("ProductKey")}/{aliyun[ipaddres]}/thing/event/property/post_reply";//订阅主题 |
|
|
|
if (mqttCollection.ContainsKey(aliyun[ipaddres])) |
|
|
|
{ |
|
|
|
mqttCollection[aliyun[ipaddres]].Publish((op) => |
|
|
|
{ |
|
|
|
op.Message = message; |
|
|
|
op.Topic = topic; |
|
|
|
op.TopicReply = topicReply; |
|
|
|
//if (!PropertyReport) |
|
|
|
//{ |
|
|
|
// op.ThresholdCallback += MqttPostProperty_MqttMsgPublishReceived; // MqttPostProperty_MqttMsgPublishReceived; |
|
|
|
// PropertyReport = true; |
|
|
|
//} |
|
|
|
}); |
|
|
|
try |
|
|
|
{ |
|
|
|
mqttCollection[aliyun[ipaddres]].Publish((op) => |
|
|
|
{ |
|
|
|
op.Message = message; |
|
|
|
op.Topic = topic; |
|
|
|
op.TopicReply = topicReply; |
|
|
|
//if (!PropertyReport) |
|
|
|
//{ |
|
|
|
// op.ThresholdCallback += MqttPostProperty_MqttMsgPublishReceived; // MqttPostProperty_MqttMsgPublishReceived; |
|
|
|
// PropertyReport = true; |
|
|
|
//} |
|
|
|
}); |
|
|
|
} |
|
|
|
catch (Exception) |
|
|
|
{ |
|
|
|
|
|
|
|
//throw; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
@@ -335,12 +360,16 @@ namespace BPASmartClient.DosingSystem |
|
|
|
{ |
|
|
|
eventIdentifier = $"{produtInfo.Get("Stock")}:{eventFlag}";//格式:模板名:事件名 |
|
|
|
deviceName = aliyun[ipaddres]; |
|
|
|
if (!mqttCollection.ContainsKey(aliyun[ipaddres])) |
|
|
|
return; |
|
|
|
messageHandler = mqttCollection[aliyun[ipaddres]]; |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
eventIdentifier = $"{produtInfo.Get("Conveyer")}:{eventFlag}"; |
|
|
|
deviceName = $"{ConveyerInfo.Get("DeviceName")}"; |
|
|
|
if (!mqttCollection.ContainsKey("Conveyer")) |
|
|
|
return; |
|
|
|
messageHandler = mqttCollection["Conveyer"]; |
|
|
|
|
|
|
|
} |
|
|
@@ -357,17 +386,25 @@ namespace BPASmartClient.DosingSystem |
|
|
|
//事件订阅主题 |
|
|
|
var eventTopicReply = $"/sys/{produtInfo.Get("ProductKey")}/{deviceName}/thing/event/{eventIdentifier}/post_reply"; |
|
|
|
|
|
|
|
messageHandler.Publish((op) => |
|
|
|
try |
|
|
|
{ |
|
|
|
op.Message = eventMessage; |
|
|
|
op.Topic = eventTopic; |
|
|
|
op.TopicReply = eventTopicReply; |
|
|
|
//if (!EventReport) |
|
|
|
//{ |
|
|
|
// op.ThresholdCallback += MqttPostEvent_MqttMsgPublishReceived; // MqttPostProperty_MqttMsgPublishReceived; |
|
|
|
// EventReport = true; |
|
|
|
//} |
|
|
|
}); |
|
|
|
messageHandler.Publish((op) => |
|
|
|
{ |
|
|
|
op.Message = eventMessage; |
|
|
|
op.Topic = eventTopic; |
|
|
|
op.TopicReply = eventTopicReply; |
|
|
|
//if (!EventReport) |
|
|
|
//{ |
|
|
|
// op.ThresholdCallback += MqttPostEvent_MqttMsgPublishReceived; // MqttPostProperty_MqttMsgPublishReceived; |
|
|
|
// EventReport = true; |
|
|
|
//} |
|
|
|
}); |
|
|
|
} |
|
|
|
catch (Exception) |
|
|
|
{ |
|
|
|
|
|
|
|
//throw; |
|
|
|
} |
|
|
|
} |
|
|
|
/// <summary> |
|
|
|
/// 输送线模板属性上报 |
|
|
@@ -399,17 +436,25 @@ namespace BPASmartClient.DosingSystem |
|
|
|
var topicReply = $"/sys/{produtInfo.Get("ProductKey")}/Conveyer/thing/event/property/post_reply";//订阅主题 |
|
|
|
if (mqttCollection.ContainsKey("Conveyer")) |
|
|
|
{ |
|
|
|
mqttCollection["Conveyer"].Publish((op) => |
|
|
|
{ |
|
|
|
op.Message = message; |
|
|
|
op.Topic = topic; |
|
|
|
op.TopicReply = topicReply; |
|
|
|
//if (!PropertyReport) |
|
|
|
//{ |
|
|
|
// op.ThresholdCallback += MqttPostProperty_MqttMsgPublishReceived; // MqttPostProperty_MqttMsgPublishReceived; |
|
|
|
// PropertyReport = true; |
|
|
|
//} |
|
|
|
}); |
|
|
|
try |
|
|
|
{ |
|
|
|
mqttCollection["Conveyer"].Publish((op) => |
|
|
|
{ |
|
|
|
op.Message = message; |
|
|
|
op.Topic = topic; |
|
|
|
op.TopicReply = topicReply; |
|
|
|
//if (!PropertyReport) |
|
|
|
//{ |
|
|
|
// op.ThresholdCallback += MqttPostProperty_MqttMsgPublishReceived; // MqttPostProperty_MqttMsgPublishReceived; |
|
|
|
// PropertyReport = true; |
|
|
|
//} |
|
|
|
}); |
|
|
|
} |
|
|
|
catch (Exception) |
|
|
|
{ |
|
|
|
|
|
|
|
//throw; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
@@ -440,20 +485,68 @@ namespace BPASmartClient.DosingSystem |
|
|
|
var eventTopicReply = $"/sys/{produtInfo.Get("ProductKey")}/Conveyer/thing/event/{eventIdentifier}/post_reply"; |
|
|
|
if (mqttCollection.ContainsKey("Conveyer")) |
|
|
|
{ |
|
|
|
mqttCollection["Conveyer"].Publish((op) => |
|
|
|
try |
|
|
|
{ |
|
|
|
op.Message = eventMessage; |
|
|
|
op.Topic = eventTopic; |
|
|
|
op.TopicReply = eventTopicReply; |
|
|
|
//if (!EventReport) |
|
|
|
//{ |
|
|
|
// op.ThresholdCallback += MqttPostEvent_MqttMsgPublishReceived; // MqttPostProperty_MqttMsgPublishReceived; |
|
|
|
// EventReport = true; |
|
|
|
//} |
|
|
|
}); |
|
|
|
mqttCollection["Conveyer"].Publish((op) => |
|
|
|
{ |
|
|
|
op.Message = eventMessage; |
|
|
|
op.Topic = eventTopic; |
|
|
|
op.TopicReply = eventTopicReply; |
|
|
|
//if (!EventReport) |
|
|
|
//{ |
|
|
|
// op.ThresholdCallback += MqttPostEvent_MqttMsgPublishReceived; // MqttPostProperty_MqttMsgPublishReceived; |
|
|
|
// EventReport = true; |
|
|
|
//} |
|
|
|
}); |
|
|
|
} |
|
|
|
catch (Exception) |
|
|
|
{ |
|
|
|
|
|
|
|
// throw; |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary> |
|
|
|
/// 业务系统属性上报 |
|
|
|
/// </summary> |
|
|
|
public void SystemPropertyReport(AliyunSystemPropertyReportModel model) |
|
|
|
{ |
|
|
|
var mqdeviceTestProperty = new PostPropertyParams<AliyunSystemPropertyReportModel>(); |
|
|
|
mqdeviceTestProperty.sys = new Sys { ack = 1 }; |
|
|
|
mqdeviceTestProperty.method = "thing.event.property.post"; |
|
|
|
mqdeviceTestProperty.version = "1.0"; |
|
|
|
mqdeviceTestProperty.Model = model; |
|
|
|
mqdeviceTestProperty.Init(); |
|
|
|
var message = JsonConvert.SerializeObject(mqdeviceTestProperty); |
|
|
|
var topic = $"/sys/{produtInfo.Get("ProductKey")}/Conveyer/thing/event/property/post";//发布主题 |
|
|
|
|
|
|
|
var topicReply = $"/sys/{produtInfo.Get("ProductKey")}/Conveyer/thing/event/property/post_reply";//订阅主题 |
|
|
|
if (mqttCollection.ContainsKey("Conveyer")) |
|
|
|
{ |
|
|
|
try |
|
|
|
{ |
|
|
|
mqttCollection["Conveyer"].Publish((op) => |
|
|
|
{ |
|
|
|
op.Message = message; |
|
|
|
op.Topic = topic; |
|
|
|
op.TopicReply = topicReply; |
|
|
|
//if (!PropertyReport) |
|
|
|
//{ |
|
|
|
// op.ThresholdCallback += MqttPostProperty_MqttMsgPublishReceived; // MqttPostProperty_MqttMsgPublishReceived; |
|
|
|
// PropertyReport = true; |
|
|
|
//} |
|
|
|
}); |
|
|
|
} |
|
|
|
catch (Exception) |
|
|
|
{ |
|
|
|
|
|
|
|
//throw; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
/// <summary> |
|
|
|
/// 云端属性设置回调方法-输送线模板 |
|
|
|
/// </summary> |
|
|
@@ -1106,7 +1199,7 @@ namespace BPASmartClient.DosingSystem |
|
|
|
|
|
|
|
if (Comcount >= Recipes.ElementAt(i).RawMaterials.Count) //配方配料完成 StockStatus.Count >= Recipes.ElementAt(i).RawMaterials.Count && |
|
|
|
{ |
|
|
|
SystemEventReport<AliyunSystemReportModel>("RecipeCompleteEvent", new AliyunSystemReportModel { RecipeName = CurrentRecipeName }); |
|
|
|
SystemEventReport<AliyunSystemEventReportModel>("RecipeCompleteEvent", new AliyunSystemEventReportModel { RecipeName = CurrentRecipeName }); |
|
|
|
int cc = recipeProcesses.ElementAt(recIndex).RawMaterials.OrderBy(p => p.RawMaterialName).Count(); |
|
|
|
for (int k = 0; k < 32; k++) |
|
|
|
{ |
|
|
|