using WIDESEAWCS_QuartzJob;
|
namespace WIDESEAWCS_Tasks
|
{
|
/// <summary>
|
/// 输送线设备请求处理器:处理拘束机/插拔钉机上下层请求。
|
/// </summary>
|
public class ConveyorLineTargetAddressSelector
|
{
|
private const string ConstraintMachineName = "拘束机";
|
private const string PinMachineName = "插拔钉机";
|
|
// 拘束机点位
|
private static readonly List<string> ConstraintMachineCodes = new List<string> { "10180", "20090" };
|
// 插拔钉机点位
|
private static readonly List<string> PinMachineCodes = new List<string> { "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<ConstraintMachine>().FirstOrDefault(d => d.DeviceName == ConstraintMachineName);
|
if (constraint == null)
|
{
|
return;
|
}
|
|
ProcessDeviceRequest(
|
conveyorLine,
|
childDeviceCode,
|
getMaterialRequest: () => isUpper
|
? constraint.GetValue<ConstraintMachineDBName, short>(ConstraintMachineDBName.MaterialRequestUpper) != 0
|
: constraint.GetValue<ConstraintMachineDBName, short>(ConstraintMachineDBName.MaterialRequestLower) != 0,
|
getOutputRequest: () => isUpper
|
? constraint.GetValue<ConstraintMachineDBName, short>(ConstraintMachineDBName.OutputRequestUpper) != 0
|
: constraint.GetValue<ConstraintMachineDBName, short>(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<PinMachine>().FirstOrDefault(d => d.DeviceName == PinMachineName);
|
if (pinMachine == null)
|
{
|
return;
|
}
|
|
ProcessDeviceRequest(
|
conveyorLine,
|
childDeviceCode,
|
getMaterialRequest: () => isUpper
|
? pinMachine.GetValue<PinMachineDBName, short>(PinMachineDBName.MaterialRequestUpper) != 0
|
: pinMachine.GetValue<PinMachineDBName, short>(PinMachineDBName.MaterialRequestLower) != 0,
|
getOutputRequest: () => isUpper
|
? pinMachine.GetValue<PinMachineDBName, short>(PinMachineDBName.OutputRequestUpper) != 0
|
: pinMachine.GetValue<PinMachineDBName, short>(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<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);
|
}
|
}
|
}
|
}
|