339 lines
12 KiB
C#
339 lines
12 KiB
C#
using System.Text;
|
||
using System.Text.RegularExpressions;
|
||
using WcsMain.Common;
|
||
using WcsMain.EquipOperation.Entity;
|
||
using WcsMain.WcsAttribute.AutoFacAttribute;
|
||
|
||
namespace WcsMain.EquipOperation.Convey;
|
||
|
||
/// <summary>
|
||
/// 输送机操作 ---- 箱式线,不包含于立库库前设备,库前请参考堆垛机操作
|
||
/// </summary>
|
||
[Component]
|
||
public class ConveyOperation
|
||
{
|
||
/// <summary>
|
||
/// 写入输送机心跳
|
||
/// </summary>
|
||
/// <returns></returns>
|
||
public string WriteHeartBeat()
|
||
{
|
||
if (!CommonData.IsConnectPlc || CommonTool.Siemens == default) return "PLC尚未连接。";
|
||
var (writeResult, _) = CommonTool.Siemens.WritePlcWhithName($"箱式线写心跳", (short)0);
|
||
return writeResult.Success ? string.Empty : writeResult.Message ?? "写入失败,未知原因";
|
||
}
|
||
|
||
/// <summary>
|
||
/// 箱式线允许取货
|
||
/// </summary>
|
||
/// <param name="point">要取货的点位</param>
|
||
/// <returns></returns>
|
||
public bool AllowGetVehicle(string? point)
|
||
{
|
||
if (!CommonData.IsConnectPlc || CommonTool.Siemens == default) return false;
|
||
var readResult = CommonTool.Siemens.ReadInt16WithName($"箱式线允许取货{point}");
|
||
return readResult.Success && readResult.Value == 1;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 箱式线允许卸货
|
||
/// </summary>
|
||
/// <param name="point">要取货的点位</param>
|
||
/// <returns></returns>
|
||
public bool AllowSetVehicle(string? point)
|
||
{
|
||
if (!CommonData.IsConnectPlc || CommonTool.Siemens == default) return false;
|
||
var readResult = CommonTool.Siemens.ReadInt16WithName($"箱式线允许卸货{point}");
|
||
return readResult.Success && readResult.Value == 1;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 读取箱式线入库站台反馈的载具号
|
||
/// </summary>
|
||
/// <param name="point"></param>
|
||
/// <returns></returns>
|
||
public List<string>? ReadAreaConveyCode(string? point)
|
||
{
|
||
if (!CommonData.IsConnectPlc || CommonTool.Siemens == default) return default;
|
||
var readResult1 = CommonTool.Siemens.ReadStringWithName($"箱式线入库载具号{point}-1", 20, Encoding.ASCII);
|
||
var readResult2 = CommonTool.Siemens.ReadStringWithName($"箱式线入库载具号{point}-2", 20, Encoding.ASCII);
|
||
if (!readResult1.Success! || !readResult2.Success!) return default;
|
||
// 返回读取到的任务号
|
||
return [Regex.Replace(readResult1.Value ?? "", "\\W", ""), Regex.Replace(readResult2.Value ?? "", "\\W", "")];
|
||
}
|
||
|
||
/// <summary>
|
||
/// 读取箱号
|
||
/// </summary>
|
||
/// <param name="point"></param>
|
||
/// <returns></returns>
|
||
public (string? errText, string? code) ReadConveyCode(string? point)
|
||
{
|
||
if (!CommonData.IsConnectPlc || CommonTool.Siemens == default) return ("设备离线", default);
|
||
var readResult1 = CommonTool.Siemens.ReadStringWithName($"箱式线入库载具号{point}", 20, Encoding.ASCII);
|
||
if (!readResult1.Success!) return (readResult1.Message, default);
|
||
// 返回读取到的任务号
|
||
return (default, 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) 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 返回任务状态
|
||
var str = Encoding.ASCII.GetString(readData, 2, 20);
|
||
string code = Regex.Replace(str, "\\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) return "PLC尚未连接。";
|
||
var (writeResult, _) = CommonTool.Siemens.WritePlcWhithName($"扫码读取{scanId}", (short)0);
|
||
if (!writeResult.Success) return writeResult.Message ?? "写入失败";
|
||
return string.Empty;
|
||
}
|
||
|
||
|
||
/// <summary>
|
||
/// 读取站台扫码点信息
|
||
/// </summary>
|
||
/// <param name="scanId"></param>
|
||
/// <returns></returns>
|
||
public string ReadStandCode(string? standId)
|
||
{
|
||
if (!CommonData.IsConnectPlc || CommonTool.Siemens == default) return string.Empty;
|
||
var readResult = CommonTool.Siemens.ReadByteWithName($"站台条码读取{standId}", 22);
|
||
if (!readResult.Success || readResult.Value == default) return string.Empty;// 读取失败
|
||
try
|
||
{
|
||
var readData = readResult.Value;
|
||
short status = Convert.ToInt16(CommonTool.Siemens.Trans<short>(readData, 0)); // PLC 返回任务状态
|
||
if (status == 0) return string.Empty;
|
||
string code = Regex.Replace(Encoding.ASCII.GetString(readData, 0, 20), "\\W", "");
|
||
return code;
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
_ = ex;
|
||
return string.Empty;
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 清除站台扫码状态
|
||
/// </summary>
|
||
/// <param name="scanId"></param>
|
||
/// <returns></returns>
|
||
public string ClearStandCodeStatus(string? standId)
|
||
{
|
||
if (!CommonData.IsConnectPlc || CommonTool.Siemens == default) return "PLC尚未连接。";
|
||
var (writeResult, _) = CommonTool.Siemens.WritePlcWhithName($"站台条码读取{standId}", (short)0);
|
||
if (!writeResult.Success) return writeResult.Message ?? "写入失败";
|
||
return string.Empty;
|
||
}
|
||
|
||
/// <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) return "PLC尚未连接。";
|
||
var (writeResult, _) = CommonTool.Siemens.WritePlcWhithName($"箱式线写任务{equipmentId}",
|
||
task.PlcId,
|
||
task.Router);
|
||
return writeResult.Success ? string.Empty : writeResult.Message ?? "写入失败,未知原因";
|
||
}
|
||
|
||
/// <summary>
|
||
/// 箱式线写任务
|
||
/// </summary>
|
||
/// <param name="equipmentId"></param>
|
||
/// <param name="plcId"></param>
|
||
/// <param name="router"></param>
|
||
/// <returns></returns>
|
||
public string WriteTask(string? equipmentId, int plcId, short router) => WriteTask(equipmentId, new ConveyPLCTask(plcId, router));
|
||
|
||
|
||
/// <summary>
|
||
/// 释放指定位置的箱子
|
||
/// </summary>
|
||
/// <param name="conveyId"></param>
|
||
/// <returns></returns>
|
||
public string DisposeVehicle(string? conveyId)
|
||
{
|
||
if (!CommonData.IsConnectPlc || CommonTool.Siemens == default) return "PLC尚未连接。";
|
||
var (writeResult, _) = CommonTool.Siemens.WritePlcWhithName($"箱式线释放{conveyId}", (short)1);
|
||
return writeResult.Success ? string.Empty : writeResult.Message ?? "写入失败,未知原因";
|
||
}
|
||
|
||
|
||
/// <summary>
|
||
/// 读取拣选站台释放的信号
|
||
/// </summary>
|
||
/// <param name="pickStandId"></param>
|
||
/// <returns></returns>
|
||
public int GetAllowPickStandGo(string pickStandId)
|
||
{
|
||
if (!CommonData.IsConnectPlc || CommonTool.Siemens == default) return 0;
|
||
var readResult = CommonTool.Siemens.ReadInt16WithName($"拣选确认按钮{pickStandId}");
|
||
if (!readResult.Success) return 0;// 读取失败
|
||
return readResult.Value;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 通知 plc 可以释放站台
|
||
/// </summary>
|
||
/// <param name="pickStandId"></param>
|
||
/// <param name="router"></param>
|
||
/// <returns></returns>
|
||
public string AllowPickStandGo(string pickStandId, short router)
|
||
{
|
||
if (!CommonData.IsConnectPlc || CommonTool.Siemens == default) return "PLC尚未连接。";
|
||
var (writeResult, _) = CommonTool.Siemens.WritePlcWhithName($"拣选站台释放{pickStandId}", router);
|
||
if (!writeResult.Success) return writeResult.Message ?? "写入失败"; // 读取失败
|
||
return string.Empty;
|
||
}
|
||
|
||
|
||
|
||
|
||
/// <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", "");
|
||
}
|
||
|
||
|
||
|
||
} |