using WIDESEAWCS_QuartzJob;
|
namespace WIDESEAWCS_Tasks
|
{
|
/// <summary>
|
/// 输送线设备请求处理器:处理拘束机/插拔钉机上下层请求。
|
/// </summary>
|
public class ConveyorLineTargetAddressSelector
|
{
|
private const string ConstraintMachineName = "拘束机";
|
private const string PinMachineName = "插拔钉机";
|
|
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 (string.Equals(nextAddress, ConstraintMachineName, StringComparison.Ordinal))
|
{
|
ConstraintMachine? constraint = devices.OfType<ConstraintMachine>().FirstOrDefault(d => d.DeviceName == ConstraintMachineName);
|
if (constraint == null)
|
{
|
return;
|
}
|
|
ProcessDeviceRequest(
|
conveyorLine,
|
childDeviceCode,
|
getMaterialRequest: () => isUpper
|
? constraint.GetValue<ConstraintMachineDBName, bool>(ConstraintMachineDBName.MaterialRequestUpper)
|
: constraint.GetValue<ConstraintMachineDBName, bool>(ConstraintMachineDBName.MaterialRequestLower),
|
getOutputRequest: () => isUpper
|
? constraint.GetValue<ConstraintMachineDBName, bool>(ConstraintMachineDBName.OutputRequestUpper)
|
: constraint.GetValue<ConstraintMachineDBName, bool>(ConstraintMachineDBName.OutputRequestLower),
|
setOutputReady: outputReq =>
|
{
|
if (isUpper)
|
{
|
constraint.SetValue(ConstraintMachineDBName.ConstraintTrayOutputReadyUpper, outputReq ? 1 : 0);
|
}
|
else
|
{
|
constraint.SetValue(ConstraintMachineDBName.ConstraintTrayOutputReadyLower, outputReq ? 1 : 0);
|
}
|
});
|
}
|
else if (string.Equals(nextAddress, PinMachineName, StringComparison.Ordinal))
|
{
|
PinMachine? pinMachine = devices.OfType<PinMachine>().FirstOrDefault(d => d.DeviceName == PinMachineName);
|
if (pinMachine == null)
|
{
|
return;
|
}
|
|
ProcessDeviceRequest(
|
conveyorLine,
|
childDeviceCode,
|
getMaterialRequest: () => isUpper
|
? pinMachine.GetValue<PinMachineDBName, bool>(PinMachineDBName.MaterialRequestUpper)
|
: pinMachine.GetValue<PinMachineDBName, bool>(PinMachineDBName.MaterialRequestLower),
|
getOutputRequest: () => isUpper
|
? pinMachine.GetValue<PinMachineDBName, bool>(PinMachineDBName.OutputRequestUpper)
|
: pinMachine.GetValue<PinMachineDBName, bool>(PinMachineDBName.OutputRequestLower),
|
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<bool> getMaterialRequest,
|
Func<bool> getOutputRequest,
|
Action<bool> 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);
|
}
|
}
|
}
|
}
|