|
- using BPA.Helper;
- using BPASmartClient.Modbus;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using BPASmartClient.S7Net;
- using BPASmartClient.CustomResource.Pages.Model;
- using System.Threading;
- using System.Collections.ObjectModel;
-
- namespace BPASmartClient.JXJFoodSmallStation.Model.HK_PLC
- {
- public class HKDeviceStatus
- {
- public SiemensHelper HK_PLC_S7 = new SiemensHelper();
- 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.ReadClass<PlcReadAddressDB45>(45);
- if (res != null && res is PlcReadAddressDB45 data)
- {
- DeviceStatus = data;
- }
- var res1 = this.HK_PLC_S7.ReadClass<PlcReadAddressDB3>(3);
- if (res1 != null && res1 is PlcReadAddressDB3 data1)
- {
- GVL_SmallStation.GetInstance.plcReadDataDB3 = data1;
- }
- }
- Thread.Sleep(10);
- }), "海科PLC设备状态", true);
- }
- ///// <summary>
- ///// 单个配料机配料完成
- ///// </summary>
- ///// <param name="value"></param>
- //public void SingleDosing(uint value)
- //{
- // if (IsConnected)
- // {
- // HK_PLC_S7.Write(HKPlcCommAddress.SingleStockBinLocationToPLC, value);
- // HK_PLC_S7.Write(HKPlcCommAddress.SingleDosingFinishToPLC, (ushort)1);
- // }
- //}
- ///// <summary>
- ///// 复位plc允许接料信号
- ///// </summary>
- //public void AllowDosingSignReset()
- //{
- // HK_PLC_S7.Write(HKPlcCommAddress.IsAllowDosing,(ushort)0);
- //}
- ///// <summary>
- ///// 复位plc到达某料仓信号
- ///// </summary>
- //public void StockStateSignReset()
- //{
- // HK_PLC_S7.Write(HKPlcCommAddress.StockState, (ushort)0);
- //}
- ///// <summary>
- ///// 复位一个配方配料完成信号
- ///// </summary>
- //public void RecipeDosingFinishReset()
- //{
- // HK_PLC_S7.Write(HKPlcCommAddress.RecipeDosingFinish, (ushort)0);
- //}
-
- 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");
- //if (StockBinLocation >= 1 && StockBinLocation <= 8)
- //{
- // HK_PLC_S7.Write<bool>("DB4.DBX10." + (StockBinLocation - 1), true);
- //}
- //else if (StockBinLocation >= 9 && StockBinLocation <= 15)
- //{
- // HK_PLC_S7.Write<bool>("DB4.DBX11." + (StockBinLocation - 9), true);
- //}
- //MessageNotify.GetInstance.ShowRunLog($"托盘1—1号桶在料仓{StockBinLocation}配料");
- }
- else if (BarrelNum == 7)
- {
- TempStockBinPar(12, StockBinLocation, "1—2");
- //if (StockBinLocation >= 1 && StockBinLocation <= 8)
- //{
- // HK_PLC_S7.Write<bool>("DB4.DBX12." + (StockBinLocation - 1), true);
- //}
- //else if (StockBinLocation >= 9 && StockBinLocation <= 15)
- //{
- // HK_PLC_S7.Write<bool>("DB4.DBX13." + (StockBinLocation - 9), true);
- //}
- //MessageNotify.GetInstance.ShowRunLog($"托盘1—2号桶在料仓{StockBinLocation}配料");
- }
- else if (BarrelNum == 8)
- {
- TempStockBinPar(14, StockBinLocation, "1—3");
- //if (StockBinLocation >= 1 && StockBinLocation <= 8)
- //{
- // HK_PLC_S7.Write<bool>("DB4.DBX14." + (StockBinLocation - 1), true);
- //}
- //else if (StockBinLocation >= 9 && StockBinLocation <= 15)
- //{
- // HK_PLC_S7.Write<bool>("DB4.DBX15." + (StockBinLocation - 9), true);
- //}
- //MessageNotify.GetInstance.ShowRunLog($"托盘1—3号桶在料仓{StockBinLocation}配料");
- }
- else if (BarrelNum == 4)
- {
- TempStockBinPar(16, StockBinLocation, "1—4");
- //if (StockBinLocation >= 1 && StockBinLocation <= 8)
- //{
- // HK_PLC_S7.Write<bool>("DB4.DBX16." + (StockBinLocation - 1), true);
- //}
- //else if (StockBinLocation >= 9 && StockBinLocation <= 15)
- //{
- // HK_PLC_S7.Write<bool>("DB4.DBX17." + (StockBinLocation - 9), true);
- //}
- //MessageNotify.GetInstance.ShowRunLog($"托盘1—4号桶在料仓{StockBinLocation}配料");
- }
- }
- }
- else if (TrayNum == 2)
- {
- if (BarrelNum >= 1 && BarrelNum <= 4 && StockBinLocation >= 1 && StockBinLocation <= 15)
- {
- if (BarrelNum == 6)
- {
- TempStockBinPar(18, StockBinLocation, "2—1");
- //if (StockBinLocation >= 1 && StockBinLocation <= 8)
- //{
- // HK_PLC_S7.Write<bool>("DB4.DBX18." + (StockBinLocation - 1), true);
- //}
- //else if (StockBinLocation >= 9 && StockBinLocation <= 15)
- //{
- // HK_PLC_S7.Write<bool>("DB4.DBX19." + (StockBinLocation - 9), true);
- //}
- //MessageNotify.GetInstance.ShowRunLog($"托盘2—1号桶在料仓{StockBinLocation}配料");
- }
- else if (BarrelNum == 7)
- {
- TempStockBinPar(20, StockBinLocation, "2—2");
- //if (StockBinLocation >= 1 && StockBinLocation <= 8)
- //{
- // HK_PLC_S7.Write<bool>("DB4.DBX20." + (StockBinLocation - 1), true);
- //}
- //else if (StockBinLocation >= 9 && StockBinLocation <= 15)
- //{
- // HK_PLC_S7.Write<bool>("DB4.DBX21." + (StockBinLocation - 9), true);
- //}
- //MessageNotify.GetInstance.ShowRunLog($"托盘2—2号桶在料仓{StockBinLocation}配料");
- }
- else if (BarrelNum == 8)
- {
- TempStockBinPar(22, StockBinLocation, "2—3");
- //if (StockBinLocation >= 1 && StockBinLocation <= 8)
- //{
- // HK_PLC_S7.Write<bool>("DB4.DBX22." + (StockBinLocation - 1), true);
- //}
- //else if (StockBinLocation >= 9 && StockBinLocation <= 15)
- //{
- // HK_PLC_S7.Write<bool>("DB4.DBX23." + (StockBinLocation - 9), true);
- //}
- //MessageNotify.GetInstance.ShowRunLog($"托盘2—3号桶在料仓{StockBinLocation}配料");
- }
- else if (BarrelNum == 4)
- {
- TempStockBinPar(24, StockBinLocation, "2—4");
- //if (StockBinLocation >= 1 && StockBinLocation <= 8)
- //{
- // HK_PLC_S7.Write<bool>("DB4.DBX24." + (StockBinLocation - 1), true);
- //}
- //else if (StockBinLocation >= 9 && StockBinLocation <= 15)
- //{
- // HK_PLC_S7.Write<bool>("DB4.DBX25." + (StockBinLocation - 9), true);
- //}
- //MessageNotify.GetInstance.ShowRunLog($"托盘2—4号桶在料仓{StockBinLocation}配料");
- }
- }
- }
- }
- }
-
- 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]);
- }
- }
- //HK_PLC_S7.Write<bool[]>(AddresBarrel1, barrel1);
- //HK_PLC_S7.Write<bool[]>(AddresBarrel2, barrel2);
- //HK_PLC_S7.Write<bool[]>(AddresBarrel3, barrel3);
- 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()}");
-
- }
- }
- }
|