master
liuwf 1 year ago
parent 6e1ff812fe
commit 0f5ac6e956

@ -27,6 +27,38 @@ namespace Khd.Core.Plc
plc.Write(address, GetValue(len, valueString)); plc.Write(address, GetValue(len, valueString));
} }
/// <summary>
/// 写入RFID
/// </summary>
/// <param name="plc"> plc </param>
/// <param name="address"> 读取地址 </param>
/// <param name="len"> 长度 </param>
/// <returns> 读取到的RFID </returns>
public static void WriteRFID(this Plc.S7.Plc plc, string address, string value,int len = 15)
{
string[] adds = address.Split(".");
int db = int.Parse(adds[0].Replace("DB", ""));
int startByteAdr = int.Parse(adds[1].Replace("DBX", ""));
// 将 value 转换为字节数组,确保其长度符合要求
byte[] byteArray = Encoding.ASCII.GetBytes(value);
if (byteArray.Length > len)
{
throw new ArgumentException($"Value length exceeds the specified length of {len} bytes.");
}
// 填充字节数组到指定长度
byte[] dataToWrite = new byte[len];
Array.Copy(byteArray, dataToWrite, byteArray.Length);
plc.Write(S7.DataType.DataBlock, db, startByteAdr, dataToWrite);
}
/// <summary> /// <summary>
/// 读取RFID /// 读取RFID
/// </summary> /// </summary>

@ -1,4 +1,5 @@
using Khd.Core.EntityFramework; using Khd.Core.Domain.Models;
using Khd.Core.EntityFramework;
using Khd.Core.Library; using Khd.Core.Library;
using Khd.Core.Wcs.Global; using Khd.Core.Wcs.Global;
using Khd.Core.Wcs.Wcs; using Khd.Core.Wcs.Wcs;
@ -61,6 +62,7 @@ namespace Khd.Core.Wcs
StaticData.PlcDic.TryAdd(plcConfig.Code, plc); StaticData.PlcDic.TryAdd(plcConfig.Code, plc);
} }
} }
//创建定时器 //创建定时器
SystemTimer systemTimer = new SystemTimer(_host); SystemTimer systemTimer = new SystemTimer(_host);
systemTimer.Start(); systemTimer.Start();

@ -579,6 +579,7 @@ namespace Khd.Core.Wcs.Wcs
} }
} }
} }
} }
else if (item.taskStatus == 7) else if (item.taskStatus == 7)
{ {
@ -590,6 +591,14 @@ namespace Khd.Core.Wcs.Wcs
} }
if (item.taskType == StaticTaskType.SecondSmallPackageToStorage) if (item.taskType == StaticTaskType.SecondSmallPackageToStorage)
{ {
//取托盘确认信号DB4.DBX310.1写true
BasePlcpoint SecondOutGetOverPoint = StaticData.BasePlcpointList.First(t => t.id == 71);
StaticData.PlcDic[2].WriteToPoint(SecondOutGetOverPoint.plcpointAddress, true, SecondOutGetOverPoint.plcpointLength.ToString());
// 清空小包出口RFID
BasePlcpoint RFID2001Point = StaticData.BasePlcpointList.First(t => t.id == 52);
StaticData.PlcDic[2].WriteRFID(RFID2001Point.plcpointAddress,"", 12);//小包出口的RFID
//WmsProductInstock? wmsProductInstock = dbContext.WmsProductInstock.FirstOrDefault(t => t.productInstockId == item.orderId); //WmsProductInstock? wmsProductInstock = dbContext.WmsProductInstock.FirstOrDefault(t => t.productInstockId == item.orderId);
//if (wmsProductInstock != null) //if (wmsProductInstock != null)
//{ //{
@ -709,6 +718,10 @@ namespace Khd.Core.Wcs.Wcs
} }
else if (item.taskType == StaticTaskType.SecondLineToSmallPackage)//输送线到小包入口 else if (item.taskType == StaticTaskType.SecondLineToSmallPackage)//输送线到小包入口
{ {
// 小包入口确认信号
BaseEquip startEquip = dbContext.BaseEquip.First(t => t.objid == item.currPointId); BaseEquip startEquip = dbContext.BaseEquip.First(t => t.objid == item.currPointId);
startEquip.equipStatus = 0; startEquip.equipStatus = 0;
dbContext.Update(startEquip); dbContext.Update(startEquip);

@ -56,11 +56,14 @@ namespace Khd.Core.Wcs.Wcs
dbContext.ChangeTracker.Entries().ToList().ForEach(e => e.Reload()); dbContext.ChangeTracker.Entries().ToList().ForEach(e => e.Reload());
var agvPutValue = StaticData.PlcDic[2].Read(agvPutPoint.plcpointAddress);//小包入口叫料 var agvPutValue = StaticData.PlcDic[2].Read(agvPutPoint.plcpointAddress);//小包入口叫料
var agvGetValue = StaticData.PlcDic[2].Read(agvGetPoint.plcpointAddress);//小包出口的到位 var agvGetValue = StaticData.PlcDic[2].Read(agvGetPoint.plcpointAddress);//小包出口的到位
var rfidValue = StaticData.PlcDic[2].ReadRFID(rfidPoint.plcpointAddress);//小包出口的RFID var rfidValue = StaticData.PlcDic[2].ReadRFID(rfidPoint.plcpointAddress,15);//小包出口的RFID
if (agvGetValue != null && agvPutValue != null && rfidValue != null)//读Plc if (agvGetValue != null && agvPutValue != null && rfidValue != null)//读Plc
{ {
//待删除
agvPutValue = 1;
if (Convert.ToInt32(agvPutValue) == 0)//小包入口叫料 if (Convert.ToInt32(agvPutValue) == 0)//小包入口叫料
{ {
bool canCreate = dbContext.WcsTask.Where(t => t.nextPointId == 8 || t.endPointId == endEquip.objid).Any();//有没有生成任务 bool canCreate = dbContext.WcsTask.Where(t => t.nextPointId == 8 || t.endPointId == endEquip.objid).Any();//有没有生成任务
//36 是小包入口的设备信息8是二楼Agv设备 //36 是小包入口的设备信息8是二楼Agv设备
if (!canCreate)//没有任务 if (!canCreate)//没有任务

Loading…
Cancel
Save