2024-05-14 16:30:56 +08:00
|
|
|
|
using System.Text;
|
|
|
|
|
|
using System.Text.RegularExpressions;
|
|
|
|
|
|
using WcsMain.Common;
|
2024-05-30 15:34:20 +08:00
|
|
|
|
using WcsMain.EquipOperation.Entity;
|
2024-05-23 07:27:57 +08:00
|
|
|
|
using WcsMain.WcsAttribute.AutoFacAttribute;
|
2024-05-14 16:30:56 +08:00
|
|
|
|
|
2024-05-30 15:34:20 +08:00
|
|
|
|
namespace WcsMain.EquipOperation.Convey;
|
2024-05-14 16:30:56 +08:00
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 输送机操作 ---- 箱式线,不包含于立库库前设备,库前请参考堆垛机操作
|
|
|
|
|
|
/// </summary>
|
2024-05-23 07:27:57 +08:00
|
|
|
|
[Component]
|
2024-05-14 16:30:56 +08:00
|
|
|
|
public class ConveyOperation
|
|
|
|
|
|
{
|
2024-05-23 07:27:57 +08:00
|
|
|
|
/// <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 ?? "写入失败,未知原因";
|
|
|
|
|
|
}
|
2024-05-14 16:30:56 +08:00
|
|
|
|
|
2024-05-23 07:27:57 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 箱式线允许取货
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="point">要取货的点位</param>
|
|
|
|
|
|
/// <returns></returns>
|
2024-06-25 09:12:20 +08:00
|
|
|
|
public bool AllowGetVehicle(string? point)
|
2024-05-23 07:27:57 +08:00
|
|
|
|
{
|
|
|
|
|
|
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>
|
2024-06-25 09:12:20 +08:00
|
|
|
|
public bool AllowSetVehicle(string? point)
|
2024-05-23 07:27:57 +08:00
|
|
|
|
{
|
|
|
|
|
|
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>
|
2024-06-25 09:12:20 +08:00
|
|
|
|
public List<string>? ReadAreaConveyCode(string? point)
|
2024-05-14 16:30:56 +08:00
|
|
|
|
{
|
2024-05-23 07:27:57 +08:00
|
|
|
|
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", "")];
|
2024-05-14 16:30:56 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2024-06-25 09:12:20 +08:00
|
|
|
|
/// <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", ""));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-05-23 07:27:57 +08:00
|
|
|
|
|
2024-06-12 07:29:44 +08:00
|
|
|
|
/// <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 返回任务状态
|
|
|
|
|
|
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) return "PLC尚未连接。";
|
|
|
|
|
|
var (writeResult, _) = CommonTool.Siemens.WritePlcWhithName($"扫码读取{scanId}", (short)0);
|
|
|
|
|
|
if (!writeResult.Success) return writeResult.Message ?? "写入失败";
|
|
|
|
|
|
return string.Empty;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-05-14 16:30:56 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 写入箱式线任务
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="equipmentId"></param>
|
|
|
|
|
|
/// <param name="task"></param>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
public string WriteTask(string? equipmentId, ConveyPLCTask task)
|
|
|
|
|
|
{
|
2024-06-12 09:23:20 +08:00
|
|
|
|
if (!CommonData.IsConnectPlc || CommonTool.Siemens == default) return "PLC尚未连接。";
|
2024-05-14 16:30:56 +08:00
|
|
|
|
var (writeResult, _) = CommonTool.Siemens.WritePlcWhithName($"箱式线写任务{equipmentId}",
|
|
|
|
|
|
task.PlcId,
|
|
|
|
|
|
task.Router);
|
2024-06-12 09:23:20 +08:00
|
|
|
|
return writeResult.Success ? string.Empty : writeResult.Message ?? "写入失败,未知原因";
|
2024-05-14 16:30:56 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2024-06-12 09:23:20 +08:00
|
|
|
|
/// <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));
|
|
|
|
|
|
|
|
|
|
|
|
|
2024-06-15 15:32:19 +08:00
|
|
|
|
/// <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 ?? "写入失败,未知原因";
|
|
|
|
|
|
}
|
2024-06-12 09:23:20 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2024-05-14 16:30:56 +08:00
|
|
|
|
|
2024-05-30 15:34:20 +08:00
|
|
|
|
|
|
|
|
|
|
|
2024-05-14 16:30:56 +08:00
|
|
|
|
/// <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", "");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|