using WIDESEAWCS_QuartzJob; namespace WIDESEAWCS_Tasks { /// /// 输送线设备请求处理器:处理拘束机/插拔钉机上下层请求。 /// public class ConveyorLineTargetAddressSelector { private const string ConstraintMachineName = "拘束机"; private const string PinMachineName = "插拔钉机"; // 拘束机点位 private static readonly List ConstraintMachineCodes = new List { "10180", "20090" }; // 插拔钉机点位 private static readonly List PinMachineCodes = new List { "10190", "20100" }; public void HandleInboundNextAddress(CommonConveyorLine conveyorLine, string nextAddress, string childDeviceCode) { HandleDeviceRequest(conveyorLine, nextAddress, childDeviceCode, isUpper: true); } public void HandleOutboundNextAddress(CommonConveyorLine conveyorLine, string nextAddress, string childDeviceCode) { HandleDeviceRequest(conveyorLine, nextAddress, childDeviceCode, isUpper: false); } private void HandleDeviceRequest(CommonConveyorLine conveyorLine, string nextAddress, string childDeviceCode, bool isUpper) { var devices = Storage.Devices; if (ConstraintMachineCodes.Contains(nextAddress)) { ConstraintMachine? constraint = devices.OfType().FirstOrDefault(d => d.DeviceName == ConstraintMachineName); if (constraint == null) { return; } ProcessDeviceRequest( conveyorLine, childDeviceCode, getMaterialRequest: () => isUpper ? constraint.GetValue(ConstraintMachineDBName.MaterialRequestUpper) != 0 : constraint.GetValue(ConstraintMachineDBName.MaterialRequestLower) != 0, getOutputRequest: () => isUpper ? constraint.GetValue(ConstraintMachineDBName.OutputRequestUpper) != 0 : constraint.GetValue(ConstraintMachineDBName.OutputRequestLower) != 0, setOutputReady: outputReq => { if (isUpper) { constraint.SetValue(ConstraintMachineDBName.ConstraintTrayOutputReadyUpper, outputReq ? 1 : 0); } else { constraint.SetValue(ConstraintMachineDBName.ConstraintTrayOutputReadyLower, outputReq ? 1 : 0); } }); } else if (PinMachineCodes.Contains(nextAddress)) { PinMachine? pinMachine = devices.OfType().FirstOrDefault(d => d.DeviceName == PinMachineName); if (pinMachine == null) { return; } ProcessDeviceRequest( conveyorLine, childDeviceCode, getMaterialRequest: () => isUpper ? pinMachine.GetValue(PinMachineDBName.MaterialRequestUpper) != 0 : pinMachine.GetValue(PinMachineDBName.MaterialRequestLower) != 0, getOutputRequest: () => isUpper ? pinMachine.GetValue(PinMachineDBName.OutputRequestUpper) != 0 : pinMachine.GetValue(PinMachineDBName.OutputRequestLower) != 0, setOutputReady: outputReq => { if (isUpper) { pinMachine.SetValue(PinMachineDBName.PlugPinTrayOutputReadyUpper, outputReq ? 1 : 0); } else { pinMachine.SetValue(PinMachineDBName.PlugPinTrayOutputReadyLower, outputReq ? 1 : 0); } }); } } private static void ProcessDeviceRequest( CommonConveyorLine conveyorLine, string childDeviceCode, Func getMaterialRequest, Func getOutputRequest, Action setOutputReady) { bool materialReq = getMaterialRequest(); bool outputReq = getOutputRequest(); if (materialReq) { conveyorLine.SetValue(ConveyorLineDBNameNew.Target, 1, childDeviceCode); conveyorLine.SetValue(ConveyorLineDBNameNew.WCS_ACK, 1, childDeviceCode); } else { setOutputReady(outputReq); } } } }