|
- using BPASmartClient.CustomResource.Pages.Model;
- using BPA.Helper;
- using System;
- using System.Collections.ObjectModel;
- using System.Threading;
-
- namespace BPASmartClient.FoodStationTest.Model.HK_PLC
- {
- public class HKDeviceStatus
- {
- public BPA.Communication.Siemens HK_PLC_S7 = new BPA.Communication.Siemens();
- public bool IsConnected => HK_PLC_S7.IsConnected();
- public PlcReadAddressDB45 DeviceStatus = new PlcReadAddressDB45();
- public void Init()
- {
- TaskManage.GetInstance.StartLong(new Action(() =>
- {
- if (IsConnected)
- {
- var res = this.HK_PLC_S7.Read<PlcReadAddressDB45>(45);
-
- if (res.IsSuccess && res.Content != null && res.Content is PlcReadAddressDB45 data)
- {
- DeviceStatus = data;
- }
- var res1 = this.HK_PLC_S7.Read<PlcReadAddressDB3>(3);
- if (res1.IsSuccess && res1.Content != null && res1.Content is PlcReadAddressDB3 data1)
- {
- GVL_SmallStation.GetInstance.plcReadDataDB3 = data1;
- }
- }
- Thread.Sleep(10);
- }), "海科PLC设备状态", true);
- }
-
- private void TempStockBinPar(int num, ushort StockBinLocation, string info)
- {
- if (StockBinLocation >= 1 && StockBinLocation <= 8)
- {
- HK_PLC_S7.Write<bool>($"DB4.DBX{num}." + (StockBinLocation - 1), true);
- }
- else if (StockBinLocation >= 9 && StockBinLocation <= 15)
- {
- HK_PLC_S7.Write<bool>($"DB4.DBX{num + 1}." + (StockBinLocation - 9), true);
- }
- MessageNotify.GetInstance.ShowRunLog($"托盘{info}号桶在料仓{StockBinLocation}配料");
- }
-
- /// <summary>
- /// 下发配方数据
- /// </summary>
- /// <param name="BarrelNum">单个桶的编号</param>
- /// <param name="StockBinLocation">单个桶对应的料仓位置</param>
- public void StockBinPar(uint BarrelNum, ushort StockBinLocation, int TrayNum = 1)
- {
- if (IsConnected)
- {
- if (TrayNum == 1)
- {
- if (BarrelNum >= 6 && BarrelNum <= 8 && StockBinLocation >= 1 && StockBinLocation <= 15)
- {
- if (BarrelNum == 6)
- {
- TempStockBinPar(10, StockBinLocation, "1—1");
- }
- else if (BarrelNum == 7)
- {
- TempStockBinPar(12, StockBinLocation, "1—2");
- }
- else if (BarrelNum == 8)
- {
- TempStockBinPar(14, StockBinLocation, "1—3");
- }
- else if (BarrelNum == 4)
- {
- TempStockBinPar(16, StockBinLocation, "1—4");
- }
- }
- }
- else if (TrayNum == 2)
- {
- if (BarrelNum >= 1 && BarrelNum <= 4 && StockBinLocation >= 1 && StockBinLocation <= 15)
- {
- if (BarrelNum == 6)
- {
- TempStockBinPar(18, StockBinLocation, "2—1");
- }
- else if (BarrelNum == 7)
- {
- TempStockBinPar(20, StockBinLocation, "2—2");
- }
- else if (BarrelNum == 8)
- {
- TempStockBinPar(22, StockBinLocation, "2—3");
- }
- else if (BarrelNum == 4)
- {
- TempStockBinPar(24, StockBinLocation, "2—4");
- }
- }
- }
- }
- }
-
- public void IssueRecipeToPlc(ObservableCollection<RemoteRecipeRawMaterial> rawMaterials, int recipeLoction)
- {
- bool[] barrel = new bool[16];
- bool[] barrel1 = new bool[16];
- bool[] barrel2 = new bool[16];
- bool[] barrel3 = new bool[16];
- ushort barrel1_short = 0;
- ushort barrel2_short = 0;
- ushort barrel3_short = 0;
-
- foreach (var item in rawMaterials)
- {
- switch (item.RawMaterialBarrelNum)
- {
- case 6:
- barrel[item.RawMaterialLocation - 1] = true;
- barrel1[item.RawMaterialLocation - 1] = true;
- break;
- case 7:
- barrel[item.RawMaterialLocation - 1] = true;
- barrel2[item.RawMaterialLocation - 1] = true;
- break;
- case 8:
- barrel[item.RawMaterialLocation - 1] = true;
- barrel3[item.RawMaterialLocation - 1] = true;
- break;
- default:
- break;
- }
- }
- for (int i = 0; i < 16; i++)
- {
- if (recipeLoction == 0)
- {
- if (i >= 8)
- {
- HK_PLC_S7.Write<bool>("DB4.DBX15." + (i - 8), barrel1[i]);
- HK_PLC_S7.Write<bool>("DB4.DBX17." + (i - 8), barrel2[i]);
- HK_PLC_S7.Write<bool>("DB4.DBX19." + (i - 8), barrel3[i]);
- }
- else
- {
- HK_PLC_S7.Write<bool>("DB4.DBX14." + i, barrel1[i]);
- HK_PLC_S7.Write<bool>("DB4.DBX16." + i, barrel2[i]);
- HK_PLC_S7.Write<bool>("DB4.DBX18." + i, barrel3[i]);
- }
- barrel1_short = barrel1_short.SetBitValue((byte)(i + 1), barrel1[i]);
- barrel2_short = barrel2_short.SetBitValue((byte)(i + 1), barrel2[i]);
- barrel3_short = barrel3_short.SetBitValue((byte)(i + 1), barrel3[i]);
- GVL_SmallStation.GetInstance.RecipeStockBinDosing[recipeLoction] = GVL_SmallStation.GetInstance.RecipeStockBinDosing[recipeLoction].SetBitValue((byte)(i + 1), barrel[i]);
- }
- else if (recipeLoction == 1)
- {
- if (i >= 8)
- {
- HK_PLC_S7.Write<bool>("DB4.DBX21." + (i - 8), barrel1[i]);
- HK_PLC_S7.Write<bool>("DB4.DBX23." + (i - 8), barrel2[i]);
- HK_PLC_S7.Write<bool>("DB4.DBX25." + (i - 8), barrel3[i]);
- }
- else
- {
- HK_PLC_S7.Write<bool>("DB4.DBX20." + i, barrel1[i]);
- HK_PLC_S7.Write<bool>("DB4.DBX22." + i, barrel2[i]);
- HK_PLC_S7.Write<bool>("DB4.DBX24." + i, barrel3[i]);
- }
- barrel1_short = barrel1_short.SetBitValue((byte)(i + 1), barrel1[i]);
- barrel2_short = barrel2_short.SetBitValue((byte)(i + 1), barrel2[i]);
- barrel3_short = barrel3_short.SetBitValue((byte)(i + 1), barrel3[i]);
- GVL_SmallStation.GetInstance.RecipeStockBinDosing[recipeLoction] = GVL_SmallStation.GetInstance.RecipeStockBinDosing[recipeLoction].SetBitValue((byte)(i + 1), barrel[i]);
- }
- }
- MessageNotify.GetInstance.ShowRunLog($"配方下发,plc配方位置{recipeLoction},桶1料仓配料{barrel1_short},配料位置{barrel1_short.ToBinString()}");
- MessageNotify.GetInstance.ShowRunLog($"配方下发,plc配方位置{recipeLoction},桶2料仓配料{barrel2_short},配料位置{barrel2_short.ToBinString()}");
- MessageNotify.GetInstance.ShowRunLog($"配方下发,plc配方位置{recipeLoction},桶3料仓配料{barrel3_short},配料位置{barrel3_short.ToBinString()}");
- MessageNotify.GetInstance.ShowRunLog($"配方下发,plc配方位置{recipeLoction},料仓配料{GVL_SmallStation.GetInstance.RecipeStockBinDosing[recipeLoction]},配料位置{GVL_SmallStation.GetInstance.RecipeStockBinDosing[recipeLoction].ToBinString()}");
-
- }
- }
- }
|