using Bro.Common.Base;
|
using Bro.Common.Helper;
|
using Bro.Common.Interface;
|
using Bro.Common.Model;
|
using System;
|
using System.Collections.Generic;
|
using System.ComponentModel;
|
using System.Drawing.Design;
|
using System.Linq;
|
using System.Text;
|
using System.Threading;
|
using System.Threading.Tasks;
|
using static Bro.Common.Helper.EnumHelper;
|
|
namespace Bro.M071.Process
|
{
|
public partial class M071Process
|
{
|
public Timer ResetTimer = null;
|
const int FULLRESETTIME = 5;
|
|
MachineState machineState = MachineState.Unknown;
|
public MachineState MachineState
|
{
|
get => machineState;
|
set
|
{
|
machineState = value;
|
|
switch (machineState)
|
{
|
case MachineState.Ready:
|
break;
|
case MachineState.Running:
|
break;
|
case MachineState.Alarm:
|
break;
|
case MachineState.Pause:
|
break;
|
default:
|
break;
|
}
|
|
OnMachineStateChanged?.Invoke(machineState);
|
}
|
}
|
|
[ProcessMethod("MotionCardBase", "Reset", "简单复位操作", InvokeType.TestInvoke)]
|
public ProcessResponse Reset(IOperationConfig opConfig, IDevice invokeDevice, IDevice sourceDevice)
|
{
|
//if (opConfig == null)
|
//{
|
// var monitorSet = Config.MonitorSetCollection.FirstOrDefault(u => u.MethodCode == "Reset");
|
// if (monitorSet == null)
|
// throw new ProcessException("未配置默认复位操作");
|
|
// opConfig = monitorSet.OpConfig;
|
// if (opConfig == null)
|
// throw new ProcessException("未配置复位操作具体配置动作");
|
|
// if (invokeDevice == null)
|
// {
|
// invokeDevice = DeviceCollection.FirstOrDefault(u => u.Id == monitorSet.InvokeDevice);
|
// if (invokeDevice == null)
|
// throw new ProcessException("未配置复位操作执行设备");
|
// }
|
//}
|
|
MotionCardDefaultRun("Reset", ref opConfig, ref invokeDevice);
|
|
RaisedAlarm("");
|
MachineState = MachineState.Ready;
|
|
if (ResetTimer == null)
|
{
|
ResetTimer = new Timer(FullReset, null, -1, -1);
|
}
|
|
if (opConfig.InputPara.Count > 0)
|
{
|
//大复位信号
|
ResetTimer.Change(-1, opConfig.InputPara[0] == 1 ? FULLRESETTIME * 1000 : -1);
|
}
|
|
//if (invokeDevice is MotionCardBase motionCard)
|
//{
|
// motionCard.Run(opConfig);
|
//}
|
|
LogAsync(DateTime.Now, "普通复位动作完成", "");
|
|
return new ProcessResponse(true);
|
}
|
|
private void FullReset(object state)
|
{
|
FullReset(null, null, null);
|
}
|
|
[ProcessMethod("MotionCardOperationConfigCollection", "FullReset", "大复位操作", InvokeType.TestInvoke)]
|
public ProcessResponse FullReset(IOperationConfig opConfig, IDevice invokeDevice, IDevice sourceDevice)
|
{
|
//if (opConfig == null)
|
//{
|
// var monitorSet = Config.MonitorSetCollection.FirstOrDefault(u => u.MethodCode == "FullReset");
|
// if (monitorSet == null)
|
// throw new ProcessException("未配置默认大复位操作");
|
|
// opConfig = monitorSet.OpConfig;
|
// if (opConfig == null)
|
// throw new ProcessException("未配置大复位操作具体配置动作");
|
|
// if (invokeDevice == null)
|
// {
|
// invokeDevice = DeviceCollection.FirstOrDefault(u => u.Id == monitorSet.InvokeDevice);
|
// if (invokeDevice == null)
|
// throw new ProcessException("未配置大复位操作执行设备");
|
// }
|
//}
|
|
//if (invokeDevice is MotionCardBase motionCard)
|
//{
|
// motionCard.Run(opConfig);
|
//}
|
|
MotionCardDefaultRun("FullReset", ref opConfig, ref invokeDevice);
|
|
productionList.ForEach(u => u.Dispose());
|
productionList.Clear();
|
|
OnFullResetDone?.Invoke();
|
|
LogAsync(DateTime.Now, "大复位动作完成", "");
|
return new ProcessResponse(true);
|
}
|
|
/// <summary>
|
/// 暂停标志
|
/// WaitHandle 暂停句柄 默认为非阻塞 可执行
|
/// WaitResult 暂停标志 true 正常执行 false 暂停中
|
/// </summary>
|
ManualWaitConfirm _pauseHandle = new ManualWaitConfirm()
|
{
|
WaitHandle = new ManualResetEvent(true),
|
WaitResult = true,
|
};
|
|
[ProcessMethod("", "PauseJob", "暂停流程", InvokeType.TestInvoke)]
|
public ProcessResponse PauseJob(IOperationConfig opConfig, IDevice invokeDevice, IDevice sourceDevice)
|
{
|
if (!_pauseHandle.WaitResult)
|
{
|
#region 板卡暂停动作
|
#endregion
|
|
_pauseHandle.WaitHandle.Reset();
|
}
|
|
_pauseHandle.WaitResult = !_pauseHandle.WaitResult;
|
return new ProcessResponse(_pauseHandle.WaitResult);
|
}
|
|
[ProcessMethod("", "ResumeJob", "继续流程", InvokeType.TestInvoke)]
|
public ProcessResponse ResumeJob(IOperationConfig opConfig, IDevice invokeDevice, IDevice sourceDevice)
|
{
|
if (_pauseHandle.WaitResult)
|
{
|
#region 板卡恢复动作
|
#endregion
|
|
_pauseHandle.WaitHandle.Set();
|
}
|
|
_pauseHandle.WaitResult = !_pauseHandle.WaitResult;
|
return new ProcessResponse(_pauseHandle.WaitResult);
|
}
|
|
[ProcessMethod("MotionCardBase", "SwitchLightRed", "切换指示灯-红", InvokeType.TestInvoke)]
|
public ProcessResponse SwitchLightRed(IOperationConfig opConfig, IDevice invokeDevice, IDevice sourceDevice)
|
{
|
MotionCardDefaultRun("SwitchLightRed", ref opConfig, ref invokeDevice);
|
return new ProcessResponse(true);
|
}
|
|
[ProcessMethod("MotionCardBase", "SwitchLightYellow", "切换指示灯-黄", InvokeType.TestInvoke)]
|
public ProcessResponse SwitchLightYellow(IOperationConfig opConfig, IDevice invokeDevice, IDevice sourceDevice)
|
{
|
return new ProcessResponse(true);
|
}
|
|
[ProcessMethod("MotionCardBase", "SwitchLightGreen", "切换指示灯-绿", InvokeType.TestInvoke)]
|
public ProcessResponse SwitchLightGreen(IOperationConfig opConfig, IDevice invokeDevice, IDevice sourceDevice)
|
{
|
return new ProcessResponse(true);
|
}
|
|
[ProcessMethod("MotionCardBase", "SwitchBeep", "切换蜂鸣器", InvokeType.TestInvoke)]
|
public ProcessResponse SwitchBeep(IOperationConfig opConfig, IDevice invokeDevice, IDevice sourceDevice)
|
{
|
return new ProcessResponse(true);
|
}
|
|
[ProcessMethod("MotionCardBase", "SwitchNormalLight", "切换日光灯", InvokeType.TestInvoke)]
|
public ProcessResponse SwitchNormalLight(IOperationConfig opConfig, IDevice invokeDevice, IDevice sourceDevice)
|
{
|
MotionCardDefaultRun("SwitchNormalLight", ref opConfig, ref invokeDevice);
|
|
return new ProcessResponse(true);
|
}
|
|
private void MotionCardDefaultRun(string methodCode, ref IOperationConfig opConfig, ref IDevice invokeDevice)
|
{
|
IMonitorSet monitorSet = null;
|
if (opConfig == null)
|
{
|
monitorSet = Config.MonitorSetCollection.FirstOrDefault(u => u.MethodCode == methodCode);
|
if (monitorSet == null)
|
throw new ProcessException("未配置默认操作");
|
|
opConfig = monitorSet.OpConfig;
|
if (opConfig == null)
|
throw new ProcessException("未配置具体配置动作");
|
}
|
|
if (invokeDevice == null)
|
{
|
invokeDevice = DeviceCollection.FirstOrDefault(u => u.Id == monitorSet.InvokeDevice);
|
if (invokeDevice == null)
|
throw new ProcessException("未配置操作执行设备");
|
}
|
|
if (invokeDevice is MotionCardBase motionCard)
|
{
|
motionCard.Run(opConfig);
|
}
|
}
|
}
|
}
|