using WcsMain.Common; using WcsMain.Enum.Plc; using WcsMain.EquipOperation.Entity; using WcsMain.EquipOperation.Entity.StackerConvey; using WcsMain.WcsAttribute.AutoFacAttribute; namespace WcsMain.EquipOperation.StackerConvey; [Component] public class StackerConveyOperation { /// /// 读取输送机状态 /// /// /// public (string? errText, StackerConveyInfo? stackerConveyInfo) GetStackerConveyInfo(string standId) { if (!CommonData.IsConnectPlc || CommonTool.Siemens == default) { return ("设备尚未连接", default); // 未连接PLC } var readResult = CommonTool.Siemens.ReadByteWithName($"输送机状态反馈{standId}", 36); if (!readResult.Success || readResult.Value == default) { return (readResult.Message, default); // 读取失败 } var data = readResult.Value; StackerConveyInfo stackerConveyInfo = new() { ConveyNo = Convert.ToInt16(CommonTool.Siemens.Trans(data, 0)), // 输送机编号 TaskType = Convert.ToInt16(CommonTool.Siemens.Trans(data, 2)), // 任务类型 StackerForbidden = Convert.ToInt16(CommonTool.Siemens.Trans(data, 4)), // 堆垛机动作禁止 PlcId = Convert.ToInt32(CommonTool.Siemens.Trans(data, 6)), // 当前任务号 ControlModel = (StackerConveyModelEnum)Convert.ToInt16(CommonTool.Siemens.Trans(data, 10)), // 控制方式 StackerConveyStatus = (StackerConveyStatusEnum)Convert.ToInt16(CommonTool.Siemens.Trans(data, 12)), // 库前输送机状态 VehicleSize = Convert.ToInt16(CommonTool.Siemens.Trans(data, 14)), // 载具尺寸 Weight = Convert.ToInt16(CommonTool.Siemens.Trans(data, 16)), // 重量 SensorStatus = Convert.ToUInt32(CommonTool.Siemens.Trans(data, 18)), // 传感器状态 ApplyCode = Convert.ToInt32(CommonTool.Siemens.Trans(data, 22)), // 申请条码 RunningCode = Convert.ToInt32(CommonTool.Siemens.Trans(data, 26)), // 正在运行的条码 ErrCode = Convert.ToInt16(CommonTool.Siemens.Trans(data, 30)), // 错误信息 Remark = Convert.ToInt32(CommonTool.Siemens.Trans(data, 32)), // 备注 }; return (string.Empty, stackerConveyInfo); } /// /// 获取输送机任务号 /// /// 输送机编号 /// public int GetConveyPlcId(string? conveyNo) { if (!CommonData.IsConnectPlc || CommonTool.Siemens == default) { // 未连接PLC return -1; } var readResult = CommonTool.Siemens.ReadInt32WithName($"输送机当前任务号{conveyNo}"); if (readResult.Success) { return readResult.Value; } return -1; } /// /// 读取输送机条码 /// /// /// public string? ReadConveyCode(string? conveyNo) { if (!CommonData.IsConnectPlc || CommonTool.Siemens == default) { // 未连接PLC return default; } var readResult = CommonTool.Siemens.ReadInt32WithName($"输送机读码{conveyNo}"); if (readResult.Success) { return readResult.Value.ToString(); } return default; } /// /// 输送机卸货完成 /// /// /// public string? SetConveyUnloadSuccess(string? conveyNo) { if (!CommonData.IsConnectPlc || CommonTool.Siemens == default) { // 未连接PLC return "PLC尚未连接"; } var writeResult = CommonTool.Siemens.WriteBoolWhithName($"输送机卸货完成{conveyNo}", true); if (writeResult.Success) { return string.Empty; } return writeResult.Message; } /// /// 获取输送机是否空闲 /// /// 输送机编号 /// public int GetConveyIsEasy(string? conveyNo) { if (!CommonData.IsConnectPlc || CommonTool.Siemens == default) { // 未连接PLC return -1; } var readResult = CommonTool.Siemens.ReadInt16WithName($"输送机空闲{conveyNo}"); if (readResult.Success) { return readResult.Value; } return -1; } /// /// 获取输送机是否有货 /// /// 输送机编号 /// public int GetConveyIsHaveGoods(string? conveyNo) { if (!CommonData.IsConnectPlc || CommonTool.Siemens == default) { // 未连接PLC return -1; } var readResult = CommonTool.Siemens.ReadInt32WithName($"输送机是否有货{conveyNo}"); if (readResult.Success) { return readResult.Value; } return -1; } /// /// 写入输送机任务,返回错误信息 /// /// /// public string WriteTask(StackerConveyPlcTask task) { if (!CommonData.IsConnectPlc || CommonTool.Siemens == default) { return "PLC尚未连接。"; // 未连接PLC } var (writeResult, _) = CommonTool.Siemens.WritePlcWhithName($"输送机写任务{task.StackerConveyId}", task.PlcId!, task.TaskType!, task.GetStand!, task.InTunnelId!, task.OutTunnelId!, task.SetStand!, task.GetQueue!, task.GetLine!, task.GetLayer!, task.SetQueue!, task.SetLine!, task.SetLayer!, task.GetDeep!, task.SetDeep!, task.Size!, task.Weight!, task.Code ); return writeResult.Success ? string.Empty : "写入失败"; } /// /// 获取过账数据 ---- 地面站控制 /// /// /// public List? GetConveyTaskFeedBackData(int dataNum) { if (!CommonData.IsConnectPlc || CommonTool.Siemens == default) { return default; // 未连接PLC } List taskFeedBackEntities = []; var readResult = CommonTool.Siemens.ReadByteWithName($"过账区", (ushort)(6 * dataNum)); if (!readResult.Success || readResult.Value == default) { return default; } var readData = readResult.Value; for (var i = 0; i < dataNum; i++) { TaskFeedBackEntity taskFeedBackEntity = new() { PlcId = Convert.ToInt32(CommonTool.Siemens.Trans(readData, 0 + i * 6)), FeedBackType = Convert.ToInt16(CommonTool.Siemens.Trans(readData, 4 + i * 6)), CountNo = i }; taskFeedBackEntities.Add(taskFeedBackEntity); } return taskFeedBackEntities; } /// /// 重置过账缓冲区 --- 写反馈区间接清除 ---- 地面站控制 /// /// public string? ResetFeedBackData(TaskFeedBackEntity taskFeedBackData) { if (!CommonData.IsConnectPlc || CommonTool.Siemens == default) { return "PLC 未连接"; // 未连接PLC } var dbAddress = CommonTool.Siemens.GetAddressWithNameAndBit($"过账区反馈区", 4 * taskFeedBackData.CountNo); if (string.IsNullOrEmpty(dbAddress)) { return "无法计算偏移量"; } var writeResult = CommonTool.Siemens.WritePlcWhithAddress(1, dbAddress, taskFeedBackData.PlcId); return writeResult.Success ? default : $"清除过账失败,异常信息:{writeResult.Message}"; } /// /// 重置过账缓冲区 --- 直接清除 ---- 地面站控制 /// /// public string? ClearFeedBackData(TaskFeedBackEntity taskFeedBackData) { if (!CommonData.IsConnectPlc || CommonTool.Siemens == default) { return "PLC 未连接"; // 未连接PLC } var dbAddress = CommonTool.Siemens.GetAddressWithNameAndBit($"过账区", 6 * taskFeedBackData.CountNo); if (string.IsNullOrEmpty(dbAddress)) { return "无法计算偏移量"; } var writeResult = CommonTool.Siemens.WritePlcWhithAddress(1, dbAddress, 0); return !writeResult.Success ? $"清除过账失败,异常信息:{writeResult.Message}" : default; } }