diff --git a/BPASmartClient.CustomResource/Pages/ViewModel/MainViewModel.cs b/BPASmartClient.CustomResource/Pages/ViewModel/MainViewModel.cs index 378cb5f2..87bc7ea1 100644 --- a/BPASmartClient.CustomResource/Pages/ViewModel/MainViewModel.cs +++ b/BPASmartClient.CustomResource/Pages/ViewModel/MainViewModel.cs @@ -57,19 +57,27 @@ namespace BPASmartClient.CustomResource.Pages.ViewModel BPA.Helper.MessageLog.GetInstance.NotifyShow = new Action((o) => { - Application.Current?.Dispatcher?.Invoke(() => + try { - //ff20aefe - var temp = new MessageModel() - { - LogInfo = o, - Forground = new SolidColorBrush(Color.FromArgb(255, 32, 174, 254)) - }; - if (DebugLogViewModel.MessageModels.Count > 0) - DebugLogViewModel.MessageModels.Insert(0, temp); - else - DebugLogViewModel.MessageModels.Add(temp); - }); + Application.Current?.Dispatcher?.Invoke(() => + { + //ff20aefe + var temp = new MessageModel() + { + LogInfo = o, + Forground = new SolidColorBrush(Color.FromArgb(255, 32, 174, 254)) + }; + if (DebugLogViewModel.MessageModels.Count > 0) + DebugLogViewModel.MessageModels.Insert(0, temp); + else + DebugLogViewModel.MessageModels.Add(temp); + }); + } + catch (Exception) + { + + //throw; + } }); BPA.Helper.MessageLog.GetInstance.NotifyShowEx = new Action((o) => { diff --git a/DosingSystem/App.config b/DosingSystem/App.config index 38b78882..ae6300c6 100644 --- a/DosingSystem/App.config +++ b/DosingSystem/App.config @@ -1,6 +1,63 @@  - - - + + +
+
+
+
+
+
+
+
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/DosingSystem/App.xaml.cs b/DosingSystem/App.xaml.cs index 671850e8..8052feff 100644 --- a/DosingSystem/App.xaml.cs +++ b/DosingSystem/App.xaml.cs @@ -1,25 +1,17 @@ -using System; -using System.Collections.Generic; -using System.Collections.ObjectModel; -using System.Configuration; -using System.Data; -using System.Linq; -using System.Threading; -using System.Threading.Tasks; -using System.Windows; +using BPA.Helper; using BPASmartClient.CustomResource.Pages.Enums; using BPASmartClient.CustomResource.Pages.Model; using BPASmartClient.CustomResource.Pages.View; using BPASmartClient.CustomResource.Pages.ViewModel; -using BPASmartClient.DosingSystem.View; -using BPA.Helper; using BPASmartClient.DosingSystem.Model; +using System; +using System.Collections.ObjectModel; +using System.Collections.Specialized; +using System.Configuration; using System.Diagnostics; -using System.IO; -using BPASmartClient.Update.Model; -using BPASmartClient.DosingSystem.ViewModel; -using System.Drawing; -using System.Windows.Media; +using System.Threading; +using System.Threading.Tasks; +using System.Windows; namespace BPASmartClient.DosingSystem { @@ -28,12 +20,15 @@ namespace BPASmartClient.DosingSystem /// public partial class App : Application { + public static Window MainWindow; + public ExcuteControl excute; public EventWaitHandle ProgramStarted { get; set; } - protected override void OnStartup(StartupEventArgs e) + protected override async void OnStartup(StartupEventArgs e) { bool createNew; + MessageLog.GetInstance.NotifyShow = new Action(o => { DebugLogViewModel.MessageModels.Add(new MessageModel() @@ -60,6 +55,7 @@ namespace BPASmartClient.DosingSystem base.OnStartup(e); SystemHelper.GetInstance.CreateDesktopShortcut(); DataInit(); + await Task.Run(() => { excute = ExcuteControl.GetInstance; }); MenuInit(); //SiemensTest.GetInstance.Init(); DeviceInquire.GetInstance.Init();//配料机设备上线监听,设备列表初始化 @@ -101,11 +97,13 @@ namespace BPASmartClient.DosingSystem protected override void OnExit(ExitEventArgs e) { base.OnExit(e); + excute?.MqttDisConnect(); Json.Save(); Json.Save(); Json.Save(); BPASmartClient.CustomResource.Pages.Model.MessageNotify.GetInstance.LogSave(); TaskManage.GetInstance.Dispose(); + //Process.GetCurrentProcess().Kill(); } private void MenuInit() diff --git a/DosingSystem/App1.config b/DosingSystem/App1.config deleted file mode 100644 index 6d2e3782..00000000 --- a/DosingSystem/App1.config +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/DosingSystem/BPASmartClient.DosingSystem.csproj b/DosingSystem/BPASmartClient.DosingSystem.csproj index bdfb6f22..eafdd7c2 100644 --- a/DosingSystem/BPASmartClient.DosingSystem.csproj +++ b/DosingSystem/BPASmartClient.DosingSystem.csproj @@ -12,7 +12,6 @@ - @@ -21,8 +20,10 @@ - - + + + aliyun + diff --git a/DosingSystem/Converter/DataTableRedundantConverter.cs b/DosingSystem/Converter/DataTableRedundantConverter.cs index fd16d65b..f3626bae 100644 --- a/DosingSystem/Converter/DataTableRedundantConverter.cs +++ b/DosingSystem/Converter/DataTableRedundantConverter.cs @@ -1,9 +1,5 @@ using System; -using System.Collections.Generic; using System.Globalization; -using System.Linq; -using System.Text; -using System.Threading.Tasks; using System.Windows.Data; using System.Windows.Media; diff --git a/DosingSystem/Converter/RunStatusConvert.cs b/DosingSystem/Converter/RunStatusConvert.cs index eb793a9a..c104e232 100644 --- a/DosingSystem/Converter/RunStatusConvert.cs +++ b/DosingSystem/Converter/RunStatusConvert.cs @@ -1,9 +1,5 @@ using System; -using System.Collections.Generic; using System.Globalization; -using System.Linq; -using System.Text; -using System.Threading.Tasks; using System.Windows.Data; namespace BPASmartClient.DosingSystem.Converter @@ -35,7 +31,7 @@ namespace BPASmartClient.DosingSystem.Converter { if (tempValue == 0) return true; if (tempValue == 1) return false; - + } return true; } diff --git a/DosingSystem/ExcuteControl.cs b/DosingSystem/ExcuteControl.cs index f3fb2efa..408763d2 100644 --- a/DosingSystem/ExcuteControl.cs +++ b/DosingSystem/ExcuteControl.cs @@ -1,16 +1,33 @@ -using BPA.Helper; +//#define Debug +extern alias aliyun; +using BPA.Helper; using BPASmartClient.CustomResource.Pages.Model; +using BPASmartClient.CustomResource.UserControls; +using BPASmartClient.CustomResource.UserControls.MessageShow; using BPASmartClient.DosingSystem.ViewModel; using BPASmartClient.Model; -using S7.Net.Types; using System; -using System.Collections.Generic; +using System.Collections.Concurrent; using System.Collections.ObjectModel; +using System.Collections.Specialized; using System.Diagnostics; using System.Linq; -using System.Text; using System.Threading; using System.Threading.Tasks; +using aliyun.uPLibrary.Networking.M2Mqtt.Messages; +using System.Collections.Generic; +using aliyun::BPA.PahoMQ; +using System.Configuration; +using BPA.Communication; +using Newtonsoft.Json; +using System.Reflection; +using System.Text; +using BPASmartClient.DosingSystem.Model; +using Microsoft.EntityFrameworkCore.Metadata.Internal; +using System.Collections; +using static Microsoft.EntityFrameworkCore.DbLoggerCategory; +using System.Windows.Navigation; +using System.Text.RegularExpressions; namespace BPASmartClient.DosingSystem { @@ -21,94 +38,1109 @@ namespace BPASmartClient.DosingSystem { private static ExcuteControl Instance; public static ExcuteControl GetInstance => Instance ??= new ExcuteControl(); + + public ConcurrentDictionary mqttCollection = new ConcurrentDictionary(); + + public ConcurrentDictionary aliyun = new ConcurrentDictionary(); + public ObservableCollection Recipes { get; set; } = Json.Data.Recipes; + public ObservableCollection StockStatus = new ObservableCollection(); + + public string CurrentRecipeName { get; set; } + /// + /// 当前正在制作的配方 + /// + public ObservableCollection recipeProcesses { get; set; } = new ObservableCollection(); + + /// + /// 等待制作的配方 + /// + public ObservableCollection UserTreeWait { get; set; } = new ObservableCollection(); + + /// + /// 已完成的配方 + /// + public ObservableCollection UserTreeCompelete { get; set; } = new ObservableCollection(); + public ConcurrentQueue RecipeNames = new ConcurrentQueue(); /// /// 配料完成计数 /// int Comcount = 0; - public ExcuteControl() { } - + public static bool PropertySet = false;//云端属性设置回调主题订阅标志 + public static bool PropertyReport = false; //属性上报主题订阅标志 + + public static bool EventReport = false; //事件上报主题订阅标志 + + public static bool ServiceCall = false;//服务调用回调主题订阅标志 + + public NameValueCollection produtInfo; + public NameValueCollection mqttInfo; + public NameValueCollection ConveyerInfo; + public NameValueCollection ServicesInfo; + + public bool AliyunIsConnect = false; + public ExcuteControl() + { + ActionManage.GetInstance.Register(new Action((o) => + { + if (o != null && o is string recipeName) + { + RecipeSend(recipeName); + } + + }), "配方下发"); + ActionManage.GetInstance.Register(new Action((ob) => + { + if (ob != null && ob is string recipeName) + { + CancelRecipe(recipeName); + } + + }), "取消配方"); + + AliYunInit(); + RecipeRun(); + BusinessExcute(); + ConveyerPropertyReport(); +#if Debug + Task.Run(() => { + while (true) + { + if (AliyunIsConnect) + { + AliyunEventReport("192.168.0.10", new AliyunStockEventReportModel { Result = "1" }, "StockJerk1StatusEvent", AliyunMaterialModelType.StockModel); + AliyunEventReport("192.168.0.10", new AliyunStockEventReportModel { Result = "1" }, "StockServoFalutEvent", AliyunMaterialModelType.StockModel); + AliyunEventReport("192.168.0.10", new AliyunStockEventReportModel { Result = "1" }, "StockJerk2StatusEvent", AliyunMaterialModelType.StockModel); + AliyunEventReport("192.168.0.10", new AliyunStockEventReportModel { Result = "1" }, "StockUpLimitEvent", AliyunMaterialModelType.StockModel); + AliyunEventReport("192.168.0.10", new AliyunStockEventReportModel { Result = "1" }, "StockDownLimitEvent", AliyunMaterialModelType.StockModel); + + AliyunStockPropertyReportModel model = new AliyunStockPropertyReportModel(); + model.StockRealWeight = 1; + model.BucketRealWeight = 2; + model.StockDeviceNum = 2; + model.StockDeviceName = "测试"; + model.StockWorkModel = 0; + model.StockSlowlyAddWeight = 6; + model.StockPreCloseValueWeight = 7; + model.StockRapidAcceleration = 46; + model.StockSlowAcceleration = 24; + model.StockServoManualSpeed = 35; + model.StockUpperLimitWeight = 57; + model.StockLowerLimitWeight = 34; + model.StockStirringSpeed = 54; + model.StockMaterialType = "粉体"; + model.StockBatchStatus = "待机"; + StokcPropertyReport("192.168.0.10", model); + } + Thread.Sleep(5000); + } + }); +#endif + + } + public void MqttDisConnect() + { + ThreadManage.GetInstance.Dispose(); + foreach (var item in mqttCollection) + { + item.Value._mqttClient?.Disconnect(); + } + } /// - /// 配料逻辑 + /// 连接阿里云Iot物联网平台 /// - /// 当前执行的配方 - public void BusinessExcute(RecipeModel recipeModel) + /// + private async void AliYunInit() { - ThreadManage.GetInstance.StartLong(new Action(() => { - #region 直线双仓型 - //拿到当前配方 - for (int j = 0; j < GlobalDevice.PlcData.IsAllowIngredients.Length; j++)//遍历允许配料的料桶 + + produtInfo = (NameValueCollection)System.Configuration.ConfigurationManager.GetSection("FlexBatchSystem/ProductInfo"); + mqttInfo = (NameValueCollection)System.Configuration.ConfigurationManager.GetSection("FlexBatchSystem/MqttInfo"); + ConveyerInfo = (NameValueCollection)System.Configuration.ConfigurationManager.GetSection("FlexBatchSystem/ConveyerInfo"); + ServicesInfo = (NameValueCollection)System.Configuration.ConfigurationManager.GetSection("FlexBatchSystem/Services"); + int count = Json.Data.BaseParModel.StockCount;//料仓数 + + #region 料仓连接阿里云 + for (int i = 0; i < count; i++) + { + if (!mqttCollection.ContainsKey($"Stock{i + 1}")) //创建料仓设备mqtt连接 { + await Task.Run(() => + { + try + { + int num = i + 1; + NameValueCollection StockInfo = ((NameValueCollection)System.Configuration.ConfigurationManager.GetSection($"FlexBatchSystem/StockInfo{num}")); - if (GlobalDevice.PlcData.IsAllowIngredients[j]) + var mes = new aliyun.BPA.PahoMQ.MessageHandler(new aliyun.BPA.PahoMQ.PahoMQOption() + { + Broker = mqttInfo.Get("mqttHostUrl"), + ProductKey = produtInfo.Get("ProductKey"), + DeviceName = StockInfo.Get("DeviceName"), + DeviceSecret = StockInfo.Get("DeviceSecret"), + Port = 1883 + }); + if (mes._mqttClient.IsConnected) + { + MessageLog.GetInstance.Show($"阿里云--料仓{num}设备激活成功!"); + } + else + { + MessageLog.GetInstance.Show($"阿里云--料仓{num}设备激活失败!"); + return; + } + + mes.Subscribe((op) => + { + op.TopicReply = $"/sys/{produtInfo.Get("ProductKey")}/{StockInfo.Get("DeviceName")}/thing/service/property/set"; + //if (!PropertySet) + //{ + op.ThresholdCallback += StockPropertySetCallback; + PropertyReport = true; + //} + }); + MessageLog.GetInstance.Show($"阿里云--料仓{num}设备属性设置订阅成功!"); + mqttCollection.TryAdd($"Stock{i + 1}", mes); + if (!aliyun.ContainsKey($"{Json.Data.BaseParModel.NetworkSegAddress}{i + 1}0")) + { + aliyun.TryAdd($"{Json.Data.BaseParModel.NetworkSegAddress}{i + 1}0", $"Stock{i + 1}"); + } + } + catch (Exception) + { + MessageLog.GetInstance.Show($"阿里云--料仓{i}设备激活失败!"); + return; + } + + }); + } + } + #endregion + + #region 输送线连接阿里云 + if (!mqttCollection.ContainsKey($"Conveyer"))//创建输送线Mqtt连接 + { + await Task.Run(() => + { + try { - int barrelNum = j + 1;//桶号 - int stockLoc = GlobalDevice.PlcData.LocationFeedback[j];//允许配料的料仓位置 0~6 双仓情况下返回的位置是否一样,料仓ip设置顺序怎样的 - if (stockLoc >= 1 && stockLoc <= Json.Data.BaseParModel.StockCount) + var res = new aliyun.BPA.PahoMQ.MessageHandler(new aliyun.BPA.PahoMQ.PahoMQOption() { - int index = Array.FindIndex(DeviceInquire.GetInstance.devices.ToArray(), p => p.DeviceNum == stockLoc); - if (index >= 0) + Broker = mqttInfo.Get("mqttHostUrl"), + ProductKey = produtInfo.Get("ProductKey"), + DeviceName = ConveyerInfo.Get("DeviceName"), + DeviceSecret = ConveyerInfo.Get("DeviceSecret"), + Port = 1883 + }); + if (res._mqttClient.IsConnected) + { + MessageLog.GetInstance.Show($"阿里云--输送线设备激活成功!"); + } + else + { + MessageLog.GetInstance.Show($"阿里云--输送线设备激活失败!"); + return; + } + //属性订阅 + res.Subscribe((op) => + { + op.TopicReply = $"/sys/{produtInfo.Get("ProductKey")}/{ConveyerInfo.Get("DeviceName")}/thing/service/property/set"; + //if (!PropertySet) + //{ + op.ThresholdCallback += ConveyerPropertySetCallback; + PropertyReport = true; + // } + }); + MessageLog.GetInstance.Show($"阿里云---输送线设备属性设置订阅成功!"); + //服务订阅 + for (int j = 0; j < ServicesInfo.AllKeys.Length; j++) + { + res.Subscribe((op) => { - //查出到配料位置的原料 - int result = Array.FindIndex(recipeModel.RawMaterials.ToArray(), p => (p.Loc == barrelNum && p.DeviceIp == DeviceInquire.GetInstance.devices.ElementAt(index).IpAddress));//待定 - if (result != -1 && DeviceInquire.GetInstance.GetDevice(recipeModel.RawMaterials[result].DeviceIp).deviceStatus.RunStatus == 1 && RecipeControlViewModel.recipeProcesses.ElementAt(0).RawMaterials[result].Status == Status.等待配料) + op.TopicReply = $"/sys/{produtInfo.Get("ProductKey")}/{ConveyerInfo.Get("DeviceName")}/thing/service/{ServicesInfo.Get(j)}"; + if (!ServiceCall) { - var weight = recipeModel.RawMaterials[result].RawMaterialWeight; - DeviceInquire.GetInstance.GetDevice(recipeModel.RawMaterials.ElementAt(index).DeviceIp).Start(weight);//所有参数下发并启动配料 - MessageNotify.GetInstance.ShowRunLog($"{recipeModel.RawMaterials[result].DeviceIp}:正在配料"); - RecipeControlViewModel.recipeProcesses.ElementAt(0).RawMaterials[result].Status = Status.正在配料; + op.ThresholdCallback += ServiceCallback; + ServiceCall = true; } - } + }); + MessageLog.GetInstance.Show($"阿里云--服务'{ServicesInfo.Get(j)}'订阅成功!"); } - else + mqttCollection.TryAdd($"Conveyer", res); + + } + catch (Exception) + { + MessageLog.GetInstance.Show($"阿里云--输送线设备激活失败!"); + return; + } + }); + + } + if (mqttCollection.Count == count + 1) + { + AliyunIsConnect = true; + } + #endregion + + } + + + /// + /// 料仓属性上报 + /// + /// + /// + public void StokcPropertyReport(string ipaddres, AliyunStockPropertyReportModel model) + { + var mqdeviceTestProperty = new PostPropertyParams(); + mqdeviceTestProperty.sys = new Sys { ack = 1 }; + mqdeviceTestProperty.method = "thing.event.property.post"; + mqdeviceTestProperty.version = "1.0"; + mqdeviceTestProperty.ModelName = $"{produtInfo.Get("Stock")}"; + mqdeviceTestProperty.Model= model; + mqdeviceTestProperty.Init(); + var message = JsonConvert.SerializeObject(mqdeviceTestProperty); + var topic = $"/sys/{produtInfo.Get("ProductKey")}/{aliyun[ipaddres]}/thing/event/property/post";//发布主题 + + 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; + //} + }); + } + + } + + + /// + /// 料仓模板或输送线模板事件上报 + /// + /// + /// + /// + public void AliyunEventReport(string ipaddres, T model, string eventFlag, AliyunMaterialModelType type) + { + string eventIdentifier; + string deviceName; + MessageHandler messageHandler = null; + if (type == AliyunMaterialModelType.StockModel) + { + eventIdentifier = $"{produtInfo.Get("Stock")}:{eventFlag}";//格式:模板名:事件名 + deviceName = aliyun[ipaddres]; + messageHandler = mqttCollection[aliyun[ipaddres]]; + } + else + { + eventIdentifier = $"{produtInfo.Get("Conveyer")}:{eventFlag}"; + deviceName = $"{ConveyerInfo.Get("DeviceName")}"; + messageHandler = mqttCollection["Conveyer"]; + + } + + var mqdeviceTestEvent = new PostEventParams(); + mqdeviceTestEvent.id = Guid.NewGuid().ToString(); + mqdeviceTestEvent.sys = new Sys { ack = 1 }; + mqdeviceTestEvent.method = $"thing.event.{eventIdentifier}.post"; + mqdeviceTestEvent.version = "1.0"; + mqdeviceTestEvent.@params = new EventParam { value = model, time = new DateTimeOffset(DateTime.Now).ToUnixTimeMilliseconds() }; + var eventMessage = JsonConvert.SerializeObject(mqdeviceTestEvent); + //事件上报 + var eventTopic = $"/sys/{produtInfo.Get("ProductKey")}/{deviceName}/thing/event/{eventIdentifier}/post"; + //事件订阅主题 + var eventTopicReply = $"/sys/{produtInfo.Get("ProductKey")}/{deviceName}/thing/event/{eventIdentifier}/post_reply"; + + messageHandler.Publish((op) => + { + op.Message = eventMessage; + op.Topic = eventTopic; + op.TopicReply = eventTopicReply; + //if (!EventReport) + //{ + // op.ThresholdCallback += MqttPostEvent_MqttMsgPublishReceived; // MqttPostProperty_MqttMsgPublishReceived; + // EventReport = true; + //} + }); + } + /// + /// 输送线模板属性上报 + /// + public void ConveyerPropertyReport() + { + TaskManage.GetInstance.StartLong(() => + { + if (AliyunIsConnect) + { + AliyunConveyerPropertyReportModel model = new AliyunConveyerPropertyReportModel(); + model.TopBucketControlStatus = Convert.ToInt32(SiemensDevice.GetInstance.MySiemens.Read("DB5.DBX4.0").Content); + model.DownBucketControlStatus = Convert.ToInt32(SiemensDevice.GetInstance.MySiemens.Read("DB5.DBX4.1").Content); + model.RunStatus = Convert.ToInt32(SiemensDevice.GetInstance.MySiemens.Read("M10.0").Content); + model.WorkModel = Convert.ToInt32(SiemensDevice.GetInstance.MySiemens.Read("M10.1").Content); + model.TopBucketSigleCheck = Convert.ToInt32(GlobalDevice.PlcData.OnDetection); + model.ButtonBucketSigleCheck = Convert.ToInt32(GlobalDevice.PlcData.UnderDetection); + model.ConveyerOnlineStatus = Convert.ToInt32(SiemensDevice.GetInstance.MySiemens.IsConnected()); + var mqdeviceTestProperty = new PostPropertyParams(); + mqdeviceTestProperty.sys = new Sys { ack = 1 }; + mqdeviceTestProperty.method = "thing.event.property.post"; + mqdeviceTestProperty.version = "1.0"; + mqdeviceTestProperty.ModelName = $"{produtInfo.Get("Conveyer")}"; + 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")) + { + mqttCollection["Conveyer"].Publish((op) => + { + op.Message = message; + op.Topic = topic; + op.TopicReply = topicReply; + //if (!PropertyReport) + //{ + // op.ThresholdCallback += MqttPostProperty_MqttMsgPublishReceived; // MqttPostProperty_MqttMsgPublishReceived; + // PropertyReport = true; + //} + }); + } + } + + Thread.Sleep(1000); + + }, "输送线属性上报", true); + + + } + /// + /// 默认模板中事件上报 + /// + /// + /// + public void SystemEventReport(string eventFlag, T t) + { + var eventIdentifier = eventFlag; + var mqdeviceTestEvent = new PostEventParams(); + mqdeviceTestEvent.id = Guid.NewGuid().ToString(); + mqdeviceTestEvent.sys = new Sys { ack = 1 }; + mqdeviceTestEvent.method = $"thing.event.{eventIdentifier}.post"; + mqdeviceTestEvent.version = "1.0"; + mqdeviceTestEvent.@params = new EventParam { value = t, time = new DateTimeOffset(DateTime.Now).ToUnixTimeMilliseconds() }; + var eventMessage = JsonConvert.SerializeObject(mqdeviceTestEvent); + //事件上报 + var eventTopic = $"/sys/{produtInfo.Get("ProductKey")}/Conveyer/thing/event/{eventIdentifier}/post"; + //事件订阅主题 + var eventTopicReply = $"/sys/{produtInfo.Get("ProductKey")}/Conveyer/thing/event/{eventIdentifier}/post_reply"; + if (mqttCollection.ContainsKey("Conveyer")) + { + mqttCollection["Conveyer"].Publish((op) => + { + op.Message = eventMessage; + op.Topic = eventTopic; + op.TopicReply = eventTopicReply; + //if (!EventReport) + //{ + // op.ThresholdCallback += MqttPostEvent_MqttMsgPublishReceived; // MqttPostProperty_MqttMsgPublishReceived; + // EventReport = true; + //} + }); + + } + } + /// + /// 云端属性设置回调方法-输送线模板 + /// + /// + /// + /// + private void ConveyerPropertySetCallback(object sender, MqttMsgPublishEventArgs e) + { + if (Regex.IsMatch(e.Topic, "[0-9a-zA-Z/]*(thing/service/property/set)$")) + { + var rtn = JsonConvert.DeserializeObject>(Encoding.UTF8.GetString(e.Message, 0, e.Message.Length)); + PropertyInfo property = rtn.@params.GetType().GetProperty("Root"); + string result = property.GetValue(rtn.@params).ToString(); + var array = result.Replace("\r\n", "").Replace(" ", "").Replace("{", "").Replace("}", "").Replace("\"", "").Split(','); + foreach (var item in array) + { + var str = item.Split(":"); //数据格式: + + if (str.Length >= 3) + { + switch (str[1]) { - continue; + case "TopBucketControlStatus": SiemensDevice.GetInstance.MySiemens.Write("DB5.DBX4.0", Convert.ToBoolean(int.Parse(str[2]))); MessageNotify.GetInstance.ShowRunLog($"云端控制上桶位气缸,状态值:{str[2]}"); break; + case "DownBucketControlStatus": SiemensDevice.GetInstance.MySiemens.Write("DB5.DBX4.1", Convert.ToBoolean(int.Parse(str[2]))); MessageNotify.GetInstance.ShowRunLog($"云端控制下桶位气缸,状态值:{str[2]}"); break; } } } - //配料完成后逻辑 - for (int k = 0; k < recipeModel.RawMaterials.Count; k++) + } + } + + + + /// + /// 云端属性设置回调方法-料仓模板 + /// + /// + /// + public void StockPropertySetCallback(object sender, MqttMsgPublishEventArgs e) + { + if (Regex.IsMatch(e.Topic, "[0-9a-zA-Z/]*(thing/service/property/set)$")) + { + var rtn = JsonConvert.DeserializeObject>(Encoding.UTF8.GetString(e.Message, 0, e.Message.Length)); + PropertyInfo property = rtn.@params.GetType().GetProperty("Root"); + string result = property.GetValue(rtn.@params).ToString(); + var array = result.Replace("\r\n", "").Replace(" ", "").Replace("{", "").Replace("}", "").Replace("\"", "").Split(','); + foreach (var item in array) { - if (DeviceInquire.GetInstance.GetDevice(recipeModel.RawMaterials.ElementAt(k).DeviceIp).deviceStatus.RunStatus == 3 && RecipeControlViewModel.recipeProcesses.ElementAt(0).RawMaterials[k].Status != Status.配料完成)//配料完成 + var str = item.Split(":"); //数据格式: + string ip = $"{Json.Data.BaseParModel.NetworkSegAddress}{e.Topic.Split('/')[3].Substring(e.Topic.Split('/')[3].Length - 1, 1)}0"; + switch (str[1]) { - int DeviceNum = DeviceInquire.GetInstance.GetDevice(recipeModel.RawMaterials.ElementAt(k).DeviceIp).deviceStatus.DeviceNum; - Comcount++; - DeviceInquire.GetInstance.GetDevice(recipeModel.RawMaterials.ElementAt(k).DeviceIp).StatusReset();//料仓复位 - SiemensDevice.GetInstance.MySiemens.Write($"DB4.DBX130.{DeviceNum - 1}", true); - Task.Run(() => + case "StockSlowlyAddWeight": DeviceInquire.GetInstance.GetDevice(ip).modbusTcp.Write(DeviceAddress.SlowlyAddWeight.ToAdd(), float.Parse(str[2])); MessageNotify.GetInstance.ShowRunLog($"云端对料仓设备{ip}设置慢加重量:值:{str[2]}"); break; + case "StockPreCloseValueWeight": DeviceInquire.GetInstance.GetDevice(ip).modbusTcp.Write(DeviceAddress.PreCloseValveWeight.ToAdd(), float.Parse(str[2])); MessageNotify.GetInstance.ShowRunLog($"云端对料仓设备{ip}设置提前关阀重量:值:{str[2]}"); break; + case "StockRapidAcceleration": DeviceInquire.GetInstance.GetDevice(ip).modbusTcp.Write(DeviceAddress.RapidAcceleration.ToAdd(), uint.Parse(str[2])); MessageNotify.GetInstance.ShowRunLog($"云端对料仓设备{ip}设置快加速:值:{str[2]}"); break; + case "StockSlowAcceleration": DeviceInquire.GetInstance.GetDevice(ip).modbusTcp.Write(DeviceAddress.SlowAcceleration.ToAdd(), uint.Parse(str[2])); MessageNotify.GetInstance.ShowRunLog($"云端对料仓设备{ip}设置慢慢重量:值:{str[2]}"); break; + case "StockServoManualSpeed": DeviceInquire.GetInstance.GetDevice(ip).modbusTcp.Write(DeviceAddress.ServoManualSpeed.ToAdd(), uint.Parse(str[2])); MessageNotify.GetInstance.ShowRunLog($"云端对料仓设备{ip}设置伺服手动速度:值:{str[2]}"); break; + case "StockUpperLimitWeight": DeviceInquire.GetInstance.GetDevice(ip).modbusTcp.Write(DeviceAddress.SiloUpperLimitWeight.ToAdd(), uint.Parse(str[2])); MessageNotify.GetInstance.ShowRunLog($"云端对料仓设备{ip}设置上限重量:值:{str[2]}"); break; + case "StockLowerLimitWeight": DeviceInquire.GetInstance.GetDevice(ip).modbusTcp.Write(DeviceAddress.LowerLimitWeightOfSilo.ToAdd(), uint.Parse(str[2])); MessageNotify.GetInstance.ShowRunLog($"云端对料仓设备{ip}设置下限重量:值:{str[2]}"); break; + case "StockStrringSpeed": DeviceInquire.GetInstance.GetDevice(ip).modbusTcp.Write(DeviceAddress.StirringSpeed.ToAdd(), uint.Parse(str[2])); MessageNotify.GetInstance.ShowRunLog($"云端对料仓设备{ip}设置搅拌速度:值:{str[2]}"); break; + } + } + } + } + + + /// + /// 云端服务调用回调方法 + /// + /// + /// + /// + private void ServiceCallback(object sender, MqttMsgPublishEventArgs e) + { + if (Regex.IsMatch(e.Topic, "[0-9a-zA-Z/]*thing/service/[0-9a-zA-Z:]*$")) + { + var rtn = JsonConvert.DeserializeObject>(Encoding.UTF8.GetString(e.Message, 0, e.Message.Length)); + PropertyInfo property = rtn.@params.GetType().GetProperty("Root"); + string result = property.GetValue(rtn.@params).ToString(); + var array = result.Replace("\r\n", "").Replace(" ", "").Replace("{", "").Replace("}", "").Replace("\"", "").Split(','); + //单一服务调用 + string res = e.Topic.Split("/")[e.Topic.Split("/").Length - 1]; + if (res.Contains(":")) //自定义模板 + { + var arr = res.Split(":"); + switch (arr[0]) + { + case "ConveyerModel": + switch (arr[1]) + { + case "RunControlService": + if (array.Count() == 1) + { + SiemensDevice.GetInstance.MySiemens.Write("M10.0", Convert.ToBoolean(int.Parse(array[0].Split(":")[1])));//输送下启停控制 + MessageNotify.GetInstance.ShowRunLog($"云端对输送线进行启动控制,值:{array[0].Split(":")[1]}"); + } + break; + case "StockAirControlService": + if (array.Count() == 2) + { + var info = array[0].Split(":"); + var info1 = array[1].Split(":"); + if (info[0].Equals("StockNum")) + { + var addRes = SiemensDevice.GetInstance.GetSiemensBitSingleAdd("DB5.DBX", int.Parse(info[1]));//输送线配料气杠控制 + SiemensDevice.GetInstance.MySiemens.Write(addRes, Convert.ToBoolean(int.Parse(info1[1]))); + MessageNotify.GetInstance.ShowRunLog($"云端对输送线配料{info[1]}气缸进行升降控制,值:{info1[1]}"); + } + else + { + var addRes = SiemensDevice.GetInstance.GetSiemensBitSingleAdd("DB5.DBX", int.Parse(info1[1])); + SiemensDevice.GetInstance.MySiemens.Write(addRes, Convert.ToBoolean(int.Parse(info[1]))); + MessageNotify.GetInstance.ShowRunLog($"云端对输送线配料{info[1]}气缸进行升降控制,值:{info[1]}"); + } + } + + break; + } + break; + case "StockModel": break; + } + } + else //默认模板 + { + switch (res) + { + case "RecipeSendService": + var info = array[0].Split(":"); + RecipeSend(info[1]); + MessageNotify.GetInstance.ShowRunLog($"云端下发配方:{info[1]}"); + break; + case "CancelRecipeService": + var info2 = array[0].Split(":"); + CancelRecipe(info2[1]); + MessageNotify.GetInstance.ShowRunLog($"云端取消配方:{info2[1]}"); + break; + } + + + } + } + } + + + + + + + + + + /// + /// 取消配方 + /// + /// + public async void CancelRecipe(string RecipeName) + { + if (RecipeName != null) + { + var res = MessageNotify.GetInstance.ShowDialog($"是否取消配方 【{RecipeName}】制作", DialogType.Warning); + if (res) + { + int index = Recipes.ToList().FindIndex(p => p.RecipeName == RecipeName); + if (index >= 0 && index < Recipes.Count) + { + await Task.Factory.StartNew(new Action(() => { - int cout = DeviceNum - 1; - while (!SiemensDevice.GetInstance.MySiemens.Read($"DB3.DBX148.{cout}").Content) //DB3.DBX148.0-31 148.0-148.5代表6个料仓位置 + Recipes.ElementAt(index).IsEnable = true; + Json.Data.Recipes.ElementAt(index).IsEnable = true; + Recipes.ElementAt(index).Are.Set(); + App.Current.Dispatcher.Invoke(new Action(() => { recipeProcesses.Clear(); })); + SiemensDevice.GetInstance.MySiemens.Write("M10.5", true); + MessageNotify.GetInstance.ShowRunLog($"M10.5:true"); + Thread.Sleep(1000); + SiemensDevice.GetInstance.MySiemens.Write("M10.5", false); + MessageNotify.GetInstance.ShowRunLog($"M10.5:false"); + NoticeDemoViewModel.OpenMsg(EnumPromptType.Success, App.MainWindow, "提示", $"配方 [{RecipeName}] 取消成功"); + MessageNotify.GetInstance.ShowUserLog($"取消配方制作 {RecipeName}"); + //取消成功 + })); + } + else + { + //取消失败 + } + } + } + else + { + //取消失败 + } + + } + /// + /// 配方下发 + /// + public void RecipeSend(string RecipeName) + { + if (RecipeName != null) + { + int index = Array.FindIndex(Recipes.ToArray(), p => p.RecipeName == RecipeName); + if (index >= 0 && index < Recipes.Count) + { + for (int i = 0; i < Recipes.ElementAt(index).RawMaterials.Count; i++) + { + if (Recipes.ElementAt(index).RawMaterials.ElementAt(i).RawMaterialSource == 1) + { + string ip = Recipes.ElementAt(index).RawMaterials.ElementAt(i).DeviceIp; + var device = DeviceInquire.GetInstance.GetDevice(ip); + if (ip == null && ip == "") { - SiemensDevice.GetInstance.MySiemens.Write($"DB4.DBX130.{cout}", true); - Thread.Sleep(200); + MessageNotify.GetInstance.ShowDialog($"原料 【{Recipes.ElementAt(index).RawMaterials.ElementAt(i).RawMaterialName}】配料系统无法配料,请人工配置此原料:原料{Recipes.ElementAt(index).RawMaterials.ElementAt(i).RawMaterialName},重量{Recipes.ElementAt(index).RawMaterials.ElementAt(i).RawMaterialWeight}", DialogType.Information); + return; } - while (SiemensDevice.GetInstance.MySiemens.Read($"DB3.DBX148.{cout}").Content) + if (!device.IsConnected) { - SiemensDevice.GetInstance.MySiemens.Write($"DB4.DBX130.{cout}", false); + MessageNotify.GetInstance.ShowDialog($"设备 【{device.DeviceName}】 未连接,不允许下发此配方", DialogType.Error); + return; } - MessageNotify.GetInstance.ShowRunLog($"{cout}号气缸复位信号写入成功!"); - }); - RecipeControlViewModel.recipeProcesses.ElementAt(0).RawMaterials[k].Status = Status.配料完成; - if (Comcount >= recipeModel.RawMaterials.Count) //配方配料完成 StockStatus.Count >= Recipes.ElementAt(i).RawMaterials.Count && + } + + } + Recipes.ElementAt(index).IsEnable = false; + Json.Data.Recipes.ElementAt(index).IsEnable = false; + } + MessageNotify.GetInstance.ShowUserLog($"下发工单 {Recipes.ElementAt(index).RecipeName}"); + RecipeNames.Enqueue(RecipeName); + + var res = Recipes.FirstOrDefault(p => p.RecipeName == RecipeName); + UserTreeWait.Add(new RecipeModel { RecipStatus = "等待制作", SerialNum = UserTreeWait.Count + 1, RecipeName = RecipeName, RawMaterials = res.RawMaterials }); + } + NoticeDemoViewModel.OpenMsg(EnumPromptType.Success, App.MainWindow, "提示", $"配方下发成功!"); + + } + /// + /// 配方业务执行 + /// + private void RecipeRun() + { + TaskManage.GetInstance.StartLong(new Action(() => + { + if (RecipeNames.Count > 0) + { + int index = Array.FindIndex(Recipes.ToArray(), p => p.RecipeName == RecipeNames.ElementAt(0)); + if (index >= 0 && index < Recipes.Count) + { + Recipes.ElementAt(index).Are.Reset(); + Recipes.ElementAt(index).IsEnable = false; + StockStatus.Clear(); + App.Current.Dispatcher.Invoke(new Action(() => + { + recipeProcesses.Clear(); + if (UserTreeWait.Count > 0) UserTreeWait.RemoveAt(0); + })); + CurrentRecipeName = Recipes.ElementAt(index).RecipeName; + + #region 配方下发到PLC操作相关 + //配方数据写入到输送机 + var res = Json.Data.Recipes.FirstOrDefault(p => p.RecipeName == CurrentRecipeName); + List BarrelNum = new List(); + ConcurrentDictionary values = new(); + if (res != null) + { + var tInfo = res.RawMaterials.GroupBy(p => p.Loc);//获取桶号信息 + if (tInfo != null) + { + for (int i = 0; i < tInfo.Count(); i++) + { + int data = 0; + for (int m = 0; m < tInfo.ElementAt(i).Count(); m++) + { + var TempName = tInfo.ElementAt(i).ElementAt(m).RawMaterialName; + var tempDevice = DeviceInquire.GetInstance.devices.FirstOrDefault(p => p.DeviceName == TempName); + if (tempDevice != null) + { + /*data = data.SetBitValue((byte)tempDevice.DeviceNum, true);*/ + if (tempDevice.DeviceNum > 0) + { + // //int a = data.SetBitValue((byte)tInfo.ElementAt(i).ElementAt(m).Loc, true); + // //byte[] test1 = a.ToBytes(BPA.Helper.DataFormat.BADC); + // //int item = test1.ToInt(); + // int item = data.SetBitValue((byte)tInfo.ElementAt(i).ElementAt(m).Loc, true).ToBytes(BPA.Helper.DataFormat.BADC).ToInt(); + // int item1 = SiemensDevice.GetInstance.MySiemens.Read($"DB4.DBD{2 + (tempDevice.DeviceNum - 1) * 4}").Content; + ////prop1: + // var RE = SiemensDevice.GetInstance.MySiemens.Write($"DB4.DBD{2 + (tempDevice.DeviceNum - 1) * 4}", item + item1); + // //var values = SiemensDevice.GetInstance.MySiemens.Read($"DB4.DBD{2 + (tempDevice.DeviceNum - 1) * 4}"); + // //if ((values != null && values.ToString() != (item + item1).ToString()) || values == null) + // // goto prop1; + // if (RE.IsSuccess) + // MessageNotify.GetInstance.ShowRunLog($"下发配方DB4.DBD{2 + (tempDevice.DeviceNum - 1) * 4} :{(byte)tInfo.ElementAt(i).ElementAt(m).Loc}-{item + item1}-{(item + item1).ToBinString()}"); + // else + // MessageNotify.GetInstance.ShowRunLog($"下发配方DB4.DBD{2 + (tempDevice.DeviceNum - 1) * 4} 失败"); + + + + int item = data.SetBitValue((byte)tInfo.ElementAt(i).ElementAt(m).Loc, true).ToBytes(BPA.Helper.DataFormat.BADC).ToInt(); + string tempAdd = $"DB4.DBD{2 + (tempDevice.DeviceNum - 1) * 4}"; + if (!values.ContainsKey(tempAdd)) values.TryAdd(tempAdd, new int[2] { 0, 0 }); + values[tempAdd][0] = values[tempAdd][0] + item; + values[tempAdd][1] = tInfo.ElementAt(i).ElementAt(m).Loc; + } + } + if (tInfo.ElementAt(i).ElementAt(m).Loc > 0) + { + if (!BarrelNum.Contains(tInfo.ElementAt(i).ElementAt(m).Loc)) + { + BarrelNum.Add(tInfo.ElementAt(i).ElementAt(m).Loc); + } + } + } + } + } + } + + values?.ToList().ForEach(x => { - Comcount = 0; - App.Current.Dispatcher.Invoke(new Action(() => { RecipeControlViewModel.recipeProcesses.Clear(); })); - MessageNotify.GetInstance.ShowUserLog($"配方:{recipeModel.RecipeName},配料完成"); + SiemensDevice.GetInstance.MySiemens.Write(x.Key, x.Value[0]).OnSuccess(() => + { + MessageNotify.GetInstance.ShowRunLog($"下发配方-{x.Key} :桶数:[{x.Value[1]}]-{x.Value[0].ToBinString()}"); + }).OnFail(s => + { + MessageNotify.GetInstance.ShowRunLog($"下发配方-{x.Key} 失败"); + }); + }); + - SiemensDevice.GetInstance.MySiemens.Write("DB4.DBX202.0", true);//配料完成 - MessageNotify.GetInstance.ShowRunLog($"配方:{recipeModel.RecipeName},配料完成"); + SiemensDevice.GetInstance.MySiemens.Write("DB4.DBD198", BarrelNum.Count);//配方使用桶数写入 - recipeModel.Are.Set();//待定 + SiemensDevice.GetInstance.MySiemens.Write("DB4.DBX0.1", true);//配方执行启动 + Stopwatch sw = new Stopwatch(); + var recipe = Recipes.ElementAt(index); + ObservableCollection RawMater = new ObservableCollection(); + foreach (var item in recipe.RawMaterials) + { + RawMater.Add(new RawMaterialModel() + { + RawMaterialName = item.RawMaterialName, + DeviceIp = item.DeviceIp, + DownLimtFeedback = item.DownLimtFeedback, + Loc = item.Loc, + RawMaterialId = item.RawMaterialId, + RawMaterialSource = item.RawMaterialSource, + RawMaterialType = item.RawMaterialType, + RawMaterialWeight = item.RawMaterialWeight, + RecipeStatus = item.RecipeStatus, + SelectIndex = item.SelectIndex, + Status = item.Status, + UpLimtFeedback = item.UpLimtFeedback, + UpLimtWeightFeedback = item.UpLimtWeightFeedback, + WeightFeedback = item.WeightFeedback, + }); + } + App.Current.Dispatcher.Invoke(() => + { + recipeProcesses.Add(new RecipeModel() + { + RawMaterials = RawMater, + IsEnable = recipe.IsEnable, + RecipeName = recipe.RecipeName, + SerialNum = recipe.SerialNum, + RecipCode = recipe.RecipCode, + }); + }); + sw.Restart(); + while (true) + { + if (sw.ElapsedMilliseconds >= 3000 && !GlobalDevice.PlcData.ResComplete) + { + MessageNotify.GetInstance.ShowRunLog("获取配方下发反馈超时"); + break; + } + if (GlobalDevice.PlcData.ResComplete) + { + SiemensDevice.GetInstance.MySiemens.Write("DB3.DBX0.1", false); + break; + } Thread.Sleep(100); } + #endregion + + Recipes.ElementAt(index).Are.WaitOne();//阻塞,直到当前配方完成 + RecipeNames.TryDequeue(out string deviceName); + var recipeComple = Recipes.ElementAt(index); + ObservableCollection RawMaterComple = new ObservableCollection(); + foreach (var item in recipeComple.RawMaterials) + { + RawMaterComple.Add(new RawMaterialModel() + { + RawMaterialName = item.RawMaterialName, + DeviceIp = item.DeviceIp, + DownLimtFeedback = item.DownLimtFeedback, + Loc = item.Loc, + RawMaterialId = item.RawMaterialId, + RawMaterialSource = item.RawMaterialSource, + RawMaterialType = item.RawMaterialType, + RawMaterialWeight = item.RawMaterialWeight, + RecipeStatus = item.RecipeStatus, + SelectIndex = item.SelectIndex, + Status = item.Status, + UpLimtFeedback = item.UpLimtFeedback, + UpLimtWeightFeedback = item.UpLimtWeightFeedback, + WeightFeedback = item.WeightFeedback, + }); + } + App.Current.Dispatcher.Invoke(() => + { + UserTreeCompelete.Add(new RecipeModel() + { + RawMaterials = RawMaterComple, + IsEnable = recipeComple.IsEnable, + RecipeName = recipeComple.RecipeName, + SerialNum = UserTreeCompelete.Count + 1, + RecipCode = recipeComple.RecipCode, + RecipStatus = "制作完成" + }); + }); + App.Current.Dispatcher.Invoke(new Action(() => + { + recipeProcesses.Clear(); + CurrentRecipeName = string.Empty; + }));//完成后清空当前配方 + } + } + Thread.Sleep(100); + }), "启动配方下发", true); + } + /// + /// 配料逻辑 + /// + /// 当前执行的配方 + public void BusinessExcute() + { + ThreadManage.GetInstance.StartLong(new Action(() => + { + + #region 测试 + ////拿到当前配方 + //for (int j = 0; j < GlobalDevice.PlcData.IsAllowIngredients.Length; j++)//遍历允许配料的料桶 + //{ + + // if (GlobalDevice.PlcData.IsAllowIngredients[j]) + // { + // int barrelNum = j + 1;//桶号 + // int stockLoc = GlobalDevice.PlcData.LocationFeedback[j];//允许配料的料仓位置 0~6 双仓情况下返回的位置是否一样,料仓ip设置顺序怎样的 + // if (stockLoc >= 1 && stockLoc <= Json.Data.BaseParModel.StockCount) + // { + // int index = Array.FindIndex(DeviceInquire.GetInstance.devices.ToArray(), p => p.DeviceNum == stockLoc); + // if (index >= 0) + // { + // //查出到配料位置的原料 + // int result = Array.FindIndex(recipeModel.RawMaterials.ToArray(), p => (p.Loc == barrelNum && p.DeviceIp == DeviceInquire.GetInstance.devices.ElementAt(index).IpAddress));//待定 + // if (result != -1 && DeviceInquire.GetInstance.GetDevice(recipeModel.RawMaterials[result].DeviceIp).deviceStatus.RunStatus == 1 && RecipeControlViewModel.recipeProcesses.ElementAt(0).RawMaterials[result].Status == Status.等待配料) + // { + // var weight = recipeModel.RawMaterials[result].RawMaterialWeight; + // DeviceInquire.GetInstance.GetDevice(recipeModel.RawMaterials.ElementAt(index).DeviceIp).Start(weight);//所有参数下发并启动配料 + // MessageNotify.GetInstance.ShowRunLog($"{recipeModel.RawMaterials[result].DeviceIp}:正在配料"); + // RecipeControlViewModel.recipeProcesses.ElementAt(0).RawMaterials[result].Status = Status.正在配料; + // } + // } + // } + // else + // { + // continue; + // } + // } + + //} + ////配料完成后逻辑 + //for (int k = 0; k < recipeModel.RawMaterials.Count; k++) + //{ + // if (DeviceInquire.GetInstance.GetDevice(recipeModel.RawMaterials.ElementAt(k).DeviceIp).deviceStatus.RunStatus == 3 && RecipeControlViewModel.recipeProcesses.ElementAt(0).RawMaterials[k].Status != Status.配料完成)//配料完成 + // { + // int DeviceNum = DeviceInquire.GetInstance.GetDevice(recipeModel.RawMaterials.ElementAt(k).DeviceIp).deviceStatus.DeviceNum; + // Comcount++; + // DeviceInquire.GetInstance.GetDevice(recipeModel.RawMaterials.ElementAt(k).DeviceIp).StatusReset();//料仓复位 + // SiemensDevice.GetInstance.MySiemens.Write($"DB4.DBX130.{DeviceNum - 1}", true); + // Task.Run(() => + // { + // int cout = DeviceNum - 1; + // while (!SiemensDevice.GetInstance.MySiemens.Read($"DB3.DBX148.{cout}").Content) //DB3.DBX148.0-31 148.0-148.5代表6个料仓位置 + // { + // SiemensDevice.GetInstance.MySiemens.Write($"DB4.DBX130.{cout}", true); + // Thread.Sleep(200); + // } + // while (SiemensDevice.GetInstance.MySiemens.Read($"DB3.DBX148.{cout}").Content) + // { + // SiemensDevice.GetInstance.MySiemens.Write($"DB4.DBX130.{cout}", false); + // } + // MessageNotify.GetInstance.ShowRunLog($"{cout}号气缸复位信号写入成功!"); + // }); + // RecipeControlViewModel.recipeProcesses.ElementAt(0).RawMaterials[k].Status = Status.配料完成; + // if (Comcount >= recipeModel.RawMaterials.Count) //配方配料完成 StockStatus.Count >= Recipes.ElementAt(i).RawMaterials.Count && + // { + // Comcount = 0; + // App.Current.Dispatcher.Invoke(new Action(() => { RecipeControlViewModel.recipeProcesses.Clear(); })); + // MessageNotify.GetInstance.ShowUserLog($"配方:{recipeModel.RecipeName},配料完成"); + + // SiemensDevice.GetInstance.MySiemens.Write("DB4.DBX202.0", true);//配料完成 + // MessageNotify.GetInstance.ShowRunLog($"配方:{recipeModel.RecipeName},配料完成"); + + // recipeModel.Are.Set();//待定 + // Thread.Sleep(100); + // } + // } + //} + #endregion + #region 正式版 + for (int i = 0; i < Recipes.Count; i++) + { + for (int m = 0; m < Recipes.ElementAt(i).RawMaterials.Count; m++) + { + var RunStatus = DeviceInquire.GetInstance.GetDevice(Recipes.ElementAt(i).RawMaterials.ElementAt(m).DeviceIp).deviceStatus.RunStatus; + //设备状态显示 + if (Recipes.ElementAt(i).RecipeName == CurrentRecipeName) + { + string tempRawMaterialName = DeviceInquire.GetInstance.GetDevice(Recipes.ElementAt(i).RawMaterials.ElementAt(m).DeviceIp).DeviceName; + int recIndex = recipeProcesses.ToList().FindIndex(p => p.RecipeName == CurrentRecipeName); + if (recIndex >= 0 && recIndex < recipeProcesses.Count) + { + int index = recipeProcesses.ElementAt(recIndex).RawMaterials.ToList().FindIndex(p => p.RawMaterialName == tempRawMaterialName); + + if (index >= 0 && index < recipeProcesses.ElementAt(recIndex).RawMaterials.Count) + { + //测试使用 + recipeProcesses.ElementAt(recIndex).RawMaterials.ElementAt(index).RecipeStatus = RunStatus; + } + for (int j = 0; j < GlobalDevice.PlcData.IsAllowIngredients.Length; j++) + { + if (GlobalDevice.PlcData.IsAllowIngredients[j]) + { + int barrel = j + 1;//桶号 + int cnt = GlobalDevice.PlcData.LocationFeedback[j];//允许配料的位置 1~6 + if (RTrig.GetInstance($"a{j}").Start(GlobalDevice.PlcData.IsAllowIngredients[j])) + { + MessageNotify.GetInstance.ShowRunLog($"桶号:{barrel},位置:{cnt},允许配料"); + } + int Location1 = 0; + int Location2 = 0; + if (cnt == -1) + { + MessageNotify.GetInstance.ShowRunLog("错误"); + return; + } + else + { + if (cnt >= 1 && cnt <= 6) + { + int a1 = Array.FindIndex(DeviceInquire.GetInstance.devices.ToArray(), p => p.DeviceNum == cnt); + if (a1 >= 0) + { + Location1 = Array.FindIndex(Recipes.ElementAt(i).RawMaterials.ToArray(), p => p.RawMaterialName == DeviceInquire.GetInstance.devices.ElementAt(a1).DeviceName && p.Loc == barrel); + } + + } + } + if (Location1 >= 0) + { + string RawName = Recipes.ElementAt(i).RawMaterials.ElementAt(Location1).RawMaterialName; + int abc = Array.FindIndex(DeviceInquire.GetInstance.devices.ToArray(), p => p.DeviceName == RawName); + int DeviceNum = DeviceInquire.GetInstance.devices.ElementAt(abc).DeviceNum; + if (DeviceNum > 0) + { + float weight = Recipes.ElementAt(i).RawMaterials.ElementAt(Location1).RawMaterialWeight; + + int loc = Array.FindIndex(Recipes.ElementAt(i).RawMaterials.ToArray(), p => (p.RawMaterialName == RawName)); + if (loc >= 0 && RawName != null && weight >= 0) + { + int St_index = Array.FindIndex(StockStatus.ToArray(), p => p.MaterialName == RawName); + + if (St_index < 0) //|| (StockStatus.Count < materialCount && St_index > 0) + { + StockStatus.Add(new StockStatusModel() + { + MaterialName = RawName, + IssueWeight = weight, + IssueStatus = 0, + }); + } + St_index = Array.FindIndex(StockStatus.ToArray(), p => p.MaterialName == RawName);//&& p.IssueStatus == 0) + if (St_index >= 0) + { + + if (RTrig.GetInstance($"ac{j}-{St_index}").Start(GlobalDevice.PlcData.IsAllowIngredients[j])) + { + MessageNotify.GetInstance.ShowRunLog($"{St_index}-{j}--》允许配料"); + if (StockStatus.ElementAt(St_index).IssueStatus == 2) + { + StockStatus.ElementAt(St_index).IssueStatus = 0; + MessageNotify.GetInstance.ShowRunLog($"{St_index}-复位"); + } + } + var rrr = DeviceInquire.GetInstance.GetDevice(Recipes.ElementAt(i).RawMaterials.ElementAt(loc).DeviceIp).deviceStatus.RunStatus; + if ((recipeProcesses.ElementAt(recIndex).RawMaterials.ElementAt(loc).RecipeStatus == 1 && StockStatus.ElementAt(St_index).IssueStatus == 0))// + { + + StockStatus.ElementAt(St_index).IssueStatus = 1; + DeviceInquire.GetInstance.GetDevice(Recipes.ElementAt(i).RawMaterials.ElementAt(loc).DeviceIp).Start(weight); + var res = recipeProcesses.ElementAt(recIndex).RawMaterials.FirstOrDefault(p => p.Status != Status.正在配料 && p.Status != Status.配料完成 && p.RawMaterialName == tempRawMaterialName && p.Loc == j + 1); + if (res != null) + res.Status = Status.正在配料; + + MessageNotify.GetInstance.ShowRunLog($"设备执行状态:{rrr}"); + MessageNotify.GetInstance.ShowRunLog($"柔性味魔方{Recipes.ElementAt(i).RawMaterials.ElementAt(loc).DeviceIp},开始出料"); + } + if (recipeProcesses.ElementAt(recIndex).RawMaterials.ElementAt(loc).RecipeStatus == 3 && StockStatus.ElementAt(St_index).IssueStatus == 1) + { + //GlobalDevice.PlcData.IsAllowIngredients[j] = false;//测试使用 + + Comcount++; + StockStatus.ElementAt(St_index).IssueStatus = 2; + DeviceInquire.GetInstance.GetDevice(Recipes.ElementAt(i).RawMaterials.ElementAt(loc).DeviceIp).StatusReset(); + //int a = 0.SetBitValue((byte)(DeviceNum), true); + //byte[] test1 = a.ToBytes(BPA.Helper.DataFormat.BADC); + //int item = test1.ToInt(); + //prop1: + // SiemensDevice.GetInstance.MySiemens.Write("DB4.DBD130", item); + SiemensDevice.GetInstance.MySiemens.Write($"DB4.DBX130.{DeviceNum - 1}", true); + Task.Run(() => + { + int cout = DeviceNum - 1; + while (!SiemensDevice.GetInstance.MySiemens.Read($"DB3.DBX148.{cout}").Content) //DB3.DBX148.0-31 148.0-148.5代表6个料仓位置 + { + SiemensDevice.GetInstance.MySiemens.Write($"DB4.DBX130.{cout}", true); + Thread.Sleep(200); + } + while (SiemensDevice.GetInstance.MySiemens.Read($"DB3.DBX148.{cout}").Content) + { + SiemensDevice.GetInstance.MySiemens.Write($"DB4.DBX130.{cout}", false); + } + MessageNotify.GetInstance.ShowRunLog($"{cout}号气缸复位信号写入成功!"); + }); + var res = recipeProcesses.ElementAt(recIndex).RawMaterials.FirstOrDefault(p => p.Status != Status.配料完成 && p.RawMaterialName == tempRawMaterialName && p.Loc == j + 1); + if (res != null) + res.Status = Status.配料完成; + + + MessageNotify.GetInstance.ShowRunLog($"设备完成执行状态:{rrr}"); + MessageNotify.GetInstance.ShowRunLog($"柔性味魔方{Recipes.ElementAt(i).RawMaterials.ElementAt(loc).DeviceIp},出料完成,状态复位"); + + } + + + } + } + } + } + } + + } + + if (Comcount >= Recipes.ElementAt(i).RawMaterials.Count) //配方配料完成 StockStatus.Count >= Recipes.ElementAt(i).RawMaterials.Count && + { + SystemEventReport("RecipeCompleteEvent", new AliyunSystemReportModel { RecipeName = CurrentRecipeName }); + int cc = recipeProcesses.ElementAt(recIndex).RawMaterials.OrderBy(p => p.RawMaterialName).Count(); + for (int k = 0; k < 32; k++) + { + for (int l = 0; l < cc; l++) + { + RTrig.GetInstance($"ac{k}-{l}").Start(false); + } + } + Comcount = 0; + + StockStatus.Clear(); + MessageNotify.GetInstance.ShowUserLog($"配方:{recipeProcesses.ElementAt(recIndex).RecipeName},配料完成"); + foreach (var item in recipeProcesses.ElementAt(recIndex).RawMaterials) + { + MessageNotify.GetInstance.ShowUserLog($"原料:{item.RawMaterialName},桶号:{item.Loc},设定配料重量{item.RawMaterialWeight}g,实际配料重量{item.UpLimtWeightFeedback}g"); + } + SiemensDevice.GetInstance.MySiemens.Write("DB4.DBX202.0", true);//配料完成 + MessageNotify.GetInstance.ShowRunLog($"配方:{CurrentRecipeName},配料完成"); + int recipIndex = Array.FindIndex(Recipes.ToArray(), p => p.RecipeName == CurrentRecipeName); + App.Current.Dispatcher.Invoke(new Action(() => { recipeProcesses.Clear(); })); + Recipes.ElementAt(recipIndex).IsEnable = true; + Json.Data.Recipes.ElementAt(recipIndex).IsEnable = true; + Recipes.ElementAt(recipIndex).Are.Set(); + Thread.Sleep(100); + } + } + } } } #endregion Thread.Sleep(10); - }),"配料业务逻辑"); - + }), "配料业务逻辑"); + } } diff --git a/DosingSystem/Model/AlarmInfo.cs b/DosingSystem/Model/AlarmInfo.cs index 7944fa96..c84739f2 100644 --- a/DosingSystem/Model/AlarmInfo.cs +++ b/DosingSystem/Model/AlarmInfo.cs @@ -1,9 +1,4 @@ using BPASmartClient.CustomResource.Pages.Model; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace BPASmartClient.DosingSystem { diff --git a/DosingSystem/Model/AliyunConveyerPropertyReportModel.cs b/DosingSystem/Model/AliyunConveyerPropertyReportModel.cs new file mode 100644 index 00000000..1528221c --- /dev/null +++ b/DosingSystem/Model/AliyunConveyerPropertyReportModel.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BPASmartClient.DosingSystem.Model +{ + public class AliyunConveyerPropertyReportModel + { + //private static AliyunConveyerPropertyReportModel Instance; + //public static AliyunConveyerPropertyReportModel GetInstance=>Instance??=new AliyunConveyerPropertyReportModel(); + public int ConveyerOnlineStatus { get; set; } + public int ButtonBucketSigleCheck { get; set; } + public int TopBucketSigleCheck { get; set; } + public int WorkModel { get; set; } + public int RunStatus { get; set; } + public int TopBucketControlStatus { get; set; } + public int DownBucketControlStatus { get; set; } + } +} diff --git a/DosingSystem/Model/AliyunMaterialModelType.cs b/DosingSystem/Model/AliyunMaterialModelType.cs new file mode 100644 index 00000000..ffb52011 --- /dev/null +++ b/DosingSystem/Model/AliyunMaterialModelType.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BPASmartClient.DosingSystem.Model +{ + /// + /// 阿里云物模型模板类型 + /// + public enum AliyunMaterialModelType + { + // DefaultModel,//默认模板 + StockModel,//料仓模板 + ConveyerModel//输送线模板 + } +} diff --git a/DosingSystem/Model/AliyunStockEventReportModel.cs b/DosingSystem/Model/AliyunStockEventReportModel.cs new file mode 100644 index 00000000..2f3479bb --- /dev/null +++ b/DosingSystem/Model/AliyunStockEventReportModel.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BPASmartClient.DosingSystem.Model +{ + public class AliyunStockEventReportModel + { + /// + /// 触发值 + /// + public string Result { get; set; } + } +} diff --git a/DosingSystem/Model/AliyunStockPropertyReportModel.cs b/DosingSystem/Model/AliyunStockPropertyReportModel.cs new file mode 100644 index 00000000..a084f96d --- /dev/null +++ b/DosingSystem/Model/AliyunStockPropertyReportModel.cs @@ -0,0 +1,37 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BPASmartClient.DosingSystem.Model +{ + public class AliyunStockPropertyReportModel + { + public int StockRealWeight { get; set; } + + public float BucketRealWeight { get; set; } + + public string StockBatchStatus { get; set; } + + public int StockWorkModel { get; set; } + + public string StockMaterialType { get; set; } + + public int StockDeviceNum { get; set; } + public string StockDeviceName { get; set; } + + public float StockSlowlyAddWeight { get; set; } + + public float StockPreCloseValueWeight { get; set; } + + public int StockRapidAcceleration { get; set; } + + public int StockSlowAcceleration { get; set; } + public int StockServoManualSpeed { get; set; } + public int StockUpperLimitWeight { get; set; } + public int StockLowerLimitWeight { get; set; } + public int StockStirringSpeed { get; set; } + + } +} diff --git a/DosingSystem/Model/AliyunSystemReportModel.cs b/DosingSystem/Model/AliyunSystemReportModel.cs new file mode 100644 index 00000000..e660766d --- /dev/null +++ b/DosingSystem/Model/AliyunSystemReportModel.cs @@ -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 AliyunSystemReportModel + { + public string RecipeName { get; set; } + } +} diff --git a/DosingSystem/Model/ConveryType.cs b/DosingSystem/Model/ConveryType.cs index ee97106a..11e8d657 100644 --- a/DosingSystem/Model/ConveryType.cs +++ b/DosingSystem/Model/ConveryType.cs @@ -1,16 +1,10 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace BPASmartClient.DosingSystem.Model +namespace BPASmartClient.DosingSystem.Model { public enum ConveryType { U型, 直线型, - + } - + } diff --git a/DosingSystem/Model/ConveyerBeltModel.cs b/DosingSystem/Model/ConveyerBeltModel.cs index 60d34f16..bfb4ee44 100644 --- a/DosingSystem/Model/ConveyerBeltModel.cs +++ b/DosingSystem/Model/ConveyerBeltModel.cs @@ -1,10 +1,5 @@ using BPA.Helper; using BPASmartClient.CustomResource.Pages.Model; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace BPASmartClient.DosingSystem { diff --git a/DosingSystem/Model/CylinderStatusModel.cs b/DosingSystem/Model/CylinderStatusModel.cs index 933851a4..f8e4aa4a 100644 --- a/DosingSystem/Model/CylinderStatusModel.cs +++ b/DosingSystem/Model/CylinderStatusModel.cs @@ -1,9 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using BPA.Helper; +using BPA.Helper; namespace BPASmartClient.DosingSystem { diff --git a/DosingSystem/Model/DeviceAddress.cs b/DosingSystem/Model/DeviceAddress.cs index e2d5530f..437f09c9 100644 --- a/DosingSystem/Model/DeviceAddress.cs +++ b/DosingSystem/Model/DeviceAddress.cs @@ -1,10 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace BPASmartClient.DosingSystem +namespace BPASmartClient.DosingSystem { public class DeviceAddress { @@ -13,6 +7,7 @@ namespace BPASmartClient.DosingSystem /// public static string DeviceName { get; set; } = "LW0"; + public static string WorkModel { get; set; } = "LW50"; /// /// 料仓重量反馈起始地址 /// diff --git a/DosingSystem/Model/DeviceCurrentStatus.cs b/DosingSystem/Model/DeviceCurrentStatus.cs index d77ddc02..1aaed4a2 100644 --- a/DosingSystem/Model/DeviceCurrentStatus.cs +++ b/DosingSystem/Model/DeviceCurrentStatus.cs @@ -1,10 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Windows; -using BPA.Helper; +using BPA.Helper; namespace BPASmartClient.DosingSystem { diff --git a/DosingSystem/Model/DeviceInquire.cs b/DosingSystem/Model/DeviceInquire.cs index f4e810b7..1784d0c8 100644 --- a/DosingSystem/Model/DeviceInquire.cs +++ b/DosingSystem/Model/DeviceInquire.cs @@ -1,4 +1,8 @@ -using BPASmartClient.CustomResource.Pages.Model; +//#define Debug +using BPA.Communication; +using BPA.Helper; +using BPASmartClient.CustomResource.Pages.Model; +using BPASmartClient.DosingSystem.Model; using BPASmartClient.DosingSystem.ViewModel; //using BPASmartClient.Modbus; using BPASmartClient.Model; @@ -6,15 +10,12 @@ using System; using System.Collections.Concurrent; using System.Collections.Generic; using System.Collections.ObjectModel; +using System.Diagnostics; using System.Linq; using System.Net.NetworkInformation; +using System.Reflection; using System.Threading; using System.Threading.Tasks; -using BPA.Helper; -using System.Text.RegularExpressions; -using BPA.Communication; -using BPASmartClient.DosingSystem.Model; -using Google.Protobuf.WellKnownTypes; namespace BPASmartClient.DosingSystem { @@ -204,7 +205,7 @@ namespace BPASmartClient.DosingSystem } } }*/ - stockCount = Json.Data.BaseParModel.StockCount; + stockCount = Json.Data.BaseParModel.StockCount; for (int i = 0; i < stockCount; i++) { IPLists.Add($"{IPSegment}{(i + 1) * 10}"); @@ -242,7 +243,7 @@ namespace BPASmartClient.DosingSystem { devices.Add(new Devices() { DeviceName = DeviceName, IpAddress = ip }); //2023/7/3调整 - if (stockCount<=8||(stockCount>8&&TopDeviceCurrentStatuses.Count <= stockCount / 2 + 1 &&int.TryParse( ip.Split('.')[3],out int res)&&res<= (stockCount / 2 + 1)*10)) + if (stockCount <= 8 || (stockCount > 8 && TopDeviceCurrentStatuses.Count <= stockCount / 2 + 1 && int.TryParse(ip.Split('.')[3], out int res) && res <= (stockCount / 2 + 1) * 10)) TopDeviceCurrentStatuses.Add(new DeviceCurrentStatus() { DeviceName = DeviceName }); else BottomDeviceCurrentStatuses.Add(new DeviceCurrentStatus() { DeviceName = DeviceName }); @@ -351,10 +352,11 @@ namespace BPASmartClient.DosingSystem AlarmHelper.Init(); if (IsConnected) { + TaskManage.GetInstance.StartLong(new Action(() => { var dn = modbusTcp.Read(DeviceAddress.DeviceName.ToAdd(), 20); - if (dn.IsSuccess) this.DeviceName = dn.Content.Trim().Replace(" ", ""); + if (dn.IsSuccess) { this.DeviceName = dn.Content.Trim().Replace(" ", ""); deviceStatus.DeviceName = this.DeviceName; } //获取设备运行状态 var rs = this.modbusTcp.Read(DeviceAddress.RunStatus.ToAdd()); @@ -376,7 +378,37 @@ namespace BPASmartClient.DosingSystem var dac = this.modbusTcp.Read(DeviceAddress.DeviceAlarmCode.ToAdd()); if (dac.IsSuccess) deviceStatus.DeviceAlarmCode = dac.Content; - + //获取原料类型 + var mt = this.modbusTcp.Read(DeviceAddress.MaterialDeviceType.ToAdd()); + if (mt.IsSuccess) deviceStatus.RawMaterialType = mt.Content; + + //获取工作模式 + var wm = this.modbusTcp.Read(DeviceAddress.WorkModel.ToAdd()); + if (wm.IsSuccess) deviceStatus.WorkModel = wm.Content.GetBitValue(1); + //慢加重量 + var ssaw = this.modbusTcp.Read(DeviceAddress.SlowlyAddWeight.ToAdd()); + if (ssaw.IsSuccess) deviceStatus.SlowAddWeight = ssaw.Content; + //提前关阀重量 + var pcvw = this.modbusTcp.Read(DeviceAddress.PreCloseValveWeight.ToAdd()); + if (pcvw.IsSuccess) deviceStatus.PreCloseValueWeight = pcvw.Content; + //快加速度 + var ra = this.modbusTcp.Read(DeviceAddress.RapidAcceleration.ToAdd()); + if (ra.IsSuccess) deviceStatus.RapidAcceleration = ra.Content; + //慢加速度 + var sa = this.modbusTcp.Read(DeviceAddress.SlowAcceleration.ToAdd()); + if (sa.IsSuccess) deviceStatus.SlowAcceleration = sa.Content; + //伺服手动速度 + var sms = this.modbusTcp.Read(DeviceAddress.ServoManualSpeed.ToAdd()); + if (sms.IsSuccess) deviceStatus.ServoManualSpeed = sms.Content; + //料仓上限重量 + var ulw = this.modbusTcp.Read(DeviceAddress.SiloUpperLimitWeight.ToAdd()); + if (ulw.IsSuccess) deviceStatus.SiloUpperLimitWeight = ulw.Content; + //料仓下限重量 + var llw = this.modbusTcp.Read(DeviceAddress.LowerLimitWeightOfSilo.ToAdd()); + if (llw.IsSuccess) deviceStatus.SiloLowerLimitWeight = llw.Content; + //料仓搅拌速度 + var ss = this.modbusTcp.Read(DeviceAddress.StirringSpeed.ToAdd()); + if (ss.IsSuccess) deviceStatus.StirringSpeed = ss.Content; //this.DeviceName = modbusTcp.Read(DeviceAddress.DeviceName.ToAdd(), 20).Content.Trim().Replace(" ", ""); //deviceStatus.RunStatus = (ushort)this.modbusTcp.Read(DeviceAddress.RunStatus.ToAdd()).Content; //获取设备运行状态 //deviceStatus.WeightFeedback = (float)this.modbusTcp.Read(DeviceAddress.WeightFeedback.ToAdd()).Content;//获取设备料仓剩余重量 @@ -391,10 +423,115 @@ namespace BPASmartClient.DosingSystem AlarmHelper.GetInstance(DeviceName).SiloUpperLimit = deviceStatus.DeviceAlarmCode.GetBitValue(8); AlarmHelper.GetInstance(DeviceName).SiloLowerLimit = deviceStatus.DeviceAlarmCode.GetBitValue(9); Thread.Sleep(10); + if (ExcuteControl.GetInstance.AliyunIsConnect) + { + + StockPropertyReport(); + StockEventReport(); + } + Thread.Sleep(10); }), $"{DeviceName} 开始监听", true); } } + /// + /// 料仓属性上报 + /// + public void StockPropertyReport() + { +#if !Debug + AliyunStockPropertyReportModel model = new AliyunStockPropertyReportModel(); + model.StockRealWeight = (int)deviceStatus.WeightFeedback; + model.BucketRealWeight = deviceStatus.NowWeightFeedback; + model.StockDeviceNum = (int)deviceStatus.DeviceNum; + model.StockDeviceName = deviceStatus.DeviceName; + model.StockWorkModel = deviceStatus.WorkModel == true ? 1 : 0; + model.StockSlowlyAddWeight = deviceStatus.SlowAddWeight; + model.StockPreCloseValueWeight = deviceStatus.PreCloseValueWeight; + model.StockRapidAcceleration = (int)deviceStatus.RapidAcceleration; + model.StockSlowAcceleration = (int)deviceStatus.SlowAcceleration; + model.StockServoManualSpeed = (int)deviceStatus.ServoManualSpeed; + model.StockUpperLimitWeight = (int)deviceStatus.SiloUpperLimitWeight; + model.StockLowerLimitWeight = (int)deviceStatus.SiloLowerLimitWeight; + model.StockStirringSpeed = (int)deviceStatus.StirringSpeed; + switch (deviceStatus.RawMaterialType) + { + case 1: + model.StockMaterialType = "膏体"; break; + case 2: + model.StockMaterialType = "液体"; break; + case 3: + model.StockMaterialType = "粉体"; break; + } + switch (deviceStatus.RunStatus) + { + case 0: + model.StockBatchStatus = "待机"; break; + case 1: + model.StockBatchStatus = "等待配料"; break; + case 2: + model.StockBatchStatus = "配料中"; break; + case 3: + model.StockBatchStatus = "配料完成"; break; + } +#endif +#if Debug + //本地模拟测试 + AliyunStockPropertyReportModel model = new AliyunStockPropertyReportModel(); + model.StockRealWeight = 1; + model.BucketRealWeight = 2; + model.StockDeviceNum = 2; + model.StockDeviceName ="测试"; + model.StockWorkModel = 0; + model.StockSlowlyAddWeight = 6; + model.StockPreCloseValueWeight = 7; + model.StockRapidAcceleration =46; + model.StockSlowAcceleration = 24; + model.StockServoManualSpeed = 35; + model.StockUpperLimitWeight = 57; + model.StockLowerLimitWeight = 34; + model.StockStirringSpeed = 54; + model.StockMaterialType = "粉体"; + model.StockBatchStatus = "待机"; + ExcuteControl.GetInstance.StokcPropertyReport(IpAddress, model); +#endif + } + /// + /// 事件上报 + /// + public void StockEventReport() + { +#if !Debug + if (ExcuteControl.GetInstance.AliyunIsConnect && RTrig.GetInstance("stop1").Start(AlarmHelper.GetInstance(DeviceName).EStop1)) + { + ExcuteControl.GetInstance.AliyunEventReport(IpAddress, new AliyunStockEventReportModel { Result = "1" }, "StockJerk1StatusEvent", AliyunMaterialModelType.StockModel); + } + if (ExcuteControl.GetInstance.AliyunIsConnect && RTrig.GetInstance("Servo").Start(AlarmHelper.GetInstance(DeviceName).Servo)) + { + ExcuteControl.GetInstance.AliyunEventReport(IpAddress, new AliyunStockEventReportModel { Result = "1" }, "StockServoFalutEvent", AliyunMaterialModelType.StockModel); + } + + if (ExcuteControl.GetInstance.AliyunIsConnect && RTrig.GetInstance("EStop2").Start(AlarmHelper.GetInstance(DeviceName).EStop2)) + { + ExcuteControl.GetInstance.AliyunEventReport(IpAddress, new AliyunStockEventReportModel { Result = "1" }, "StockJerk2StatusEvent", AliyunMaterialModelType.StockModel); + } + if (ExcuteControl.GetInstance.AliyunIsConnect && RTrig.GetInstance("SiloUpperLimit").Start(AlarmHelper.GetInstance(DeviceName).SiloUpperLimit)) + { + ExcuteControl.GetInstance.AliyunEventReport(IpAddress, new AliyunStockEventReportModel { Result = "1" }, "StockUpLimitEvent", AliyunMaterialModelType.StockModel); + } + if (ExcuteControl.GetInstance.AliyunIsConnect && RTrig.GetInstance("SiloLowerLimit").Start(AlarmHelper.GetInstance(DeviceName).SiloLowerLimit)) + { + ExcuteControl.GetInstance.AliyunEventReport(IpAddress, new AliyunStockEventReportModel { Result = "1" }, "StockDownLimitEvent", AliyunMaterialModelType.StockModel); + } +#endif +#if Debug + ExcuteControl.GetInstance.AliyunEventReport(IpAddress, new AliyunStockEventReportModel { Result = "1" }, "StockJerk1StatusEvent", AliyunMaterialModelType.StockModel); + ExcuteControl.GetInstance.AliyunEventReport(IpAddress, new AliyunStockEventReportModel { Result = "1" }, "StockServoFalutEvent", AliyunMaterialModelType.StockModel); + ExcuteControl.GetInstance.AliyunEventReport(IpAddress, new AliyunStockEventReportModel { Result = "1" }, "StockJerk2StatusEvent", AliyunMaterialModelType.StockModel); + ExcuteControl.GetInstance.AliyunEventReport(IpAddress, new AliyunStockEventReportModel { Result = "1" }, "StockUpLimitEvent", AliyunMaterialModelType.StockModel); + ExcuteControl.GetInstance.AliyunEventReport(IpAddress, new AliyunStockEventReportModel { Result = "1" }, "StockDownLimitEvent", AliyunMaterialModelType.StockModel); +#endif + } public void SetDeviceName(string name) { this.modbusTcp.Write(DeviceAddress.DeviceName.ToAdd(), new ushort[20]); @@ -403,7 +540,7 @@ namespace BPASmartClient.DosingSystem public void StatusReset() { - // prop1: + // prop1: this.modbusTcp.Write(DeviceAddress.FinfishStatus.ToAdd(), (ushort)1); //MessageNotify.GetInstance.ShowRunLog($"料仓复位,值:{1}"); //var value = this.modbusTcp.Read(DeviceAddress.FinfishStatus.ToAdd(), 1, BPA.Helper.DataFormat.CDAB).Content; @@ -422,17 +559,17 @@ namespace BPASmartClient.DosingSystem var res = Json.Data.deviceParModels.FirstOrDefault(p => p.MaterialName == DeviceName); if (res != null) { - //modbusTcp.Write(DeviceAddress.SlowlyAddWeight.ToAdd(), res.SlowlyAddWeight); - - //modbusTcp.Write(DeviceAddress.PreCloseValveWeight.ToAdd(), res.PreCloseValveWeight); - //modbusTcp.Write(DeviceAddress.RapidAcceleration.ToAdd(), (uint)res.RapidAcceleration); - //modbusTcp.Write(DeviceAddress.SlowAcceleration.ToAdd(), (uint)res.SlowAcceleration); - //modbusTcp.Write(DeviceAddress.ServoManualSpeed.ToAdd(), (uint)res.ServoManualSpeed); - //modbusTcp.Write(DeviceAddress.SiloUpperLimitWeight.ToAdd(), (uint)res.SiloUpperLimitWeight); - //modbusTcp.Write(DeviceAddress.LowerLimitWeightOfSilo.ToAdd(), (uint)res.LowerLimitWeightOfSilo); - //modbusTcp.Write(DeviceAddress.StirringSpeed.ToAdd(), (uint)res.StirringSpeed); - - //MessageNotify.GetInstance.ShowRunLog($"{res.MaterialName},配料参数下发完成"); + //modbusTcp.Write(DeviceAddress.SlowlyAddWeight.ToAdd(), res.SlowlyAddWeight); + + //modbusTcp.Write(DeviceAddress.PreCloseValveWeight.ToAdd(), res.PreCloseValveWeight); + //modbusTcp.Write(DeviceAddress.RapidAcceleration.ToAdd(), (uint)res.RapidAcceleration); + //modbusTcp.Write(DeviceAddress.SlowAcceleration.ToAdd(), (uint)res.SlowAcceleration); + //modbusTcp.Write(DeviceAddress.ServoManualSpeed.ToAdd(), (uint)res.ServoManualSpeed); + //modbusTcp.Write(DeviceAddress.SiloUpperLimitWeight.ToAdd(), (uint)res.SiloUpperLimitWeight); + //modbusTcp.Write(DeviceAddress.LowerLimitWeightOfSilo.ToAdd(), (uint)res.LowerLimitWeightOfSilo); + //modbusTcp.Write(DeviceAddress.StirringSpeed.ToAdd(), (uint)res.StirringSpeed); + + //MessageNotify.GetInstance.ShowRunLog($"{res.MaterialName},配料参数下发完成"); prop1: modbusTcp.Write(DeviceAddress.SlowlyAddWeight.ToAdd(), res.SlowlyAddWeight); @@ -481,7 +618,7 @@ namespace BPASmartClient.DosingSystem modbusTcp.Write(DeviceAddress.WeightSet.ToAdd(), Value);//写入配方重量 MessageNotify.GetInstance.ShowRunLog($"{DeviceName},设置重量:{Value}"); - var value9 = modbusTcp.Read(DeviceAddress.WeightSet.ToAdd(), 1, BPA.Helper.DataFormat.CDAB).Content; + var value9 = modbusTcp.Read(DeviceAddress.WeightSet.ToAdd(), 1, BPA.Helper.DataFormat.CDAB).Content; if ((value9 != null && value9.ToString() != Value.ToString()) || value9 == 0) goto prop9; //prop10: //MessageNotify.GetInstance.ShowRunLog($"写入配方重量,值{Value}:{value9}"); @@ -507,10 +644,11 @@ namespace BPASmartClient.DosingSystem }); - + MessageNotify.GetInstance.ShowRunLog($"{DeviceName},设置重量:{Value},味魔方启动配料"); } } + static string DecToBinary(int a) { int r; diff --git a/DosingSystem/Model/Expand.cs b/DosingSystem/Model/Expand.cs index cfcfc7f4..c18feeab 100644 --- a/DosingSystem/Model/Expand.cs +++ b/DosingSystem/Model/Expand.cs @@ -1,8 +1,4 @@ using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace BPASmartClient.DosingSystem.Model { diff --git a/DosingSystem/Model/GlobalDevice.cs b/DosingSystem/Model/GlobalDevice.cs index bbc78b27..4263b81c 100644 --- a/DosingSystem/Model/GlobalDevice.cs +++ b/DosingSystem/Model/GlobalDevice.cs @@ -1,10 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace BPASmartClient.DosingSystem +namespace BPASmartClient.DosingSystem { public class GlobalDevice { diff --git a/DosingSystem/Model/OutletInfoModel.cs b/DosingSystem/Model/OutletInfoModel.cs index 470115dc..0cf6b17d 100644 --- a/DosingSystem/Model/OutletInfoModel.cs +++ b/DosingSystem/Model/OutletInfoModel.cs @@ -1,9 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using BPA.Helper; +using BPA.Helper; using System.Collections.ObjectModel; namespace BPASmartClient.DosingSystem diff --git a/DosingSystem/Model/RawMaterialDeviceStatus.cs b/DosingSystem/Model/RawMaterialDeviceStatus.cs index fde2c917..7bc7edd2 100644 --- a/DosingSystem/Model/RawMaterialDeviceStatus.cs +++ b/DosingSystem/Model/RawMaterialDeviceStatus.cs @@ -1,10 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace BPASmartClient.DosingSystem +namespace BPASmartClient.DosingSystem { public class RawMaterialDeviceStatus { @@ -61,5 +55,46 @@ namespace BPASmartClient.DosingSystem /// public ushort DeviceNum { get; set; } + /// + /// 原料名称 + /// + public string DeviceName { get; set; } + /// + /// 工作模式0:手动 1:自动 + /// + public bool WorkModel { get; set; } + /// + /// 慢加重量 + /// + public float SlowAddWeight { get; set; } + /// + /// 提前关阀重量 + /// + public float PreCloseValueWeight { get; set; } + + /// + /// 快加速度 + /// + public uint RapidAcceleration { get; set; } + /// + /// 慢加速度 + /// + public uint SlowAcceleration { get; set; } + /// + /// 伺服手动速度 + /// + public uint ServoManualSpeed { get; set; } + /// + /// 料仓上限重量 + /// + public uint SiloUpperLimitWeight { get; set; } + /// + /// 料仓下限重量 + /// + public uint SiloLowerLimitWeight { get; set; } + /// + /// 搅拌速度 + /// + public uint StirringSpeed { get; set; } } } diff --git a/DosingSystem/Model/RecipeModel.cs b/DosingSystem/Model/RecipeModel.cs index d68b97c1..7f84e2ba 100644 --- a/DosingSystem/Model/RecipeModel.cs +++ b/DosingSystem/Model/RecipeModel.cs @@ -1,12 +1,7 @@ -using System; -using System.Collections.Generic; +using BPA.Helper; +using BPASmartClient.Model; using System.Collections.ObjectModel; -using System.Linq; -using System.Text; using System.Threading; -using System.Threading.Tasks; -using BPASmartClient.Model; -using BPA.Helper; namespace BPASmartClient.DosingSystem { diff --git a/DosingSystem/Model/RecipeProcess.cs b/DosingSystem/Model/RecipeProcess.cs index d9f5c708..522bb62d 100644 --- a/DosingSystem/Model/RecipeProcess.cs +++ b/DosingSystem/Model/RecipeProcess.cs @@ -1,9 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using BPA.Helper; +using BPA.Helper; namespace BPASmartClient.DosingSystem { diff --git a/DosingSystem/Model/SiemensPlc/ComputerToPlc.cs b/DosingSystem/Model/SiemensPlc/ComputerToPlc.cs index 6c4c5020..76f7f993 100644 --- a/DosingSystem/Model/SiemensPlc/ComputerToPlc.cs +++ b/DosingSystem/Model/SiemensPlc/ComputerToPlc.cs @@ -1,10 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace BPASmartClient.DosingSystem.Model +namespace BPASmartClient.DosingSystem.Model { public class ComputerToPlc diff --git a/DosingSystem/Model/SiemensPlc/PlcToComputer.cs b/DosingSystem/Model/SiemensPlc/PlcToComputer.cs index e1c31c3a..d832e1a9 100644 --- a/DosingSystem/Model/SiemensPlc/PlcToComputer.cs +++ b/DosingSystem/Model/SiemensPlc/PlcToComputer.cs @@ -1,10 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace BPASmartClient.DosingSystem +namespace BPASmartClient.DosingSystem { /// /// PLC 到上位机数据 diff --git a/DosingSystem/Model/StockStatusModel.cs b/DosingSystem/Model/StockStatusModel.cs index 1866cfb6..b759006f 100644 --- a/DosingSystem/Model/StockStatusModel.cs +++ b/DosingSystem/Model/StockStatusModel.cs @@ -1,9 +1,4 @@ using BPA.Helper; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace BPASmartClient.DosingSystem { @@ -42,7 +37,7 @@ namespace BPASmartClient.DosingSystem /// /// 是否故障报警 /// - public bool IsFault { get { return _isFault; } set { _isFault = value; OnPropertyChanged(); } } + public bool IsFault { get { return _isFault; } set { _isFault = value; OnPropertyChanged(); } } private bool _isFault; /// diff --git a/DosingSystem/Model/ViewModelBase.cs b/DosingSystem/Model/ViewModelBase.cs index dcb58164..13bad0b6 100644 --- a/DosingSystem/Model/ViewModelBase.cs +++ b/DosingSystem/Model/ViewModelBase.cs @@ -1,11 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using BPA.Helper; - -using System.Collections.ObjectModel; +using BPA.Helper; namespace BPASmartClient.DosingSystem { diff --git a/DosingSystem/Model/par/BasePar.cs b/DosingSystem/Model/par/BasePar.cs index aff96e9e..d3439bb0 100644 --- a/DosingSystem/Model/par/BasePar.cs +++ b/DosingSystem/Model/par/BasePar.cs @@ -1,11 +1,5 @@ -using System; +using BPA.Helper; using System.Collections.Generic; -using System.Collections.ObjectModel; -using System.Diagnostics; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using BPA.Helper; namespace BPASmartClient.DosingSystem { @@ -42,21 +36,25 @@ namespace BPASmartClient.DosingSystem /// /// 输送线类型集合 /// - private List _converyTypeList=new List (); - public List ConveryTypeList { + private List _converyTypeList = new List(); + public List ConveryTypeList + { get { return _converyTypeList; } - - set { + + set + { foreach (var item in value) { if (_converyTypeList.Contains(item)) { continue; } - _converyTypeList.Add(item); + _converyTypeList.Add(item); } - - OnPropertyChanged(); } } + + OnPropertyChanged(); + } + } /// /// 输送带数量 /// diff --git a/DosingSystem/Model/par/DevicePar.cs b/DosingSystem/Model/par/DevicePar.cs index eee4f434..6f628f6d 100644 --- a/DosingSystem/Model/par/DevicePar.cs +++ b/DosingSystem/Model/par/DevicePar.cs @@ -1,10 +1,5 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +using BPA.Helper; using System.Collections.ObjectModel; -using BPA.Helper; namespace BPASmartClient.DosingSystem { diff --git a/DosingSystem/Model/par/DeviceParModel.cs b/DosingSystem/Model/par/DeviceParModel.cs index d7a0d5f3..c2097445 100644 --- a/DosingSystem/Model/par/DeviceParModel.cs +++ b/DosingSystem/Model/par/DeviceParModel.cs @@ -1,9 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using BPA.Helper; +using BPA.Helper; namespace BPASmartClient.DosingSystem { diff --git a/DosingSystem/Model/par/LocaPar.cs b/DosingSystem/Model/par/LocaPar.cs index 992f898f..3a01b769 100644 --- a/DosingSystem/Model/par/LocaPar.cs +++ b/DosingSystem/Model/par/LocaPar.cs @@ -1,11 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Collections.ObjectModel; -using BPASmartClient.DosingSystem.ViewModel; -using BPASmartClient.Model; +using System.Collections.ObjectModel; namespace BPASmartClient.DosingSystem { diff --git a/DosingSystem/Model/par/LocalRecipe.cs b/DosingSystem/Model/par/LocalRecipe.cs index 8b5cc4ae..65980d91 100644 --- a/DosingSystem/Model/par/LocalRecipe.cs +++ b/DosingSystem/Model/par/LocalRecipe.cs @@ -1,11 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Collections.ObjectModel; -using BPASmartClient.DosingSystem.ViewModel; -using BPASmartClient.Model; +using System.Collections.ObjectModel; namespace BPASmartClient.DosingSystem { diff --git a/DosingSystem/Service/SiemensDevice.cs b/DosingSystem/Service/SiemensDevice.cs index 962cddb6..3f1efb93 100644 --- a/DosingSystem/Service/SiemensDevice.cs +++ b/DosingSystem/Service/SiemensDevice.cs @@ -1,13 +1,7 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading; -using System.Threading.Tasks; +using BPA.Communication; using BPA.Helper; -using S7.Net; -using BPASmartClient.CustomResource.Pages.Model; -using BPA.Communication; +using System; +using System.Threading; namespace BPASmartClient.DosingSystem { @@ -38,7 +32,7 @@ namespace BPASmartClient.DosingSystem TaskManage.GetInstance.StartLong(new Action(() => { GlobalDevice.PlcData = MySiemens.Read(3).Content;//获取PLC到上位机的数据 - //var tt = MySiemens.Read(3);//获取PLC到上位机的数据 + //var tt = MySiemens.Read(3);//获取PLC到上位机的数据 var res = MySiemens.Read("DB4.DBW134", 32).Content; if (res != null && res is ushort[] ushorts && ushorts.Length == 32) { @@ -52,8 +46,8 @@ namespace BPASmartClient.DosingSystem }; try { - IsConnect = MySiemens.Connect(new BPA.Communication.Base.ConfigurationOptions() { IpAddress = "192.168.0.100", cpuType = BPA.Communication.CpuType.S71200, Port = 102 }); - + IsConnect = MySiemens.Connect(new BPA.Communication.Base.ConfigurationOptions() { IpAddress = "192.168.0.100", cpuType = BPA.Communication.CpuType.S71200, Port = 102 }); + } catch (Exception) { diff --git a/DosingSystem/View/ChangeDeviceNameView.xaml.cs b/DosingSystem/View/ChangeDeviceNameView.xaml.cs index 4b349bd3..253d53f5 100644 --- a/DosingSystem/View/ChangeDeviceNameView.xaml.cs +++ b/DosingSystem/View/ChangeDeviceNameView.xaml.cs @@ -1,17 +1,7 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +using BPA.Helper; +using System; using System.Windows; -using System.Windows.Controls; -using System.Windows.Data; -using System.Windows.Documents; using System.Windows.Input; -using System.Windows.Media; -using System.Windows.Media.Imaging; -using System.Windows.Shapes; -using BPA.Helper; namespace BPASmartClient.DosingSystem.View { diff --git a/DosingSystem/View/CommParSetView.xaml.cs b/DosingSystem/View/CommParSetView.xaml.cs index 9d9dbf95..f355c69e 100644 --- a/DosingSystem/View/CommParSetView.xaml.cs +++ b/DosingSystem/View/CommParSetView.xaml.cs @@ -1,18 +1,5 @@ using BPA.Helper; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Windows; using System.Windows.Controls; -using System.Windows.Data; -using System.Windows.Documents; -using System.Windows.Input; -using System.Windows.Media; -using System.Windows.Media.Imaging; -using System.Windows.Navigation; -using System.Windows.Shapes; namespace BPASmartClient.DosingSystem.View { diff --git a/DosingSystem/View/ConveyerBeltManualView.xaml.cs b/DosingSystem/View/ConveyerBeltManualView.xaml.cs index 181758ba..b410336b 100644 --- a/DosingSystem/View/ConveyerBeltManualView.xaml.cs +++ b/DosingSystem/View/ConveyerBeltManualView.xaml.cs @@ -1,17 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Windows; -using System.Windows.Controls; -using System.Windows.Data; -using System.Windows.Documents; -using System.Windows.Input; -using System.Windows.Media; -using System.Windows.Media.Imaging; -using System.Windows.Navigation; -using System.Windows.Shapes; +using System.Windows.Controls; namespace BPASmartClient.DosingSystem.View { diff --git a/DosingSystem/View/DeviceListView.xaml.cs b/DosingSystem/View/DeviceListView.xaml.cs index 16366e98..2430a6d0 100644 --- a/DosingSystem/View/DeviceListView.xaml.cs +++ b/DosingSystem/View/DeviceListView.xaml.cs @@ -1,17 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Windows; -using System.Windows.Controls; -using System.Windows.Data; -using System.Windows.Documents; -using System.Windows.Input; -using System.Windows.Media; -using System.Windows.Media.Imaging; -using System.Windows.Navigation; -using System.Windows.Shapes; +using System.Windows.Controls; namespace BPASmartClient.DosingSystem.View { diff --git a/DosingSystem/View/DeviceMaterialParView.xaml.cs b/DosingSystem/View/DeviceMaterialParView.xaml.cs index b585e57c..3cec8b69 100644 --- a/DosingSystem/View/DeviceMaterialParView.xaml.cs +++ b/DosingSystem/View/DeviceMaterialParView.xaml.cs @@ -1,17 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Windows; -using System.Windows.Controls; -using System.Windows.Data; -using System.Windows.Documents; -using System.Windows.Input; -using System.Windows.Media; -using System.Windows.Media.Imaging; -using System.Windows.Navigation; -using System.Windows.Shapes; +using System.Windows.Controls; namespace BPASmartClient.DosingSystem.View { diff --git a/DosingSystem/View/HardwareStatusView.xaml.cs b/DosingSystem/View/HardwareStatusView.xaml.cs index 551a9b18..2dc3737b 100644 --- a/DosingSystem/View/HardwareStatusView.xaml.cs +++ b/DosingSystem/View/HardwareStatusView.xaml.cs @@ -1,18 +1,5 @@ using BPA.Helper; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Windows; using System.Windows.Controls; -using System.Windows.Data; -using System.Windows.Documents; -using System.Windows.Input; -using System.Windows.Media; -using System.Windows.Media.Imaging; -using System.Windows.Navigation; -using System.Windows.Shapes; namespace BPASmartClient.DosingSystem.View { diff --git a/DosingSystem/View/ManualControlView.xaml.cs b/DosingSystem/View/ManualControlView.xaml.cs index 49fc62bf..1e83c443 100644 --- a/DosingSystem/View/ManualControlView.xaml.cs +++ b/DosingSystem/View/ManualControlView.xaml.cs @@ -1,18 +1,6 @@ using BPA.Helper; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; using System.Windows; using System.Windows.Controls; -using System.Windows.Data; -using System.Windows.Documents; -using System.Windows.Input; -using System.Windows.Media; -using System.Windows.Media.Imaging; -using System.Windows.Navigation; -using System.Windows.Shapes; namespace BPASmartClient.DosingSystem.View { diff --git a/DosingSystem/View/NewMaterialView.xaml.cs b/DosingSystem/View/NewMaterialView.xaml.cs index 4e3a9753..c68934c8 100644 --- a/DosingSystem/View/NewMaterialView.xaml.cs +++ b/DosingSystem/View/NewMaterialView.xaml.cs @@ -1,17 +1,5 @@ -using BPA.Helper; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Windows; -using System.Windows.Controls; -using System.Windows.Data; -using System.Windows.Documents; +using System.Windows; using System.Windows.Input; -using System.Windows.Media; -using System.Windows.Media.Imaging; -using System.Windows.Shapes; namespace BPASmartClient.DosingSystem.View { diff --git a/DosingSystem/View/NewOutletView.xaml.cs b/DosingSystem/View/NewOutletView.xaml.cs index 2a6172a7..40391933 100644 --- a/DosingSystem/View/NewOutletView.xaml.cs +++ b/DosingSystem/View/NewOutletView.xaml.cs @@ -1,17 +1,6 @@ using BPA.Helper; using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; using System.Windows; -using System.Windows.Controls; -using System.Windows.Data; -using System.Windows.Documents; -using System.Windows.Input; -using System.Windows.Media; -using System.Windows.Media.Imaging; -using System.Windows.Shapes; namespace BPASmartClient.DosingSystem.View { diff --git a/DosingSystem/View/NewRecipeView.xaml.cs b/DosingSystem/View/NewRecipeView.xaml.cs index b2d9eefa..c2614648 100644 --- a/DosingSystem/View/NewRecipeView.xaml.cs +++ b/DosingSystem/View/NewRecipeView.xaml.cs @@ -1,17 +1,8 @@ using BPA.Helper; using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; using System.Windows; using System.Windows.Controls; -using System.Windows.Data; -using System.Windows.Documents; using System.Windows.Input; -using System.Windows.Media; -using System.Windows.Media.Imaging; -using System.Windows.Shapes; namespace BPASmartClient.DosingSystem.View { diff --git a/DosingSystem/View/OutletManagementView.xaml.cs b/DosingSystem/View/OutletManagementView.xaml.cs index 77b08cd8..085efcd6 100644 --- a/DosingSystem/View/OutletManagementView.xaml.cs +++ b/DosingSystem/View/OutletManagementView.xaml.cs @@ -1,18 +1,6 @@ using BPA.Helper; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; using System.Windows; using System.Windows.Controls; -using System.Windows.Data; -using System.Windows.Documents; -using System.Windows.Input; -using System.Windows.Media; -using System.Windows.Media.Imaging; -using System.Windows.Navigation; -using System.Windows.Shapes; namespace BPASmartClient.DosingSystem.View { diff --git a/DosingSystem/View/RecipeControlView.xaml.cs b/DosingSystem/View/RecipeControlView.xaml.cs index 8fbb4fa5..2b393bbc 100644 --- a/DosingSystem/View/RecipeControlView.xaml.cs +++ b/DosingSystem/View/RecipeControlView.xaml.cs @@ -1,18 +1,6 @@ using BPASmartClient.DosingSystem.ViewModel; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; using System.Windows; using System.Windows.Controls; -using System.Windows.Data; -using System.Windows.Documents; -using System.Windows.Input; -using System.Windows.Media; -using System.Windows.Media.Imaging; -using System.Windows.Navigation; -using System.Windows.Shapes; namespace BPASmartClient.DosingSystem.View { @@ -32,7 +20,7 @@ namespace BPASmartClient.DosingSystem.View //repiceList.ItemsSource = RecipeControlViewModel.UserTreeCompelete; //repiceList.Visibility = Visibility.Visible; //repiceListMaking.Visibility = Visibility.Hidden; - this.Wait.ItemsSource = RecipeControlViewModel.UserTreeCompelete; + this.Wait.ItemsSource = ExcuteControl.GetInstance.UserTreeCompelete; CookingGrid.Visibility = Visibility.Collapsed; WaitOrCompleteGrid.Visibility = Visibility.Visible; this.Wait.Visibility = Visibility.Visible; @@ -43,7 +31,7 @@ namespace BPASmartClient.DosingSystem.View //repiceList.ItemsSource = RecipeControlViewModel.UserTreeWait; //repiceList.Visibility = Visibility.Visible; //repiceListMaking.Visibility = Visibility.Hidden; - this.Wait.ItemsSource = RecipeControlViewModel.UserTreeWait; + this.Wait.ItemsSource = ExcuteControl.GetInstance.UserTreeWait; CookingGrid.Visibility = Visibility.Collapsed; WaitOrCompleteGrid.Visibility = Visibility.Visible; this.Wait.Visibility = Visibility.Visible; diff --git a/DosingSystem/View/RecipeSettingsView.xaml.cs b/DosingSystem/View/RecipeSettingsView.xaml.cs index fe2f5a1d..279c2c19 100644 --- a/DosingSystem/View/RecipeSettingsView.xaml.cs +++ b/DosingSystem/View/RecipeSettingsView.xaml.cs @@ -1,19 +1,6 @@ using BPA.Helper; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Reflection; -using System.Text; -using System.Threading.Tasks; using System.Windows; using System.Windows.Controls; -using System.Windows.Data; -using System.Windows.Documents; -using System.Windows.Input; -using System.Windows.Media; -using System.Windows.Media.Imaging; -using System.Windows.Navigation; -using System.Windows.Shapes; namespace BPASmartClient.DosingSystem.View { diff --git a/DosingSystem/View/StockControlView.xaml.cs b/DosingSystem/View/StockControlView.xaml.cs index c6e15364..ccc9e79e 100644 --- a/DosingSystem/View/StockControlView.xaml.cs +++ b/DosingSystem/View/StockControlView.xaml.cs @@ -1,17 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Windows; -using System.Windows.Controls; -using System.Windows.Data; -using System.Windows.Documents; -using System.Windows.Input; -using System.Windows.Media; -using System.Windows.Media.Imaging; -using System.Windows.Navigation; -using System.Windows.Shapes; +using System.Windows.Controls; namespace BPASmartClient.DosingSystem.View { @@ -25,6 +12,6 @@ namespace BPASmartClient.DosingSystem.View InitializeComponent(); } - + } } diff --git a/DosingSystem/View/TempManageControlView.xaml.cs b/DosingSystem/View/TempManageControlView.xaml.cs index cd3b265a..964ad5c9 100644 --- a/DosingSystem/View/TempManageControlView.xaml.cs +++ b/DosingSystem/View/TempManageControlView.xaml.cs @@ -1,17 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Windows; -using System.Windows.Controls; -using System.Windows.Data; -using System.Windows.Documents; -using System.Windows.Input; -using System.Windows.Media; -using System.Windows.Media.Imaging; -using System.Windows.Navigation; -using System.Windows.Shapes; +using System.Windows.Controls; namespace BPASmartClient.DosingSystem.View { diff --git a/DosingSystem/View/UHardwareStatusView.xaml.cs b/DosingSystem/View/UHardwareStatusView.xaml.cs index 8a36ec17..a732875c 100644 --- a/DosingSystem/View/UHardwareStatusView.xaml.cs +++ b/DosingSystem/View/UHardwareStatusView.xaml.cs @@ -1,17 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Windows; -using System.Windows.Controls; -using System.Windows.Data; -using System.Windows.Documents; -using System.Windows.Input; -using System.Windows.Media; -using System.Windows.Media.Imaging; -using System.Windows.Navigation; -using System.Windows.Shapes; +using System.Windows.Controls; namespace BPASmartClient.DosingSystem.View { diff --git a/DosingSystem/ViewModel/ChangeDeviceNameViewModel.cs b/DosingSystem/ViewModel/ChangeDeviceNameViewModel.cs index 614de6ed..281d0a4f 100644 --- a/DosingSystem/ViewModel/ChangeDeviceNameViewModel.cs +++ b/DosingSystem/ViewModel/ChangeDeviceNameViewModel.cs @@ -1,10 +1,7 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using BPA.Helper; +using BPA.Helper; using BPASmartClient.CustomResource.Pages.Model; +using System; +using System.Linq; namespace BPASmartClient.DosingSystem.ViewModel { diff --git a/DosingSystem/ViewModel/CommparSetViewModel.cs b/DosingSystem/ViewModel/CommparSetViewModel.cs index 79f32ad0..e3f26539 100644 --- a/DosingSystem/ViewModel/CommparSetViewModel.cs +++ b/DosingSystem/ViewModel/CommparSetViewModel.cs @@ -1,12 +1,7 @@ -using System; -using System.Collections.Generic; -using System.Collections.ObjectModel; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using BPA.Helper; +using BPA.Helper; using BPASmartClient.CustomResource.UserControls; using BPASmartClient.CustomResource.UserControls.MessageShow; +using System.Text; namespace BPASmartClient.DosingSystem.ViewModel { @@ -38,7 +33,7 @@ namespace BPASmartClient.DosingSystem.ViewModel //private BasePar _mCommBaseParModel; - + public BPARelayCommand SaveCommand { get; set; } } diff --git a/DosingSystem/ViewModel/ConveyerBeltManualViewModel.cs b/DosingSystem/ViewModel/ConveyerBeltManualViewModel.cs index ca3be653..15c07ccf 100644 --- a/DosingSystem/ViewModel/ConveyerBeltManualViewModel.cs +++ b/DosingSystem/ViewModel/ConveyerBeltManualViewModel.cs @@ -1,10 +1,5 @@ -using System; -using System.Collections.Generic; +using BPA.Helper; using System.Collections.ObjectModel; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using BPA.Helper; namespace BPASmartClient.DosingSystem.ViewModel { @@ -20,7 +15,7 @@ namespace BPASmartClient.DosingSystem.ViewModel Num = i + 1, Speed = GlobalDevice.MotorSpeed[i], ConveyerBeltWork = GlobalDevice.MotorControl.GetBitValue((byte)(i + 1)) - }) ; + }); } } public ObservableCollection ConveyerBeltModels { get; set; } = new ObservableCollection(); diff --git a/DosingSystem/ViewModel/DeviceListViewModel.cs b/DosingSystem/ViewModel/DeviceListViewModel.cs index f8c30ea3..ab22fc8c 100644 --- a/DosingSystem/ViewModel/DeviceListViewModel.cs +++ b/DosingSystem/ViewModel/DeviceListViewModel.cs @@ -1,14 +1,9 @@ -using System; +using BPA.Helper; +using BPASmartClient.DosingSystem.View; +using System; using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using BPA.Helper; -using System.Collections.Concurrent; using System.Collections.ObjectModel; -using System.Windows; -using BPASmartClient.DosingSystem.View; -using System.Windows.Data; +using System.Linq; namespace BPASmartClient.DosingSystem.ViewModel { @@ -16,7 +11,7 @@ namespace BPASmartClient.DosingSystem.ViewModel { public DeviceListViewModel() { - + DetailsCommand = new BPARelayCommand((o) => { if (o != null && o is string str) @@ -26,20 +21,20 @@ namespace BPASmartClient.DosingSystem.ViewModel cdn.ShowDialog(); } }); - //devices = DeviceInquire.GetInstance.devices; + //devices = DeviceInquire.GetInstance.devices; //2023/6/29新加 改为升序排列显示 devices = ConvertToObservableCollention(DeviceInquire.GetInstance.devices.OrderByDescending(p => p.IpAddress.Split(".")[3]).Reverse()); } - + public ObservableCollection devices { get; set; } public ObservableCollection ConvertToObservableCollention(IEnumerable array) { - ObservableCollection collec =new ObservableCollection(); + ObservableCollection collec = new ObservableCollection(); foreach (var item in array) { - collec.Add(item); + collec.Add(item); } return collec; } diff --git a/DosingSystem/ViewModel/DeviceMaterialParViewModel.cs b/DosingSystem/ViewModel/DeviceMaterialParViewModel.cs index 7dca646b..25465940 100644 --- a/DosingSystem/ViewModel/DeviceMaterialParViewModel.cs +++ b/DosingSystem/ViewModel/DeviceMaterialParViewModel.cs @@ -1,13 +1,8 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using BPA.Helper; -using System.Collections.ObjectModel; -using BPASmartClient.CustomResource.UserControls.MessageShow; +using BPA.Helper; using BPASmartClient.CustomResource.UserControls; -using System.Diagnostics; +using BPASmartClient.CustomResource.UserControls.MessageShow; +using System.Collections.ObjectModel; +using System.Linq; namespace BPASmartClient.DosingSystem.ViewModel { diff --git a/DosingSystem/ViewModel/HardwareStatusViewModel.cs b/DosingSystem/ViewModel/HardwareStatusViewModel.cs index 4202c24c..3d86f67b 100644 --- a/DosingSystem/ViewModel/HardwareStatusViewModel.cs +++ b/DosingSystem/ViewModel/HardwareStatusViewModel.cs @@ -1,14 +1,9 @@ -using System; +using BPA.Helper; +using System; using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using BPA.Helper; -using System.Collections.Concurrent; using System.Collections.ObjectModel; -using System.Windows; +using System.Linq; using System.Threading; -using BPASmartClient.DosingSystem.Model; namespace BPASmartClient.DosingSystem.ViewModel { @@ -16,7 +11,7 @@ namespace BPASmartClient.DosingSystem.ViewModel { public HardwareStatusViewModel() { - + //TopDeviceCurrentStatuses = DeviceInquire.GetInstance.TopDeviceCurrentStatuses; //BottomDeviceCurrentStatuses = DeviceInquire.GetInstance.BottomDeviceCurrentStatuses; diff --git a/DosingSystem/ViewModel/ManualControlViewModel.cs b/DosingSystem/ViewModel/ManualControlViewModel.cs index 48b80e45..b6e91a8d 100644 --- a/DosingSystem/ViewModel/ManualControlViewModel.cs +++ b/DosingSystem/ViewModel/ManualControlViewModel.cs @@ -1,10 +1,7 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using BPA.Helper; +using BPA.Helper; +using System; using System.Collections.ObjectModel; +using System.Linq; using System.Threading; //using BPASmartClient.S7Net; diff --git a/DosingSystem/ViewModel/NewMaterialViewModel.cs b/DosingSystem/ViewModel/NewMaterialViewModel.cs index 0fd5b448..96371690 100644 --- a/DosingSystem/ViewModel/NewMaterialViewModel.cs +++ b/DosingSystem/ViewModel/NewMaterialViewModel.cs @@ -1,14 +1,9 @@ -using BPASmartClient.CustomResource.Pages.Model; -using BPA.Helper; +using BPA.Helper; +using BPASmartClient.CustomResource.Pages.Model; using BPASmartClient.Model; -using BPA.Helper; - using System; -using System.Collections.Generic; using System.Collections.ObjectModel; using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace BPASmartClient.DosingSystem.ViewModel; diff --git a/DosingSystem/ViewModel/NewOutletViewModel.cs b/DosingSystem/ViewModel/NewOutletViewModel.cs index b0e5fab0..6638764c 100644 --- a/DosingSystem/ViewModel/NewOutletViewModel.cs +++ b/DosingSystem/ViewModel/NewOutletViewModel.cs @@ -1,11 +1,7 @@ -using System; -using System.Collections.Generic; +using BPA.Helper; +using System; using System.Collections.ObjectModel; using System.Linq; -using System.Text; -using System.Threading.Tasks; -using BPA.Helper; -using BPA.Helper; namespace BPASmartClient.DosingSystem.ViewModel diff --git a/DosingSystem/ViewModel/NewRecipeViewModel.cs b/DosingSystem/ViewModel/NewRecipeViewModel.cs index c9cdd8aa..b34c38e4 100644 --- a/DosingSystem/ViewModel/NewRecipeViewModel.cs +++ b/DosingSystem/ViewModel/NewRecipeViewModel.cs @@ -1,14 +1,12 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using BPA.Helper; -using System.Collections.ObjectModel; +using BPA.Helper; using BPASmartClient.CustomResource.Pages.Model; -using BPASmartClient.Model; -using BPASmartClient.CustomResource.UserControls.MessageShow; using BPASmartClient.CustomResource.UserControls; +using BPASmartClient.CustomResource.UserControls.MessageShow; +using BPASmartClient.Model; +using System; +using System.Collections.ObjectModel; +using System.Linq; +using System.Text; namespace BPASmartClient.DosingSystem.ViewModel { @@ -18,13 +16,13 @@ namespace BPASmartClient.DosingSystem.ViewModel { ActionManage.GetInstance.RegisterAsync(new Action((o) => { - if (!string.IsNullOrEmpty(o?.ToString())) - { - if (RawMaterials.FirstOrDefault(p => p.RawMaterialName == o.ToString()) != null) - { - App.Current.Dispatcher.Invoke(() => { MessageNotify.GetInstance.ShowDialog("当前原料和其它原料重复,请重新选择!", DialogType.Warning); }); - } - } + if (!string.IsNullOrEmpty(o?.ToString())) + { + if (RawMaterials.FirstOrDefault(p => p.RawMaterialName == o.ToString()) != null) + { + App.Current.Dispatcher.Invoke(() => { MessageNotify.GetInstance.ShowDialog("当前原料和其它原料重复,请重新选择!", DialogType.Warning); }); + } + } }), "原料选择修改"); ActionManage.GetInstance.Register(new Action((o) => { @@ -43,11 +41,11 @@ namespace BPASmartClient.DosingSystem.ViewModel AddCommand = new BPARelayCommand(() => { - //if (RawMaterials.Count >= DeviceInquire.GetInstance.devices.Count) - //{ - // MessageNotify.GetInstance.ShowDialog("原材料不足!"); - // return; - //} + //if (RawMaterials.Count >= DeviceInquire.GetInstance.devices.Count) + //{ + // MessageNotify.GetInstance.ShowDialog("原材料不足!"); + // return; + //} p: string guid = Guid.NewGuid().ToString(); if (RawMaterials.FirstOrDefault(p => p.RawMaterialId == guid) == null) diff --git a/DosingSystem/ViewModel/OutletManagementViewModel.cs b/DosingSystem/ViewModel/OutletManagementViewModel.cs index 474869aa..db124644 100644 --- a/DosingSystem/ViewModel/OutletManagementViewModel.cs +++ b/DosingSystem/ViewModel/OutletManagementViewModel.cs @@ -1,11 +1,7 @@ -using System; -using System.Collections.Generic; +using BPA.Helper; +using BPASmartClient.DosingSystem.View; using System.Collections.ObjectModel; using System.Linq; -using System.Text; -using System.Threading.Tasks; -using BPA.Helper; -using BPASmartClient.DosingSystem.View; namespace BPASmartClient.DosingSystem.ViewModel diff --git a/DosingSystem/ViewModel/RecipeControlViewModel.cs b/DosingSystem/ViewModel/RecipeControlViewModel.cs index 147a7148..14fdb031 100644 --- a/DosingSystem/ViewModel/RecipeControlViewModel.cs +++ b/DosingSystem/ViewModel/RecipeControlViewModel.cs @@ -1,1044 +1,1050 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +using BPA.Communication; using BPA.Helper; -using System.Collections.Concurrent; -using System.Collections.ObjectModel; -using System.Windows; -using System.Threading; using BPASmartClient.CustomResource.Pages.Model; -using BPASmartClient.CustomResource.UserControls.MessageShow; using BPASmartClient.CustomResource.UserControls; -using BPASmartClient.Model.柔性味魔方; +using BPASmartClient.CustomResource.UserControls.MessageShow; using BPASmartClient.Model; +using System; +using System.Collections.Concurrent; +using System.Collections.Generic; +using System.Collections.ObjectModel; using System.Diagnostics; -using Microsoft.EntityFrameworkCore.Metadata.Internal; -using System.Data.SqlClient; -using S7.Net.Types; -using BPA.Communication; -using BPASmartClient.DosingSystem.Model; -using System.Security.Cryptography; +using System.Linq; +using System.Threading; +using System.Threading.Tasks; namespace BPASmartClient.DosingSystem.ViewModel { public class RecipeControlViewModel : NotifyBase { - int ComCount = 0;//配料完成计数 - static ConcurrentQueue RecipeNames = new ConcurrentQueue(); - static ObservableCollection StockStatus = new ObservableCollection(); + //int ComCount = 0;//配料完成计数 + // static ConcurrentQueue RecipeNames = new ConcurrentQueue(); + // static ObservableCollection StockStatus = new ObservableCollection(); public RecipeControlViewModel() { - StartCommand = new BPARelayCommand(RecipeIssued); - ChangeRecipeStateCommand = new BPARelayCommand(ChangeRecipeState); - CancelRecipeCommand = new BPARelayCommand(CancelRecipe); - RecipeRun(); - RecipeStatusInquire(); - } + //StartCommand = new BPARelayCommand(RecipeIssued); + //// ChangeRecipeStateCommand = new BPARelayCommand(ChangeRecipeState); + //CancelRecipeCommand = new BPARelayCommand(CancelRecipe); + //RecipeRun(); + //RecipeStatusInquire(); - private async void CancelRecipe(object o) - { - if (o != null && o is RecipeModel recipe) - { - var res = MessageNotify.GetInstance.ShowDialog($"是否取消配方 【{recipe.RecipeName}】制作", DialogType.Warning); - if (res) + StartCommand = new BPARelayCommand(new Action((o) => { + if (o != null && o is string recipeName) { - int index = Recipes.ToList().FindIndex(p => p.RecipeName == recipe.RecipeName); - if (index >= 0 && index < Recipes.Count) - { - await Task.Factory.StartNew(new Action(() => - { - Recipes.ElementAt(index).IsEnable = true; - Json.Data.Recipes.ElementAt(index).IsEnable = true; - Recipes.ElementAt(index).Are.Set(); - App.Current.Dispatcher.Invoke(new Action(() => { recipeProcesses.Clear(); })); - SiemensDevice.GetInstance.MySiemens.Write("M10.5", true); - MessageNotify.GetInstance.ShowRunLog($"M10.5:true"); - Thread.Sleep(1000); - SiemensDevice.GetInstance.MySiemens.Write("M10.5", false); - MessageNotify.GetInstance.ShowRunLog($"M10.5:false"); - NoticeDemoViewModel.OpenMsg(EnumPromptType.Success, App.MainWindow, "提示", $"配方 [{recipe.RecipeName}] 取消成功"); - - MessageNotify.GetInstance.ShowUserLog($"取消配方制作 {recipe.RecipeName}"); - })); - } + ActionManage.GetInstance.Send("配方下发", recipeName); + } + })); + CancelRecipeCommand = new BPARelayCommand(new Action((ob) => { + if (ob != null && ob is RecipeModel recipe) + { + ActionManage.GetInstance.Send("取消配方", recipe.RecipeName); } - } + + })); } + //private async void CancelRecipe(object o) + //{ + // if (o != null && o is RecipeModel recipe) + // { + // var res = MessageNotify.GetInstance.ShowDialog($"是否取消配方 【{recipe.RecipeName}】制作", DialogType.Warning); + // if (res) + // { + // int index = Recipes.ToList().FindIndex(p => p.RecipeName == recipe.RecipeName); + // if (index >= 0 && index < Recipes.Count) + // { + // await Task.Factory.StartNew(new Action(() => + // { + // Recipes.ElementAt(index).IsEnable = true; + // Json.Data.Recipes.ElementAt(index).IsEnable = true; + // Recipes.ElementAt(index).Are.Set(); + // App.Current.Dispatcher.Invoke(new Action(() => { recipeProcesses.Clear(); })); + // SiemensDevice.GetInstance.MySiemens.Write("M10.5", true); + // MessageNotify.GetInstance.ShowRunLog($"M10.5:true"); + // Thread.Sleep(1000); + // SiemensDevice.GetInstance.MySiemens.Write("M10.5", false); + // MessageNotify.GetInstance.ShowRunLog($"M10.5:false"); + // NoticeDemoViewModel.OpenMsg(EnumPromptType.Success, App.MainWindow, "提示", $"配方 [{recipe.RecipeName}] 取消成功"); + + // MessageNotify.GetInstance.ShowUserLog($"取消配方制作 {recipe.RecipeName}"); + // })); + // } + // } + // } + //} + /// /// 配方下发 /// - private void RecipeIssued(object o) - { - if (o != null && o is string deviceName) - { - int index = Array.FindIndex(Recipes.ToArray(), p => p.RecipeName == deviceName); - if (index >= 0 && index < Recipes.Count) - { - for (int i = 0; i < Recipes.ElementAt(index).RawMaterials.Count; i++) - { - if (Recipes.ElementAt(index).RawMaterials.ElementAt(i).RawMaterialSource == 1) - { - string ip = Recipes.ElementAt(index).RawMaterials.ElementAt(i).DeviceIp; - var device = DeviceInquire.GetInstance.GetDevice(ip); - if (ip == null && ip == "") - { - MessageNotify.GetInstance.ShowDialog($"原料 【{Recipes.ElementAt(index).RawMaterials.ElementAt(i).RawMaterialName}】配料系统无法配料,请人工配置此原料:原料{Recipes.ElementAt(index).RawMaterials.ElementAt(i).RawMaterialName},重量{Recipes.ElementAt(index).RawMaterials.ElementAt(i).RawMaterialWeight}", DialogType.Information); - return; - } - if (!device.IsConnected) - { - MessageNotify.GetInstance.ShowDialog($"设备 【{device.DeviceName}】 未连接,不允许下发此配方", DialogType.Error); - return; - } - } + //private void RecipeIssued(object o) + //{ + // if (o != null && o is string deviceName) + // { + // int index = Array.FindIndex(Recipes.ToArray(), p => p.RecipeName == deviceName); + // if (index >= 0 && index < Recipes.Count) + // { + // for (int i = 0; i < Recipes.ElementAt(index).RawMaterials.Count; i++) + // { + // if (Recipes.ElementAt(index).RawMaterials.ElementAt(i).RawMaterialSource == 1) + // { + // string ip = Recipes.ElementAt(index).RawMaterials.ElementAt(i).DeviceIp; + // var device = DeviceInquire.GetInstance.GetDevice(ip); + // if (ip == null && ip == "") + // { + // MessageNotify.GetInstance.ShowDialog($"原料 【{Recipes.ElementAt(index).RawMaterials.ElementAt(i).RawMaterialName}】配料系统无法配料,请人工配置此原料:原料{Recipes.ElementAt(index).RawMaterials.ElementAt(i).RawMaterialName},重量{Recipes.ElementAt(index).RawMaterials.ElementAt(i).RawMaterialWeight}", DialogType.Information); + // return; + // } + // if (!device.IsConnected) + // { + // MessageNotify.GetInstance.ShowDialog($"设备 【{device.DeviceName}】 未连接,不允许下发此配方", DialogType.Error); + // return; + // } + // } - } - Recipes.ElementAt(index).IsEnable = false; - Json.Data.Recipes.ElementAt(index).IsEnable = false; - } - MessageNotify.GetInstance.ShowUserLog($"下发工单 {Recipes.ElementAt(index).RecipeName}"); - RecipeNames.Enqueue(deviceName); - //var t = RecipeNames.GetHashCode(); - var res = Recipes.FirstOrDefault(p => p.RecipeName == deviceName); - UserTreeWait.Add(new RecipeModel { RecipStatus = "等待制作", SerialNum = UserTreeWait.Count + 1, RecipeName = deviceName, RawMaterials = res.RawMaterials }); - } - NoticeDemoViewModel.OpenMsg(EnumPromptType.Success, App.MainWindow, "提示", $"配方下发成功!"); - } + // } + // Recipes.ElementAt(index).IsEnable = false; + // Json.Data.Recipes.ElementAt(index).IsEnable = false; + // } + // MessageNotify.GetInstance.ShowUserLog($"下发工单 {Recipes.ElementAt(index).RecipeName}"); + // RecipeNames.Enqueue(deviceName); + // //var t = RecipeNames.GetHashCode(); + // var res = Recipes.FirstOrDefault(p => p.RecipeName == deviceName); + // UserTreeWait.Add(new RecipeModel { RecipStatus = "等待制作", SerialNum = UserTreeWait.Count + 1, RecipeName = deviceName, RawMaterials = res.RawMaterials }); + // } + // NoticeDemoViewModel.OpenMsg(EnumPromptType.Success, App.MainWindow, "提示", $"配方下发成功!"); + //} /// /// 配方业务执行 /// - private void RecipeRun() - { - TaskManage.GetInstance.StartLong(new Action(() => - { - if (RecipeNames.Count > 0) - { - int index = Array.FindIndex(Recipes.ToArray(), p => p.RecipeName == RecipeNames.ElementAt(0)); - if (index >= 0 && index < Recipes.Count) - { - Recipes.ElementAt(index).Are.Reset(); - Recipes.ElementAt(index).IsEnable = false; - StockStatus.Clear(); - App.Current.Dispatcher.Invoke(new Action(() => - { - recipeProcesses.Clear(); - if (UserTreeWait.Count > 0) UserTreeWait.RemoveAt(0); - })); - CurrentRecipeName = Recipes.ElementAt(index).RecipeName; + //private void RecipeRun() + //{ + // TaskManage.GetInstance.StartLong(new Action(() => + // { + // if (RecipeNames.Count > 0) + // { + // int index = Array.FindIndex(Recipes.ToArray(), p => p.RecipeName == RecipeNames.ElementAt(0)); + // if (index >= 0 && index < Recipes.Count) + // { + // Recipes.ElementAt(index).Are.Reset(); + // Recipes.ElementAt(index).IsEnable = false; + // StockStatus.Clear(); + // App.Current.Dispatcher.Invoke(new Action(() => + // { + // recipeProcesses.Clear(); + // if (UserTreeWait.Count > 0) UserTreeWait.RemoveAt(0); + // })); + // CurrentRecipeName = Recipes.ElementAt(index).RecipeName; - #region 配方下发到PLC操作相关 - //配方数据写入到输送机 - var res = Json.Data.Recipes.FirstOrDefault(p => p.RecipeName == CurrentRecipeName); - List BarrelNum = new List(); - ConcurrentDictionary values = new (); - if (res != null) - { - var tInfo = res.RawMaterials.GroupBy(p => p.Loc);//获取桶号信息 - if (tInfo != null) - { - for (int i = 0; i < tInfo.Count(); i++) - { - int data = 0; - for (int m = 0; m < tInfo.ElementAt(i).Count(); m++) - { - var TempName = tInfo.ElementAt(i).ElementAt(m).RawMaterialName; - var tempDevice = DeviceInquire.GetInstance.devices.FirstOrDefault(p => p.DeviceName == TempName); - if (tempDevice != null) - { - /*data = data.SetBitValue((byte)tempDevice.DeviceNum, true);*/ - if (tempDevice.DeviceNum > 0) - { - // //int a = data.SetBitValue((byte)tInfo.ElementAt(i).ElementAt(m).Loc, true); - // //byte[] test1 = a.ToBytes(BPA.Helper.DataFormat.BADC); - // //int item = test1.ToInt(); - // int item = data.SetBitValue((byte)tInfo.ElementAt(i).ElementAt(m).Loc, true).ToBytes(BPA.Helper.DataFormat.BADC).ToInt(); - // int item1 = SiemensDevice.GetInstance.MySiemens.Read($"DB4.DBD{2 + (tempDevice.DeviceNum - 1) * 4}").Content; - ////prop1: - // var RE = SiemensDevice.GetInstance.MySiemens.Write($"DB4.DBD{2 + (tempDevice.DeviceNum - 1) * 4}", item + item1); - // //var values = SiemensDevice.GetInstance.MySiemens.Read($"DB4.DBD{2 + (tempDevice.DeviceNum - 1) * 4}"); - // //if ((values != null && values.ToString() != (item + item1).ToString()) || values == null) - // // goto prop1; - // if (RE.IsSuccess) - // MessageNotify.GetInstance.ShowRunLog($"下发配方DB4.DBD{2 + (tempDevice.DeviceNum - 1) * 4} :{(byte)tInfo.ElementAt(i).ElementAt(m).Loc}-{item + item1}-{(item + item1).ToBinString()}"); - // else - // MessageNotify.GetInstance.ShowRunLog($"下发配方DB4.DBD{2 + (tempDevice.DeviceNum - 1) * 4} 失败"); + // #region 配方下发到PLC操作相关 + // //配方数据写入到输送机 + // var res = Json.Data.Recipes.FirstOrDefault(p => p.RecipeName == CurrentRecipeName); + // List BarrelNum = new List(); + // ConcurrentDictionary values = new(); + // if (res != null) + // { + // var tInfo = res.RawMaterials.GroupBy(p => p.Loc);//获取桶号信息 + // if (tInfo != null) + // { + // for (int i = 0; i < tInfo.Count(); i++) + // { + // int data = 0; + // for (int m = 0; m < tInfo.ElementAt(i).Count(); m++) + // { + // var TempName = tInfo.ElementAt(i).ElementAt(m).RawMaterialName; + // var tempDevice = DeviceInquire.GetInstance.devices.FirstOrDefault(p => p.DeviceName == TempName); + // if (tempDevice != null) + // { + // /*data = data.SetBitValue((byte)tempDevice.DeviceNum, true);*/ + // if (tempDevice.DeviceNum > 0) + // { + // // //int a = data.SetBitValue((byte)tInfo.ElementAt(i).ElementAt(m).Loc, true); + // // //byte[] test1 = a.ToBytes(BPA.Helper.DataFormat.BADC); + // // //int item = test1.ToInt(); + // // int item = data.SetBitValue((byte)tInfo.ElementAt(i).ElementAt(m).Loc, true).ToBytes(BPA.Helper.DataFormat.BADC).ToInt(); + // // int item1 = SiemensDevice.GetInstance.MySiemens.Read($"DB4.DBD{2 + (tempDevice.DeviceNum - 1) * 4}").Content; + // ////prop1: + // // var RE = SiemensDevice.GetInstance.MySiemens.Write($"DB4.DBD{2 + (tempDevice.DeviceNum - 1) * 4}", item + item1); + // // //var values = SiemensDevice.GetInstance.MySiemens.Read($"DB4.DBD{2 + (tempDevice.DeviceNum - 1) * 4}"); + // // //if ((values != null && values.ToString() != (item + item1).ToString()) || values == null) + // // // goto prop1; + // // if (RE.IsSuccess) + // // MessageNotify.GetInstance.ShowRunLog($"下发配方DB4.DBD{2 + (tempDevice.DeviceNum - 1) * 4} :{(byte)tInfo.ElementAt(i).ElementAt(m).Loc}-{item + item1}-{(item + item1).ToBinString()}"); + // // else + // // MessageNotify.GetInstance.ShowRunLog($"下发配方DB4.DBD{2 + (tempDevice.DeviceNum - 1) * 4} 失败"); - - int item = data.SetBitValue((byte)tInfo.ElementAt(i).ElementAt(m).Loc, true).ToBytes(BPA.Helper.DataFormat.BADC).ToInt(); - string tempAdd = $"DB4.DBD{2 + (tempDevice.DeviceNum - 1) * 4}"; - if (!values.ContainsKey(tempAdd)) values.TryAdd(tempAdd, new int[2] { 0,0}); - values[tempAdd][0] = values[tempAdd][0] + item; - values[tempAdd][1] = tInfo.ElementAt(i).ElementAt(m).Loc; - } - } - if (tInfo.ElementAt(i).ElementAt(m).Loc > 0) - { - if (!BarrelNum.Contains(tInfo.ElementAt(i).ElementAt(m).Loc)) - { - BarrelNum.Add(tInfo.ElementAt(i).ElementAt(m).Loc); - } - } - } - } - } - } - values?.ToList().ForEach(x => - { - SiemensDevice.GetInstance.MySiemens.Write(x.Key, x.Value[0]).OnSuccess(() => - { - MessageNotify.GetInstance.ShowRunLog($"下发配方-{x.Key} :桶数:[{x.Value[1]}]-{x.Value[0].ToBinString()}"); - }).OnFail(s => - { - MessageNotify.GetInstance.ShowRunLog($"下发配方-{x.Key} 失败"); - }); - }); + // int item = data.SetBitValue((byte)tInfo.ElementAt(i).ElementAt(m).Loc, true).ToBytes(BPA.Helper.DataFormat.BADC).ToInt(); + // string tempAdd = $"DB4.DBD{2 + (tempDevice.DeviceNum - 1) * 4}"; + // if (!values.ContainsKey(tempAdd)) values.TryAdd(tempAdd, new int[2] { 0, 0 }); + // values[tempAdd][0] = values[tempAdd][0] + item; + // values[tempAdd][1] = tInfo.ElementAt(i).ElementAt(m).Loc; + // } + // } + // if (tInfo.ElementAt(i).ElementAt(m).Loc > 0) + // { + // if (!BarrelNum.Contains(tInfo.ElementAt(i).ElementAt(m).Loc)) + // { + // BarrelNum.Add(tInfo.ElementAt(i).ElementAt(m).Loc); + // } + // } + // } + // } + // } + // } + // values?.ToList().ForEach(x => + // { + // SiemensDevice.GetInstance.MySiemens.Write(x.Key, x.Value[0]).OnSuccess(() => + // { + // MessageNotify.GetInstance.ShowRunLog($"下发配方-{x.Key} :桶数:[{x.Value[1]}]-{x.Value[0].ToBinString()}"); + // }).OnFail(s => + // { + // MessageNotify.GetInstance.ShowRunLog($"下发配方-{x.Key} 失败"); + // }); + // }); + + + // SiemensDevice.GetInstance.MySiemens.Write("DB4.DBD198", BarrelNum.Count);//配方使用桶数写入 + + // SiemensDevice.GetInstance.MySiemens.Write("DB4.DBX0.1", true);//配方执行启动 + // Stopwatch sw = new Stopwatch(); + // var recipe = Recipes.ElementAt(index); + // ObservableCollection RawMater = new ObservableCollection(); + // foreach (var item in recipe.RawMaterials) + // { + // RawMater.Add(new RawMaterialModel() + // { + // RawMaterialName = item.RawMaterialName, + // DeviceIp = item.DeviceIp, + // DownLimtFeedback = item.DownLimtFeedback, + // Loc = item.Loc, + // RawMaterialId = item.RawMaterialId, + // RawMaterialSource = item.RawMaterialSource, + // RawMaterialType = item.RawMaterialType, + // RawMaterialWeight = item.RawMaterialWeight, + // RecipeStatus = item.RecipeStatus, + // SelectIndex = item.SelectIndex, + // Status = item.Status, + // UpLimtFeedback = item.UpLimtFeedback, + // UpLimtWeightFeedback = item.UpLimtWeightFeedback, + // WeightFeedback = item.WeightFeedback, + // }); + // } + // App.Current.Dispatcher.Invoke(() => + // { + // recipeProcesses.Add(new RecipeModel() + // { + // RawMaterials = RawMater, + // IsEnable = recipe.IsEnable, + // RecipeName = recipe.RecipeName, + // SerialNum = recipe.SerialNum, + // RecipCode = recipe.RecipCode, + // }); + // }); + // sw.Restart(); + // while (true) + // { + // if (sw.ElapsedMilliseconds >= 3000 && !GlobalDevice.PlcData.ResComplete) + // { + // MessageNotify.GetInstance.ShowRunLog("获取配方下发反馈超时"); + // break; + // } + // if (GlobalDevice.PlcData.ResComplete) + // { + // SiemensDevice.GetInstance.MySiemens.Write("DB3.DBX0.1", false); + // break; + // } + // Thread.Sleep(100); + // } + // #endregion + + // Recipes.ElementAt(index).Are.WaitOne();//阻塞,直到当前配方完成 + // RecipeNames.TryDequeue(out string deviceName); + // var recipeComple = Recipes.ElementAt(index); + // ObservableCollection RawMaterComple = new ObservableCollection(); + // foreach (var item in recipeComple.RawMaterials) + // { + // RawMaterComple.Add(new RawMaterialModel() + // { + // RawMaterialName = item.RawMaterialName, + // DeviceIp = item.DeviceIp, + // DownLimtFeedback = item.DownLimtFeedback, + // Loc = item.Loc, + // RawMaterialId = item.RawMaterialId, + // RawMaterialSource = item.RawMaterialSource, + // RawMaterialType = item.RawMaterialType, + // RawMaterialWeight = item.RawMaterialWeight, + // RecipeStatus = item.RecipeStatus, + // SelectIndex = item.SelectIndex, + // Status = item.Status, + // UpLimtFeedback = item.UpLimtFeedback, + // UpLimtWeightFeedback = item.UpLimtWeightFeedback, + // WeightFeedback = item.WeightFeedback, + // }); + // } + // App.Current.Dispatcher.Invoke(() => + // { + // UserTreeCompelete.Add(new RecipeModel() + // { + // RawMaterials = RawMaterComple, + // IsEnable = recipeComple.IsEnable, + // RecipeName = recipeComple.RecipeName, + // SerialNum = UserTreeCompelete.Count + 1, + // RecipCode = recipeComple.RecipCode, + // RecipStatus = "制作完成" + // }); + // }); + // App.Current.Dispatcher.Invoke(new Action(() => + // { + // recipeProcesses.Clear(); + // CurrentRecipeName = string.Empty; + // }));//完成后清空当前配方 + // } + // } + // Thread.Sleep(100); + // }), "启动配方下发", true); + //} - SiemensDevice.GetInstance.MySiemens.Write("DB4.DBD198", BarrelNum.Count);//配方使用桶数写入 - - SiemensDevice.GetInstance.MySiemens.Write("DB4.DBX0.1", true);//配方执行启动 - Stopwatch sw = new Stopwatch(); - var recipe = Recipes.ElementAt(index); - ObservableCollection RawMater = new ObservableCollection(); - foreach (var item in recipe.RawMaterials) - { - RawMater.Add(new RawMaterialModel() - { - RawMaterialName = item.RawMaterialName, - DeviceIp = item.DeviceIp, - DownLimtFeedback = item.DownLimtFeedback, - Loc = item.Loc, - RawMaterialId = item.RawMaterialId, - RawMaterialSource = item.RawMaterialSource, - RawMaterialType = item.RawMaterialType, - RawMaterialWeight = item.RawMaterialWeight, - RecipeStatus = item.RecipeStatus, - SelectIndex = item.SelectIndex, - Status = item.Status, - UpLimtFeedback = item.UpLimtFeedback, - UpLimtWeightFeedback = item.UpLimtWeightFeedback, - WeightFeedback = item.WeightFeedback, - }); - } - App.Current.Dispatcher.Invoke(() => - { - recipeProcesses.Add(new RecipeModel() - { - RawMaterials = RawMater, - IsEnable = recipe.IsEnable, - RecipeName = recipe.RecipeName, - SerialNum = recipe.SerialNum, - RecipCode = recipe.RecipCode, - }); - }); - sw.Restart(); - while (true) - { - if (sw.ElapsedMilliseconds >= 3000 && !GlobalDevice.PlcData.ResComplete) - { - MessageNotify.GetInstance.ShowRunLog("获取配方下发反馈超时"); - break; - } - if (GlobalDevice.PlcData.ResComplete) - { - SiemensDevice.GetInstance.MySiemens.Write("DB3.DBX0.1", false); - break; - } - Thread.Sleep(100); - } - #endregion - Recipes.ElementAt(index).Are.WaitOne();//阻塞,直到当前配方完成 - RecipeNames.TryDequeue(out string deviceName); - var recipeComple = Recipes.ElementAt(index); - ObservableCollection RawMaterComple = new ObservableCollection(); - foreach (var item in recipeComple.RawMaterials) - { - RawMaterComple.Add(new RawMaterialModel() - { - RawMaterialName = item.RawMaterialName, - DeviceIp = item.DeviceIp, - DownLimtFeedback = item.DownLimtFeedback, - Loc = item.Loc, - RawMaterialId = item.RawMaterialId, - RawMaterialSource = item.RawMaterialSource, - RawMaterialType = item.RawMaterialType, - RawMaterialWeight = item.RawMaterialWeight, - RecipeStatus = item.RecipeStatus, - SelectIndex = item.SelectIndex, - Status = item.Status, - UpLimtFeedback = item.UpLimtFeedback, - UpLimtWeightFeedback = item.UpLimtWeightFeedback, - WeightFeedback = item.WeightFeedback, - }); - } - App.Current.Dispatcher.Invoke(() => - { - UserTreeCompelete.Add(new RecipeModel() - { - RawMaterials = RawMaterComple, - IsEnable = recipeComple.IsEnable, - RecipeName = recipeComple.RecipeName, - SerialNum = UserTreeCompelete.Count + 1, - RecipCode = recipeComple.RecipCode, - RecipStatus = "制作完成" - }); - }); - App.Current.Dispatcher.Invoke(new Action(() => - { - recipeProcesses.Clear(); - CurrentRecipeName = string.Empty; - }));//完成后清空当前配方 - } - } - Thread.Sleep(100); - }), "启动配方下发", true); - } - - /// /// 配方执行状态监听 /// - private void RecipeStatusInquire() - { - TaskManage.GetInstance.StartLong(new Action(() => - { - #region v1.0 - //for (int i = 0; i < Recipes.Count; i++) - //{ - // for (int m = 0; m < Recipes.ElementAt(i).RawMaterials.Count; m++) - // { - // var RunStatus = DeviceInquire.GetInstance.GetDevice(Recipes.ElementAt(i).RawMaterials.ElementAt(m).DeviceIp).deviceStatus.RunStatus; - // //设备状态显示 - // if (Recipes.ElementAt(i).RecipeName == CurrentRecipeName) - // { - // string tempRawMaterialName = DeviceInquire.GetInstance.GetDevice(Recipes.ElementAt(i).RawMaterials.ElementAt(m).DeviceIp).DeviceName; - // int recIndex = recipeProcesses.ToList().FindIndex(p => p.RecipeName == CurrentRecipeName); - // if (recIndex >= 0 && recIndex < recipeProcesses.Count) - // { - // int index = recipeProcesses.ElementAt(recIndex).RawMaterials.ToList().FindIndex(p => p.RawMaterialName == tempRawMaterialName); - // if (index >= 0 && index < recipeProcesses.ElementAt(recIndex).RawMaterials.Count) - // { - // //测试使用 - // recipeProcesses.ElementAt(recIndex).RawMaterials.ElementAt(index).RecipeStatus = RunStatus; - // } - // for (int j = 0; j < GlobalDevice.PlcData.IsAllowIngredients.Length; j++) - // { - // if (GlobalDevice.PlcData.IsAllowIngredients[j]) - // { - // int barrel = j + 1;//桶号 - // int cnt = GlobalDevice.PlcData.LocationFeedback[j];//允许配料的位置 0~6 - // if (RTrig.GetInstance("a").Start(GlobalDevice.PlcData.IsAllowIngredients[j])) - // { - // MessageNotify.GetInstance.ShowRunLog($"桶号:{barrel},位置:{cnt},允许配料"); - // } - // int Location1 = 0; - // int Location2 = 0; - // if (cnt == -1) - // { - // MessageNotify.GetInstance.ShowRunLog("错误"); - // return; - // } - // else - // { - // if (cnt >= 1 && cnt <= 6) - // { + //private void RecipeStatusInquire() + //{ + // TaskManage.GetInstance.StartLong(new Action(() => + // { + // #region v1.0 + // //for (int i = 0; i < Recipes.Count; i++) + // //{ + // // for (int m = 0; m < Recipes.ElementAt(i).RawMaterials.Count; m++) + // // { + // // var RunStatus = DeviceInquire.GetInstance.GetDevice(Recipes.ElementAt(i).RawMaterials.ElementAt(m).DeviceIp).deviceStatus.RunStatus; + // // //设备状态显示 + // // if (Recipes.ElementAt(i).RecipeName == CurrentRecipeName) + // // { + // // string tempRawMaterialName = DeviceInquire.GetInstance.GetDevice(Recipes.ElementAt(i).RawMaterials.ElementAt(m).DeviceIp).DeviceName; + // // int recIndex = recipeProcesses.ToList().FindIndex(p => p.RecipeName == CurrentRecipeName); + // // if (recIndex >= 0 && recIndex < recipeProcesses.Count) + // // { + // // int index = recipeProcesses.ElementAt(recIndex).RawMaterials.ToList().FindIndex(p => p.RawMaterialName == tempRawMaterialName); + // // if (index >= 0 && index < recipeProcesses.ElementAt(recIndex).RawMaterials.Count) + // // { + // // //测试使用 + // // recipeProcesses.ElementAt(recIndex).RawMaterials.ElementAt(index).RecipeStatus = RunStatus; + // // } + // // for (int j = 0; j < GlobalDevice.PlcData.IsAllowIngredients.Length; j++) + // // { + // // if (GlobalDevice.PlcData.IsAllowIngredients[j]) + // // { + // // int barrel = j + 1;//桶号 + // // int cnt = GlobalDevice.PlcData.LocationFeedback[j];//允许配料的位置 0~6 + // // if (RTrig.GetInstance("a").Start(GlobalDevice.PlcData.IsAllowIngredients[j])) + // // { + // // MessageNotify.GetInstance.ShowRunLog($"桶号:{barrel},位置:{cnt},允许配料"); + // // } + // // int Location1 = 0; + // // int Location2 = 0; + // // if (cnt == -1) + // // { + // // MessageNotify.GetInstance.ShowRunLog("错误"); + // // return; + // // } + // // else + // // { + // // if (cnt >= 1 && cnt <= 6) + // // { - // //int a1 = Array.FindIndex(DeviceInquire.GetInstance.devices.ToArray(), p => p.DeviceNum == cnt * 2 - 1); - // //int b1 = Array.FindIndex(DeviceInquire.GetInstance.devices.ToArray(), p => p.DeviceNum == cnt * 2); - // //if (a1 >= 0) - // //{ - // // Location1 = Array.FindIndex(Recipes.ElementAt(i).RawMaterials.ToArray(), p => p.RawMaterialName == DeviceInquire.GetInstance.devices.ElementAt(a1).DeviceName && p.Loc == barrel); - // //} - // //if (b1 >= 0) - // //{ - // // Location2 = Array.FindIndex(Recipes.ElementAt(i).RawMaterials.ToArray(), p => p.RawMaterialName == DeviceInquire.GetInstance.devices.ElementAt(b1).DeviceName && p.Loc == barrel); - // //} + // // //int a1 = Array.FindIndex(DeviceInquire.GetInstance.devices.ToArray(), p => p.DeviceNum == cnt * 2 - 1); + // // //int b1 = Array.FindIndex(DeviceInquire.GetInstance.devices.ToArray(), p => p.DeviceNum == cnt * 2); + // // //if (a1 >= 0) + // // //{ + // // // Location1 = Array.FindIndex(Recipes.ElementAt(i).RawMaterials.ToArray(), p => p.RawMaterialName == DeviceInquire.GetInstance.devices.ElementAt(a1).DeviceName && p.Loc == barrel); + // // //} + // // //if (b1 >= 0) + // // //{ + // // // Location2 = Array.FindIndex(Recipes.ElementAt(i).RawMaterials.ToArray(), p => p.RawMaterialName == DeviceInquire.GetInstance.devices.ElementAt(b1).DeviceName && p.Loc == barrel); + // // //} - // int a1 = Array.FindIndex(DeviceInquire.GetInstance.devices.ToArray(), p => p.DeviceNum == cnt); - // //int b1 = Array.FindIndex(DeviceInquire.GetInstance.devices.ToArray(), p => p.DeviceNum == cnt * 2); - // if (a1 >= 0) - // { - // Location1 = Array.FindIndex(Recipes.ElementAt(i).RawMaterials.ToArray(), p => p.RawMaterialName == DeviceInquire.GetInstance.devices.ElementAt(a1).DeviceName && p.Loc == barrel); - // } - // //if (b1 >= 0) - // //{ - // // Location2 = Array.FindIndex(Recipes.ElementAt(i).RawMaterials.ToArray(), p => p.RawMaterialName == DeviceInquire.GetInstance.devices.ElementAt(b1).DeviceName && p.Loc == barrel); - // //} - // Location2 = Location1; - // } + // // int a1 = Array.FindIndex(DeviceInquire.GetInstance.devices.ToArray(), p => p.DeviceNum == cnt); + // // //int b1 = Array.FindIndex(DeviceInquire.GetInstance.devices.ToArray(), p => p.DeviceNum == cnt * 2); + // // if (a1 >= 0) + // // { + // // Location1 = Array.FindIndex(Recipes.ElementAt(i).RawMaterials.ToArray(), p => p.RawMaterialName == DeviceInquire.GetInstance.devices.ElementAt(a1).DeviceName && p.Loc == barrel); + // // } + // // //if (b1 >= 0) + // // //{ + // // // Location2 = Array.FindIndex(Recipes.ElementAt(i).RawMaterials.ToArray(), p => p.RawMaterialName == DeviceInquire.GetInstance.devices.ElementAt(b1).DeviceName && p.Loc == barrel); + // // //} + // // Location2 = Location1; + // // } - // } - // if (Location1 >= 0) - // { - // string RawName = Recipes.ElementAt(i).RawMaterials.ElementAt(Location1).RawMaterialName; - // int abc = Array.FindIndex(DeviceInquire.GetInstance.devices.ToArray(), p => p.DeviceName == RawName); - // int DeviceNum = DeviceInquire.GetInstance.devices.ElementAt(abc).DeviceNum; - // if (DeviceNum > 0) - // { - // float weight = Recipes.ElementAt(i).RawMaterials.ElementAt(Location1).RawMaterialWeight; - // //测试 - // int loc = Array.FindIndex(Recipes.ElementAt(i).RawMaterials.ToArray(), p => (p.RawMaterialName == RawName)); - // if (loc >= 0 && RawName != null && weight >= 0) - // { - // int St_index = Array.FindIndex(StockStatus.ToArray(), p => p.MaterialName == RawName); - // int materialCount = recipeProcesses.ElementAt(recIndex).RawMaterials.Where(p => p.RawMaterialName == RawName).Count(); - // if (St_index < 0 || (StockStatus.Count < materialCount && St_index > 0)) - // { - // StockStatus.Add(new StockStatusModel() - // { - // MaterialName = RawName, - // IssueWeight = weight, - // IssueStatus = 0, - // }); - // } - // St_index = Array.FindIndex(StockStatus.ToArray(), p => (p.MaterialName == RawName && p.IssueStatus == 0)); + // // } + // // if (Location1 >= 0) + // // { + // // string RawName = Recipes.ElementAt(i).RawMaterials.ElementAt(Location1).RawMaterialName; + // // int abc = Array.FindIndex(DeviceInquire.GetInstance.devices.ToArray(), p => p.DeviceName == RawName); + // // int DeviceNum = DeviceInquire.GetInstance.devices.ElementAt(abc).DeviceNum; + // // if (DeviceNum > 0) + // // { + // // float weight = Recipes.ElementAt(i).RawMaterials.ElementAt(Location1).RawMaterialWeight; + // // //测试 + // // int loc = Array.FindIndex(Recipes.ElementAt(i).RawMaterials.ToArray(), p => (p.RawMaterialName == RawName)); + // // if (loc >= 0 && RawName != null && weight >= 0) + // // { + // // int St_index = Array.FindIndex(StockStatus.ToArray(), p => p.MaterialName == RawName); + // // int materialCount = recipeProcesses.ElementAt(recIndex).RawMaterials.Where(p => p.RawMaterialName == RawName).Count(); + // // if (St_index < 0 || (StockStatus.Count < materialCount && St_index > 0)) + // // { + // // StockStatus.Add(new StockStatusModel() + // // { + // // MaterialName = RawName, + // // IssueWeight = weight, + // // IssueStatus = 0, + // // }); + // // } + // // St_index = Array.FindIndex(StockStatus.ToArray(), p => (p.MaterialName == RawName && p.IssueStatus == 0)); - // int St_index1 = Array.FindIndex(StockStatus.ToArray(), p => (p.MaterialName == RawName && p.IssueStatus == 1)); - // if (St_index >= 0) - // { - // if ((recipeProcesses.ElementAt(recIndex).RawMaterials.ElementAt(loc).RecipeStatus == 1 && StockStatus.ElementAt(St_index).IssueStatus == 0))// - // { - // StockStatus.ElementAt(St_index).IssueStatus = 1; - // DeviceInquire.GetInstance.GetDevice(Recipes.ElementAt(i).RawMaterials.ElementAt(loc).DeviceIp).Start(weight); - // MessageNotify.GetInstance.ShowRunLog($"柔性味魔方{Recipes.ElementAt(i).RawMaterials.ElementAt(loc).DeviceIp},开始出料"); - // } - // //if (recipeProcesses.ElementAt(recIndex).RawMaterials.ElementAt(loc).RecipeStatus == 3 && StockStatus.ElementAt(St_index).IssueStatus == 1) - // //{ - // // //GlobalDevice.PlcData.IsAllowIngredients[j] = false;//测试使用 - // // StockStatus.ElementAt(St_index).IssueStatus = 2; - // // DeviceInquire.GetInstance.GetDevice(Recipes.ElementAt(i).RawMaterials.ElementAt(loc).DeviceIp).StatusReset(); - // // int a = 0.SetBitValue((byte)(DeviceNum), true); - // // byte[] test1 = a.ToBytes(BPA.Helper.DataFormat.BADC); - // // int item = test1.ToInt(); - // // SiemensDevice.GetInstance.MySiemens.Write("DB4.DBD130", item); - // // //MessageNotify.GetInstance.ShowRunLog($"{res}"); - // // MessageNotify.GetInstance.ShowRunLog($"DB4.DBD130:{item.ToBinString()}"); - // // MessageNotify.GetInstance.ShowRunLog($"柔性味魔方{Recipes.ElementAt(i).RawMaterials.ElementAt(loc).DeviceIp},出料完成,状态复位"); - // //} + // // int St_index1 = Array.FindIndex(StockStatus.ToArray(), p => (p.MaterialName == RawName && p.IssueStatus == 1)); + // // if (St_index >= 0) + // // { + // // if ((recipeProcesses.ElementAt(recIndex).RawMaterials.ElementAt(loc).RecipeStatus == 1 && StockStatus.ElementAt(St_index).IssueStatus == 0))// + // // { + // // StockStatus.ElementAt(St_index).IssueStatus = 1; + // // DeviceInquire.GetInstance.GetDevice(Recipes.ElementAt(i).RawMaterials.ElementAt(loc).DeviceIp).Start(weight); + // // MessageNotify.GetInstance.ShowRunLog($"柔性味魔方{Recipes.ElementAt(i).RawMaterials.ElementAt(loc).DeviceIp},开始出料"); + // // } + // // //if (recipeProcesses.ElementAt(recIndex).RawMaterials.ElementAt(loc).RecipeStatus == 3 && StockStatus.ElementAt(St_index).IssueStatus == 1) + // // //{ + // // // //GlobalDevice.PlcData.IsAllowIngredients[j] = false;//测试使用 + // // // StockStatus.ElementAt(St_index).IssueStatus = 2; + // // // DeviceInquire.GetInstance.GetDevice(Recipes.ElementAt(i).RawMaterials.ElementAt(loc).DeviceIp).StatusReset(); + // // // int a = 0.SetBitValue((byte)(DeviceNum), true); + // // // byte[] test1 = a.ToBytes(BPA.Helper.DataFormat.BADC); + // // // int item = test1.ToInt(); + // // // SiemensDevice.GetInstance.MySiemens.Write("DB4.DBD130", item); + // // // //MessageNotify.GetInstance.ShowRunLog($"{res}"); + // // // MessageNotify.GetInstance.ShowRunLog($"DB4.DBD130:{item.ToBinString()}"); + // // // MessageNotify.GetInstance.ShowRunLog($"柔性味魔方{Recipes.ElementAt(i).RawMaterials.ElementAt(loc).DeviceIp},出料完成,状态复位"); + // // //} - // //测试 - // if (recipeProcesses.ElementAt(recIndex).RawMaterials.ElementAt(loc).RecipeStatus == 3 && StockStatus.ElementAt(St_index1).IssueStatus == 1) - // { - // //GlobalDevice.PlcData.IsAllowIngredients[j] = false;//测试使用 - // StockStatus.ElementAt(St_index1).IssueStatus = 2; - // DeviceInquire.GetInstance.GetDevice(Recipes.ElementAt(i).RawMaterials.ElementAt(loc).DeviceIp).StatusReset(); - // int a = 0.SetBitValue((byte)(DeviceNum), true); - // byte[] test1 = a.ToBytes(BPA.Helper.DataFormat.BADC); - // int item = test1.ToInt(); - // SiemensDevice.GetInstance.MySiemens.Write("DB4.DBD130", item); - // //MessageNotify.GetInstance.ShowRunLog($"{res}"); - // MessageNotify.GetInstance.ShowRunLog($"DB4.DBD130:{item.ToBinString()}"); - // MessageNotify.GetInstance.ShowRunLog($"柔性味魔方{Recipes.ElementAt(i).RawMaterials.ElementAt(loc).DeviceIp},出料完成,状态复位"); - // } - // } - // } - // } - // } + // // //测试 + // // if (recipeProcesses.ElementAt(recIndex).RawMaterials.ElementAt(loc).RecipeStatus == 3 && StockStatus.ElementAt(St_index1).IssueStatus == 1) + // // { + // // //GlobalDevice.PlcData.IsAllowIngredients[j] = false;//测试使用 + // // StockStatus.ElementAt(St_index1).IssueStatus = 2; + // // DeviceInquire.GetInstance.GetDevice(Recipes.ElementAt(i).RawMaterials.ElementAt(loc).DeviceIp).StatusReset(); + // // int a = 0.SetBitValue((byte)(DeviceNum), true); + // // byte[] test1 = a.ToBytes(BPA.Helper.DataFormat.BADC); + // // int item = test1.ToInt(); + // // SiemensDevice.GetInstance.MySiemens.Write("DB4.DBD130", item); + // // //MessageNotify.GetInstance.ShowRunLog($"{res}"); + // // MessageNotify.GetInstance.ShowRunLog($"DB4.DBD130:{item.ToBinString()}"); + // // MessageNotify.GetInstance.ShowRunLog($"柔性味魔方{Recipes.ElementAt(i).RawMaterials.ElementAt(loc).DeviceIp},出料完成,状态复位"); + // // } + // // } + // // } + // // } + // // } - // //调试 - // //if (Location1 >= 0) - // //{ - // // string RawName = Recipes.ElementAt(i).RawMaterials.ElementAt(Location1).RawMaterialName; - // // int abc = Array.FindIndex(DeviceInquire.GetInstance.devices.ToArray(), p => p.DeviceName == RawName); - // // int DeviceNum = DeviceInquire.GetInstance.devices.ElementAt(abc).DeviceNum; - // // if (DeviceNum > 0) - // // { - // // float weight = Recipes.ElementAt(i).RawMaterials.ElementAt(Location1).RawMaterialWeight; - // // //测试 - // // // int loc = Array.FindIndex(Recipes.ElementAt(i).RawMaterials.ToArray(), p => (p.RawMaterialName == RawName)); - // // if (Location1 >= 0 && RawName != null && weight >= 0) - // // { - // // int St_index = Array.FindIndex(StockStatus.ToArray(), p => p.MaterialName == RawName); - // // int materialCount = recipeProcesses.ElementAt(recIndex).RawMaterials.Where(p => p.RawMaterialName == RawName).Count(); - // // if (St_index < 0 || (StockStatus.Count < materialCount && St_index > 0)) - // // { - // // StockStatus.Add(new StockStatusModel() - // // { - // // MaterialName = RawName, - // // IssueWeight = weight, - // // IssueStatus = 0, - // // }); - // // } - // // St_index = Array.FindIndex(StockStatus.ToArray(), p => (p.MaterialName == RawName && p.IssueStatus == 0)); + // // //调试 + // // //if (Location1 >= 0) + // // //{ + // // // string RawName = Recipes.ElementAt(i).RawMaterials.ElementAt(Location1).RawMaterialName; + // // // int abc = Array.FindIndex(DeviceInquire.GetInstance.devices.ToArray(), p => p.DeviceName == RawName); + // // // int DeviceNum = DeviceInquire.GetInstance.devices.ElementAt(abc).DeviceNum; + // // // if (DeviceNum > 0) + // // // { + // // // float weight = Recipes.ElementAt(i).RawMaterials.ElementAt(Location1).RawMaterialWeight; + // // // //测试 + // // // // int loc = Array.FindIndex(Recipes.ElementAt(i).RawMaterials.ToArray(), p => (p.RawMaterialName == RawName)); + // // // if (Location1 >= 0 && RawName != null && weight >= 0) + // // // { + // // // int St_index = Array.FindIndex(StockStatus.ToArray(), p => p.MaterialName == RawName); + // // // int materialCount = recipeProcesses.ElementAt(recIndex).RawMaterials.Where(p => p.RawMaterialName == RawName).Count(); + // // // if (St_index < 0 || (StockStatus.Count < materialCount && St_index > 0)) + // // // { + // // // StockStatus.Add(new StockStatusModel() + // // // { + // // // MaterialName = RawName, + // // // IssueWeight = weight, + // // // IssueStatus = 0, + // // // }); + // // // } + // // // St_index = Array.FindIndex(StockStatus.ToArray(), p => (p.MaterialName == RawName && p.IssueStatus == 0)); - // // int St_index1 = Array.FindIndex(StockStatus.ToArray(), p => (p.MaterialName == RawName && p.IssueStatus == 1)); - // // if (St_index >= 0) - // // { - // // if ((recipeProcesses.ElementAt(recIndex).RawMaterials.ElementAt(Location1).RecipeStatus == 1 && StockStatus.ElementAt(St_index).IssueStatus == 0))// - // // { - // // StockStatus.ElementAt(St_index).IssueStatus = 1; - // // DeviceInquire.GetInstance.GetDevice(Recipes.ElementAt(i).RawMaterials.ElementAt(Location1).DeviceIp).Start(weight); - // // MessageNotify.GetInstance.ShowRunLog($"柔性味魔方{Recipes.ElementAt(i).RawMaterials.ElementAt(Location1).DeviceIp},开始出料"); - // // } - // // //if (recipeProcesses.ElementAt(recIndex).RawMaterials.ElementAt(loc).RecipeStatus == 3 && StockStatus.ElementAt(St_index).IssueStatus == 1) - // // //{ - // // // //GlobalDevice.PlcData.IsAllowIngredients[j] = false;//测试使用 - // // // StockStatus.ElementAt(St_index).IssueStatus = 2; - // // // DeviceInquire.GetInstance.GetDevice(Recipes.ElementAt(i).RawMaterials.ElementAt(loc).DeviceIp).StatusReset(); - // // // int a = 0.SetBitValue((byte)(DeviceNum), true); - // // // byte[] test1 = a.ToBytes(BPA.Helper.DataFormat.BADC); - // // // int item = test1.ToInt(); - // // // SiemensDevice.GetInstance.MySiemens.Write("DB4.DBD130", item); - // // // //MessageNotify.GetInstance.ShowRunLog($"{res}"); - // // // MessageNotify.GetInstance.ShowRunLog($"DB4.DBD130:{item.ToBinString()}"); - // // // MessageNotify.GetInstance.ShowRunLog($"柔性味魔方{Recipes.ElementAt(i).RawMaterials.ElementAt(loc).DeviceIp},出料完成,状态复位"); - // // //} + // // // int St_index1 = Array.FindIndex(StockStatus.ToArray(), p => (p.MaterialName == RawName && p.IssueStatus == 1)); + // // // if (St_index >= 0) + // // // { + // // // if ((recipeProcesses.ElementAt(recIndex).RawMaterials.ElementAt(Location1).RecipeStatus == 1 && StockStatus.ElementAt(St_index).IssueStatus == 0))// + // // // { + // // // StockStatus.ElementAt(St_index).IssueStatus = 1; + // // // DeviceInquire.GetInstance.GetDevice(Recipes.ElementAt(i).RawMaterials.ElementAt(Location1).DeviceIp).Start(weight); + // // // MessageNotify.GetInstance.ShowRunLog($"柔性味魔方{Recipes.ElementAt(i).RawMaterials.ElementAt(Location1).DeviceIp},开始出料"); + // // // } + // // // //if (recipeProcesses.ElementAt(recIndex).RawMaterials.ElementAt(loc).RecipeStatus == 3 && StockStatus.ElementAt(St_index).IssueStatus == 1) + // // // //{ + // // // // //GlobalDevice.PlcData.IsAllowIngredients[j] = false;//测试使用 + // // // // StockStatus.ElementAt(St_index).IssueStatus = 2; + // // // // DeviceInquire.GetInstance.GetDevice(Recipes.ElementAt(i).RawMaterials.ElementAt(loc).DeviceIp).StatusReset(); + // // // // int a = 0.SetBitValue((byte)(DeviceNum), true); + // // // // byte[] test1 = a.ToBytes(BPA.Helper.DataFormat.BADC); + // // // // int item = test1.ToInt(); + // // // // SiemensDevice.GetInstance.MySiemens.Write("DB4.DBD130", item); + // // // // //MessageNotify.GetInstance.ShowRunLog($"{res}"); + // // // // MessageNotify.GetInstance.ShowRunLog($"DB4.DBD130:{item.ToBinString()}"); + // // // // MessageNotify.GetInstance.ShowRunLog($"柔性味魔方{Recipes.ElementAt(i).RawMaterials.ElementAt(loc).DeviceIp},出料完成,状态复位"); + // // // //} - // // //测试 - // // if (recipeProcesses.ElementAt(recIndex).RawMaterials.ElementAt(Location1).RecipeStatus == 3 && StockStatus.ElementAt(St_index1).IssueStatus == 1) - // // { - // // //GlobalDevice.PlcData.IsAllowIngredients[j] = false;//测试使用 - // // StockStatus.ElementAt(St_index1).IssueStatus = 2; - // // DeviceInquire.GetInstance.GetDevice(Recipes.ElementAt(i).RawMaterials.ElementAt(Location1).DeviceIp).StatusReset(); - // // int a = 0.SetBitValue((byte)(DeviceNum), true); - // // byte[] test1 = a.ToBytes(BPA.Helper.DataFormat.BADC); - // // int item = test1.ToInt(); - // // SiemensDevice.GetInstance.MySiemens.Write("DB4.DBD130", item); - // // //MessageNotify.GetInstance.ShowRunLog($"{res}"); - // // MessageNotify.GetInstance.ShowRunLog($"DB4.DBD130:{item.ToBinString()}"); - // // MessageNotify.GetInstance.ShowRunLog($"柔性味魔方{Recipes.ElementAt(i).RawMaterials.ElementAt(Location1).DeviceIp},出料完成,状态复位"); - // // } - // // } - // // } - // // } - // //} - // if (Location1 >= 0) - // { + // // // //测试 + // // // if (recipeProcesses.ElementAt(recIndex).RawMaterials.ElementAt(Location1).RecipeStatus == 3 && StockStatus.ElementAt(St_index1).IssueStatus == 1) + // // // { + // // // //GlobalDevice.PlcData.IsAllowIngredients[j] = false;//测试使用 + // // // StockStatus.ElementAt(St_index1).IssueStatus = 2; + // // // DeviceInquire.GetInstance.GetDevice(Recipes.ElementAt(i).RawMaterials.ElementAt(Location1).DeviceIp).StatusReset(); + // // // int a = 0.SetBitValue((byte)(DeviceNum), true); + // // // byte[] test1 = a.ToBytes(BPA.Helper.DataFormat.BADC); + // // // int item = test1.ToInt(); + // // // SiemensDevice.GetInstance.MySiemens.Write("DB4.DBD130", item); + // // // //MessageNotify.GetInstance.ShowRunLog($"{res}"); + // // // MessageNotify.GetInstance.ShowRunLog($"DB4.DBD130:{item.ToBinString()}"); + // // // MessageNotify.GetInstance.ShowRunLog($"柔性味魔方{Recipes.ElementAt(i).RawMaterials.ElementAt(Location1).DeviceIp},出料完成,状态复位"); + // // // } + // // // } + // // // } + // // // } + // // //} + // // if (Location1 >= 0) + // // { - // string RawName111 = Recipes.ElementAt(i).RawMaterials.ElementAt(Location1).RawMaterialName; - // int St_index111 = Array.FindIndex(StockStatus.ToArray(), p => p.MaterialName == RawName111); - // if (Location2 >= 0 && ((Location1 >= 0 && StockStatus.ElementAt(St_index111).IssueStatus == 2))) - // { - // string RawName = Recipes.ElementAt(i).RawMaterials.ElementAt(Location2).RawMaterialName; - // int abc = Array.FindIndex(DeviceInquire.GetInstance.devices.ToArray(), p => p.DeviceName == RawName); - // int DeviceNum = DeviceInquire.GetInstance.devices.ElementAt(abc).DeviceNum; - // if (DeviceNum > 0) - // { - // float weight = Recipes.ElementAt(i).RawMaterials.ElementAt(Location2).RawMaterialWeight; - // int loc = Array.FindIndex(Recipes.ElementAt(i).RawMaterials.ToArray(), p => p.RawMaterialName == RawName); - // if (loc >= 0 && RawName != null && weight >= 0) - // { - // int St_index = Array.FindIndex(StockStatus.ToArray(), p => p.MaterialName == RawName); - // if (St_index < 0) - // { - // StockStatus.Add(new StockStatusModel() - // { - // MaterialName = RawName, - // IssueWeight = weight, - // IssueStatus = 0, - // }); - // } - // St_index = Array.FindIndex(StockStatus.ToArray(), p => p.MaterialName == RawName); - // if (St_index >= 0) - // { - // if (recipeProcesses.ElementAt(recIndex).RawMaterials.ElementAt(loc).RecipeStatus == 1 && StockStatus.ElementAt(St_index).IssueStatus == 0) - // { - // StockStatus.ElementAt(St_index).IssueStatus = 1; - // DeviceInquire.GetInstance.GetDevice(Recipes.ElementAt(i).RawMaterials.ElementAt(loc).DeviceIp).Start(weight); - // MessageNotify.GetInstance.ShowRunLog($"柔性味魔方{Recipes.ElementAt(i).RawMaterials.ElementAt(loc).DeviceIp},开始出料"); - // } - // if (recipeProcesses.ElementAt(recIndex).RawMaterials.ElementAt(loc).RecipeStatus == 3 && StockStatus.ElementAt(St_index).IssueStatus == 1) - // { - // //GlobalDevice.PlcData.IsAllowIngredients[j] = false;//测试使用 - // StockStatus.ElementAt(St_index).IssueStatus = 2; - // DeviceInquire.GetInstance.GetDevice(Recipes.ElementAt(i).RawMaterials.ElementAt(loc).DeviceIp).StatusReset(); - // int a = 0.SetBitValue((byte)(DeviceNum), true); - // byte[] test1 = a.ToBytes(BPA.Helper.DataFormat.BADC); - // int item = test1.ToInt(); - // SiemensDevice.GetInstance.MySiemens.Write("DB4.DBD130", item); - // //MessageNotify.GetInstance.ShowRunLog($"{res}"); - // //MessageNotify.GetInstance.ShowRunLog($"DB4.DBD130:{item.ToBinString()}"); - // MessageNotify.GetInstance.ShowRunLog($"DB4.DBD130:{item}"); - // MessageNotify.GetInstance.ShowRunLog($"柔性味魔方{Recipes.ElementAt(i).RawMaterials.ElementAt(loc).DeviceIp},出料完成,状态复位"); - // } - // } - // } - // } - // } - // } - // else - // { - // if (Location2 >= 0) - // { - // string RawName = Recipes.ElementAt(i).RawMaterials.ElementAt(Location2).RawMaterialName; - // int abc = Array.FindIndex(DeviceInquire.GetInstance.devices.ToArray(), p => p.DeviceName == RawName); - // int DeviceNum = DeviceInquire.GetInstance.devices.ElementAt(abc).DeviceNum; - // if (DeviceNum >= 0) - // { - // float weight = Recipes.ElementAt(i).RawMaterials.ElementAt(Location2).RawMaterialWeight; - // int loc = Array.FindIndex(Recipes.ElementAt(i).RawMaterials.ToArray(), p => p.RawMaterialName == RawName); - // if (cnt > 0 && loc >= 0 && RawName != null && weight >= 0) - // { - // int St_index = Array.FindIndex(StockStatus.ToArray(), p => p.MaterialName == RawName); - // if (St_index < 0) - // { - // StockStatus.Add(new StockStatusModel() - // { - // MaterialName = RawName, - // IssueWeight = weight, - // IssueStatus = 0, - // }); - // } - // St_index = Array.FindIndex(StockStatus.ToArray(), p => p.MaterialName == RawName); - // if (St_index >= 0) - // { - // if (recipeProcesses.ElementAt(recIndex).RawMaterials.ElementAt(loc).RecipeStatus == 1 && StockStatus.ElementAt(St_index).IssueStatus == 0) - // { - // StockStatus.ElementAt(St_index).IssueStatus = 1; - // DeviceInquire.GetInstance.GetDevice(Recipes.ElementAt(i).RawMaterials.ElementAt(loc).DeviceIp).Start(weight); - // MessageNotify.GetInstance.ShowRunLog($"柔性味魔方{Recipes.ElementAt(i).RawMaterials.ElementAt(loc).DeviceIp},开始出料"); - // } - // if (recipeProcesses.ElementAt(recIndex).RawMaterials.ElementAt(loc).RecipeStatus == 3 && StockStatus.ElementAt(St_index).IssueStatus == 1) - // { - // //GlobalDevice.PlcData.IsAllowIngredients[j] = false;//测试使用 - // StockStatus.ElementAt(St_index).IssueStatus = 2; - // DeviceInquire.GetInstance.GetDevice(Recipes.ElementAt(i).RawMaterials.ElementAt(loc).DeviceIp).StatusReset(); - // int a = 0.SetBitValue((byte)(DeviceNum), true); - // byte[] test1 = a.ToBytes(BPA.Helper.DataFormat.BADC); - // int item = test1.ToInt(); - // SiemensDevice.GetInstance.MySiemens.Write("DB4.DBD130", item); - // recipeProcesses.ElementAt(recIndex).RawMaterials.ElementAt(loc).UpLimtWeightFeedback = DeviceInquire.GetInstance.GetDevice(Recipes.ElementAt(i).RawMaterials.ElementAt(loc).DeviceIp).deviceStatus.NowWeightFeedback; - // //MessageNotify.GetInstance.ShowRunLog($"{res}"); - // MessageNotify.GetInstance.ShowRunLog($"DB4.DBD130:{item.ToBinString()}"); - // MessageNotify.GetInstance.ShowRunLog($"柔性味魔方{Recipes.ElementAt(i).RawMaterials.ElementAt(loc).DeviceIp},出料完成,状态复位"); - // } - // } - // } - // } - // } - // } - // } - // //508配料项目代码 - // //if (GlobalDevice.PlcData.IsAllowIngredients[j]) - // //{ - // // int barrel = j + 1;//桶号 - // // int cnt = GlobalDevice.PlcData.LocationFeedback[j];//允许配料的位置 1~10 - // // if (RTrig.GetInstance("a").Start(GlobalDevice.PlcData.IsAllowIngredients[j])) - // // { - // // MessageNotify.GetInstance.ShowRunLog($"桶号:{barrel},位置:{cnt},允许配料"); - // // } - // // int Location1 = 0; - // // if (cnt == -1) - // // { - // // MessageNotify.GetInstance.ShowRunLog("没有读取到配料的位置"); - // // return; - // // } - // // else - // // { - // // int a1 = Array.FindIndex(DeviceInquire.GetInstance.devices.ToArray(), p => p.DeviceNum == cnt); - // // Location1 = Array.FindIndex(Recipes.ElementAt(i).RawMaterials.ToArray(), p => p.RawMaterialName == DeviceInquire.GetInstance.devices.ElementAt(a1).DeviceName && p.Loc == barrel); - // // } - // // if (Location1 >= 0) - // // { - // // string RawName = Recipes.ElementAt(i).RawMaterials.ElementAt(Location1).RawMaterialName; - // // int abc = Array.FindIndex(DeviceInquire.GetInstance.devices.ToArray(), p => p.DeviceName == RawName); - // // int DeviceNum = DeviceInquire.GetInstance.devices.ElementAt(abc).DeviceNum; - // // if (DeviceNum > 0) - // // { - // // float weight = Recipes.ElementAt(i).RawMaterials.ElementAt(Location1).RawMaterialWeight; - // // int loc = Array.FindIndex(Recipes.ElementAt(i).RawMaterials.ToArray(), p => p.RawMaterialName == RawName); - // // if (loc >= 0 && RawName != null && weight >= 0) - // // { - // // int St_index = Array.FindIndex(StockStatus.ToArray(), p => p.MaterialName == RawName); - // // if (St_index < 0) - // // { - // // StockStatus.Add(new StockStatusModel() - // // { - // // MaterialName = RawName, - // // IssueWeight = weight, - // // IssueStatus = 0, - // // }); - // // } - // // St_index = Array.FindIndex(StockStatus.ToArray(), p => p.MaterialName == RawName); - // // if (St_index >= 0) - // // { - // // if (recipeProcesses.ElementAt(recIndex).RawMaterials.ElementAt(loc).RecipeStatus == 1 && StockStatus.ElementAt(St_index).IssueStatus == 0) - // // { - // // StockStatus.ElementAt(St_index).IssueStatus = 1; - // // DeviceInquire.GetInstance.GetDevice(Recipes.ElementAt(i).RawMaterials.ElementAt(loc).DeviceIp).Start(weight); - // // MessageNotify.GetInstance.ShowRunLog($"柔性味魔方{Recipes.ElementAt(i).RawMaterials.ElementAt(loc).DeviceIp},开始出料"); - // // } - // // if (recipeProcesses.ElementAt(recIndex).RawMaterials.ElementAt(loc).RecipeStatus == 3 && StockStatus.ElementAt(St_index).IssueStatus == 1) - // // { - // // //GlobalDevice.PlcData.IsAllowIngredients[j] = false;//测试使用 - // // StockStatus.ElementAt(St_index).IssueStatus = 2; - // // DeviceInquire.GetInstance.GetDevice(Recipes.ElementAt(i).RawMaterials.ElementAt(loc).DeviceIp).StatusReset(); - // // /*int a = 0.SetBitValue((byte)(DeviceNum), true); - // // byte[] test1 = a.ToBytes(BPA.Helper.DataFormat.ABCD); - // // int item = test1.ToInt();*/ - // // if (DeviceNum >= 1 && DeviceNum <= 8) - // // { - // // SiemensDevice.GetInstance.MySiemens.Write("DB4.DBX130." + (DeviceNum - 1), true); - // // }else if (DeviceNum >= 9 && DeviceNum <= 16) - // // { - // // SiemensDevice.GetInstance.MySiemens.Write("DB4.DBX131." + (DeviceNum - 9), true); - // // } - // // else if (DeviceNum >=17 && DeviceNum <= 24) - // // { - // // SiemensDevice.GetInstance.MySiemens.Write("DB4.DBX132." + (DeviceNum - 17), true); - // // }else if (DeviceNum >= 25 && DeviceNum <= 32) - // // { - // // SiemensDevice.GetInstance.MySiemens.Write("DB4.DBX133." + (DeviceNum - 25), true); - // // } - // // MessageNotify.GetInstance.ShowRunLog($"料仓:{DeviceNum},配料完成"); - // // /*string res = SiemensDevice.GetInstance.MySiemens.Write("DB4.DBD130", item, 2); - // // MessageNotify.GetInstance.ShowRunLog($"{res}"); - // // MessageNotify.GetInstance.ShowRunLog($"DB4.DBD130:{item.ToBinString()}");*/ - // // MessageNotify.GetInstance.ShowRunLog($"柔性味魔方{Recipes.ElementAt(i).RawMaterials.ElementAt(loc).DeviceIp},出料完成,状态复位"); - // // } - // // } - // // } - // // } - // // } - // //} - // } - // int Finish_Count = StockStatus.Where(s => s.IssueStatus == 2).Count(); - // int Finish = Recipes.ElementAt(i).RawMaterials.Where(p => p.RecipeStatus == 3).Count(); - // if (StockStatus.Count >= Recipes.ElementAt(i).RawMaterials.Count && Finish == Recipes.ElementAt(i).RawMaterials.Count) //配方配料完成 Finish_Count >= Recipes.ElementAt(i).RawMaterials.Count - // { - // StockStatus.Clear(); - // MessageNotify.GetInstance.ShowUserLog($"配方:{recipeProcesses.ElementAt(recIndex).RecipeName},配料完成"); - // foreach (var item in recipeProcesses.ElementAt(recIndex).RawMaterials) - // { - // MessageNotify.GetInstance.ShowUserLog($"原料:{item.RawMaterialName},桶号:{item.Loc},设定配料重量{item.RawMaterialWeight}g,实际配料重量{item.UpLimtWeightFeedback}g"); - // } - // SiemensDevice.GetInstance.MySiemens.Write("DB4.DBX202.0", true);//配料完成 - // MessageNotify.GetInstance.ShowRunLog($"配方:{CurrentRecipeName},配料完成"); - // int recipIndex = Array.FindIndex(Recipes.ToArray(), p => p.RecipeName == CurrentRecipeName); - // App.Current.Dispatcher.Invoke(new Action(() => { recipeProcesses.Clear(); })); - // Recipes.ElementAt(recipIndex).IsEnable = true; - // Json.Data.Recipes.ElementAt(recipIndex).IsEnable = true; - // Recipes.ElementAt(recipIndex).Are.Set(); - // Thread.Sleep(100); - // } - // } - // } - // } - //} - #endregion + // // string RawName111 = Recipes.ElementAt(i).RawMaterials.ElementAt(Location1).RawMaterialName; + // // int St_index111 = Array.FindIndex(StockStatus.ToArray(), p => p.MaterialName == RawName111); + // // if (Location2 >= 0 && ((Location1 >= 0 && StockStatus.ElementAt(St_index111).IssueStatus == 2))) + // // { + // // string RawName = Recipes.ElementAt(i).RawMaterials.ElementAt(Location2).RawMaterialName; + // // int abc = Array.FindIndex(DeviceInquire.GetInstance.devices.ToArray(), p => p.DeviceName == RawName); + // // int DeviceNum = DeviceInquire.GetInstance.devices.ElementAt(abc).DeviceNum; + // // if (DeviceNum > 0) + // // { + // // float weight = Recipes.ElementAt(i).RawMaterials.ElementAt(Location2).RawMaterialWeight; + // // int loc = Array.FindIndex(Recipes.ElementAt(i).RawMaterials.ToArray(), p => p.RawMaterialName == RawName); + // // if (loc >= 0 && RawName != null && weight >= 0) + // // { + // // int St_index = Array.FindIndex(StockStatus.ToArray(), p => p.MaterialName == RawName); + // // if (St_index < 0) + // // { + // // StockStatus.Add(new StockStatusModel() + // // { + // // MaterialName = RawName, + // // IssueWeight = weight, + // // IssueStatus = 0, + // // }); + // // } + // // St_index = Array.FindIndex(StockStatus.ToArray(), p => p.MaterialName == RawName); + // // if (St_index >= 0) + // // { + // // if (recipeProcesses.ElementAt(recIndex).RawMaterials.ElementAt(loc).RecipeStatus == 1 && StockStatus.ElementAt(St_index).IssueStatus == 0) + // // { + // // StockStatus.ElementAt(St_index).IssueStatus = 1; + // // DeviceInquire.GetInstance.GetDevice(Recipes.ElementAt(i).RawMaterials.ElementAt(loc).DeviceIp).Start(weight); + // // MessageNotify.GetInstance.ShowRunLog($"柔性味魔方{Recipes.ElementAt(i).RawMaterials.ElementAt(loc).DeviceIp},开始出料"); + // // } + // // if (recipeProcesses.ElementAt(recIndex).RawMaterials.ElementAt(loc).RecipeStatus == 3 && StockStatus.ElementAt(St_index).IssueStatus == 1) + // // { + // // //GlobalDevice.PlcData.IsAllowIngredients[j] = false;//测试使用 + // // StockStatus.ElementAt(St_index).IssueStatus = 2; + // // DeviceInquire.GetInstance.GetDevice(Recipes.ElementAt(i).RawMaterials.ElementAt(loc).DeviceIp).StatusReset(); + // // int a = 0.SetBitValue((byte)(DeviceNum), true); + // // byte[] test1 = a.ToBytes(BPA.Helper.DataFormat.BADC); + // // int item = test1.ToInt(); + // // SiemensDevice.GetInstance.MySiemens.Write("DB4.DBD130", item); + // // //MessageNotify.GetInstance.ShowRunLog($"{res}"); + // // //MessageNotify.GetInstance.ShowRunLog($"DB4.DBD130:{item.ToBinString()}"); + // // MessageNotify.GetInstance.ShowRunLog($"DB4.DBD130:{item}"); + // // MessageNotify.GetInstance.ShowRunLog($"柔性味魔方{Recipes.ElementAt(i).RawMaterials.ElementAt(loc).DeviceIp},出料完成,状态复位"); + // // } + // // } + // // } + // // } + // // } + // // } + // // else + // // { + // // if (Location2 >= 0) + // // { + // // string RawName = Recipes.ElementAt(i).RawMaterials.ElementAt(Location2).RawMaterialName; + // // int abc = Array.FindIndex(DeviceInquire.GetInstance.devices.ToArray(), p => p.DeviceName == RawName); + // // int DeviceNum = DeviceInquire.GetInstance.devices.ElementAt(abc).DeviceNum; + // // if (DeviceNum >= 0) + // // { + // // float weight = Recipes.ElementAt(i).RawMaterials.ElementAt(Location2).RawMaterialWeight; + // // int loc = Array.FindIndex(Recipes.ElementAt(i).RawMaterials.ToArray(), p => p.RawMaterialName == RawName); + // // if (cnt > 0 && loc >= 0 && RawName != null && weight >= 0) + // // { + // // int St_index = Array.FindIndex(StockStatus.ToArray(), p => p.MaterialName == RawName); + // // if (St_index < 0) + // // { + // // StockStatus.Add(new StockStatusModel() + // // { + // // MaterialName = RawName, + // // IssueWeight = weight, + // // IssueStatus = 0, + // // }); + // // } + // // St_index = Array.FindIndex(StockStatus.ToArray(), p => p.MaterialName == RawName); + // // if (St_index >= 0) + // // { + // // if (recipeProcesses.ElementAt(recIndex).RawMaterials.ElementAt(loc).RecipeStatus == 1 && StockStatus.ElementAt(St_index).IssueStatus == 0) + // // { + // // StockStatus.ElementAt(St_index).IssueStatus = 1; + // // DeviceInquire.GetInstance.GetDevice(Recipes.ElementAt(i).RawMaterials.ElementAt(loc).DeviceIp).Start(weight); + // // MessageNotify.GetInstance.ShowRunLog($"柔性味魔方{Recipes.ElementAt(i).RawMaterials.ElementAt(loc).DeviceIp},开始出料"); + // // } + // // if (recipeProcesses.ElementAt(recIndex).RawMaterials.ElementAt(loc).RecipeStatus == 3 && StockStatus.ElementAt(St_index).IssueStatus == 1) + // // { + // // //GlobalDevice.PlcData.IsAllowIngredients[j] = false;//测试使用 + // // StockStatus.ElementAt(St_index).IssueStatus = 2; + // // DeviceInquire.GetInstance.GetDevice(Recipes.ElementAt(i).RawMaterials.ElementAt(loc).DeviceIp).StatusReset(); + // // int a = 0.SetBitValue((byte)(DeviceNum), true); + // // byte[] test1 = a.ToBytes(BPA.Helper.DataFormat.BADC); + // // int item = test1.ToInt(); + // // SiemensDevice.GetInstance.MySiemens.Write("DB4.DBD130", item); + // // recipeProcesses.ElementAt(recIndex).RawMaterials.ElementAt(loc).UpLimtWeightFeedback = DeviceInquire.GetInstance.GetDevice(Recipes.ElementAt(i).RawMaterials.ElementAt(loc).DeviceIp).deviceStatus.NowWeightFeedback; + // // //MessageNotify.GetInstance.ShowRunLog($"{res}"); + // // MessageNotify.GetInstance.ShowRunLog($"DB4.DBD130:{item.ToBinString()}"); + // // MessageNotify.GetInstance.ShowRunLog($"柔性味魔方{Recipes.ElementAt(i).RawMaterials.ElementAt(loc).DeviceIp},出料完成,状态复位"); + // // } + // // } + // // } + // // } + // // } + // // } + // // } + // // //508配料项目代码 + // // //if (GlobalDevice.PlcData.IsAllowIngredients[j]) + // // //{ + // // // int barrel = j + 1;//桶号 + // // // int cnt = GlobalDevice.PlcData.LocationFeedback[j];//允许配料的位置 1~10 + // // // if (RTrig.GetInstance("a").Start(GlobalDevice.PlcData.IsAllowIngredients[j])) + // // // { + // // // MessageNotify.GetInstance.ShowRunLog($"桶号:{barrel},位置:{cnt},允许配料"); + // // // } + // // // int Location1 = 0; + // // // if (cnt == -1) + // // // { + // // // MessageNotify.GetInstance.ShowRunLog("没有读取到配料的位置"); + // // // return; + // // // } + // // // else + // // // { + // // // int a1 = Array.FindIndex(DeviceInquire.GetInstance.devices.ToArray(), p => p.DeviceNum == cnt); + // // // Location1 = Array.FindIndex(Recipes.ElementAt(i).RawMaterials.ToArray(), p => p.RawMaterialName == DeviceInquire.GetInstance.devices.ElementAt(a1).DeviceName && p.Loc == barrel); + // // // } + // // // if (Location1 >= 0) + // // // { + // // // string RawName = Recipes.ElementAt(i).RawMaterials.ElementAt(Location1).RawMaterialName; + // // // int abc = Array.FindIndex(DeviceInquire.GetInstance.devices.ToArray(), p => p.DeviceName == RawName); + // // // int DeviceNum = DeviceInquire.GetInstance.devices.ElementAt(abc).DeviceNum; + // // // if (DeviceNum > 0) + // // // { + // // // float weight = Recipes.ElementAt(i).RawMaterials.ElementAt(Location1).RawMaterialWeight; + // // // int loc = Array.FindIndex(Recipes.ElementAt(i).RawMaterials.ToArray(), p => p.RawMaterialName == RawName); + // // // if (loc >= 0 && RawName != null && weight >= 0) + // // // { + // // // int St_index = Array.FindIndex(StockStatus.ToArray(), p => p.MaterialName == RawName); + // // // if (St_index < 0) + // // // { + // // // StockStatus.Add(new StockStatusModel() + // // // { + // // // MaterialName = RawName, + // // // IssueWeight = weight, + // // // IssueStatus = 0, + // // // }); + // // // } + // // // St_index = Array.FindIndex(StockStatus.ToArray(), p => p.MaterialName == RawName); + // // // if (St_index >= 0) + // // // { + // // // if (recipeProcesses.ElementAt(recIndex).RawMaterials.ElementAt(loc).RecipeStatus == 1 && StockStatus.ElementAt(St_index).IssueStatus == 0) + // // // { + // // // StockStatus.ElementAt(St_index).IssueStatus = 1; + // // // DeviceInquire.GetInstance.GetDevice(Recipes.ElementAt(i).RawMaterials.ElementAt(loc).DeviceIp).Start(weight); + // // // MessageNotify.GetInstance.ShowRunLog($"柔性味魔方{Recipes.ElementAt(i).RawMaterials.ElementAt(loc).DeviceIp},开始出料"); + // // // } + // // // if (recipeProcesses.ElementAt(recIndex).RawMaterials.ElementAt(loc).RecipeStatus == 3 && StockStatus.ElementAt(St_index).IssueStatus == 1) + // // // { + // // // //GlobalDevice.PlcData.IsAllowIngredients[j] = false;//测试使用 + // // // StockStatus.ElementAt(St_index).IssueStatus = 2; + // // // DeviceInquire.GetInstance.GetDevice(Recipes.ElementAt(i).RawMaterials.ElementAt(loc).DeviceIp).StatusReset(); + // // // /*int a = 0.SetBitValue((byte)(DeviceNum), true); + // // // byte[] test1 = a.ToBytes(BPA.Helper.DataFormat.ABCD); + // // // int item = test1.ToInt();*/ + // // // if (DeviceNum >= 1 && DeviceNum <= 8) + // // // { + // // // SiemensDevice.GetInstance.MySiemens.Write("DB4.DBX130." + (DeviceNum - 1), true); + // // // }else if (DeviceNum >= 9 && DeviceNum <= 16) + // // // { + // // // SiemensDevice.GetInstance.MySiemens.Write("DB4.DBX131." + (DeviceNum - 9), true); + // // // } + // // // else if (DeviceNum >=17 && DeviceNum <= 24) + // // // { + // // // SiemensDevice.GetInstance.MySiemens.Write("DB4.DBX132." + (DeviceNum - 17), true); + // // // }else if (DeviceNum >= 25 && DeviceNum <= 32) + // // // { + // // // SiemensDevice.GetInstance.MySiemens.Write("DB4.DBX133." + (DeviceNum - 25), true); + // // // } + // // // MessageNotify.GetInstance.ShowRunLog($"料仓:{DeviceNum},配料完成"); + // // // /*string res = SiemensDevice.GetInstance.MySiemens.Write("DB4.DBD130", item, 2); + // // // MessageNotify.GetInstance.ShowRunLog($"{res}"); + // // // MessageNotify.GetInstance.ShowRunLog($"DB4.DBD130:{item.ToBinString()}");*/ + // // // MessageNotify.GetInstance.ShowRunLog($"柔性味魔方{Recipes.ElementAt(i).RawMaterials.ElementAt(loc).DeviceIp},出料完成,状态复位"); + // // // } + // // // } + // // // } + // // // } + // // // } + // // //} + // // } + // // int Finish_Count = StockStatus.Where(s => s.IssueStatus == 2).Count(); + // // int Finish = Recipes.ElementAt(i).RawMaterials.Where(p => p.RecipeStatus == 3).Count(); + // // if (StockStatus.Count >= Recipes.ElementAt(i).RawMaterials.Count && Finish == Recipes.ElementAt(i).RawMaterials.Count) //配方配料完成 Finish_Count >= Recipes.ElementAt(i).RawMaterials.Count + // // { + // // StockStatus.Clear(); + // // MessageNotify.GetInstance.ShowUserLog($"配方:{recipeProcesses.ElementAt(recIndex).RecipeName},配料完成"); + // // foreach (var item in recipeProcesses.ElementAt(recIndex).RawMaterials) + // // { + // // MessageNotify.GetInstance.ShowUserLog($"原料:{item.RawMaterialName},桶号:{item.Loc},设定配料重量{item.RawMaterialWeight}g,实际配料重量{item.UpLimtWeightFeedback}g"); + // // } + // // SiemensDevice.GetInstance.MySiemens.Write("DB4.DBX202.0", true);//配料完成 + // // MessageNotify.GetInstance.ShowRunLog($"配方:{CurrentRecipeName},配料完成"); + // // int recipIndex = Array.FindIndex(Recipes.ToArray(), p => p.RecipeName == CurrentRecipeName); + // // App.Current.Dispatcher.Invoke(new Action(() => { recipeProcesses.Clear(); })); + // // Recipes.ElementAt(recipIndex).IsEnable = true; + // // Json.Data.Recipes.ElementAt(recipIndex).IsEnable = true; + // // Recipes.ElementAt(recipIndex).Are.Set(); + // // Thread.Sleep(100); + // // } + // // } + // // } + // // } + // //} + // #endregion - #region 正式版 - for (int i = 0; i < Recipes.Count; i++) - { - for (int m = 0; m < Recipes.ElementAt(i).RawMaterials.Count; m++) - { - var RunStatus = DeviceInquire.GetInstance.GetDevice(Recipes.ElementAt(i).RawMaterials.ElementAt(m).DeviceIp).deviceStatus.RunStatus; - //设备状态显示 - if (Recipes.ElementAt(i).RecipeName == CurrentRecipeName) - { - string tempRawMaterialName = DeviceInquire.GetInstance.GetDevice(Recipes.ElementAt(i).RawMaterials.ElementAt(m).DeviceIp).DeviceName; - int recIndex = recipeProcesses.ToList().FindIndex(p => p.RecipeName == CurrentRecipeName); - if (recIndex >= 0 && recIndex < recipeProcesses.Count) - { - int index = recipeProcesses.ElementAt(recIndex).RawMaterials.ToList().FindIndex(p => p.RawMaterialName == tempRawMaterialName); + // #region 正式版 + // for (int i = 0; i < Recipes.Count; i++) + // { + // for (int m = 0; m < Recipes.ElementAt(i).RawMaterials.Count; m++) + // { + // var RunStatus = DeviceInquire.GetInstance.GetDevice(Recipes.ElementAt(i).RawMaterials.ElementAt(m).DeviceIp).deviceStatus.RunStatus; + // //设备状态显示 + // if (Recipes.ElementAt(i).RecipeName == CurrentRecipeName) + // { + // string tempRawMaterialName = DeviceInquire.GetInstance.GetDevice(Recipes.ElementAt(i).RawMaterials.ElementAt(m).DeviceIp).DeviceName; + // int recIndex = recipeProcesses.ToList().FindIndex(p => p.RecipeName == CurrentRecipeName); + // if (recIndex >= 0 && recIndex < recipeProcesses.Count) + // { + // int index = recipeProcesses.ElementAt(recIndex).RawMaterials.ToList().FindIndex(p => p.RawMaterialName == tempRawMaterialName); - if (index >= 0 && index < recipeProcesses.ElementAt(recIndex).RawMaterials.Count) - { - //测试使用 - recipeProcesses.ElementAt(recIndex).RawMaterials.ElementAt(index).RecipeStatus = RunStatus; - } - for (int j = 0; j < GlobalDevice.PlcData.IsAllowIngredients.Length; j++) - { - if (GlobalDevice.PlcData.IsAllowIngredients[j]) - { - int barrel = j + 1;//桶号 - int cnt = GlobalDevice.PlcData.LocationFeedback[j];//允许配料的位置 1~6 - if (RTrig.GetInstance($"a{j}").Start(GlobalDevice.PlcData.IsAllowIngredients[j])) - { - MessageNotify.GetInstance.ShowRunLog($"桶号:{barrel},位置:{cnt},允许配料"); - } - int Location1 = 0; - int Location2 = 0; - if (cnt == -1) - { - MessageNotify.GetInstance.ShowRunLog("错误"); - return; - } - else - { - if (cnt >= 1 && cnt <= 6) - { - int a1 = Array.FindIndex(DeviceInquire.GetInstance.devices.ToArray(), p => p.DeviceNum == cnt); - if (a1 >= 0) - { - Location1 = Array.FindIndex(Recipes.ElementAt(i).RawMaterials.ToArray(), p => p.RawMaterialName == DeviceInquire.GetInstance.devices.ElementAt(a1).DeviceName && p.Loc == barrel); - } - - } - } - if (Location1 >= 0) - { - string RawName = Recipes.ElementAt(i).RawMaterials.ElementAt(Location1).RawMaterialName; - int abc = Array.FindIndex(DeviceInquire.GetInstance.devices.ToArray(), p => p.DeviceName == RawName); - int DeviceNum = DeviceInquire.GetInstance.devices.ElementAt(abc).DeviceNum; - if (DeviceNum > 0) - { - float weight = Recipes.ElementAt(i).RawMaterials.ElementAt(Location1).RawMaterialWeight; - - int loc = Array.FindIndex(Recipes.ElementAt(i).RawMaterials.ToArray(), p => (p.RawMaterialName == RawName)); - if (loc >= 0 && RawName != null && weight >= 0) - { - int St_index = Array.FindIndex(StockStatus.ToArray(), p => p.MaterialName == RawName); - - if (St_index < 0) //|| (StockStatus.Count < materialCount && St_index > 0) - { - StockStatus.Add(new StockStatusModel() - { - MaterialName = RawName, - IssueWeight = weight, - IssueStatus = 0, - }); - } - St_index = Array.FindIndex(StockStatus.ToArray(), p => p.MaterialName == RawName);//&& p.IssueStatus == 0) - if (St_index >= 0) - { + // if (index >= 0 && index < recipeProcesses.ElementAt(recIndex).RawMaterials.Count) + // { + // //测试使用 + // recipeProcesses.ElementAt(recIndex).RawMaterials.ElementAt(index).RecipeStatus = RunStatus; + // } + // for (int j = 0; j < GlobalDevice.PlcData.IsAllowIngredients.Length; j++) + // { + // if (GlobalDevice.PlcData.IsAllowIngredients[j]) + // { + // int barrel = j + 1;//桶号 + // int cnt = GlobalDevice.PlcData.LocationFeedback[j];//允许配料的位置 1~6 + // if (RTrig.GetInstance($"a{j}").Start(GlobalDevice.PlcData.IsAllowIngredients[j])) + // { + // MessageNotify.GetInstance.ShowRunLog($"桶号:{barrel},位置:{cnt},允许配料"); + // } + // int Location1 = 0; + // int Location2 = 0; + // if (cnt == -1) + // { + // MessageNotify.GetInstance.ShowRunLog("错误"); + // return; + // } + // else + // { + // if (cnt >= 1 && cnt <= 6) + // { + // int a1 = Array.FindIndex(DeviceInquire.GetInstance.devices.ToArray(), p => p.DeviceNum == cnt); + // if (a1 >= 0) + // { + // Location1 = Array.FindIndex(Recipes.ElementAt(i).RawMaterials.ToArray(), p => p.RawMaterialName == DeviceInquire.GetInstance.devices.ElementAt(a1).DeviceName && p.Loc == barrel); + // } - if (RTrig.GetInstance($"ac{j}-{St_index}").Start(GlobalDevice.PlcData.IsAllowIngredients[j])) - { - MessageNotify.GetInstance.ShowRunLog($"{St_index}-{j}--》允许配料"); - if (StockStatus.ElementAt(St_index).IssueStatus == 2) - { - StockStatus.ElementAt(St_index).IssueStatus = 0; - MessageNotify.GetInstance.ShowRunLog($"{St_index}-复位"); - } - } - var rrr = DeviceInquire.GetInstance.GetDevice(Recipes.ElementAt(i).RawMaterials.ElementAt(loc).DeviceIp).deviceStatus.RunStatus; - if ((recipeProcesses.ElementAt(recIndex).RawMaterials.ElementAt(loc).RecipeStatus == 1 && StockStatus.ElementAt(St_index).IssueStatus == 0))// - { + // } + // } + // if (Location1 >= 0) + // { + // string RawName = Recipes.ElementAt(i).RawMaterials.ElementAt(Location1).RawMaterialName; + // int abc = Array.FindIndex(DeviceInquire.GetInstance.devices.ToArray(), p => p.DeviceName == RawName); + // int DeviceNum = DeviceInquire.GetInstance.devices.ElementAt(abc).DeviceNum; + // if (DeviceNum > 0) + // { + // float weight = Recipes.ElementAt(i).RawMaterials.ElementAt(Location1).RawMaterialWeight; - StockStatus.ElementAt(St_index).IssueStatus = 1; - DeviceInquire.GetInstance.GetDevice(Recipes.ElementAt(i).RawMaterials.ElementAt(loc).DeviceIp).Start(weight); - var res = recipeProcesses.ElementAt(recIndex).RawMaterials.FirstOrDefault(p => p.Status !=Status.正在配料 &&p.Status!=Status.配料完成&& p.RawMaterialName == tempRawMaterialName && p.Loc == j + 1); - if (res != null) - res.Status = Status.正在配料; - - MessageNotify.GetInstance.ShowRunLog($"设备执行状态:{rrr}"); - MessageNotify.GetInstance.ShowRunLog($"柔性味魔方{Recipes.ElementAt(i).RawMaterials.ElementAt(loc).DeviceIp},开始出料"); - } - if (recipeProcesses.ElementAt(recIndex).RawMaterials.ElementAt(loc).RecipeStatus == 3 && StockStatus.ElementAt(St_index).IssueStatus == 1) - { - //GlobalDevice.PlcData.IsAllowIngredients[j] = false;//测试使用 + // int loc = Array.FindIndex(Recipes.ElementAt(i).RawMaterials.ToArray(), p => (p.RawMaterialName == RawName)); + // if (loc >= 0 && RawName != null && weight >= 0) + // { + // int St_index = Array.FindIndex(StockStatus.ToArray(), p => p.MaterialName == RawName); - ComCount++; - StockStatus.ElementAt(St_index).IssueStatus = 2; - DeviceInquire.GetInstance.GetDevice(Recipes.ElementAt(i).RawMaterials.ElementAt(loc).DeviceIp).StatusReset(); - //int a = 0.SetBitValue((byte)(DeviceNum), true); - //byte[] test1 = a.ToBytes(BPA.Helper.DataFormat.BADC); - //int item = test1.ToInt(); - //prop1: - // SiemensDevice.GetInstance.MySiemens.Write("DB4.DBD130", item); - SiemensDevice.GetInstance.MySiemens.Write($"DB4.DBX130.{DeviceNum - 1}", true); - Task.Run(() => - { - int cout = DeviceNum - 1; - while (!SiemensDevice.GetInstance.MySiemens.Read($"DB3.DBX148.{cout}").Content) //DB3.DBX148.0-31 148.0-148.5代表6个料仓位置 - { - SiemensDevice.GetInstance.MySiemens.Write($"DB4.DBX130.{cout}", true); - Thread.Sleep(200); - } - while (SiemensDevice.GetInstance.MySiemens.Read($"DB3.DBX148.{cout}").Content) - { - SiemensDevice.GetInstance.MySiemens.Write($"DB4.DBX130.{cout}", false); - } - MessageNotify.GetInstance.ShowRunLog($"{cout}号气缸复位信号写入成功!"); - }); - var res = recipeProcesses.ElementAt(recIndex).RawMaterials.FirstOrDefault(p => p.Status != Status.配料完成 && p.RawMaterialName == tempRawMaterialName && p.Loc == j + 1); - if (res != null) - res.Status = Status.配料完成; - + // if (St_index < 0) //|| (StockStatus.Count < materialCount && St_index > 0) + // { + // StockStatus.Add(new StockStatusModel() + // { + // MaterialName = RawName, + // IssueWeight = weight, + // IssueStatus = 0, + // }); + // } + // St_index = Array.FindIndex(StockStatus.ToArray(), p => p.MaterialName == RawName);//&& p.IssueStatus == 0) + // if (St_index >= 0) + // { - MessageNotify.GetInstance.ShowRunLog($"设备完成执行状态:{rrr}"); - MessageNotify.GetInstance.ShowRunLog($"柔性味魔方{Recipes.ElementAt(i).RawMaterials.ElementAt(loc).DeviceIp},出料完成,状态复位"); + // if (RTrig.GetInstance($"ac{j}-{St_index}").Start(GlobalDevice.PlcData.IsAllowIngredients[j])) + // { + // MessageNotify.GetInstance.ShowRunLog($"{St_index}-{j}--》允许配料"); + // if (StockStatus.ElementAt(St_index).IssueStatus == 2) + // { + // StockStatus.ElementAt(St_index).IssueStatus = 0; + // MessageNotify.GetInstance.ShowRunLog($"{St_index}-复位"); + // } + // } + // var rrr = DeviceInquire.GetInstance.GetDevice(Recipes.ElementAt(i).RawMaterials.ElementAt(loc).DeviceIp).deviceStatus.RunStatus; + // if ((recipeProcesses.ElementAt(recIndex).RawMaterials.ElementAt(loc).RecipeStatus == 1 && StockStatus.ElementAt(St_index).IssueStatus == 0))// + // { - } + // StockStatus.ElementAt(St_index).IssueStatus = 1; + // DeviceInquire.GetInstance.GetDevice(Recipes.ElementAt(i).RawMaterials.ElementAt(loc).DeviceIp).Start(weight); + // var res = recipeProcesses.ElementAt(recIndex).RawMaterials.FirstOrDefault(p => p.Status != Status.正在配料 && p.Status != Status.配料完成 && p.RawMaterialName == tempRawMaterialName && p.Loc == j + 1); + // if (res != null) + // res.Status = Status.正在配料; - - } - } - } - } - } - //508配料项目代码 - //if (GlobalDevice.PlcData.IsAllowIngredients[j]) - //{ - // int barrel = j + 1;//桶号 - // int cnt = GlobalDevice.PlcData.LocationFeedback[j];//允许配料的位置 1~10 - // if (RTrig.GetInstance("a").Start(GlobalDevice.PlcData.IsAllowIngredients[j])) - // { - // MessageNotify.GetInstance.ShowRunLog($"桶号:{barrel},位置:{cnt},允许配料"); - // } - // int Location1 = 0; - // if (cnt == -1) - // { - // MessageNotify.GetInstance.ShowRunLog("没有读取到配料的位置"); - // return; - // } - // else - // { - // int a1 = Array.FindIndex(DeviceInquire.GetInstance.devices.ToArray(), p => p.DeviceNum == cnt); - // Location1 = Array.FindIndex(Recipes.ElementAt(i).RawMaterials.ToArray(), p => p.RawMaterialName == DeviceInquire.GetInstance.devices.ElementAt(a1).DeviceName && p.Loc == barrel); - // } - // if (Location1 >= 0) - // { - // string RawName = Recipes.ElementAt(i).RawMaterials.ElementAt(Location1).RawMaterialName; - // int abc = Array.FindIndex(DeviceInquire.GetInstance.devices.ToArray(), p => p.DeviceName == RawName); - // int DeviceNum = DeviceInquire.GetInstance.devices.ElementAt(abc).DeviceNum; - // if (DeviceNum > 0) - // { - // float weight = Recipes.ElementAt(i).RawMaterials.ElementAt(Location1).RawMaterialWeight; - // int loc = Array.FindIndex(Recipes.ElementAt(i).RawMaterials.ToArray(), p => p.RawMaterialName == RawName); - // if (loc >= 0 && RawName != null && weight >= 0) - // { - // int St_index = Array.FindIndex(StockStatus.ToArray(), p => p.MaterialName == RawName); - // if (St_index < 0) - // { - // StockStatus.Add(new StockStatusModel() - // { - // MaterialName = RawName, - // IssueWeight = weight, - // IssueStatus = 0, - // }); - // } - // St_index = Array.FindIndex(StockStatus.ToArray(), p => p.MaterialName == RawName); - // if (St_index >= 0) - // { - // if (recipeProcesses.ElementAt(recIndex).RawMaterials.ElementAt(loc).RecipeStatus == 1 && StockStatus.ElementAt(St_index).IssueStatus == 0) - // { - // StockStatus.ElementAt(St_index).IssueStatus = 1; - // DeviceInquire.GetInstance.GetDevice(Recipes.ElementAt(i).RawMaterials.ElementAt(loc).DeviceIp).Start(weight); - // MessageNotify.GetInstance.ShowRunLog($"柔性味魔方{Recipes.ElementAt(i).RawMaterials.ElementAt(loc).DeviceIp},开始出料"); - // } - // if (recipeProcesses.ElementAt(recIndex).RawMaterials.ElementAt(loc).RecipeStatus == 3 && StockStatus.ElementAt(St_index).IssueStatus == 1) - // { - // //GlobalDevice.PlcData.IsAllowIngredients[j] = false;//测试使用 - // StockStatus.ElementAt(St_index).IssueStatus = 2; - // DeviceInquire.GetInstance.GetDevice(Recipes.ElementAt(i).RawMaterials.ElementAt(loc).DeviceIp).StatusReset(); - // /*int a = 0.SetBitValue((byte)(DeviceNum), true); - // byte[] test1 = a.ToBytes(BPA.Helper.DataFormat.ABCD); - // int item = test1.ToInt();*/ - // if (DeviceNum >= 1 && DeviceNum <= 8) - // { - // SiemensDevice.GetInstance.MySiemens.Write("DB4.DBX130." + (DeviceNum - 1), true); - // }else if (DeviceNum >= 9 && DeviceNum <= 16) - // { - // SiemensDevice.GetInstance.MySiemens.Write("DB4.DBX131." + (DeviceNum - 9), true); - // } - // else if (DeviceNum >=17 && DeviceNum <= 24) - // { - // SiemensDevice.GetInstance.MySiemens.Write("DB4.DBX132." + (DeviceNum - 17), true); - // }else if (DeviceNum >= 25 && DeviceNum <= 32) - // { - // SiemensDevice.GetInstance.MySiemens.Write("DB4.DBX133." + (DeviceNum - 25), true); - // } - // MessageNotify.GetInstance.ShowRunLog($"料仓:{DeviceNum},配料完成"); - // /*string res = SiemensDevice.GetInstance.MySiemens.Write("DB4.DBD130", item, 2); - // MessageNotify.GetInstance.ShowRunLog($"{res}"); - // MessageNotify.GetInstance.ShowRunLog($"DB4.DBD130:{item.ToBinString()}");*/ - // MessageNotify.GetInstance.ShowRunLog($"柔性味魔方{Recipes.ElementAt(i).RawMaterials.ElementAt(loc).DeviceIp},出料完成,状态复位"); - // } - // } - // } - // } - // } - //} - } - - if (ComCount >= Recipes.ElementAt(i).RawMaterials.Count) //配方配料完成 StockStatus.Count >= Recipes.ElementAt(i).RawMaterials.Count && - { - int cc = recipeProcesses.ElementAt(recIndex).RawMaterials.OrderBy(p => p.RawMaterialName).Count(); - for (int k = 0; k < 32; k++) - { - for (int l = 0; l < cc; l++) - { - RTrig.GetInstance($"ac{k}-{l}").Start(false); - } - } - ComCount = 0; + // MessageNotify.GetInstance.ShowRunLog($"设备执行状态:{rrr}"); + // MessageNotify.GetInstance.ShowRunLog($"柔性味魔方{Recipes.ElementAt(i).RawMaterials.ElementAt(loc).DeviceIp},开始出料"); + // } + // if (recipeProcesses.ElementAt(recIndex).RawMaterials.ElementAt(loc).RecipeStatus == 3 && StockStatus.ElementAt(St_index).IssueStatus == 1) + // { + // //GlobalDevice.PlcData.IsAllowIngredients[j] = false;//测试使用 - StockStatus.Clear(); - MessageNotify.GetInstance.ShowUserLog($"配方:{recipeProcesses.ElementAt(recIndex).RecipeName},配料完成"); - foreach (var item in recipeProcesses.ElementAt(recIndex).RawMaterials) - { - MessageNotify.GetInstance.ShowUserLog($"原料:{item.RawMaterialName},桶号:{item.Loc},设定配料重量{item.RawMaterialWeight}g,实际配料重量{item.UpLimtWeightFeedback}g"); - } - SiemensDevice.GetInstance.MySiemens.Write("DB4.DBX202.0", true);//配料完成 - MessageNotify.GetInstance.ShowRunLog($"配方:{CurrentRecipeName},配料完成"); - int recipIndex = Array.FindIndex(Recipes.ToArray(), p => p.RecipeName == CurrentRecipeName); - App.Current.Dispatcher.Invoke(new Action(() => { recipeProcesses.Clear(); })); - Recipes.ElementAt(recipIndex).IsEnable = true; - Json.Data.Recipes.ElementAt(recipIndex).IsEnable = true; - Recipes.ElementAt(recipIndex).Are.Set(); - Thread.Sleep(100); - } - } - } - } - } - #endregion + // ComCount++; + // StockStatus.ElementAt(St_index).IssueStatus = 2; + // DeviceInquire.GetInstance.GetDevice(Recipes.ElementAt(i).RawMaterials.ElementAt(loc).DeviceIp).StatusReset(); + // //int a = 0.SetBitValue((byte)(DeviceNum), true); + // //byte[] test1 = a.ToBytes(BPA.Helper.DataFormat.BADC); + // //int item = test1.ToInt(); + // //prop1: + // // SiemensDevice.GetInstance.MySiemens.Write("DB4.DBD130", item); + // SiemensDevice.GetInstance.MySiemens.Write($"DB4.DBX130.{DeviceNum - 1}", true); + // Task.Run(() => + // { + // int cout = DeviceNum - 1; + // while (!SiemensDevice.GetInstance.MySiemens.Read($"DB3.DBX148.{cout}").Content) //DB3.DBX148.0-31 148.0-148.5代表6个料仓位置 + // { + // SiemensDevice.GetInstance.MySiemens.Write($"DB4.DBX130.{cout}", true); + // Thread.Sleep(200); + // } + // while (SiemensDevice.GetInstance.MySiemens.Read($"DB3.DBX148.{cout}").Content) + // { + // SiemensDevice.GetInstance.MySiemens.Write($"DB4.DBX130.{cout}", false); + // } + // MessageNotify.GetInstance.ShowRunLog($"{cout}号气缸复位信号写入成功!"); + // }); + // var res = recipeProcesses.ElementAt(recIndex).RawMaterials.FirstOrDefault(p => p.Status != Status.配料完成 && p.RawMaterialName == tempRawMaterialName && p.Loc == j + 1); + // if (res != null) + // res.Status = Status.配料完成; - Thread.Sleep(100); - }), "RecipeControlViewModelStatusInquire", true); - } + + // MessageNotify.GetInstance.ShowRunLog($"设备完成执行状态:{rrr}"); + // MessageNotify.GetInstance.ShowRunLog($"柔性味魔方{Recipes.ElementAt(i).RawMaterials.ElementAt(loc).DeviceIp},出料完成,状态复位"); + + // } + + + // } + // } + // } + // } + // } + // //508配料项目代码 + // //if (GlobalDevice.PlcData.IsAllowIngredients[j]) + // //{ + // // int barrel = j + 1;//桶号 + // // int cnt = GlobalDevice.PlcData.LocationFeedback[j];//允许配料的位置 1~10 + // // if (RTrig.GetInstance("a").Start(GlobalDevice.PlcData.IsAllowIngredients[j])) + // // { + // // MessageNotify.GetInstance.ShowRunLog($"桶号:{barrel},位置:{cnt},允许配料"); + // // } + // // int Location1 = 0; + // // if (cnt == -1) + // // { + // // MessageNotify.GetInstance.ShowRunLog("没有读取到配料的位置"); + // // return; + // // } + // // else + // // { + // // int a1 = Array.FindIndex(DeviceInquire.GetInstance.devices.ToArray(), p => p.DeviceNum == cnt); + // // Location1 = Array.FindIndex(Recipes.ElementAt(i).RawMaterials.ToArray(), p => p.RawMaterialName == DeviceInquire.GetInstance.devices.ElementAt(a1).DeviceName && p.Loc == barrel); + // // } + // // if (Location1 >= 0) + // // { + // // string RawName = Recipes.ElementAt(i).RawMaterials.ElementAt(Location1).RawMaterialName; + // // int abc = Array.FindIndex(DeviceInquire.GetInstance.devices.ToArray(), p => p.DeviceName == RawName); + // // int DeviceNum = DeviceInquire.GetInstance.devices.ElementAt(abc).DeviceNum; + // // if (DeviceNum > 0) + // // { + // // float weight = Recipes.ElementAt(i).RawMaterials.ElementAt(Location1).RawMaterialWeight; + // // int loc = Array.FindIndex(Recipes.ElementAt(i).RawMaterials.ToArray(), p => p.RawMaterialName == RawName); + // // if (loc >= 0 && RawName != null && weight >= 0) + // // { + // // int St_index = Array.FindIndex(StockStatus.ToArray(), p => p.MaterialName == RawName); + // // if (St_index < 0) + // // { + // // StockStatus.Add(new StockStatusModel() + // // { + // // MaterialName = RawName, + // // IssueWeight = weight, + // // IssueStatus = 0, + // // }); + // // } + // // St_index = Array.FindIndex(StockStatus.ToArray(), p => p.MaterialName == RawName); + // // if (St_index >= 0) + // // { + // // if (recipeProcesses.ElementAt(recIndex).RawMaterials.ElementAt(loc).RecipeStatus == 1 && StockStatus.ElementAt(St_index).IssueStatus == 0) + // // { + // // StockStatus.ElementAt(St_index).IssueStatus = 1; + // // DeviceInquire.GetInstance.GetDevice(Recipes.ElementAt(i).RawMaterials.ElementAt(loc).DeviceIp).Start(weight); + // // MessageNotify.GetInstance.ShowRunLog($"柔性味魔方{Recipes.ElementAt(i).RawMaterials.ElementAt(loc).DeviceIp},开始出料"); + // // } + // // if (recipeProcesses.ElementAt(recIndex).RawMaterials.ElementAt(loc).RecipeStatus == 3 && StockStatus.ElementAt(St_index).IssueStatus == 1) + // // { + // // //GlobalDevice.PlcData.IsAllowIngredients[j] = false;//测试使用 + // // StockStatus.ElementAt(St_index).IssueStatus = 2; + // // DeviceInquire.GetInstance.GetDevice(Recipes.ElementAt(i).RawMaterials.ElementAt(loc).DeviceIp).StatusReset(); + // // /*int a = 0.SetBitValue((byte)(DeviceNum), true); + // // byte[] test1 = a.ToBytes(BPA.Helper.DataFormat.ABCD); + // // int item = test1.ToInt();*/ + // // if (DeviceNum >= 1 && DeviceNum <= 8) + // // { + // // SiemensDevice.GetInstance.MySiemens.Write("DB4.DBX130." + (DeviceNum - 1), true); + // // }else if (DeviceNum >= 9 && DeviceNum <= 16) + // // { + // // SiemensDevice.GetInstance.MySiemens.Write("DB4.DBX131." + (DeviceNum - 9), true); + // // } + // // else if (DeviceNum >=17 && DeviceNum <= 24) + // // { + // // SiemensDevice.GetInstance.MySiemens.Write("DB4.DBX132." + (DeviceNum - 17), true); + // // }else if (DeviceNum >= 25 && DeviceNum <= 32) + // // { + // // SiemensDevice.GetInstance.MySiemens.Write("DB4.DBX133." + (DeviceNum - 25), true); + // // } + // // MessageNotify.GetInstance.ShowRunLog($"料仓:{DeviceNum},配料完成"); + // // /*string res = SiemensDevice.GetInstance.MySiemens.Write("DB4.DBD130", item, 2); + // // MessageNotify.GetInstance.ShowRunLog($"{res}"); + // // MessageNotify.GetInstance.ShowRunLog($"DB4.DBD130:{item.ToBinString()}");*/ + // // MessageNotify.GetInstance.ShowRunLog($"柔性味魔方{Recipes.ElementAt(i).RawMaterials.ElementAt(loc).DeviceIp},出料完成,状态复位"); + // // } + // // } + // // } + // // } + // // } + // //} + // } + + // if (ComCount >= Recipes.ElementAt(i).RawMaterials.Count) //配方配料完成 StockStatus.Count >= Recipes.ElementAt(i).RawMaterials.Count && + // { + // int cc = recipeProcesses.ElementAt(recIndex).RawMaterials.OrderBy(p => p.RawMaterialName).Count(); + // for (int k = 0; k < 32; k++) + // { + // for (int l = 0; l < cc; l++) + // { + // RTrig.GetInstance($"ac{k}-{l}").Start(false); + // } + // } + // ComCount = 0; + + // StockStatus.Clear(); + // MessageNotify.GetInstance.ShowUserLog($"配方:{recipeProcesses.ElementAt(recIndex).RecipeName},配料完成"); + // foreach (var item in recipeProcesses.ElementAt(recIndex).RawMaterials) + // { + // MessageNotify.GetInstance.ShowUserLog($"原料:{item.RawMaterialName},桶号:{item.Loc},设定配料重量{item.RawMaterialWeight}g,实际配料重量{item.UpLimtWeightFeedback}g"); + // } + // SiemensDevice.GetInstance.MySiemens.Write("DB4.DBX202.0", true);//配料完成 + // MessageNotify.GetInstance.ShowRunLog($"配方:{CurrentRecipeName},配料完成"); + // int recipIndex = Array.FindIndex(Recipes.ToArray(), p => p.RecipeName == CurrentRecipeName); + // App.Current.Dispatcher.Invoke(new Action(() => { recipeProcesses.Clear(); })); + // Recipes.ElementAt(recipIndex).IsEnable = true; + // Json.Data.Recipes.ElementAt(recipIndex).IsEnable = true; + // Recipes.ElementAt(recipIndex).Are.Set(); + // Thread.Sleep(100); + // } + // } + // } + // } + // } + // #endregion + + // Thread.Sleep(100); + // }), "RecipeControlViewModelStatusInquire", true); + //} public BPARelayCommand StartCommand { get; set; } - public BPARelayCommand ChangeRecipeStateCommand { get; set; } + //public BPARelayCommand ChangeRecipeStateCommand { get; set; } public BPARelayCommand CancelRecipeCommand { get; set; } - public static ObservableCollection Recipes { get; set; } = Json.Data.Recipes; + //public static ObservableCollection Recipes { get; set; } = Json.Data.Recipes; - public static string CurrentRecipeName { get { return _RecipeName; } set { _RecipeName = value; OnStaticPropertyChanged(); } } - private static string _RecipeName; + // public static string CurrentRecipeName { get { return _RecipeName; } set { _RecipeName = value; OnStaticPropertyChanged(); } } + // private static string _RecipeName; /// /// 当前正在制作的配方 /// - public static ObservableCollection recipeProcesses { get; set; } = new ObservableCollection(); + public static ObservableCollection recipeProcesses { get; set; } = ExcuteControl.GetInstance.recipeProcesses; /// /// 等待制作的配方 /// - public static ObservableCollection UserTreeWait { get; set; } = new ObservableCollection(); + //public static ObservableCollection UserTreeWait { get; set; } = new ObservableCollection(); /// /// 已完成的配方 /// - public static ObservableCollection UserTreeCompelete { get; set; } = new ObservableCollection(); + //public static ObservableCollection UserTreeCompelete { get; set; } = new ObservableCollection(); - private void ChangeRecipeState(object o) - { - if (o == null) return; - if (o is string id) - { - var Recipe = recipeProcesses.FirstOrDefault(p => p.RecipeName == CurrentRecipeName); - if (Recipe != null) - { - var res = Recipe.RawMaterials.FirstOrDefault(p => p.RawMaterialId == id); - //var res1=Recipe.RawMaterials.Where(p => p.RawMaterialId == id); - if (res != null) - { - if (res.RecipeStatus == 3) - { - res.RecipeStatus = 1; - } - else - { - res.RecipeStatus = 3; - } - } - } - } - } + //private void ChangeRecipeState(object o) + //{ + // if (o == null) return; + // if (o is string id) + // { + // var Recipe = recipeProcesses.FirstOrDefault(p => p.RecipeName == CurrentRecipeName); + // if (Recipe != null) + // { + // var res = Recipe.RawMaterials.FirstOrDefault(p => p.RawMaterialId == id); + // //var res1=Recipe.RawMaterials.Where(p => p.RawMaterialId == id); + // if (res != null) + // { + // if (res.RecipeStatus == 3) + // { + // res.RecipeStatus = 1; + // } + // else + // { + // res.RecipeStatus = 3; + // } + // } + // } + // } + //} } diff --git a/DosingSystem/ViewModel/RecipeSettingsViewModel.cs b/DosingSystem/ViewModel/RecipeSettingsViewModel.cs index 7e97422b..c0bdc6db 100644 --- a/DosingSystem/ViewModel/RecipeSettingsViewModel.cs +++ b/DosingSystem/ViewModel/RecipeSettingsViewModel.cs @@ -1,22 +1,10 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using BPA.Helper; -using System.Collections.Concurrent; -using System.Collections.ObjectModel; -using System.Windows; -using BPA.Helper; - -using BPASmartClient.DosingSystem.View; +using BPA.Helper; +using BPASmartClient.CustomResource.Pages.Model; using BPASmartClient.CustomResource.UserControls; -using BPASmartClient.CustomResource.UserControls.Model; -using BPASmartClient.CustomResource.UserControls.Enum; -using System.Windows.Media; using BPASmartClient.CustomResource.UserControls.MessageShow; -using BPASmartClient.CustomResource.Pages.Model; -using BPASmartClient.Model; +using BPASmartClient.DosingSystem.View; +using System.Collections.ObjectModel; +using System.Linq; namespace BPASmartClient.DosingSystem.ViewModel { diff --git a/DosingSystem/ViewModel/StockControViewModel.cs b/DosingSystem/ViewModel/StockControViewModel.cs index 7b864bfe..8709c829 100644 --- a/DosingSystem/ViewModel/StockControViewModel.cs +++ b/DosingSystem/ViewModel/StockControViewModel.cs @@ -1,11 +1,5 @@ - -using System; -using System.Collections.Generic; +using BPA.Helper; using System.Collections.ObjectModel; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using BPA.Helper; namespace BPASmartClient.DosingSystem.ViewModel diff --git a/DosingSystem/ViewModel/TempManageControlViewModel.cs b/DosingSystem/ViewModel/TempManageControlViewModel.cs index 727c4f30..0bb9b37c 100644 --- a/DosingSystem/ViewModel/TempManageControlViewModel.cs +++ b/DosingSystem/ViewModel/TempManageControlViewModel.cs @@ -1,10 +1,6 @@ using BPA.Communication; using BPA.Helper; //using BPASmartClient.S7Net; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; using System.Threading; using System.Threading.Tasks; diff --git a/DosingSystem/ViewModel/UHardwareStatusViewModel.cs b/DosingSystem/ViewModel/UHardwareStatusViewModel.cs index 82481bfd..885dddd0 100644 --- a/DosingSystem/ViewModel/UHardwareStatusViewModel.cs +++ b/DosingSystem/ViewModel/UHardwareStatusViewModel.cs @@ -1,13 +1,9 @@ using BPA.Helper; -using BPASmartClient.DosingSystem.Model; -using BPASmartClient.DosingSystem; using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Linq; -using System.Text; using System.Threading; -using System.Threading.Tasks; namespace BPASmartClient.DosingSystem.ViewModel { @@ -37,10 +33,10 @@ namespace BPASmartClient.DosingSystem.ViewModel //TopDeviceCurrentStatuses = DeviceInquire.GetInstance.TopDeviceCurrentStatuses; //BottomDeviceCurrentStatuses = DeviceInquire.GetInstance.BottomDeviceCurrentStatuses; //2023/7/3调整 - TopDeviceCurrentStatuses= ConvertToObservableCollention(DeviceInquire.GetInstance.TopDeviceCurrentStatuses.OrderByDescending(p => p.DeviceNum).Reverse()); + TopDeviceCurrentStatuses = ConvertToObservableCollention(DeviceInquire.GetInstance.TopDeviceCurrentStatuses.OrderByDescending(p => p.DeviceNum).Reverse()); BottomDeviceCurrentStatuses = ConvertToObservableCollention(DeviceInquire.GetInstance.BottomDeviceCurrentStatuses.OrderByDescending(p => p.DeviceNum).Reverse()); UnifordColumNum(); - + TaskManage.GetInstance.StartLong(new Action(() => { for (int i = 0; i < Json.Data.OutletInfoModels.Count; i++) @@ -64,7 +60,7 @@ namespace BPASmartClient.DosingSystem.ViewModel StatusUpdate(BottomDeviceCurrentStatuses); OnDetection = GlobalDevice.PlcData.OnDetection; UnderDetection = GlobalDevice.PlcData.UnderDetection; - ConveyerBeltStatus = GlobalDevice.MotorControlFeedback>0?2: GlobalDevice.MotorControlFeedback; + ConveyerBeltStatus = GlobalDevice.MotorControlFeedback > 0 ? 2 : GlobalDevice.MotorControlFeedback; Thread.Sleep(100); }), "输送带料仓状态监控", true); @@ -115,7 +111,7 @@ namespace BPASmartClient.DosingSystem.ViewModel { //StockNum = Json.Data.BaseParModel.StockCount; - StockNum=TopDeviceCurrentStatuses.Count >= BottomDeviceCurrentStatuses.Count ? TopDeviceCurrentStatuses.Count : BottomDeviceCurrentStatuses.Count; + StockNum = TopDeviceCurrentStatuses.Count >= BottomDeviceCurrentStatuses.Count ? TopDeviceCurrentStatuses.Count : BottomDeviceCurrentStatuses.Count; } @@ -166,5 +162,5 @@ namespace BPASmartClient.DosingSystem.ViewModel public bool UnderDetection { get { return _mUnderDetection; } set { _mUnderDetection = value; OnPropertyChanged(); } } private bool _mUnderDetection; } -} +} diff --git a/SmartClient.sln b/SmartClient.sln index 38c467a6..4a6cb3e9 100644 --- a/SmartClient.sln +++ b/SmartClient.sln @@ -164,9 +164,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BPASmartClient.FoodStationT EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BPASmartClient.MorkCL", "BPASmartClient.MorkCL\BPASmartClient.MorkCL.csproj", "{918B73A6-B6FF-46FE-8C96-8474A5BD648B}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Test", "Test\Test.csproj", "{36E8EDC4-DD22-4968-B43A-984A5DDE5D78}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Test", "Test\Test.csproj", "{36E8EDC4-DD22-4968-B43A-984A5DDE5D78}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "阿里云IOT平台测试", "阿里云IOT平台测试\阿里云IOT平台测试.csproj", "{774286FD-0C88-4592-972C-101239F75954}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "阿里云IOT平台测试", "阿里云IOT平台测试\阿里云IOT平台测试.csproj", "{774286FD-0C88-4592-972C-101239F75954}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -1542,6 +1542,26 @@ Global {918B73A6-B6FF-46FE-8C96-8474A5BD648B}.Release|x64.Build.0 = Release|Any CPU {918B73A6-B6FF-46FE-8C96-8474A5BD648B}.Release|x86.ActiveCfg = Release|Any CPU {918B73A6-B6FF-46FE-8C96-8474A5BD648B}.Release|x86.Build.0 = Release|Any CPU + {36E8EDC4-DD22-4968-B43A-984A5DDE5D78}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {36E8EDC4-DD22-4968-B43A-984A5DDE5D78}.Debug|Any CPU.Build.0 = Debug|Any CPU + {36E8EDC4-DD22-4968-B43A-984A5DDE5D78}.Debug|ARM.ActiveCfg = Debug|Any CPU + {36E8EDC4-DD22-4968-B43A-984A5DDE5D78}.Debug|ARM.Build.0 = Debug|Any CPU + {36E8EDC4-DD22-4968-B43A-984A5DDE5D78}.Debug|ARM64.ActiveCfg = Debug|Any CPU + {36E8EDC4-DD22-4968-B43A-984A5DDE5D78}.Debug|ARM64.Build.0 = Debug|Any CPU + {36E8EDC4-DD22-4968-B43A-984A5DDE5D78}.Debug|x64.ActiveCfg = Debug|Any CPU + {36E8EDC4-DD22-4968-B43A-984A5DDE5D78}.Debug|x64.Build.0 = Debug|Any CPU + {36E8EDC4-DD22-4968-B43A-984A5DDE5D78}.Debug|x86.ActiveCfg = Debug|Any CPU + {36E8EDC4-DD22-4968-B43A-984A5DDE5D78}.Debug|x86.Build.0 = Debug|Any CPU + {36E8EDC4-DD22-4968-B43A-984A5DDE5D78}.Release|Any CPU.ActiveCfg = Release|Any CPU + {36E8EDC4-DD22-4968-B43A-984A5DDE5D78}.Release|Any CPU.Build.0 = Release|Any CPU + {36E8EDC4-DD22-4968-B43A-984A5DDE5D78}.Release|ARM.ActiveCfg = Release|Any CPU + {36E8EDC4-DD22-4968-B43A-984A5DDE5D78}.Release|ARM.Build.0 = Release|Any CPU + {36E8EDC4-DD22-4968-B43A-984A5DDE5D78}.Release|ARM64.ActiveCfg = Release|Any CPU + {36E8EDC4-DD22-4968-B43A-984A5DDE5D78}.Release|ARM64.Build.0 = Release|Any CPU + {36E8EDC4-DD22-4968-B43A-984A5DDE5D78}.Release|x64.ActiveCfg = Release|Any CPU + {36E8EDC4-DD22-4968-B43A-984A5DDE5D78}.Release|x64.Build.0 = Release|Any CPU + {36E8EDC4-DD22-4968-B43A-984A5DDE5D78}.Release|x86.ActiveCfg = Release|Any CPU + {36E8EDC4-DD22-4968-B43A-984A5DDE5D78}.Release|x86.Build.0 = Release|Any CPU {774286FD-0C88-4592-972C-101239F75954}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {774286FD-0C88-4592-972C-101239F75954}.Debug|Any CPU.Build.0 = Debug|Any CPU {774286FD-0C88-4592-972C-101239F75954}.Debug|ARM.ActiveCfg = Debug|Any CPU diff --git a/Test/Test.csproj b/Test/Test.csproj index f511bb04..7d7f36a7 100644 --- a/Test/Test.csproj +++ b/Test/Test.csproj @@ -9,6 +9,8 @@ + + diff --git a/阿里云IOT平台测试/App.config b/阿里云IOT平台测试/App.config new file mode 100644 index 00000000..2e79a7ec --- /dev/null +++ b/阿里云IOT平台测试/App.config @@ -0,0 +1,61 @@ + + + + +
+
+
+
+
+
+
+
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/阿里云IOT平台测试/Program.cs b/阿里云IOT平台测试/Program.cs index 5651753f..6a6d103a 100644 --- a/阿里云IOT平台测试/Program.cs +++ b/阿里云IOT平台测试/Program.cs @@ -1,10 +1,275 @@ -namespace 阿里云IOT平台测试 +using BPA.PahoMQ; +using Newtonsoft.Json; +using System.Collections.Specialized; +using System.Reflection; +using System.Text; +using System.Text.RegularExpressions; +using uPLibrary.Networking.M2Mqtt.Messages; + +namespace 阿里云IOT平台测试 { + /// + /// 以输送线设备作为测试对象 + /// internal class Program { + public static bool PropertyReport = false; //属性上报主题订阅标志 + //public static bool PropertySet = false; //属性设置主题订阅标志 + + public static bool EventReport = false; //事件上报主题订阅标志 + + + //public static bool ServiceCall = false; //服务调用主题订阅标志 + + + public static string productKey = "j090GlJPJNv"; + //public static string deviceName = "Conveyer"; + //public static string deviceSecret = "b3df8aaa82de59f478dffb172acf78cd"; + + public static string deviceName = "Stock1"; + public static string deviceSecret = "b0928d8f6e36aabd94f0fce3f9b02536"; + + private static MessageHandler _messageHandler; static void Main(string[] args) { - + + //string s= JsonConvert.SerializeObject(new Test()); + //string s2 = JsonConvert.SerializeXmlNode(); + //string s1 = JsonConvert.SerializeXNode(new Test()); + + if (_messageHandler == null) + _messageHandler = new MessageHandler(new PahoMQOption() + { + Broker = "iot-06z00carjduqaue.mqtt.iothub.aliyuncs.com", + ProductKey = productKey, + DeviceName = deviceName, + DeviceSecret = deviceSecret, + Port = 1883 + + }); + //云端属性设置主题订阅及回调 + _messageHandler.Subscribe((op) => + { + op.TopicReply = $"/sys/{productKey}/{deviceName}/thing/service/property/set"; + + op.ThresholdCallback += Op_ThresholdCallback; + + }); + + + //服务订阅 + var serviceIdentifier = "RecipeSendService"; + var serviceTopicReply = $"/sys/{productKey}/{deviceName}/thing/service/{serviceIdentifier}"; + _messageHandler.Subscribe((op) => + { + op.TopicReply = serviceTopicReply; + op.ThresholdCallback += Op_ThresholdCallback1; ; // MqttPostProperty_MqttMsgPublishReceived; + + }); + + + + Console.WriteLine("云端属性设置主题订阅成功"); + Console.WriteLine("云端服务调用主题订阅成功"); + ep: string result = Console.ReadLine(); + if (result.Equals("属性上报")) + { + //属性上报与订阅 + var mqdeviceTestProperty = new PostPropertyParams(); + mqdeviceTestProperty.sys = new Sys { ack = 1 }; + mqdeviceTestProperty.method = "thing.event.property.post"; + mqdeviceTestProperty.version = "1.0"; + //默认模板 + // mqdeviceTestProperty.Model = new StockModel(); + //自定义模板 + mqdeviceTestProperty.ModelName = "StockModel"; + mqdeviceTestProperty.Model = new StockModel(); + + mqdeviceTestProperty.Init(); + var message = JsonConvert.SerializeObject(mqdeviceTestProperty); + var topic = $"/sys/{productKey}/{deviceName}/thing/event/property/post";//发布主题 + + var topicReply = $"/sys/{productKey}/{deviceName}/thing/event/property/post_reply";//订阅主题 + _messageHandler.Publish((op) => + { + op.Message = message; + op.Topic = topic; + op.TopicReply = topicReply; + if (!PropertyReport) + { + op.ThresholdCallback += MqttPostProperty_MqttMsgPublishReceived; // MqttPostProperty_MqttMsgPublishReceived; + PropertyReport = true; + } + }); + } + if (result.Equals("事件上报")) + { + string eventIdentifier = "StockModel:StockJerk1StatusEvent"; + var mqdeviceTestEvent = new PostEventParams(); + mqdeviceTestEvent.id = Guid.NewGuid().ToString(); + mqdeviceTestEvent.sys = new Sys { ack = 1 }; + mqdeviceTestEvent.method = $"thing.event.{eventIdentifier}.post"; + mqdeviceTestEvent.version = "1.0"; + mqdeviceTestEvent.@params = new EventParam { value = new EventModel (), time = new DateTimeOffset(DateTime.Now).ToUnixTimeMilliseconds() }; + var eventMessage = JsonConvert.SerializeObject(mqdeviceTestEvent); + //事件上报 + var eventTopic = $"/sys/{productKey}/{deviceName}/thing/event/{eventIdentifier}/post"; + //事件订阅主题 + var eventTopicReply = $"/sys/{productKey}/{deviceName}/thing/event/{eventIdentifier}/post_reply"; + + _messageHandler.Publish((op) => + { + op.Message = eventMessage; + op.Topic = eventTopic; + op.TopicReply = eventTopicReply; + if (!EventReport) + { + op.ThresholdCallback += MqttPostEvent_MqttMsgPublishReceived; // MqttPostProperty_MqttMsgPublishReceived; + EventReport= true; + } + }); + } + //if (result.Equals("事件上报2")) + //{ + // string eventIdentifier = "StockServoFaultEvent"; + // var mqdeviceTestEvent = new PostEventParams(); + // mqdeviceTestEvent.id = Guid.NewGuid().ToString(); + // mqdeviceTestEvent.sys = new Sys { ack = 1 }; + // mqdeviceTestEvent.method = $"thing.event.{eventIdentifier}.post"; + // mqdeviceTestEvent.version = "1.0"; + // mqdeviceTestEvent.@params = new EventParam { value = new EventModel { StockNum = 1 }, time = new DateTimeOffset(DateTime.Now).ToUnixTimeMilliseconds() }; + // var eventMessage = JsonConvert.SerializeObject(mqdeviceTestEvent); + // //事件上报 + // var eventTopic = $"/sys/{productKey}/{deviceName}/thing/event/{eventIdentifier}/post"; + // //事件订阅主题 + // var eventTopicReply = $"/sys/{productKey}/{deviceName}/thing/event/{eventIdentifier}/post_reply"; + + // _messageHandler.Publish((op) => + // { + // op.Message = eventMessage; + // op.Topic = eventTopic; + // op.TopicReply = eventTopicReply; + // if (!EventReport) + // { + // op.ThresholdCallback += MqttPostEvent_MqttMsgPublishReceived; // MqttPostProperty_MqttMsgPublishReceived; + // EventReport = true; + // } + // }); + // } + goto ep; + } + /// + /// 云端服务调用回调 + /// + /// + /// + private static void Op_ThresholdCallback1(object sender, MqttMsgPublishEventArgs e) + { + if (Regex.IsMatch(e.Topic, "[0-9a-zA-Z/]*thing/service/[0-9a-zA-Z:]*$")) + { + Console.WriteLine("---------------------------云端设备服务调用Start---------------------"); + Console.WriteLine("reply topic :" + e.Topic); + var rtn = JsonConvert.DeserializeObject>(Encoding.UTF8.GetString(e.Message, 0, e.Message.Length)); + PropertyInfo property = rtn.@params.GetType().GetProperty("Root"); + string result = property.GetValue(rtn.@params).ToString(); + var array = result.Replace("\r\n", "").Replace(" ", "").Replace("{", "").Replace("}", "").Replace("\"", "").Split(','); + Console.WriteLine("reply payload:" + Encoding.UTF8.GetString(e.Message, 0, e.Message.Length)); + Console.WriteLine("---------------------------云端设备服务调用End---------------------"); + } + } + + /// + /// 事件上报 + /// + /// + /// + /// + private static void MqttPostEvent_MqttMsgPublishReceived(object sender, MqttMsgPublishEventArgs e) + { + if (Regex.IsMatch(e.Topic, "[0-9a-zA-Z/]*thing/event/(?!property).*/(post_reply)$")) + { + Console.WriteLine("---------------------------设备事件上报Start---------------------"); + Console.WriteLine("reply topic :" + e.Topic); + var rtn = JsonConvert.DeserializeObject>(Encoding.UTF8.GetString(e.Message, 0, e.Message.Length)); + Console.WriteLine("reply payload:" + Encoding.UTF8.GetString(e.Message, 0, e.Message.Length)); + Console.WriteLine("---------------------------设备事件上报End---------------------"); + } + + } + + /// + /// 云端属性设置回调 + /// + /// + /// + /// + private static void Op_ThresholdCallback(object sender, MqttMsgPublishEventArgs e) + { + if (Regex.IsMatch(e.Topic, "[0-9a-zA-Z/]*(thing/service/property/set)$")) + { + Console.WriteLine("---------------------------云端设置属性Start---------------------"); + Console.WriteLine("reply topic :" + e.Topic); + var rtn = JsonConvert.DeserializeObject>(Encoding.UTF8.GetString(e.Message, 0, e.Message.Length)); + PropertyInfo property= rtn.@params.GetType().GetProperty("Root"); + string result=property.GetValue(rtn.@params).ToString(); + var array= result.Replace("\r\n", "").Replace(" ","").Replace("{","").Replace("}","").Replace("\"", "").Split(','); + foreach (var item in array) + { + var str=item.Split(":"); //数据格式: + switch (str[1]) + { + + + } + } + Console.WriteLine("reply payload:" + Encoding.UTF8.GetString(e.Message, 0, e.Message.Length)); + Console.WriteLine("---------------------------云端设置属性End---------------------"); + } + } + + private static void MqttPostProperty_MqttMsgPublishReceived(object sender, MqttMsgPublishEventArgs e) + { + //考虑使用正则表达判断是属性,事件,服务其中那个回调 + if (Regex.IsMatch(e.Topic, "[0-9a-zA-Z/]*thing/event/property/post_reply")) + { + Console.WriteLine("---------------------------设备端属性上报回调Start---------------------"); + var rtn = JsonConvert.DeserializeObject>(Encoding.UTF8.GetString(e.Message, 0, e.Message.Length)); + + Console.WriteLine($"code:{rtn.code}"); + Console.WriteLine("reply topic :" + e.Topic); + Console.WriteLine("messageID :" + rtn.id); + Console.WriteLine("reply payload:" + Encoding.UTF8.GetString(e.Message, 0, e.Message.Length)); + Console.WriteLine("---------------------------设备端属性上报回调End---------------------"); + } + } + } + + + /// + /// 属性测试类 + /// + public class StockModel + { + + //public string Test { get; set; } = "测试2"; + + + public int StockRealWeight { get; set; } = 250000; + + public float BucketRealWeight { get; set; } = 16000; + + public string StockBatchStatus { get; set; } = "配料完成"; + public int StockWorkModel { get; set; } = 1; + + } + + /// + /// 事件测试类 + /// + public class EventModel + { + // public string Result { get; set; } + } } \ No newline at end of file diff --git a/阿里云IOT平台测试/阿里云IOT平台测试.csproj b/阿里云IOT平台测试/阿里云IOT平台测试.csproj index 74abf5c9..b6b3e9f0 100644 --- a/阿里云IOT平台测试/阿里云IOT平台测试.csproj +++ b/阿里云IOT平台测试/阿里云IOT平台测试.csproj @@ -1,4 +1,4 @@ - + Exe @@ -7,4 +7,10 @@ enable + + + + + +