소스 검색

新系统逻辑更新

一拖四味魔方配料系统
lyw 9 달 전
부모
커밋
82411d6fd7
19개의 변경된 파일609개의 추가작업 그리고 237개의 파일을 삭제
  1. +5
    -0
      BPASmartClient.Model/柔性味魔方/RawMaterialModel.cs
  2. +23
    -1
      DosingSystem/App.xaml.cs
  3. +1
    -0
      DosingSystem/BPASmartClient.DosingSystem.csproj
  4. +334
    -168
      DosingSystem/ExcuteControl .cs
  5. +17
    -0
      DosingSystem/Model/Ctrl_AdressModel.cs
  6. +77
    -32
      DosingSystem/Model/DeviceInquire.cs
  7. +7
    -3
      DosingSystem/Model/RawMaterialDeviceStatus.cs
  8. +2
    -0
      DosingSystem/Model/RecipeModel.cs
  9. +1
    -0
      DosingSystem/Model/ViewModelBase.cs
  10. +1
    -1
      DosingSystem/Model/par/BasePar.cs
  11. +6
    -0
      DosingSystem/Model/par/LocalRecipe.cs
  12. +25
    -3
      DosingSystem/Service/SiemensDevice.cs
  13. +35
    -7
      DosingSystem/View/NewRecipeView.xaml
  14. +23
    -6
      DosingSystem/View/RecipeControlView.xaml
  15. +1
    -0
      DosingSystem/ViewModel/NewMaterialViewModel.cs
  16. +25
    -2
      DosingSystem/ViewModel/NewRecipeViewModel.cs
  17. +7
    -3
      DosingSystem/ViewModel/RecipeControlViewModel.cs
  18. +1
    -1
      Test/MainWindow.xaml
  19. +18
    -10
      Test/MainWindow.xaml.cs

+ 5
- 0
BPASmartClient.Model/柔性味魔方/RawMaterialModel.cs 파일 보기

@@ -13,6 +13,11 @@ namespace BPASmartClient.Model
/// </summary>
public class RawMaterialModel : NotifyBase
{
/// <summary>
/// 配方料仓下料总量
/// </summary>
public float TotalWeight { get { return _totalWeight; } set { _totalWeight = value; OnPropertyChanged(); } }
private float _totalWeight;
/// <summary>
/// 原料名称
/// </summary>


+ 23
- 1
DosingSystem/App.xaml.cs 파일 보기

@@ -6,6 +6,7 @@ using BPASmartClient.CustomResource.Pages.ViewModel;
using BPASmartClient.DosingSystem.Model;
using BPASmartClient.DosingSystem.Model.MQTT;
using BPASmartClient.DosingSystem.Service;
using Google.Protobuf.WellKnownTypes;
using System;
using System.Collections.ObjectModel;
using System.Collections.Specialized;
@@ -14,6 +15,7 @@ using System.Diagnostics;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using Enum = System.Enum;

namespace BPASmartClient.DosingSystem
{
@@ -102,11 +104,28 @@ namespace BPASmartClient.DosingSystem
}
else
mv.Close();
/*if (Json<DevicePar>.Data.deviceParModels.Count == 0)
{
for (int i = 0; i < Json<DevicePar>.Data.BaseParModel.StockCount; i++)
{
DeviceParModel devicePar = new DeviceParModel();
devicePar.MaterialName = $"{i+1}";
devicePar.SlowlyAddWeight = 50;
devicePar.PreCloseValveWeight = 3;
devicePar.RapidAcceleration = 20000;
devicePar.SlowAcceleration = 0;
devicePar.ServoManualSpeed = 20000;
devicePar.SiloUpperLimitWeight = 0;
devicePar.LowerLimitWeightOfSilo = 0;
devicePar.StirringSpeed = 0;
Json<DevicePar>.Data.deviceParModels.Add(devicePar);
}
}
Json<DevicePar>.Save();*/
//ServerFactory.GetInstance.Set(new APIServer());
//MqttServer.GetInstance.Init();
MainWindow = mv;
}

protected override void OnExit(ExitEventArgs e)
{
base.OnExit(e);
@@ -114,11 +133,13 @@ namespace BPASmartClient.DosingSystem
//excute?.MqttDisConnect();
Json<LocalRecipe>.Save();
Json<DevicePar>.Save();
Json<OnRecipe>.Save();
Json<LocaMaterial>.Save();
BPASmartClient.CustomResource.Pages.Model.MessageNotify.GetInstance.LogSave();
TaskManage.GetInstance.Dispose();
//Process.GetCurrentProcess().Kill();
}

private void MenuInit()
{
@@ -378,6 +399,7 @@ namespace BPASmartClient.DosingSystem
{
//Config.GetInstance.Init();
Json<LocalRecipe>.Read();
Json<OnRecipe>.Read();
Json<DevicePar>.Read();
Json<LocaMaterial>.Read();
}


+ 1
- 0
DosingSystem/BPASmartClient.DosingSystem.csproj 파일 보기

@@ -30,6 +30,7 @@
</PackageReference>
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
<PackageReference Include="System.Text.Encoding.CodePages" Version="7.0.0" />
<PackageReference Include="System.Windows.Interactivity.WPF" Version="2.0.20525" />
</ItemGroup>

<ItemGroup>


+ 334
- 168
DosingSystem/ExcuteControl .cs 파일 보기

@@ -31,6 +31,10 @@ using System.Text.RegularExpressions;
using static System.Resources.ResXFileRef;
using BPASmartClient.DosingSystem.Model.Dto;
using BPASmartClient.DosingSystem.Model.MQTT;
using Microsoft.VisualBasic.Logging;
using Org.BouncyCastle.Asn1.Utilities;
using Google.Protobuf.WellKnownTypes;
using System.Windows;

namespace BPASmartClient.DosingSystem
{
@@ -48,6 +52,8 @@ namespace BPASmartClient.DosingSystem
public ObservableCollection<RecipeModel> Recipes { get; set; } = Json<LocalRecipe>.Data.Recipes;
public ObservableCollection<StockStatusModel> StockStatus = new ObservableCollection<StockStatusModel>();

public Action<string,float> Raction { get; set; }

public string CurrentRecipeName { get; set; }
/// <summary>
/// 当前正在制作的配方
@@ -367,10 +373,11 @@ namespace BPASmartClient.DosingSystem
Json<LocalRecipe>.Data.Recipes.ElementAt(index).IsEnable = false;
}
MessageNotify.GetInstance.ShowUserLog($"下发工单 {Recipes.ElementAt(index).RecipeName}");
RecipeNames.Enqueue(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() });

@@ -388,27 +395,30 @@ namespace BPASmartClient.DosingSystem
List<Task> tasks = new();
tasks.Add( SimensSend.GetInstance.SendSimens.WriteAsync("M0.0", false));
tasks.Add( SimensSend.GetInstance.SendSimens.WriteAsync("M0.1", false));
foreach (var item in DeviceInquire.GetInstance.DeviceLists.Values)
/* foreach (var item in DeviceInquire.GetInstance.DeviceLists.Values)
{
tasks.Add( item.modbusTcp.WriteAsync<ushort>(DeviceAddress.TranspportSwitch.ToAdd(), 0));
}
Task.WaitAll(tasks.ToArray(),TimeSpan.FromSeconds(5));
Task.WaitAll(tasks.ToArray(),TimeSpan.FromSeconds(5));*/
}

public void ShutDown()
{
TaskManage.GetInstance.StopTask("设备下发配方");
TaskManage.GetInstance.StopTask("下发设备参数");
TaskManage.GetInstance.StopTask("控制传送带");
TaskManage.GetInstance.StopTask("监控允许配料点位");
TaskManage.GetInstance.StopTask("下料控制");
List<Task> tasks = new();
tasks.Add(SimensSend.GetInstance.SendSimens.WriteAsync("M0.0", false));
tasks.Add(SimensSend.GetInstance.SendSimens.WriteAsync("M0.1", false));
var writeTasks = DeviceInquire.GetInstance.DeviceLists.Values.Select(async item =>
/*var writeTasks = DeviceInquire.GetInstance.DeviceLists.Values.Select(async item =>
{
bool writeSuccessful = false;
int maxRetries = 3;
int retryCount = 0;

while (item.deviceStatus.TranspportSwitch == (ushort)1)
{
item.modbusTcp.Write<ushort>(DeviceAddress.TranspportSwitch.ToAdd(), (ushort)0);
}
while (!writeSuccessful && retryCount < maxRetries)
{
var result = await item.modbusTcp.WriteAsync<ushort>(DeviceAddress.TranspportSwitch.ToAdd(), 0);
@@ -422,21 +432,126 @@ namespace BPASmartClient.DosingSystem
retryCount++;
}
}
});
});*/

tasks.AddRange(writeTasks);
/*tasks.AddRange(writeTasks);*/
Task.WaitAll(tasks.ToArray(), TimeSpan.FromSeconds(5));
}
private void MatchRun()
public ConcurrentDictionary<string, bool> rTrig = new ConcurrentDictionary<string, bool>();
public ConcurrentDictionary<string, bool> tTrig = new ConcurrentDictionary<string, bool>();
bool stop = true;


private void MonitorStatus()
{
TaskManage.GetInstance.StartLong(() =>
{
for (int i = 0; i < DeviceInquire.GetInstance.devices.Count; i++)
{
if (DeviceInquire.GetInstance.DeviceLists.ContainsKey(DeviceInquire.GetInstance.devices[i].IpAddress))
{
if (!rTrig.ContainsKey(DeviceInquire.GetInstance.devices[i].IpAddress))
{
rTrig.TryAdd(DeviceInquire.GetInstance.devices[i].IpAddress, false);
}
if (!tTrig.ContainsKey(DeviceInquire.GetInstance.devices[i].IpAddress))
{
tTrig.TryAdd(DeviceInquire.GetInstance.devices[i].IpAddress, false);
}
RTrig.GetInstance(DeviceInquire.GetInstance.devices[i].IpAddress).Start(DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].deviceStatus.PailArrive);
TTrig.GetInstance(DeviceInquire.GetInstance.devices[i].IpAddress).Start(DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].deviceStatus.Finish_mt);
if (RTrig.GetInstance(DeviceInquire.GetInstance.devices[i].IpAddress).Q)
{
MessageNotify.GetInstance.ShowRunLog($"检测到上升源");
if (rTrig.ContainsKey(DeviceInquire.GetInstance.devices[i].IpAddress))
{
rTrig.TryUpdate(DeviceInquire.GetInstance.devices[i].IpAddress, true, false);
}
else
{
rTrig.TryAdd(DeviceInquire.GetInstance.devices[i].IpAddress, true);
}
}
if (TTrig.GetInstance(DeviceInquire.GetInstance.devices[i].IpAddress).Q)
{
MessageNotify.GetInstance.ShowRunLog($"检测到下降源");
if (tTrig.ContainsKey(DeviceInquire.GetInstance.devices[i].IpAddress))
{
tTrig.TryUpdate(DeviceInquire.GetInstance.devices[i].IpAddress, true, false);
}
else
{
tTrig.TryAdd(DeviceInquire.GetInstance.devices[i].IpAddress, true);
}
}


if (rTrig[DeviceInquire.GetInstance.devices[i].IpAddress] || tTrig[DeviceInquire.GetInstance.devices[i].IpAddress])
{
int recipeNameNum = doDeviceCount[DeviceInquire.GetInstance.devices[i].IpAddress];
if (recipeNameNum >= 0)
{
int doCount = Array.FindIndex(Recipes.ToArray(), p => p.RecipeName == RecipeNames.ElementAt(recipeNameNum - 1));
if (doCount >= 0)
{
int res = Recipes.ElementAt(doCount).RawMaterials.ToList().FindIndex(a => a.RawMaterialName == DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].DeviceName && a.Loc == DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].deviceStatus.PassPail);
if (res>=0)
{
int finish = UserTreeCompelete.Count;
int re =0;
int re_1 = 0;
if (recipeNameNum - finish<=recipeProcesses.Count)
{
re = recipeProcesses.ElementAt(recipeProcesses.Count-(recipeNameNum-finish)).RawMaterials.ToList().FindIndex(a => a.RawMaterialName == DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].DeviceName && a.Loc == DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].deviceStatus.PassPail && a.RecipeStatus == 1);
re_1 = recipeProcesses.ElementAt(recipeProcesses.Count - (recipeNameNum - finish)).RawMaterials.ToList().FindIndex(a => a.RawMaterialName == DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].DeviceName && a.Loc == DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].deviceStatus.PassPail && a.RecipeStatus == 2);
}
if (rTrig[DeviceInquire.GetInstance.devices[i].IpAddress] && re>=0)
{
MessageNotify.GetInstance.ShowRunLog($"找到配方桶,开始下{Recipes.ElementAt(doCount).RawMaterials.ElementAt(res).RawMaterialWeight}g料");
recipeProcesses.ElementAt(recipeNameNum - finish - 1).RawMaterials.ElementAt(re).RecipeStatus = 2;
Raction?.Invoke(DeviceInquire.GetInstance.devices[i].IpAddress, Recipes.ElementAt(doCount).RawMaterials.ElementAt(res).RawMaterialWeight);
rTrig.TryUpdate(DeviceInquire.GetInstance.devices[i].IpAddress,false,true);
}
if (tTrig[DeviceInquire.GetInstance.devices[i].IpAddress] &&re_1>=0)
{
recipeProcesses.ElementAt(recipeNameNum - finish - 1).RawMaterials.ElementAt(re_1).RecipeStatus = 3;
Recipes.ElementAt(doCount).RawMaterials.ElementAt(res).TotalWeight = DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].deviceStatus.CutWeightFeedback;
MessageNotify.GetInstance.ShowRunLog($"设备{DeviceInquire.GetInstance.devices[i].IpAddress}已下料{Recipes.ElementAt(doCount).RawMaterials.ElementAt(res).TotalWeight}g");
tTrig.TryUpdate(DeviceInquire.GetInstance.devices[i].IpAddress, false, true);
}
}
}
}
}
}
}
Thread.Sleep(10);
}, "监控允许配料点位");
}
private void MatchRun()
{
MonitorStatus();
recipeProcesses.Clear();
/*recipeProcesses = new ObservableCollection<RecipeModel>(Json<OnRecipe>.Data.Recipes.ToList()?.FindAll(o => o.RecipStatus == "正在制作"));
foreach (var recipe in recipeProcesses)
{
RecipeNames.Enqueue(recipe.RecipeName);
}
App.Current.Dispatcher.Invoke(() => { recipeProcesses.Add(Recipes.ElementAt(0)); });*/
TaskManage.GetInstance.StartLong(() =>
{
if (RecipeNames.Count > 0)
if (RecipeNames.Count > 0 && SimensSend.GetInstance.IsConnect)
{
SimensSend.GetInstance.SendSimens.Write("M0.0", true);
SimensSend.GetInstance.SendSimens.Write("M0.1", true);
//下发设备参数

//遍历每一个味魔方。
for (int i = 0; i < DeviceInquire.GetInstance.devices.Count; i++)
{
@@ -446,174 +561,223 @@ namespace BPASmartClient.DosingSystem
//只有设备在等待配料状态才能下发数据
if (DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].deviceStatus.RunStatus == 1)
{
//判断MaxPassPail--配方的最大桶数,小于已经通过的桶数。
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))
{
if (doDeviceCount.ContainsKey(DeviceInquire.GetInstance.devices[i].IpAddress))
int index = 0;//配方索引
int maxPail = 0;//最大桶数
List<int> device_Loc = new List<int>();//下发桶号
int recipeNameNum = doDeviceCount[DeviceInquire.GetInstance.devices[i].IpAddress];
var dnum = DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].deviceStatus.DeviceNum;
if (recipeNameNum == 0)
{
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)
MessageNotify.GetInstance.ShowRunLog("执行首个配方");
index = Array.FindIndex(Recipes.ToArray(), p => p.RecipeName == RecipeNames.ElementAt(recipeNameNum));
if (index >= 0 && dnum > 0)
{
//查找配方。根据名称查找。
index = Array.FindIndex(Recipes.ToArray(), p => p.RecipeName == RecipeNames.ElementAt(recipeNameNum));
if (index >= 0 && index < Recipes.Count)
foreach (var rawMaterial in Recipes.ElementAt(index).RawMaterials)
{
int maxPail = 0;
//查找配方的最大桶号。
foreach (var rawMaterial in Recipes.ElementAt(index).RawMaterials)
if (rawMaterial.Loc > maxPail)
{
if (rawMaterial.Loc > maxPail)
{
maxPail = rawMaterial.Loc;
}
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);
if (rawMaterial.DeviceIp == DeviceInquire.GetInstance.devices[i].IpAddress)
{
device_Loc.Add(rawMaterial.Loc);
}
}
MessageNotify.GetInstance.ShowRunLog($"{DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].deviceStatus.PassPail}/{maxPail}/{device_Loc}");
if (DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].deviceStatus.PassPail == 0)
{
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)
foreach (var down_Loc in device_Loc)
{
SimensSend.GetInstance.SendSimens.Write<bool>($"DB1.DBX{710 + 4 * (dnum - 1) + (int)((down_Loc - 1) / 8)}.{(down_Loc - 1) % 8}", true);
}
SimensSend.GetInstance.SendSimens.Write<ushort>($"DB1.DBW{106 + 2 * (dnum - 1)}", 500);
MessageNotify.GetInstance.ShowRunLog($"设备{dnum}下发配方{RecipeNames.ElementAt(recipeNameNum)}");
if (dnum == 1)
{
App.Current.Dispatcher.Invoke(() =>
{
recipeProcesses.Insert(0, UserTreeWait?.ToList().Find(a => a.RecipeName == RecipeNames.ElementAt(recipeNameNum)));
RecipeModel recipe = UserTreeWait?.ToList().Find(a => a.RecipeName == RecipeNames.ElementAt(recipeNameNum));
recipe.RecipStatus = "正在配料";
recipeProcesses.Insert(0, recipe);
/*Json<OnRecipe>.Data.Recipes.Insert(0, recipe);
Json<OnRecipe>.Save();*/
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)
}
}
}
if (recipeNameNum > 0 && recipeNameNum <= RecipeNames.Count)
{
index = Array.FindIndex(Recipes.ToArray(), p => p.RecipeName == RecipeNames.ElementAt(recipeNameNum - 1));
if (index >= 0 && dnum > 0)
{
foreach (var rawMaterial in Recipes.ElementAt(index).RawMaterials)
{
if (rawMaterial.Loc > maxPail)
{
maxPail = rawMaterial.Loc;
}
if (rawMaterial.DeviceIp == DeviceInquire.GetInstance.devices[i].IpAddress)
{
App.Current.Dispatcher.Invoke(() =>
device_Loc.Add(rawMaterial.Loc);
}
}
if (dnum == 18 && maxPail <= DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].deviceStatus.PassPail)
{
App.Current.Dispatcher.Invoke(() =>
{
RecipeModel recipe = recipeProcesses?.ToList().Find(a => a.RecipeName == RecipeNames.ElementAt(recipeNameNum));
if (recipe.RecipStatus != "制作完成")
{
RecipeModel recipe = recipeProcesses?.ToList().Find(a => a.RecipeName == RecipeNames.ElementAt(recipeNameNum));
/*Json<OnRecipe>.Data.Recipes.RemoveAt(recipeProcesses.ToList().FindIndex(a => a.RecipeName == RecipeNames.ElementAt(recipeNameNum)));
Json<OnRecipe>.Save();*/
recipe.RecipStatus = "制作完成";
UserTreeCompelete.Insert(0, recipe);
recipeProcesses.RemoveAt(recipeProcesses.ToList().FindIndex(a => a.RecipeName == RecipeNames.ElementAt(recipeNameNum)));
}
});
}
if (maxPail <= DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].deviceStatus.PassPail&& recipeNameNum < RecipeNames.Count)
{
MessageNotify.GetInstance.ShowRunLog("下发下一个配方");
doDeviceCount.TryUpdate(DeviceInquire.GetInstance.devices[i].IpAddress, recipeNameNum + 1, doDeviceCount[DeviceInquire.GetInstance.devices[i].IpAddress]);
index = Array.FindIndex(Recipes.ToArray(), p => p.RecipeName == RecipeNames.ElementAt(recipeNameNum-1));
if (index >= 0)
{
foreach (var rawMaterial in Recipes.ElementAt(index).RawMaterials)
{
if (rawMaterial.Loc > maxPail)
{
maxPail = rawMaterial.Loc;
}
if (rawMaterial.DeviceIp == DeviceInquire.GetInstance.devices[i].IpAddress)
{
device_Loc.Add(rawMaterial.Loc);
}
}
}
foreach (var down_Loc in device_Loc)
{
SimensSend.GetInstance.SendSimens.Write<bool>($"DB1.DBX{710 + 4 * (dnum - 1) + (int)((down_Loc - 1) / 8)}.{(down_Loc - 1) % 8}", true);
}
SimensSend.GetInstance.SendSimens.Write<ushort>($"DB1.DBW{106 + 2 * (dnum - 1)}", 600);
SimensSend.GetInstance.SendSimens.Write<ushort>($"DB1.DBW{810 + 2 * (dnum - 1)}", 0);
MessageNotify.GetInstance.ShowRunLog($"设备{dnum}下发配方{RecipeNames.ElementAt(recipeNameNum)},桶数已清零");
if (dnum == 1)
{
App.Current.Dispatcher.Invoke(() =>
{
RecipeModel recipe = UserTreeWait?.ToList().Find(a => a.RecipeName == RecipeNames.ElementAt(recipeNameNum));
recipe.RecipStatus = "正在配料";
recipeProcesses.Insert(0, recipe);
/* Json<OnRecipe>.Data.Recipes.Insert(0, recipe);
Json<OnRecipe>.Save();*/
UserTreeWait.RemoveAt(UserTreeWait.ToList().FindIndex(a => a.RecipeName == RecipeNames.ElementAt(recipeNameNum)));
});
}
}

}
}
else
{
doDeviceCount.TryAdd(DeviceInquire.GetInstance.devices[i].IpAddress, 0);
}

}
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(() =>
MessageNotify.GetInstance.ShowRunLog($"设备下发配方运行");
Raction = ((s,f) =>
{
while (!DeviceInquire.GetInstance.DeviceLists[s].modbusTcp.Write<float>(DeviceAddress.WeightSet.ToAdd(), f).IsSuccess)
{
DeviceInquire.GetInstance.DeviceLists[s].modbusTcp.Write<float>(DeviceAddress.WeightSet.ToAdd(), f);
}
while (!DeviceInquire.GetInstance.DeviceLists[s].modbusTcp.Write<ushort>(DeviceAddress.Start.ToAdd(), 1).IsSuccess)
{
DeviceInquire.GetInstance.DeviceLists[s].modbusTcp.Write<ushort>(DeviceAddress.Start.ToAdd(), 1);
stop = false;
}
stop = true;
MessageNotify.GetInstance.ShowRunLog($"允许下发复位信号");
});


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.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)
if (DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].deviceStatus.Finish_mt)
{
int dnum = DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].deviceStatus.DeviceNum;
SimensSend.GetInstance.SendSimens.Write<bool>($"DB1.DBX70{(int)((dnum-1)/8)}.{(dnum-1)%8}", true);
MessageNotify.GetInstance.ShowRunLog($"设备{dnum}下发完成信号");
}
if (DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].deviceStatus.RunStatus==2&& DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].deviceStatus.RunStatus==3)
{
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)
if (stop)
{
//根据物料名称查找
var res = Recipes.ElementAt(doCount).RawMaterials?.ToList().FindAll(a => a.RawMaterialName == DeviceInquire.GetInstance.devices[i].DeviceName);
foreach (RawMaterialModel item in res)
MessageNotify.GetInstance.ShowRunLog($"下发复位信号");
while (DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].modbusTcp.Write<ushort>(DeviceAddress.Start.ToAdd(), 0).IsSuccess)
{
//可能是多个桶都需要下同一种料,根据已通过桶数和当前物料信息的通号做对比。
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);
Thread.Sleep(50);
//设置下料重量
deviceModbus.Write<float>(DeviceAddress.WeightSet.ToAdd(), item.RawMaterialWeight);
Thread.Sleep(50);
//设置慢加重量
deviceModbus.Write<float>(DeviceAddress.SlowlyAddWeight.ToAdd(), deviceSet.SlowlyAddWeight);
Thread.Sleep(50);
//设置提前关阀重量
deviceModbus.Write<float>(DeviceAddress.PreCloseValveWeight.ToAdd(), deviceSet.PreCloseValveWeight);
Thread.Sleep(50);

//设置快慢加速度
deviceModbus.Write<int>(DeviceAddress.SlowAcceleration.ToAdd(), (int)deviceSet.SlowAcceleration);
Thread.Sleep(50);
deviceModbus.Write<int>(DeviceAddress.RapidAcceleration.ToAdd(), (int)deviceSet.RapidAcceleration);
Thread.Sleep(50);
//设置伺服手动速度
deviceModbus.Write<int>(DeviceAddress.ServoManualSpeed.ToAdd(), deviceSet.ServoManualSpeed);
Thread.Sleep(50);
//设置料仓上下限重量
deviceModbus.Write<int>(DeviceAddress.SiloUpperLimitWeight.ToAdd(), deviceSet.SiloUpperLimitWeight);
Thread.Sleep(50);
deviceModbus.Write<int>(DeviceAddress.LowerLimitWeightOfSilo.ToAdd(), deviceSet.LowerLimitWeightOfSilo);
Thread.Sleep(50);
//开始配料信号
deviceModbus.Write<ushort>(DeviceAddress.Start.ToAdd(), (ushort)1);
////设置搅拌速度
//DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].modbusTcp.Write<int>(DeviceAddress.StirringSpeed.ToAdd(), deviceSet.StirringSpeed);
}
}
DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].modbusTcp.Write<ushort>(DeviceAddress.Start.ToAdd(), 0);
}
}
}
}
}
Thread.Sleep(10);

}, "下料控制");
MessageNotify.GetInstance.ShowRunLog($"下料控制运行");

//弃用
/*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 && doDeviceCount[DeviceInquire.GetInstance.devices[i].IpAddress] >= 0)
{
int recipeNameNum = doDeviceCount[DeviceInquire.GetInstance.devices[i].IpAddress];
int doCount = Array.FindIndex(Recipes.ToArray(), p => p.RecipeName == RecipeNames.ElementAt(recipeNameNum));
var res = Recipes.ElementAt(doCount).RawMaterials?.ToList().Find(a => a.RawMaterialName == DeviceInquire.GetInstance.devices[i].DeviceName && a.Loc == DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].deviceStatus.PassPail);
if (res != null)
{
var deviceModbus = DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].modbusTcp;
deviceModbus.Write<float>(DeviceAddress.WeightSet.ToAdd(), res.RawMaterialWeight);
deviceModbus.Write<bool>(DeviceAddress.Start.ToAdd(), true);
}

}
}

}

Thread.Sleep(10);
}, "下发设备参数");
DeviceStatus nextDevice = new DeviceStatus();
}, "下发设备参数");*/
/*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))
@@ -621,7 +785,7 @@ namespace BPASmartClient.DosingSystem
if (DeviceInquire.GetInstance.devices[i].IpAddress == "192.168.2.90")
{

if (DeviceInquire.GetInstance.DeviceLists[ DeviceInquire.GetInstance.devices[i].IpAddress].deviceStatus.PailArrive == 1)
if (DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].deviceStatus.PailArrive == 1)
{
SimensSend.GetInstance.SendSimens.Write("DB1.DBX702.0", 0);
}
@@ -634,56 +798,56 @@ namespace BPASmartClient.DosingSystem
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 != "")
ushort deviceNum = DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].deviceStatus.DeviceNum;
string nextIp = "";
if (DeviceInquire.GetInstance.DeviceLists.ContainsKey($"{Json<DevicePar>.Data.BaseParModel.NetworkSegAddress}{(deviceNum + 1) * 10}") && deviceNum != 0)
{
nextIp = $"{Json<DevicePar>.Data.BaseParModel.NetworkSegAddress}{(deviceNum + 1) * 10}";
}
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["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);
}
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.TranspportSwitch.ToAdd(), 0);
//传送带停止
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);
}

//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);
//传送带停止
}

//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
{
@@ -708,11 +872,13 @@ namespace BPASmartClient.DosingSystem

}
}

}
Thread.Sleep(10);
}, "控制传送带");
}, "控制传送带");*/


#region 弃用配料流程
//弃用配料流程


+ 17
- 0
DosingSystem/Model/Ctrl_AdressModel.cs 파일 보기

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

namespace BPASmartClient.DosingSystem.Model
{
public class Ctrl_AdressModel
{
public string PailArrive { get; set; }
public string MaxPail { get; set; }
public string ClearPail { get; set; }
public string PassPail { get; set; }
public string DoingRecipe { get; set; }
}
}

+ 77
- 32
DosingSystem/Model/DeviceInquire.cs 파일 보기

@@ -2,6 +2,8 @@
using BPA.Communication;
using BPA.Helper;
using BPASmartClient.CustomResource.Pages.Model;
using BPASmartClient.CustomResource.UserControls;
using BPASmartClient.CustomResource.UserControls.MessageShow;
using BPASmartClient.DosingSystem.Model;
using BPASmartClient.DosingSystem.ViewModel;
using BPASmartClient.Model;
@@ -24,6 +26,7 @@ namespace BPASmartClient.DosingSystem
int stockCount;//料仓数
private volatile static DeviceInquire _Instance;
public static DeviceInquire GetInstance => _Instance ?? (_Instance = new DeviceInquire());

private DeviceInquire() { }

string IPSegment = "192.168.2.";
@@ -159,10 +162,14 @@ namespace BPASmartClient.DosingSystem
else Json<DevicePar>.Data.BaseParModel.NetworkSegAddress = IPSegment;
stockCount = Json<DevicePar>.Data.BaseParModel.StockCount;
//TestData();
IpAddressLines();
/*IpAddressLines();*/
Task.Factory.StartNew(() =>
{
SimensSend.GetInstance.Connect();
/*while(!clearValue)
{
clearValue = ClearData();
}*/
//SiemensDevice.GetInstance.Connect(Json<DevicePar>.Data.BaseParModel.DeviceAddress);
});
DeviceDataInit();
@@ -173,6 +180,40 @@ namespace BPASmartClient.DosingSystem
Thread.Sleep(5000);
}), "配料机设备上线监听", true);
}
/// <summary>
/// 清除所有数据
/// </summary>
/// <returns></returns>
public bool ClearData()
{
if (SimensSend.GetInstance.SendSimens.IsReconnect)
{
var res = SimensSend.GetInstance.SendSimens.Write<ushort>("DB1.DBW840", (ushort)1).IsSuccess;
Thread.Sleep(2000);
bool result = false;
if (res)
{
result = SimensSend.GetInstance.SendSimens.Write<ushort>("DB1.DBW840", (ushort)0).IsSuccess;
}
if (result)
{
App.Current.Dispatcher.Invoke(() => { NoticeDemoViewModel.OpenMsg(EnumPromptType.Success, App.MainWindow, "成功", $"数据清除完成"); });
}
/* #region 2023-11-20-17新增:在软件重启时,自动清零设备上的配方执行数量等数据。
var result1= modbusTcp.Write<ushort>(DeviceAddress.ZeroRecipeCount.ToAdd(), 1).IsSuccess;
Thread.Sleep(500);
var result2= modbusTcp.Write<ushort>(DeviceAddress.ZeroRecipeCount.ToAdd(), 0).IsSuccess;

return result1 && result2;
#endregion*/
return result;
}
else
{
return false;
}
}

public void Rescan()
{
@@ -239,6 +280,7 @@ namespace BPASmartClient.DosingSystem

});
}
bool clearValue = false;

private void _myPing_PingCompleted(object sender, PingCompletedEventArgs e)
{
@@ -250,7 +292,18 @@ namespace BPASmartClient.DosingSystem
{
DeviceStatus DS = new DeviceStatus();
DS.modbusTcp.IsReconnect = false;

#region 2023-11-23修改:在该IP第一次连接时清除设备的数据,后续重连时不清除。
/*if (IsClearData.ContainsKey(ip) && IsClearData[ip] == false)
{
if (DS.ClearData())
{
//清除成功就置位。
IsClearData[ip] = true;
}
} */
//备注:2024-1-22修改,连接后整体数据清理
#endregion
DS.modbusTcp.Connected = new Action(() =>
{
var tt = DS.modbusTcp.Read<string>(DeviceAddress.DeviceName.ToAdd(), 20);
@@ -263,16 +316,7 @@ namespace BPASmartClient.DosingSystem
DeviceLists[ip].Init(DeviceName);
DeviceLists[ip].modbusTcp.IsReconnect = false;

#region 2023-11-23修改:在该IP第一次连接时清除设备的数据,后续重连时不清除。
if (IsClearData.ContainsKey(ip) && IsClearData[ip] == false)
{
if (DS.ClearData())
{
//清除成功就置位。
IsClearData[ip] = true;
}
}
#endregion

App.Current.Dispatcher.Invoke(new Action(() =>
{
@@ -383,6 +427,7 @@ namespace BPASmartClient.DosingSystem

public void Init(string DeviceName)
{
//modbusTcp.Show = new Action<string>((s) => { MessageNotify.GetInstance.ShowRunLog(s); });
//modbusTcp.ShowEx = new Action<string>((s) => { MessageNotify.GetInstance.ShowRunLog(s); });
this.DeviceName = DeviceName;
@@ -408,7 +453,15 @@ namespace BPASmartClient.DosingSystem

////获取设备编号
var dnum = this.modbusTcp.Read<ushort>(DeviceAddress.DeviceNum.ToAdd(), 1, BPA.Helper.DataFormat.CDAB);
if (dnum.IsSuccess) deviceStatus.DeviceNum = dnum.Content;
if (dnum.IsSuccess)
{
deviceStatus.DeviceNum = dnum.Content;
if (dnum.Content > 0&& SimensSend.GetInstance.IsConnect)
{
deviceStatus.PailArrive = SimensSend.GetInstance.SendSimens.Read<bool>($"DB1.DBX80{(int)((dnum.Content-1)/8)}.{(dnum.Content-1)%8}").Content;
deviceStatus.PassPail = SimensSend.GetInstance.SendSimens.Read<ushort>($"DB1.DBW{810 + 2 * (dnum.Content - 1)}").Content;
}
}

////获取设备故障编码
var dac = this.modbusTcp.Read<ushort>(DeviceAddress.DeviceAlarmCode.ToAdd(), 1, BPA.Helper.DataFormat.CDAB);
@@ -420,8 +473,11 @@ namespace BPASmartClient.DosingSystem

//获取工作模式
var wm = this.modbusTcp.Read<ushort>(DeviceAddress.WorkModel.ToAdd(),1, BPA.Helper.DataFormat.CDAB);
if (wm.IsSuccess) deviceStatus.WorkModel = wm.Content.GetBitValue(1);
//慢加重量
if (wm.IsSuccess) {
deviceStatus.WorkModel = wm.Content.GetBitValue(1);
deviceStatus.Finish_mt = wm.Content.GetBitValue(6);
}
/* //慢加重量
var ssaw = this.modbusTcp.Read<float>(DeviceAddress.SlowlyAddWeight.ToAdd(), 1, BPA.Helper.DataFormat.CDAB);
if (ssaw.IsSuccess) deviceStatus.SlowAddWeight = ssaw.Content;
//提前关阀重量
@@ -444,8 +500,8 @@ namespace BPASmartClient.DosingSystem
if (llw.IsSuccess) deviceStatus.SiloLowerLimitWeight = llw.Content;
//料仓搅拌速度
var ss = this.modbusTcp.Read<uint>(DeviceAddress.StirringSpeed.ToAdd(), 1, BPA.Helper.DataFormat.CDAB);
if (ss.IsSuccess) deviceStatus.StirringSpeed = ss.Content;
//获取桶是否到位
if (ss.IsSuccess) deviceStatus.StirringSpeed = ss.Content;*/
/* //获取桶是否到位
var pailArrive = this.modbusTcp.Read<ushort>(DeviceAddress.PailArrive.ToAdd(), 1, BPA.Helper.DataFormat.CDAB);
if (pailArrive.IsSuccess) deviceStatus.PailArrive = pailArrive.Content;
//已通过桶数
@@ -456,7 +512,10 @@ namespace BPASmartClient.DosingSystem
if (max.IsSuccess) deviceStatus.MaxPassPail = max.Content;
//执行配方数
var doCount = this.modbusTcp.Read<ushort>(DeviceAddress.DoRecipeCount.ToAdd(), 1, BPA.Helper.DataFormat.CDAB);
if (doCount.IsSuccess) deviceStatus.DoRecipeCount = doCount.Content;
if (doCount.IsSuccess) deviceStatus.DoRecipeCount = doCount.Content;*/

/*var ts = this.modbusTcp.Read<ushort>(DeviceAddress.TranspportSwitch.ToAdd(), 1, BPA.Helper.DataFormat.CDAB);
if (ts.IsSuccess) deviceStatus.TranspportSwitch = ts.Content;*/
//this.DeviceName = modbusTcp.Read<string>(DeviceAddress.DeviceName.ToAdd(), 20).Content.Trim().Replace(" ", "");
//deviceStatus.RunStatus = (ushort)this.modbusTcp.Read<ushort>(DeviceAddress.RunStatus.ToAdd()).Content; //获取设备运行状态
//deviceStatus.WeightFeedback = (float)this.modbusTcp.Read<uint>(DeviceAddress.WeightFeedback.ToAdd()).Content;//获取设备料仓剩余重量
@@ -477,20 +536,6 @@ namespace BPASmartClient.DosingSystem
}
}

public bool ClearData()
{
if (IsConnected)
{
#region 2023-11-20-17新增:在软件重启时,自动清零设备上的配方执行数量等数据。
var result1= modbusTcp.Write<ushort>(DeviceAddress.ZeroRecipeCount.ToAdd(), 1).IsSuccess;
Thread.Sleep(500);
var result2= modbusTcp.Write<ushort>(DeviceAddress.ZeroRecipeCount.ToAdd(), 0).IsSuccess;

return result1 && result2;
#endregion
}
return false;
}
public void SetDeviceName(string name,int index)
{
this.modbusTcp.Write(DeviceAddress.DeviceName.ToAdd(), new ushort[20]);


+ 7
- 3
DosingSystem/Model/RawMaterialDeviceStatus.cs 파일 보기

@@ -66,6 +66,10 @@ namespace BPASmartClient.DosingSystem
/// </summary>
public bool WorkModel { get; set; }
/// <summary>
/// 配料完成
/// </summary>
public bool Finish_mt { get; set; }
/// <summary>
/// 慢加重量
/// </summary>
public float SlowAddWeight { get; set; }
@@ -103,13 +107,13 @@ namespace BPASmartClient.DosingSystem
/// </summary>
public ushort MaxPassPail { get; set; }
/// <summary>
/// 已通过桶数
/// 已通过桶数 通过桶数计数
/// </summary>
public ushort PassPail { get; set; }
/// <summary>
/// 到位检测 为1有桶。0无桶
/// 到位检测 为1有桶。0无桶 是否允许下料信号
/// </summary>
public ushort PailArrive { get; set; }
public bool PailArrive { get; set; }
/// <summary>
/// 设备执行配方数量
/// </summary>


+ 2
- 0
DosingSystem/Model/RecipeModel.cs 파일 보기

@@ -44,5 +44,7 @@ namespace BPASmartClient.DosingSystem
/// </summary>
public ObservableCollection<RawMaterialModel> RawMaterials { get; set; } = new ObservableCollection<RawMaterialModel>();

public int all_RawMt_weight = 0;
public int All_RawMt_weight { get { return all_RawMt_weight; } set { all_RawMt_weight = value;OnPropertyChanged(); } }
}
}

+ 1
- 0
DosingSystem/Model/ViewModelBase.cs 파일 보기

@@ -10,6 +10,7 @@ namespace BPASmartClient.DosingSystem
public BPARelayCommand SaveCommand { get; set; }//保存
public BPARelayCommand<object> RemoveCommand { get; set; }//移除
public BPARelayCommand<object> DetailsCommand { get; set; }//编辑
public BPARelayCommand TextChanged { get; set; }//输入变化

/// <summary>
/// 错误信息


+ 1
- 1
DosingSystem/Model/par/BasePar.cs 파일 보기

@@ -25,7 +25,7 @@ namespace BPASmartClient.DosingSystem
/// 料仓数量
/// </summary>
public int StockCount { get { return _stockCount; } set { _stockCount = value; OnPropertyChanged(); } }
private int _stockCount = 0;
private int _stockCount = 18;


/// <summary>


+ 6
- 0
DosingSystem/Model/par/LocalRecipe.cs 파일 보기

@@ -7,5 +7,11 @@ namespace BPASmartClient.DosingSystem
public ObservableCollection<RecipeModel> Recipes { get; set; } = new ObservableCollection<RecipeModel>();


}
public class OnRecipe
{
public ObservableCollection<RecipeModel> Recipes { get; set; } = new ObservableCollection<RecipeModel>();


}
}

+ 25
- 3
DosingSystem/Service/SiemensDevice.cs 파일 보기

@@ -1,5 +1,6 @@
using BPA.Communication;
using BPA.Helper;
using BPASmartClient.CustomResource.Pages.Model;
using BPASmartClient.DosingSystem.Model;
using Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.Internal;
using System;
@@ -19,14 +20,18 @@ namespace BPASmartClient.DosingSystem
public ObservableCollection<SendCtrlModel> sendCtrlModels { get; set; } = new ObservableCollection<SendCtrlModel>();
public SendCtrlModel sendCtrlModel { get; set; } = new SendCtrlModel();
public Siemens SendSimens { get; set; } = new Siemens();
private bool IsConnect { get; set; }
public bool IsConnect { get; set; }
public bool tempValue = false;
public void Connect()
{
try
{
IsConnect = SendSimens.Connect(new BPA.Communication.Base.ConfigurationOptions() { IpAddress = "192.168.2.200", cpuType = BPA.Communication.CpuType.S71200, Port = 102 });
IsConnect = SendSimens.Connect(new BPA.Communication.Base.ConfigurationOptions() { IpAddress = ip, cpuType = BPA.Communication.CpuType.S71200, Port = 102 });
if (IsConnect)
{
MessageNotify.GetInstance.ShowRunLog("连接成功");
}

}
catch (Exception)
@@ -35,6 +40,23 @@ namespace BPASmartClient.DosingSystem
//throw;
}
try
{
TaskManage.GetInstance.StartLong(new Action(() =>
{
if (SendSimens.IsConnected())
{
SendSimens.Write("M5.0", tempValue);//设备心跳
tempValue = !tempValue;
}
Thread.Sleep(1000);
}), "设备心跳", true);
}
catch (Exception)
{

/*throw;*/
}
/* try
{

TaskManage.GetInstance.StartLong(new Action(() =>
@@ -98,7 +120,7 @@ namespace BPASmartClient.DosingSystem
{

}
}*/
}
}
//public class SiemensDevice


+ 35
- 7
DosingSystem/View/NewRecipeView.xaml 파일 보기

@@ -6,6 +6,7 @@
xmlns:local="clr-namespace:BPASmartClient.DosingSystem.View"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:vm="clr-namespace:BPASmartClient.DosingSystem.ViewModel"
xmlns:i ="http://schemas.microsoft.com/expression/2010/interactivity"
Title="NewRecipeView"
Width="550"
Height="600"
@@ -93,12 +94,30 @@
<RowDefinition />
</Grid.RowDefinitions>

<TextBlock
Margin="10,0,0,0"
Background="Transparent"
FontSize="20"
Foreground="#FF2AB2E7"
Text="请输入配方名称:" />
<StackPanel Orientation="Horizontal" VerticalAlignment="Center">
<TextBlock
Margin="10,0,0,0"
Background="Transparent"
FontSize="20"
Foreground="#FF2AB2E7"
Text="请输入配方名称:"
/>
<TextBlock
Margin="100,0,0,0"
Background="Transparent"
Text="配方总量:"
Foreground="#FF2AB2E7"
/>
<TextBox
Width="160"
Height="30"
Margin="0,0,7,0"
FontSize="16"
IsReadOnly="True"
Text="{Binding All_RawMt_weight}"
/>
</StackPanel>

<TextBlock
Margin="0,0,10,0"
@@ -242,7 +261,16 @@
VerticalAlignment="Center"
FontSize="20"
Foreground="#FF2AB2E7"
Text="{Binding RawMaterialWeight}" />
Text="{Binding RawMaterialWeight}">
<i:Interaction.Triggers>
<i:EventTrigger EventName="TextChanged">
<i:InvokeCommandAction Command="{Binding DataContext.TextChanged, RelativeSource={RelativeSource AncestorType=ItemsControl, Mode=FindAncestor}}"/>
</i:EventTrigger>
<i:EventTrigger EventName="LostFocus">
<i:InvokeCommandAction Command="{Binding DataContext.TextChanged, RelativeSource={RelativeSource AncestorType=ItemsControl, Mode=FindAncestor}}"/>
</i:EventTrigger>
</i:Interaction.Triggers>
</TextBox>

<TextBlock
Grid.Column="2"


+ 23
- 6
DosingSystem/View/RecipeControlView.xaml 파일 보기

@@ -353,7 +353,8 @@
<Grid.RowDefinitions>
<RowDefinition Height="30" />
<RowDefinition Height="20" />
<RowDefinition Height="128" />
<RowDefinition Height="20" />
<RowDefinition Height="108" />
<RowDefinition Height="2" />
<RowDefinition Height="40" />
</Grid.RowDefinitions>
@@ -384,9 +385,25 @@
FontSize="12"
Foreground="#FF2AB2E7"
Text="{Binding RecipeName}" />
<ScrollViewer
<TextBlock
Grid.Row="2"
Margin="20,0,0,0"
HorizontalAlignment="Left"
VerticalAlignment="Center"
FontSize="12"
Foreground="#FF2AB2E7"
Text="配方总重:" />
<TextBlock
Grid.Row="2"
Margin="100,0,0,0"
HorizontalAlignment="Left"
VerticalAlignment="Center"
FontSize="12"
Foreground="#FF2AB2E7"
Text="{Binding All_RawMt_weight}" />

<ScrollViewer
Grid.Row="3"
VerticalAlignment="Top"
Background="Transparent"
HorizontalScrollBarVisibility="Hidden"
@@ -458,7 +475,7 @@
</Grid>-->

<Image
Grid.Row="3"
Grid.Row="4"
Width="{Binding ElementName=tt, Path=ActualWidth}"
Height="2"
VerticalAlignment="Bottom"
@@ -467,7 +484,7 @@

<Grid
Name="gr"
Grid.Row="4"
Grid.Row="5"
Height="30"
Margin="0,0,0,10"
VerticalAlignment="Bottom"
@@ -899,7 +916,7 @@
</ItemsControl>
</ScrollViewer>

<Button Grid.Row="2" Style="{DynamicResource ControlButtonStyle}" Content="停止配料" Command="{Binding }"/>
<Button Grid.Row="2" Style="{DynamicResource ControlButtonStyle}" Content="停止配料" Command="{Binding Close}"/>
</Grid>
<!--#endregion-->



+ 1
- 0
DosingSystem/ViewModel/NewMaterialViewModel.cs 파일 보기

@@ -41,6 +41,7 @@ public class NewMaterialViewModel : ViewModelBase

SaveCommand = new BPARelayCommand(() =>
{
if (MaterialName == String.Empty) { ErrorInfo = "原料名称不能为空"; return; }
if (Global.DeviceRawMaterials.FirstOrDefault(p => p.RawMaterialName == MaterialName) != null) { ErrorInfo = "设备中已存在该原料名称"; return; }
if (Json<LocaMaterial>.Data.LocalMaterails.FirstOrDefault(p => p.RawMaterialName == MaterialName) != null) { ErrorInfo = "本地原料名称重复"; return; }


+ 25
- 2
DosingSystem/ViewModel/NewRecipeViewModel.cs 파일 보기

@@ -8,6 +8,7 @@ using System;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Windows.Controls;

namespace BPASmartClient.DosingSystem.ViewModel
{
@@ -37,6 +38,11 @@ namespace BPASmartClient.DosingSystem.ViewModel
}
RecipCode = rm.RecipCode;
Index = Array.FindIndex(Json<LocalRecipe>.Data.Recipes.ToArray(), p => p.RecipeName == RecipeName);
All_RawMt_weight = 0;
RawMaterials.ToList()?.ForEach(item =>
{
All_RawMt_weight += (int)item.RawMaterialWeight;
});
}
}), "Details", true);

@@ -65,11 +71,23 @@ namespace BPASmartClient.DosingSystem.ViewModel
{
if (obj is string rm)
{
All_RawMt_weight = 0;
var res = RawMaterials.FirstOrDefault(p => p.RawMaterialId == rm);
if (res != null) RawMaterials.Remove(res);
RawMaterials.ToList()?.ForEach(item =>
{
All_RawMt_weight += (int)item.RawMaterialWeight;
});
}
});

TextChanged = new BPARelayCommand(() =>
{
All_RawMt_weight = 0;
RawMaterials.ToList()?.ForEach(item =>
{
All_RawMt_weight += (int)item.RawMaterialWeight;
});
});
SaveCommand = new BPARelayCommand(() =>
{
if (string.IsNullOrEmpty(RecipeName)) { MessageNotify.GetInstance.ShowDialog("请输入配方名称!", DialogType.Warning); ErrorInfo = "请输入配方名称"; return; }
@@ -84,6 +102,7 @@ namespace BPASmartClient.DosingSystem.ViewModel
if (Index >= 0 && Index < Json<LocalRecipe>.Data.Recipes.Count)
{
var res = Array.FindIndex(Json<LocalRecipe>.Data.Recipes.ToArray(), p => p.RecipeName == RecipeName);
if (res >= 0 && res != Index)
{
ErrorInfo = "配方名称已经存在!";
@@ -106,6 +125,7 @@ namespace BPASmartClient.DosingSystem.ViewModel
}
Json<LocalRecipe>.Data.Recipes.ElementAt(Index).RawMaterials.Add(item);
});
Json<LocalRecipe>.Data.Recipes.ElementAt(Index).all_RawMt_weight = All_RawMt_weight;
Json<LocalRecipe>.Save();
NoticeDemoViewModel.OpenMsg(EnumPromptType.Success, App.MainWindow, "提示", $"{RecipeName} 配方编辑完成");
}
@@ -136,6 +156,7 @@ namespace BPASmartClient.DosingSystem.ViewModel
{
RecipeName = RecipeName,
RawMaterials = TempRawMaterials,
All_RawMt_weight = All_RawMt_weight
});
Json<LocalRecipe>.Save();
NoticeDemoViewModel.OpenMsg(EnumPromptType.Success, App.MainWindow, "提示", $"新建配方成功!");
@@ -181,6 +202,7 @@ namespace BPASmartClient.DosingSystem.ViewModel

}


private void AddRecipes()
{
string date = DateTime.Now.ToString("yyyy-MM-dd-HH-mm-ss");
@@ -198,6 +220,8 @@ namespace BPASmartClient.DosingSystem.ViewModel


private string RecipCode = string.Empty;
public int all_RawMt_weight = 0;
public int All_RawMt_weight { get { return all_RawMt_weight; } set { all_RawMt_weight = value; OnPropertyChanged(); } }

public string RecipeName { get { return _mRecipeName; } set { _mRecipeName = value; OnPropertyChanged(); } }
private string _mRecipeName = string.Empty;
@@ -210,7 +234,6 @@ namespace BPASmartClient.DosingSystem.ViewModel
//public BPARelayCommand<object> RemoveCommand { get; set; }

//public BPARelayCommand SaveCommand { get; set; }

public ObservableCollection<RawMaterialModel> RawMaterials { get; set; } = new ObservableCollection<RawMaterialModel>();




+ 7
- 3
DosingSystem/ViewModel/RecipeControlViewModel.cs 파일 보기

@@ -51,10 +51,14 @@ namespace BPASmartClient.DosingSystem.ViewModel
{
SimensSend.GetInstance.SendSimens.Write("M0.0", false);
SimensSend.GetInstance.SendSimens.Write("M0.1", false);
for (int i = 0; i < DeviceInquire.GetInstance.devices.Count; i++)
/* for (int i = 0; i < DeviceInquire.GetInstance.devices.Count; i++)
{
DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].modbusTcp.Write<ushort>(DeviceAddress.TranspportSwitch.ToAdd(), (ushort)0);
}
while (DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].deviceStatus.TranspportSwitch == (ushort)1)
{
DeviceInquire.GetInstance.DeviceLists[DeviceInquire.GetInstance.devices[i].IpAddress].modbusTcp.Write<ushort>(DeviceAddress.TranspportSwitch.ToAdd(), (ushort)0);
}
}*/
});
}



+ 1
- 1
Test/MainWindow.xaml 파일 보기

@@ -24,7 +24,7 @@
Width="150"
Height="30"
Click="Button_Click_1"
Content="连接设备" />
Content="发送" />
</StackPanel>
</Grid>
</Window>

+ 18
- 10
Test/MainWindow.xaml.cs 파일 보기

@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
@@ -26,23 +27,30 @@ namespace Test
public MainWindow()
{
InitializeComponent();
command = I
modbusTcp.GetConfigPar().IpAddress = "192.168.2.10";
modbusTcp.Connected = new Action(() =>
{
t = modbusTcp.IsConnected();
});
if (t)
{
MessageBox.Show("设备连接成功");
}
}

ICommunication mySiemens = new Siemens();
byte bit = 0;

public ModbusTcp modbusTcp = new ModbusTcp();
bool t;
public ICommand command { get; set; }

private void Button_Click_1(object sender, RoutedEventArgs e)
{

mySiemens.WithSiemens(CpuType.S71200, "192.168.100.162").UseConnected(() =>
if (t)
{
MessageBox.Show("设备连接成功");
//System.Text.Encoding.RegisterProvider(System.Text.CodePagesEncodingProvider.Instance);
byte[] bytes = Encoding.Unicode.GetBytes(textBox.Text);
mySiemens.Write<byte[]>("DB1.DBB0", bytes);
});

}

}
}
}

불러오는 중...
취소
저장