|
- //#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 System;
- using System.Collections.Concurrent;
- using System.Collections.ObjectModel;
- using System.Collections.Specialized;
- using System.Diagnostics;
- using System.Linq;
- 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;
- using static System.Resources.ResXFileRef;
- using BPASmartClient.DosingSystem.Model.Dto;
- using BPASmartClient.DosingSystem.Model.MQTT;
-
- namespace BPASmartClient.DosingSystem
- {
- /// <summary>
- /// 业务逻辑执行类
- /// </summary>
- public class ExcuteControl
- {
- private static ExcuteControl Instance;
- public static ExcuteControl GetInstance => Instance ??= new ExcuteControl();
-
- public ConcurrentDictionary<string, aliyun.BPA.PahoMQ.MessageHandler> mqttCollection = new ConcurrentDictionary<string, aliyun.BPA.PahoMQ.MessageHandler>();
-
- public ConcurrentDictionary<string, string> aliyun = new ConcurrentDictionary<string, string>();
- public ObservableCollection<RecipeModel> Recipes { get; set; } = Json<LocalRecipe>.Data.Recipes;
- public ObservableCollection<StockStatusModel> StockStatus = new ObservableCollection<StockStatusModel>();
-
- public string CurrentRecipeName { get; set; }
- /// <summary>
- /// 当前正在制作的配方
- /// </summary>
- public ObservableCollection<RecipeModel> recipeProcesses { get; set; } = new ObservableCollection<RecipeModel>();
-
- /// <summary>
- /// 等待制作的配方
- /// </summary>
- public ObservableCollection<RecipeModel> UserTreeWait { get; set; } = new ObservableCollection<RecipeModel>();
-
- /// <summary>
- /// 已完成的配方
- /// </summary>
- public ObservableCollection<RecipeModel> UserTreeCompelete { get; set; } = new ObservableCollection<RecipeModel>();
- public ConcurrentQueue<string> RecipeNames = new ConcurrentQueue<string>();
- /// <summary>
- /// 配料完成计数
- /// </summary>
- int Comcount = 0;
- 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<object>(new Action<object>((o) =>
- {
- if (o != null && o is string recipeName)
- {
- RecipeSend(recipeName);
- }
-
- }), "配方下发");
- ActionManage.GetInstance.Register<object>(new Action<object>((ob) =>
- {
- if (ob != null && ob is string recipeName)
- {
- CancelRecipe(recipeName);
- }
-
- }), "取消配方");
-
- //AliYunInit();
- //RecipeRun();
- //BusinessExcute();
- MatchRun();
- //ConveyerPropertyReport();
- //ThreadTaskInit();
- #if Debug
- Task.Run(() => {
- while (true)
- {
- if (AliyunIsConnect)
- {
- for (int i = 0; i < 6; i++)
- {
- AliyunEventReport($"192.168.0.{i+1}0", new AliyunStockEventReportModel { Result = "1" }, "StockJerk1StatusEvent", AliyunMaterialModelType.StockModel);
- AliyunEventReport($"192.168.0.{i + 1}0", new AliyunStockEventReportModel { Result = "1" }, "StockServoFalutEvent", AliyunMaterialModelType.StockModel);
- AliyunEventReport($"192.168.0.{i + 1}0", new AliyunStockEventReportModel { Result = "1" }, "StockJerk2StatusEvent", AliyunMaterialModelType.StockModel);
- AliyunEventReport($"192.168.0.{i + 1}0", new AliyunStockEventReportModel { Result = "1" }, "StockUpLimitEvent", AliyunMaterialModelType.StockModel);
- AliyunEventReport($"192.168.0.{i + 1}0", 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.{i + 1}0", model);
- }
- AliyunConveyerPropertyReportModel model1 = new AliyunConveyerPropertyReportModel();
- model1.TopBucketControlStatus = 1;
- model1.DownBucketControlStatus =1;
- model1.RunStatus = 1;
- model1.WorkModel = 1;
- model1.TopBucketSigleCheck = 1;
- model1.ButtonBucketSigleCheck = 1;
- model1.ConveyerOnlineStatus =1;
- var mqdeviceTestProperty = new PostPropertyParams<AliyunConveyerPropertyReportModel>();
- mqdeviceTestProperty.sys = new Sys { ack = 1 };
- mqdeviceTestProperty.method = "thing.event.property.post";
- mqdeviceTestProperty.version = "1.0";
- mqdeviceTestProperty.ModelName = $"{produtInfo.Get("Conveyer")}";
- mqdeviceTestProperty.Model = model1;
- mqdeviceTestProperty.Init();
- var message = JsonConvert.SerializeObject(mqdeviceTestProperty);
- var topic = $"/sys/{produtInfo.Get("ProductKey")}/Conveyer/thing/event/property/post";//发布主题
-
- var topicReply = $"/sys/{produtInfo.Get("ProductKey")}/Conveyer/thing/event/property/post_reply";//订阅主题
- if (mqttCollection.ContainsKey("Conveyer"))
- {
- try
- {
- mqttCollection["Conveyer"].Publish((op) =>
- {
- op.Message = message;
- op.Topic = topic;
- op.TopicReply = topicReply;
- //if (!PropertyReport)
- //{
- // op.ThresholdCallback += MqttPostProperty_MqttMsgPublishReceived; // MqttPostProperty_MqttMsgPublishReceived;
- // PropertyReport = true;
- //}
- });
- }
- catch (Exception)
- {
-
- //throw;
- }
- }
- SystemEventReport("ProcessRecipe", new { RecipeName = "测试5" });//正在执行配方上报
- if (UserTreeWait.Count > 0)
- {
- string[] recipeNames = new string[UserTreeWait.Count];
- for (int i = 0; i < recipeNames.Length; i++)
- {
- recipeNames[i] = UserTreeWait.ElementAt(i).RecipeName;
- }
- SystemEventReport("WaitProcessRecipe", new { RecipeNames = recipeNames });//等待执行配方上报
- }
- else
- {
- SystemEventReport("WaitProcessRecipe", new { RecipeNames = new string[] { } });//等待执行配方上报
- }
- }
- Thread.Sleep(5000);
- }
- });
- #endif
-
- }
-
-
- /// <summary>
- /// 料仓属性上报
- /// </summary>
- /// <param name="ipaddres"></param>
- /// <param name="model"></param>
- public void StokcPropertyReport<T>(string ipaddres, T model)
- {
- var mqdeviceTestProperty = new PostPropertyParams<T>();
- 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]))
- {
- try
- {
- mqttCollection[aliyun[ipaddres]].Publish((op) =>
- {
- op.Message = message;
- op.Topic = topic;
- op.TopicReply = topicReply;
- //if (!PropertyReport)
- //{
- // op.ThresholdCallback += MqttPostProperty_MqttMsgPublishReceived; // MqttPostProperty_MqttMsgPublishReceived;
- // PropertyReport = true;
- //}
- });
- }
- catch (Exception)
- {
-
- //throw;
- }
- }
-
- }
-
-
-
- /// <summary>
- /// 业务系统属性上报
- /// </summary>
- public void SystemPropertyReport<T>(T model)
- {
- var mqdeviceTestProperty = new PostPropertyParams<T>();
- mqdeviceTestProperty.sys = new Sys { ack = 1 };
- mqdeviceTestProperty.method = "thing.event.property.post";
- mqdeviceTestProperty.version = "1.0";
- mqdeviceTestProperty.Model = model;
- mqdeviceTestProperty.Init();
- var message = JsonConvert.SerializeObject(mqdeviceTestProperty);
- var topic = $"/sys/{produtInfo.Get("ProductKey")}/Conveyer/thing/event/property/post";//发布主题
-
- var topicReply = $"/sys/{produtInfo.Get("ProductKey")}/Conveyer/thing/event/property/post_reply";//订阅主题
- if (mqttCollection.ContainsKey("Conveyer"))
- {
- try
- {
- mqttCollection["Conveyer"].Publish((op) =>
- {
- op.Message = message;
- op.Topic = topic;
- op.TopicReply = topicReply;
- //if (!PropertyReport)
- //{
- // op.ThresholdCallback += MqttPostProperty_MqttMsgPublishReceived; // MqttPostProperty_MqttMsgPublishReceived;
- // PropertyReport = true;
- //}
- });
- }
- catch (Exception)
- {
-
- //throw;
- }
- }
-
- }
-
-
-
-
-
-
-
- /// <summary>
- /// 取消配方
- /// </summary>
- /// <param name="RecipeName"></param>
- 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(() =>
- {
- Recipes.ElementAt(index).IsEnable = true;
- Json<LocalRecipe>.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");
- App.Current.Dispatcher.Invoke(() =>
- {
- NoticeDemoViewModel.OpenMsg(EnumPromptType.Success, App.MainWindow, "提示", $"配方 [{RecipeName}] 取消成功");
- });
- MessageNotify.GetInstance.ShowUserLog($"取消配方制作 {RecipeName}");
- //取消成功
- }));
- }
- else
- {
- //取消失败
- }
- //}
- }
- else
- {
- MessageNotify.GetInstance.ShowUserLog($"配方 {RecipeName}取消失败");
- }
-
- }
- /// <summary>
- /// 配方下发
- /// </summary>
- 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++)
- {
- string ip = Recipes.ElementAt(index).RawMaterials.ElementAt(i).DeviceIp;
- var device = DeviceInquire.GetInstance.GetDevice(ip);
- if (!device.IsConnected)
- {
- MessageNotify.GetInstance.ShowDialog($"设备 【{device.DeviceName}】 未连接,不允许下发此配方", DialogType.Error);
- return;
- }
- if (Recipes.ElementAt(index).RawMaterials.ElementAt(i).RawMaterialSource == 1)
- {
-
- 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;
- }
-
- }
-
-
- }
- Recipes.ElementAt(index).IsEnable = false;
- Json<LocalRecipe>.Data.Recipes.ElementAt(index).IsEnable = false;
- }
- MessageNotify.GetInstance.ShowUserLog($"下发工单 {Recipes.ElementAt(index).RecipeName}");
- RecipeNames.Enqueue(RecipeName);
- var res = Recipes.FirstOrDefault(p => p.RecipeName == RecipeName);
- App.Current.Dispatcher.Invoke(() => { UserTreeWait.Add(new RecipeModel { RecipStatus = "等待制作", SerialNum = UserTreeWait.Count + 1, RecipeName = RecipeName, RawMaterials = res.RawMaterials }); });
- }
- App.Current.Dispatcher.Invoke(() => { NoticeDemoViewModel.OpenMsg(EnumPromptType.Success, App.MainWindow, "提示", $"配方下发成功!"); });
- MessageNotify.GetInstance.runLogs.Add(new RunLog() { RunLogInfo = $"下发配方:{RecipeNames.Count}", Time = DateTime.Now.ToString() });
-
- }
-
- public ConcurrentDictionary<string, int> doDeviceCount = new ConcurrentDictionary<string, int>();
-
- int doDecipeCount = 0;
-
- /// <summary>
- /// 关闭上位机需要做的处理。
- /// </summary>
- public void ShutDown()
- {
-
- SimensSend.GetInstance.SendSimens.Write("M0.0", false);
- SimensSend.GetInstance.SendSimens.Write("M0.1", false);
- foreach (var item in DeviceInquire.GetInstance.DeviceLists.Values)
- {
- item.modbusTcp.Write<ushort>(DeviceAddress.TranspportSwitch.ToAdd(), 0);
- }
- TaskManage.GetInstance.StopTask("设备下发配方");
- TaskManage.GetInstance.StopTask("下发设备参数", () =>
- {
-
- });
- TaskManage.GetInstance.StopTask("控制传送带");
- }
-
- public ConcurrentDictionary<string, int> doDeviceCount = new ConcurrentDictionary<string, int>();
-
- int dd = 0;
- private void MatchRun()
- {
-
- recipeProcesses.Clear();
- TaskManage.GetInstance.StartLong(() =>
- {
- if (RecipeNames.Count > 0)
- {
- SimensSend.GetInstance.SendSimens.Write("M0.0", true);
- SimensSend.GetInstance.SendSimens.Write("M0.1", true);
- for (int i = 0; i < DeviceInquire.GetInstance.devices.Count; i++)
- {
- //判断IP是否在列表中
- if (DeviceInquire.GetInstance.DeviceLists.ContainsKey(DeviceInquire.GetInstance.devices[i].IpAddress))
- {
- //只有设备在等待配料状态才能下发数据
- if (DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].deviceStatus.RunStatus == 1)
- {
- //判断
- if (DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].deviceStatus.MaxPassPail <= DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].deviceStatus.PassPail && DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].deviceStatus.PailArrive == 0)
- {
- if (doDeviceCount.ContainsKey(DeviceInquire.GetInstance.devices[i].IpAddress))
- {
- int index = 0;
- int recipeNameNum = doDeviceCount[DeviceInquire.GetInstance.devices[i].IpAddress];
- if (recipeNameNum == DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].deviceStatus.DoRecipeCount && recipeNameNum < RecipeNames.Count)
- {
- //查找
- index = Array.FindIndex(Recipes.ToArray(), p => p.RecipeName == RecipeNames.ElementAt(recipeNameNum));
- if (index >= 0 && index < Recipes.Count)
- {
- int maxPail = 0;
- //查找配方的最大桶号。
- foreach (var rawMaterial in Recipes.ElementAt(index).RawMaterials)
- {
- if (rawMaterial.Loc > maxPail)
- {
- maxPail = rawMaterial.Loc;
- }
- }
- //清除下位设备的最大桶号,下位设备认为配方制作完一个了。
- DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].modbusTcp.Write<ushort>(DeviceAddress.DeletePassPail.ToAdd(), 1);
- DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].modbusTcp.Write<ushort>(DeviceAddress.MaxPail.ToAdd(), (ushort)maxPail);
- doDeviceCount.TryUpdate(DeviceInquire.GetInstance.devices[i].IpAddress, recipeNameNum + 1, doDeviceCount[DeviceInquire.GetInstance.devices[i].IpAddress]);
-
- App.Current.Dispatcher.Invoke(() => { NoticeDemoViewModel.OpenMsg(EnumPromptType.Success, App.MainWindow, "提示", $"配方{RecipeNames.ElementAt(recipeNameNum)}{recipeNameNum}下发到设备{DeviceInquire.GetInstance.devices[i].DeviceName}"); });
-
- if (doDeviceCount.ContainsKey("192.168.2.10") && UserTreeWait.Count > 0 && doDeviceCount["192.168.2.10"] > recipeProcesses.Count)
- {
- App.Current.Dispatcher.Invoke(() =>
- {
- recipeProcesses.Insert(0, UserTreeWait?.ToList().Find(a => a.RecipeName == RecipeNames.ElementAt(recipeNameNum)));
- UserTreeWait.RemoveAt(UserTreeWait.ToList().FindIndex(a => a.RecipeName == RecipeNames.ElementAt(recipeNameNum)));
- });
- }
- if (DeviceInquire.GetInstance.devices[i].IpAddress == "192.168.2.180" && recipeNameNum > 1 && recipeProcesses.Count > 0)
- {
- App.Current.Dispatcher.Invoke(() =>
- {
- RecipeModel recipe = recipeProcesses?.ToList().Find(a => a.RecipeName == RecipeNames.ElementAt(recipeNameNum));
- recipe.RecipStatus = "制作完成";
- UserTreeCompelete.Insert(0, recipe);
- recipeProcesses.RemoveAt(recipeProcesses.ToList().FindIndex(a => a.RecipeName == RecipeNames.ElementAt(recipeNameNum)));
- });
- }
- }
-
- }
- }
- else
- {
- doDeviceCount.TryAdd(DeviceInquire.GetInstance.devices[i].IpAddress, 0);
- }
-
- }
- }
-
-
- }
- }
- //if (doDeviceCount.ContainsKey("192.168.2.10")&&doDeviceCount.ContainsKey($"192.168.2.{Json<DevicePar>.Data.BaseParModel.StockCount * 10}"))
- //{
- // if (doDeviceCount[$"192.168.2.{Json<DevicePar>.Data.BaseParModel.StockCount * 10}"] > 0 && DeviceInquire.GetInstance.DeviceLists[$"192.168.2.{Json<DevicePar>.Data.BaseParModel.StockCount * 10}"].deviceStatus.DoRecipeCount == doDeviceCount[$"192.168.2.{Json<DevicePar>.Data.BaseParModel.StockCount * 10}"])
- // {
- // App.Current.Dispatcher.Invoke(new Action(() =>
- // {
- // UserTreeCompelete.Insert(0, recipeProcesses.Last());
- // recipeProcesses.Remove(recipeProcesses.Last());
- // }));
-
- // }
- // if (DeviceInquire.GetInstance.DeviceLists["192.168.2.10"].deviceStatus.DoRecipeCount == doDeviceCount["192.168.2.10"])
- // {
- // App.Current.Dispatcher.Invoke(new Action(() =>
- // {
- // if (UserTreeWait.Count > 0)
- // {
- // recipeProcesses.Insert(0, UserTreeWait[0]);
- // UserTreeWait.RemoveAt(0);
- // }
- // }));
- // }
- //}
-
-
- }
-
-
- Thread.Sleep(10);
- }, "设备下发配方");
- TaskManage.GetInstance.StartLong(() =>
- {
-
- for (int i = 0; i < DeviceInquire.GetInstance.devices.Count; i++)
- {
- if (DeviceInquire.GetInstance.DeviceLists.ContainsKey(DeviceInquire.GetInstance.devices[i].IpAddress) && doDeviceCount.ContainsKey(DeviceInquire.GetInstance.devices[i].IpAddress))
- {
- //判断桶到位 和 状态为等待配料。
- if (DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].deviceStatus.PailArrive == 1 && DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].deviceStatus.RunStatus == 1 && DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].deviceStatus.DoRecipeCount > 0)
- {
- int doCount = Array.FindIndex(Recipes.ToArray(), p => p.RecipeName == RecipeNames.ElementAt(DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].deviceStatus.DoRecipeCount - 1));
- if (doCount >= 0 && doCount < Recipes.Count)
- {
- //根据物料名称查找
- var res = Recipes.ElementAt(doCount).RawMaterials?.ToList().FindAll(a => a.RawMaterialName == DeviceInquire.GetInstance.devices[i].DeviceName);
-
- foreach (RawMaterialModel item in res)
- {
- //可能是多个桶都需要下同一种料,根据已通过桶数和当前物料信息的通号做对比。
- if (item != null && item.Loc == DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].deviceStatus.PassPail)
- {
- DeviceParModel deviceSet = Json<DevicePar>.Data.deviceParModels?.ToList().Find(a => a.MaterialName == DeviceInquire.GetInstance.devices[i].DeviceName);
- if (deviceSet != null && DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].IsConnected == true)
- {
- var deviceModbus = DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].modbusTcp;
- //传送带停止
- deviceModbus.Write<ushort>(DeviceAddress.TranspportSwitch.ToAdd(), 0);
- //设置下料重量
- deviceModbus.Write<float>(DeviceAddress.WeightSet.ToAdd(), item.RawMaterialWeight);
- //设置慢加重量
- deviceModbus.Write<float>(DeviceAddress.SlowlyAddWeight.ToAdd(), deviceSet.SlowlyAddWeight);
- //设置快慢加速度
- deviceModbus.Write<float>(DeviceAddress.SlowlyAddWeight.ToAdd(), deviceSet.SlowAcceleration);
- deviceModbus.Write<float>(DeviceAddress.RapidAcceleration.ToAdd(), deviceSet.RapidAcceleration);
- //设置提前关阀重量
- deviceModbus.Write<float>(DeviceAddress.PreCloseValveWeight.ToAdd(), deviceSet.PreCloseValveWeight);
- //设置伺服手动速度
- deviceModbus.Write<float>(DeviceAddress.ServoManualSpeed.ToAdd(), deviceSet.ServoManualSpeed);
- //设置料仓上下限重量
- deviceModbus.Write<float>(DeviceAddress.SiloUpperLimitWeight.ToAdd(), deviceSet.SiloUpperLimitWeight);
- deviceModbus.Write<float>(DeviceAddress.LowerLimitWeightOfSilo.ToAdd(), deviceSet.LowerLimitWeightOfSilo);
- //开始配料信号
- deviceModbus.Write<ushort>(DeviceAddress.Start.ToAdd(), (ushort)1);
- ////设置搅拌速度
- //DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].modbusTcp.Write<int>(DeviceAddress.StirringSpeed.ToAdd(), deviceSet.StirringSpeed);
- }
- }
- }
- }
-
-
- }
- }
-
- }
-
- Thread.Sleep(10);
- }, "下发设备参数");
- DeviceStatus nextDevice = new DeviceStatus();
- TaskManage.GetInstance.StartLong(() =>
- {
-
- for (int i = 0; i < DeviceInquire.GetInstance.devices.Count; i++)
- {
- if (DeviceInquire.GetInstance.DeviceLists.ContainsKey(DeviceInquire.GetInstance.devices[i].IpAddress))
- {
- //90 是中转流水线的IP。
- if (DeviceInquire.GetInstance.devices[i].IpAddress == "192.168.2.90")
- {
- //如果中转线的下一个设备有桶的话,就先把中转线停住。
- if (DeviceInquire.GetInstance.DeviceLists[ DeviceInquire.GetInstance.devices[i].IpAddress].deviceStatus.PailArrive == 1)
- {
- SimensSend.GetInstance.SendSimens.Write("DB1.DBX702.0", 0);
- }
- else
- {
- SimensSend.GetInstance.SendSimens.Write("DB1.DBW104", (ushort)1400);
- SimensSend.GetInstance.SendSimens.Write("DB1.DBX702.0", 1);
- }
- }
- if (DeviceInquire.GetInstance.devices[i].IpAddress != $"192.168.2.{Json<DevicePar>.Data.BaseParModel.StockCount * 10}")
- {
-
- ushort deviceNum = DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].deviceStatus.DeviceNum;
- string nextIp = "";
- if (DeviceInquire.GetInstance.DeviceLists.TryGetValue($"{Json<DevicePar>.Data.BaseParModel.NetworkSegAddress}{(deviceNum+1) * 10}", out nextDevice)&& deviceNum!=0)
- {
- nextIp = DeviceInquire.GetInstance.DeviceLists.ToList().Find(q => q.Value == nextDevice).Key;
- }
- if ( nextIp != "")
- {
- //if (DeviceInquire.GetInstance.DeviceLists["192.168.2.10"].deviceStatus.RunStatus == 1 || DeviceInquire.GetInstance.DeviceLists["192.168.2.10"].deviceStatus.RunStatus == 3)
- //{
- // DeviceParModel deviceSet = Json<DevicePar>.Data.deviceParModels?.ToList().Find(a => a.MaterialName == DeviceInquire.GetInstance.devices[i].DeviceName);
- // DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].modbusTcp.Write<ushort>(DeviceAddress.TranspportSp.ToAdd(), 1000);
- // DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].modbusTcp.Write<ushort>(DeviceAddress.TranspportSwitch.ToAdd(), 1);
- //}
- if (DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].deviceStatus.RunStatus == 1 || DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].deviceStatus.RunStatus == 3)
- {
-
- if (DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].deviceStatus.PailArrive == 1 && DeviceInquire.GetInstance.DeviceLists[nextIp].deviceStatus.PailArrive == 1)
- {
- DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].modbusTcp.Write<ushort>(DeviceAddress.TranspportSwitch.ToAdd(),(ushort)0);
- }
- else
- {
- DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].modbusTcp.Write<ushort>(DeviceAddress.TranspportSp.ToAdd(), 600);
- DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].modbusTcp.Write<ushort>(DeviceAddress.TranspportSwitch.ToAdd(), (ushort)1);
- }
- }
- else
- {
- DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].modbusTcp.Write<ushort>(DeviceAddress.TranspportSwitch.ToAdd(), 0);
- //传送带停止
- }
-
- //DeviceInquire.GetInstance.DeviceLists["192.168.2.130"].modbusTcp.Write<ushort>(DeviceAddress.TranspportSp.ToAdd(), 1000);
- //DeviceInquire.GetInstance.DeviceLists["192.168.2.130"].modbusTcp.Write<ushort>(DeviceAddress.TranspportSwitch.ToAdd(), 0);
- //else if (DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].deviceStatus.RunStatus == 3 && DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i + 1].IpAddress].deviceStatus.PailArrive == 1)
- //{
- // //传送带运行
- // DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].modbusTcp.Write<ushort>(DeviceAddress.Start.ToAdd(), (ushort)1);
- // DeviceParModel deviceSet = Json<DevicePar>.Data.deviceParModels?.ToList().Find(a => a.MaterialName == DeviceInquire.GetInstance.devices[i].DeviceName);
- // DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].modbusTcp.Write<ushort>(DeviceAddress.TranspportSp.ToAdd(), deviceSet.SendSp);
- // DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].modbusTcp.Write<ushort>(DeviceAddress.TranspportSwitch.ToAdd(), 1);
- //}
-
- }
- else
- {
- DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].modbusTcp.Write<ushort>(DeviceAddress.TranspportSwitch.ToAdd(), 0);
- }
-
- }
- else
- {
- if (SimensSend.GetInstance.sendCtrlModel.SendInfo&& DeviceInquire.GetInstance.DeviceLists[$"192.168.2.{(Json<DevicePar>.Data.BaseParModel.StockCount) * 10}"].deviceStatus.PailArrive == 1)
- {
- DeviceInquire.GetInstance.DeviceLists[$"192.168.2.{Json<DevicePar>.Data.BaseParModel.StockCount * 10}"].modbusTcp.Write<ushort>(DeviceAddress.TranspportSwitch.ToAdd(), (ushort)0);
- }
- else
- {
- DeviceInquire.GetInstance.DeviceLists[$"192.168.2.{Json<DevicePar>.Data.BaseParModel.StockCount * 10}"].modbusTcp.Write<ushort>(DeviceAddress.TranspportSp.ToAdd(), 600);
- DeviceInquire.GetInstance.DeviceLists[$"192.168.2.{Json<DevicePar>.Data.BaseParModel.StockCount * 10}"].modbusTcp.Write<ushort>(DeviceAddress.TranspportSwitch.ToAdd(), (ushort)1);
- }
- }
- }
- }
-
-
- Thread.Sleep(10);
- }, "控制传送带");
-
- #region 弃用配料流程
- //弃用配料流程
- //TaskManage.GetInstance.StartLong(() =>
- //{
- // if (RecipeNames.Count > 0)
- // {
- // SimensSend.GetInstance.SendSimens.Write("M0.0", true);
- // SimensSend.GetInstance.SendSimens.Write("M0.1", true);
- // if (DeviceInquire.GetInstance.DeviceLists[$"192.168.2.{Json<DevicePar>.Data.BaseParModel.StockCount * 10}"].deviceStatus.MaxPassPail != 0 && DeviceInquire.GetInstance.DeviceLists[$"192.168.2.{Json<DevicePar>.Data.BaseParModel.StockCount * 10}"].deviceStatus.MaxPassPail == DeviceInquire.GetInstance.DeviceLists[$"192.168.2.{Json<DevicePar>.Data.BaseParModel.StockCount * 10}"].deviceStatus.PassPail && DeviceInquire.GetInstance.DeviceLists[$"192.168.2.{Json<DevicePar>.Data.BaseParModel.StockCount * 10}"].deviceStatus.RunStatus == 1)
- // {
- // recipeProcesses.Remove(recipeProcesses.Last());
- // UserTreeCompelete.Insert(0, recipeProcesses.Last());
-
- // }
- // for (int i = 0; i < DeviceInquire.GetInstance.devices.Count; i++)
- // {
- // if (DeviceInquire.GetInstance.DeviceLists.ContainsKey(DeviceInquire.GetInstance.devices[i].IpAddress))
- // {
-
-
- // if (DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].deviceStatus.MaxPassPail == 0 || DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].deviceStatus.RunStatus == 1)
- // {
-
- // if (DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].deviceStatus.MaxPassPail == DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].deviceStatus.PassPail|| recipeProcesses.Count==0)
- // {
-
- // int index = Array.FindIndex(Recipes.ToArray(), p => p.RecipeName == RecipeNames.ElementAt(0));
- // if (index >= 0 && index < Recipes.Count)
- // {
- // App.Current.Dispatcher.Invoke(new Action(() =>
- // {
- // if (UserTreeWait.Count > 0)
- // {
- // recipeProcesses.Insert(0, UserTreeWait?.ToList().Find(a => a.RecipeName == RecipeNames.ElementAt(0)));
- // UserTreeWait.RemoveAt(UserTreeWait.ToList().FindIndex(a => a.RecipeName == RecipeNames.ElementAt(0)));
- // }
- // }));
- // int maxPail = 0;
- // foreach (var rawMaterial in Recipes.ElementAt(index).RawMaterials)
- // {
- // if (rawMaterial.Loc > maxPail)
- // {
- // maxPail = rawMaterial.Loc;
- // }
- // }
- // DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].modbusTcp.Write<ushort>(DeviceAddress.DeletePassPail.ToAdd(), 1);
- // //Thread s = new Thread(() => { mmm(); });
- // DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].modbusTcp.Write<ushort>(DeviceAddress.MaxPail.ToAdd(), (ushort)maxPail);
-
- // }
- // }
-
-
-
- // if (DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].deviceStatus.PailArrive == 1 && DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].deviceStatus.RunStatus == 1)
- // {
- // int doCount = Array.FindIndex(Recipes.ToArray(), p => p.SerialNum == (int)DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].deviceStatus.DoRecipeCount-1) ;
- // if (doCount >=0)
- // {
- // var res = Recipes.ElementAt(doCount).RawMaterials?.ToList().FindAll(a => a.RawMaterialName == DeviceInquire.GetInstance.devices[i].DeviceName);
- // foreach (RawMaterialModel item in res)
- // {
- // if (item != null && item.Loc == DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].deviceStatus.PassPail)
- // {
- // DeviceParModel deviceSet = Json<DevicePar>.Data.deviceParModels?.ToList().Find(a => a.MaterialName == DeviceInquire.GetInstance.devices[i].DeviceName);
- // if (deviceSet != null)
- // {
- // //开始配料信号
- // DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].modbusTcp.Write<ushort>(DeviceAddress.Start.ToAdd(), (ushort)1);
- // //传送带停止
- // DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].modbusTcp.Write<ushort>(DeviceAddress.TranspportSwitch.ToAdd(), 0);
- // //设置下料重量
- // DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].modbusTcp.Write<float>(DeviceAddress.WeightSet.ToAdd(), item.RawMaterialWeight);
- // //设置慢加重量
- // DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].modbusTcp.Write<float>(DeviceAddress.SlowlyAddWeight.ToAdd(), deviceSet.SlowlyAddWeight);
- // //设置快慢加速度
- // DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].modbusTcp.Write<float>(DeviceAddress.SlowlyAddWeight.ToAdd(), deviceSet.SlowAcceleration);
- // DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].modbusTcp.Write<float>(DeviceAddress.RapidAcceleration.ToAdd(), deviceSet.RapidAcceleration);
- // //设置提前关阀重量
- // DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].modbusTcp.Write<float>(DeviceAddress.PreCloseValveWeight.ToAdd(), deviceSet.PreCloseValveWeight);
- // //设置伺服手动速度
- // DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].modbusTcp.Write<float>(DeviceAddress.ServoManualSpeed.ToAdd(), deviceSet.ServoManualSpeed);
- // //设置料仓上下限重量
- // DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].modbusTcp.Write<float>(DeviceAddress.SiloUpperLimitWeight.ToAdd(), deviceSet.SiloUpperLimitWeight);
- // DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].modbusTcp.Write<float>(DeviceAddress.LowerLimitWeightOfSilo.ToAdd(), deviceSet.LowerLimitWeightOfSilo);
- // ////设置搅拌速度
- // //DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].modbusTcp.Write<int>(DeviceAddress.StirringSpeed.ToAdd(), deviceSet.StirringSpeed);
- // }
- // }
- // }
- // }
- // }
-
-
-
- // }
- // if (DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].deviceStatus.MaxPassPail != 0 && (DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].deviceStatus.RunStatus == 3 && DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].deviceStatus.MaxPassPail == DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].deviceStatus.PassPail))
- // {
- // string passName = RecipeNames.ElementAt(0);
- // RecipeNames.TryDequeue(out passName);
- // }
- // if (DeviceInquire.GetInstance.devices[i].IpAddress != $"192.168.2.{Json<DevicePar>.Data.BaseParModel.StockCount * 10}")
- // {
- // if (DeviceInquire.GetInstance.DeviceLists["192.168.2.10"].deviceStatus.RunStatus == 1 || DeviceInquire.GetInstance.DeviceLists["192.168.2.10"].deviceStatus.RunStatus == 3)
- // {
- // DeviceParModel deviceSet = Json<DevicePar>.Data.deviceParModels?.ToList().Find(a => a.MaterialName == DeviceInquire.GetInstance.devices[i].DeviceName);
- // DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].modbusTcp.Write<ushort>(DeviceAddress.TranspportSp.ToAdd(), 1000);
- // DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].modbusTcp.Write<ushort>(DeviceAddress.TranspportSwitch.ToAdd(), 1);
- // }
- // //if (DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].deviceStatus.RunStatus == 1 || DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].deviceStatus.RunStatus == 3)
- // //{
- // // DeviceParModel deviceSet = Json<DevicePar>.Data.deviceParModels?.ToList().Find(a => a.MaterialName == DeviceInquire.GetInstance.devices[i].DeviceName);
- // // DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].modbusTcp.Write<ushort>(DeviceAddress.TranspportSp.ToAdd(), 1000);
- // // DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].modbusTcp.Write<ushort>(DeviceAddress.TranspportSwitch.ToAdd(), 1);
- // //}
- // //DeviceInquire.GetInstance.DeviceLists["192.168.2.130"].modbusTcp.Write<ushort>(DeviceAddress.TranspportSp.ToAdd(), 1000);
- // //DeviceInquire.GetInstance.DeviceLists["192.168.2.130"].modbusTcp.Write<ushort>(DeviceAddress.TranspportSwitch.ToAdd(), 0);
- // //else if (DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].deviceStatus.RunStatus == 3 && DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i + 1].IpAddress].deviceStatus.PailArrive == 1)
- // //{
- // // //传送带运行
- // // DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].modbusTcp.Write<ushort>(DeviceAddress.Start.ToAdd(), (ushort)1);
- // // DeviceParModel deviceSet = Json<DevicePar>.Data.deviceParModels?.ToList().Find(a => a.MaterialName == DeviceInquire.GetInstance.devices[i].DeviceName);
- // // DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].modbusTcp.Write<ushort>(DeviceAddress.TranspportSp.ToAdd(), deviceSet.SendSp);
- // // DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].modbusTcp.Write<ushort>(DeviceAddress.TranspportSwitch.ToAdd(), 1);
- // //}
- // else
- // {
- // DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].modbusTcp.Write<ushort>(DeviceAddress.TranspportSwitch.ToAdd(), 0);
- // //传送带停止
- // }
- // }
- // else
- // {
- // if (SimensSend.GetInstance.sendCtrlModel.Stop)
- // {
- // DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].modbusTcp.Write<ushort>(DeviceAddress.TranspportSwitch.ToAdd(), 0);
- // }
- // else
- // {
- // DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].modbusTcp.Write<ushort>(DeviceAddress.TranspportSwitch.ToAdd(), 1);
- // }
- // //传送带终点为3则传送带停止,小于3则按照出料状态运行
- // }
- // }
-
- // }
-
- // }
-
- // Thread.Sleep(10);
- //}, "启动配方下发", true);
- #endregion
-
- }
-
- }
- }
|