Browse Source

物模型属性更新

煮面机(新)
Mr_z 1 year ago
parent
commit
176c56a537
6 changed files with 167 additions and 45 deletions
  1. +1
    -0
      DosingSystem/App.xaml.cs
  2. +136
    -43
      DosingSystem/ExcuteControl.cs
  3. +3
    -1
      DosingSystem/Model/AliyunSystemEventReportModel.cs
  4. +13
    -0
      DosingSystem/Model/AliyunSystemPropertyReportModel.cs
  5. +2
    -1
      DosingSystem/Model/DeviceInquire.cs
  6. +12
    -0
      DosingSystem/ViewModel/NewRecipeViewModel.cs

+ 1
- 0
DosingSystem/App.xaml.cs View File

@@ -57,6 +57,7 @@ namespace BPASmartClient.DosingSystem
DataInit();
await Task.Run(() => { excute = ExcuteControl.GetInstance; });
MenuInit();

//SiemensTest.GetInstance.Init();
DeviceInquire.GetInstance.Init();//配料机设备上线监听,设备列表初始化
MainView mv = new MainView();


+ 136
- 43
DosingSystem/ExcuteControl.cs View File

@@ -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++)
{


DosingSystem/Model/AliyunSystemReportModel.cs → DosingSystem/Model/AliyunSystemEventReportModel.cs View File

@@ -6,7 +6,9 @@ using System.Threading.Tasks;

namespace BPASmartClient.DosingSystem.Model
{
public class AliyunSystemReportModel

public class AliyunSystemEventReportModel
{
public string RecipeName { get; set; }
}

+ 13
- 0
DosingSystem/Model/AliyunSystemPropertyReportModel.cs View File

@@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BPASmartClient.DosingSystem.Model
{
public class AliyunSystemPropertyReportModel
{
public string[] RecipeCollection { get; set; }
}
}

+ 2
- 1
DosingSystem/Model/DeviceInquire.cs View File

@@ -494,8 +494,9 @@ namespace BPASmartClient.DosingSystem
model.StockStirringSpeed = 54;
model.StockMaterialType = "粉体";
model.StockBatchStatus = "待机";
ExcuteControl.GetInstance.StokcPropertyReport(IpAddress, model);
#endif
ExcuteControl.GetInstance.StokcPropertyReport(IpAddress, model);
}
/// <summary>
/// 事件上报


+ 12
- 0
DosingSystem/ViewModel/NewRecipeViewModel.cs View File

@@ -2,6 +2,7 @@
using BPASmartClient.CustomResource.Pages.Model;
using BPASmartClient.CustomResource.UserControls;
using BPASmartClient.CustomResource.UserControls.MessageShow;
using BPASmartClient.DosingSystem.Model;
using BPASmartClient.Model;
using System;
using System.Collections.ObjectModel;
@@ -138,6 +139,17 @@ namespace BPASmartClient.DosingSystem.ViewModel
});
Json<LocalRecipe>.Save();
NoticeDemoViewModel.OpenMsg(EnumPromptType.Success, App.MainWindow, "提示", $"新建配方成功!");
//配方名称集合上报
if (ExcuteControl.GetInstance.AliyunIsConnect)
{
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;
}
ExcuteControl.GetInstance.SystemPropertyReport(m1);
}
}
ActionManage.GetInstance.Send("CloseNewRecipeView");
});


Loading…
Cancel
Save