233 lines
7.3 KiB
C#
233 lines
7.3 KiB
C#
|
|
using System.Text;
|
|||
|
|
using System.Text.RegularExpressions;
|
|||
|
|
using WcsMain.Common;
|
|||
|
|
using WcsMain.PlcOperation.Entity;
|
|||
|
|
|
|||
|
|
namespace WcsMain.PlcOperation;
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// 输送机操作 ---- 箱式线,不包含于立库库前设备,库前请参考堆垛机操作
|
|||
|
|
/// </summary>
|
|||
|
|
public class ConveyOperation
|
|||
|
|
{
|
|||
|
|
private static ConveyOperation? _instance;
|
|||
|
|
|
|||
|
|
public static ConveyOperation Instance()
|
|||
|
|
{
|
|||
|
|
return _instance ??= new ConveyOperation();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// 写入箱式线任务
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="equipmentId"></param>
|
|||
|
|
/// <param name="task"></param>
|
|||
|
|
/// <returns></returns>
|
|||
|
|
public string WriteTask(string? equipmentId, ConveyPLCTask task)
|
|||
|
|
{
|
|||
|
|
if (!CommonData.IsConnectPlc || CommonTool.Siemens == default)
|
|||
|
|
{
|
|||
|
|
// 未连接PLC
|
|||
|
|
return "PLC尚未连接。";
|
|||
|
|
}
|
|||
|
|
var (writeResult, _) = CommonTool.Siemens.WritePlcWhithName($"箱式线写任务{equipmentId}",
|
|||
|
|
task.PlcId,
|
|||
|
|
task.Router);
|
|||
|
|
if (writeResult.Success)
|
|||
|
|
{
|
|||
|
|
return string.Empty;
|
|||
|
|
}
|
|||
|
|
return writeResult.Message ?? "写入失败,未知原因";
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// 写入输送机心跳
|
|||
|
|
/// </summary>
|
|||
|
|
/// <returns></returns>
|
|||
|
|
public string WriteHeartBeat()
|
|||
|
|
{
|
|||
|
|
if (!CommonData.IsConnectPlc || CommonTool.Siemens == default)
|
|||
|
|
{
|
|||
|
|
// 未连接PLC
|
|||
|
|
return "PLC尚未连接。";
|
|||
|
|
}
|
|||
|
|
var (writeResult, _) = CommonTool.Siemens.WritePlcWhithName($"箱式线写心跳", (short)0);
|
|||
|
|
if (writeResult.Success)
|
|||
|
|
{
|
|||
|
|
return string.Empty;
|
|||
|
|
}
|
|||
|
|
return writeResult.Message ?? "写入失败,未知原因";
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// 获取箱式线出库站台状态
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="standId"></param>
|
|||
|
|
/// <returns></returns>
|
|||
|
|
public bool GetOutConveyStatus(string? standId)
|
|||
|
|
{
|
|||
|
|
if (!CommonData.IsConnectPlc || CommonTool.Siemens == default)
|
|||
|
|
{
|
|||
|
|
// 未连接PLC
|
|||
|
|
return false;
|
|||
|
|
}
|
|||
|
|
var readGoodsExistResult = CommonTool.Siemens.ReadBoolWithName($"站台货物检测{standId}");
|
|||
|
|
if (!readGoodsExistResult.Success || readGoodsExistResult.Value) // 读取失败,或者有货 就不允许出库
|
|||
|
|
{
|
|||
|
|
return false;
|
|||
|
|
}
|
|||
|
|
var readAGVExistResult = CommonTool.Siemens.ReadBoolWithName($"站台AGV检测{standId}");
|
|||
|
|
if (!readAGVExistResult.Success || readAGVExistResult.Value) // 读取失败,或者有AGV 就不允许出库
|
|||
|
|
{
|
|||
|
|
return false;
|
|||
|
|
}
|
|||
|
|
if (!readGoodsExistResult.Value && !readAGVExistResult.Value) // 无货并且没有AGV才能出库
|
|||
|
|
{
|
|||
|
|
return true;
|
|||
|
|
}
|
|||
|
|
return false;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
|
|||
|
|
// 10.40.200.210
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// 获取入库站台状态 --- 是否可以入库
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="standId"></param>
|
|||
|
|
/// <returns></returns>
|
|||
|
|
public bool GetInConveyStatus(string? standId)
|
|||
|
|
{
|
|||
|
|
if (!CommonData.IsConnectPlc || CommonTool.Siemens == default)
|
|||
|
|
{
|
|||
|
|
// 未连接PLC
|
|||
|
|
return false;
|
|||
|
|
}
|
|||
|
|
if (string.IsNullOrEmpty(standId)) { return false; }
|
|||
|
|
if (standId.StartsWith('P'))
|
|||
|
|
{
|
|||
|
|
var readGoodsNeedIn = CommonTool.Siemens.ReadBoolWithName($"站台请求入库{standId}");
|
|||
|
|
if (!readGoodsNeedIn.Success || !readGoodsNeedIn.Value) // 读取失败,或者没有货 就不允许入库
|
|||
|
|
{
|
|||
|
|
return false;
|
|||
|
|
}
|
|||
|
|
return true;
|
|||
|
|
}
|
|||
|
|
var readGoodsExistResult = CommonTool.Siemens.ReadBoolWithName($"站台货物检测{standId}");
|
|||
|
|
if (!readGoodsExistResult.Success || !readGoodsExistResult.Value) // 读取失败,或者没有货 就不允许入库
|
|||
|
|
{
|
|||
|
|
return false;
|
|||
|
|
}
|
|||
|
|
var readAGVExistResult = CommonTool.Siemens.ReadBoolWithName($"站台AGV检测{standId}");
|
|||
|
|
if (!readAGVExistResult.Success || readAGVExistResult.Value) // 读取失败,或者有AGV 就不允许入库
|
|||
|
|
{
|
|||
|
|
return false;
|
|||
|
|
}
|
|||
|
|
if (readGoodsExistResult.Value && !readAGVExistResult.Value) // 有货并且没有AGV才能入库
|
|||
|
|
{
|
|||
|
|
return true;
|
|||
|
|
}
|
|||
|
|
return false;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// 获取箱式线拣选站台状态
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="standId"></param>
|
|||
|
|
/// <returns></returns>
|
|||
|
|
public bool GetPickConveyStatus(string? standId)
|
|||
|
|
{
|
|||
|
|
if (!CommonData.IsConnectPlc || CommonTool.Siemens == default)
|
|||
|
|
{
|
|||
|
|
// 未连接PLC
|
|||
|
|
return false;
|
|||
|
|
}
|
|||
|
|
var readGoodsExistResult = CommonTool.Siemens.ReadBoolWithName($"站台货物检测{standId}");
|
|||
|
|
if (!readGoodsExistResult.Success) // 读取失败,或者有货 就不允许出库
|
|||
|
|
{
|
|||
|
|
return false;
|
|||
|
|
}
|
|||
|
|
return !readGoodsExistResult.Value;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// 获取输送机箱子号
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="stackerId"></param>
|
|||
|
|
/// <returns></returns>
|
|||
|
|
public string GetStandCode(int stackerId)
|
|||
|
|
{
|
|||
|
|
if (!CommonData.IsConnectPlc || CommonTool.Siemens == default)
|
|||
|
|
{
|
|||
|
|
// 未连接PLC
|
|||
|
|
return string.Empty;
|
|||
|
|
}
|
|||
|
|
var readResult1 = CommonTool.Siemens.ReadStringWithName($"箱式线入库载具号{stackerId}", 10, Encoding.ASCII);
|
|||
|
|
if (!readResult1.Success)
|
|||
|
|
{
|
|||
|
|
// 读取失败
|
|||
|
|
return string.Empty;
|
|||
|
|
}
|
|||
|
|
// 返回读取到的任务号
|
|||
|
|
return Regex.Replace(readResult1.Value ?? "", "\\W", "");
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// 读取扫码点信息
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="scanId"></param>
|
|||
|
|
/// <returns></returns>
|
|||
|
|
public (string? errText, short scanOk, string code) ReadScanInfo(string scanId)
|
|||
|
|
{
|
|||
|
|
if (!CommonData.IsConnectPlc || CommonTool.Siemens == default)
|
|||
|
|
{
|
|||
|
|
// 未连接PLC
|
|||
|
|
return ("PLC尚未连接。", 0, "");
|
|||
|
|
}
|
|||
|
|
var readResult = CommonTool.Siemens.ReadByteWithName($"扫码读取{scanId}", 22);
|
|||
|
|
if (!readResult.Success || readResult.Value == default) // 读取失败
|
|||
|
|
{
|
|||
|
|
return (readResult.Message, 0, "");
|
|||
|
|
}
|
|||
|
|
try
|
|||
|
|
{
|
|||
|
|
var readData = readResult.Value;
|
|||
|
|
short status = Convert.ToInt16(CommonTool.Siemens.Trans<short>(readData, 0)); // PLC 返回任务状态
|
|||
|
|
string code = Regex.Replace(Encoding.ASCII.GetString(readData, 2, 20), "\\W", "");
|
|||
|
|
return (string.Empty, status, code);
|
|||
|
|
}
|
|||
|
|
catch (Exception ex)
|
|||
|
|
{
|
|||
|
|
return (ex.Message, 0, "");
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// 清除扫码状态
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="scanId"></param>
|
|||
|
|
/// <returns></returns>
|
|||
|
|
public string ClearScanStatus(string scanId)
|
|||
|
|
{
|
|||
|
|
if (!CommonData.IsConnectPlc || CommonTool.Siemens == default)
|
|||
|
|
{
|
|||
|
|
// 未连接PLC
|
|||
|
|
return "PLC尚未连接。";
|
|||
|
|
}
|
|||
|
|
var (writeResult, _) = CommonTool.Siemens.WritePlcWhithName($"扫码读取{scanId}", (short)0);
|
|||
|
|
if (!writeResult.Success) // 读取失败
|
|||
|
|
{
|
|||
|
|
return writeResult.Message ?? "写入失败";
|
|||
|
|
}
|
|||
|
|
try
|
|||
|
|
{
|
|||
|
|
return string.Empty;
|
|||
|
|
}
|
|||
|
|
catch (Exception ex)
|
|||
|
|
{
|
|||
|
|
return ex.Message;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
}
|