275 lines
9.8 KiB
C#
275 lines
9.8 KiB
C#
using Aurora.Api;
|
|
using AuroraCellTracker;
|
|
using AuroraLaserScanner;
|
|
using AuroraOCT;
|
|
using AuroraPLC;
|
|
using CoreUnit.Control.UserControl.Canvas;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Runtime.Remoting.Contexts;
|
|
using System.Text;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
using WeldingCommon.Alarm;
|
|
using WeldingCommon.RMS;
|
|
using WeldingCommon.Settings;
|
|
using WeldingCommon.Utils;
|
|
|
|
namespace WeldingCommon.Sequences
|
|
{
|
|
class SeqReportCellResult
|
|
{
|
|
static readonly Logger Log = new Logger("SeqReportCellResult");
|
|
|
|
const string SEQ_ENTER = "[SeqReportCellResult] SEQ_ENTER"; // inputParam 으로 받자.
|
|
const string SEQ_CHECK_INIT_CONDITION = "[SeqReportCellResult] Check Init Condition"; // Check Init Condition
|
|
|
|
const string SEQ_READ_CELL_RESULT = "[SeqReportCellResult] Read CellResult";
|
|
const string SEQ_READ_EQUIPMENT_DATA = "[SeqReportCellResult] Read EquipmentData";
|
|
const string SEQ_REPORT_CELL_RESULT = "[SeqReportCellResult] Report CellResult";
|
|
|
|
const string SEQ_SAVE_RESULT_DATA = "[SeqReportCellResult] Save Result Data";
|
|
|
|
const string SEQ_WRITE_COMPLETION_PLC_BIT = "[SeqReportCellResult] Write Completion PLC Bit";
|
|
const string SEQ_COMPLETE = "[SeqReportCellResult] SEQ_COMPLETE"; // 완료
|
|
|
|
static class ContextKey
|
|
{
|
|
public const string KEY_SEQUENCE_RESULT = "KEY_SEQUENCE_RESULT_SeqReportCellResult";
|
|
public const string KEY_SEQUENCE_START_TIME = "KEY_SEQUENCE_START_TIME_SeqReportCellResult";
|
|
}
|
|
|
|
private SeqReportCellResult_InitParam _InitParam;
|
|
|
|
private CellTracker _CellTracker;
|
|
private PLCBase _PLC;
|
|
private OCT _OCT;
|
|
private SystemParameter _SystemParameter;
|
|
|
|
private IEDC _EDC;
|
|
//private List<IDrawObject> _SelectedDrawObjectList = new List<IDrawObject>();
|
|
private string _StrCellData = "";
|
|
|
|
//public SequenceBuilder Builder(IEDC edcInterface)
|
|
public SequenceBuilder Builder()
|
|
{
|
|
//_EDC = edcInterface;
|
|
|
|
var sb = new SequenceBuilder(1000, true);
|
|
////var sb = new SequenceBuilder(1000, false); // With log
|
|
|
|
sb.AddAction(SEQ_ENTER, Sequence_Enter);
|
|
sb.AddDecision(SEQ_CHECK_INIT_CONDITION, CheckInitCondition); //분기
|
|
|
|
sb.AddAction(SEQ_READ_CELL_RESULT, ReadCellResult);
|
|
sb.AddAction(SEQ_READ_EQUIPMENT_DATA, ReadEquipmentData);
|
|
sb.AddAction(SEQ_REPORT_CELL_RESULT, ReportCellResult);
|
|
|
|
sb.AddAction(SEQ_SAVE_RESULT_DATA, SaveResultData); // 해당 공정의 정보를 기록 함.
|
|
sb.AddAction(SEQ_WRITE_COMPLETION_PLC_BIT, WriteCompletionPLCBit); // 정상적으로 종료 되면, complete bit write
|
|
sb.AddAction(SEQ_COMPLETE, Complete);
|
|
|
|
|
|
sb.Flows(sb.Init > sb[SEQ_ENTER] > sb[SEQ_CHECK_INIT_CONDITION]
|
|
> sb[SEQ_READ_CELL_RESULT] > sb[SEQ_READ_EQUIPMENT_DATA] > sb[SEQ_REPORT_CELL_RESULT]
|
|
> sb[SEQ_SAVE_RESULT_DATA] > sb[SEQ_WRITE_COMPLETION_PLC_BIT] > sb[SEQ_COMPLETE]);
|
|
|
|
sb.Flows(sb[SEQ_CHECK_INIT_CONDITION] > sb[SEQ_COMPLETE] > sb.Final);
|
|
|
|
|
|
sb.OnStopped(OnStopped);
|
|
sb.OnForceError(OnForceError);
|
|
|
|
|
|
//sb.Draw("SeqReportCellResult.pdf");
|
|
|
|
return sb;
|
|
}
|
|
|
|
private SequenceActionResult Sequence_Enter(SequenceContext context, string id, SequenceActionResult param)
|
|
{
|
|
Log.I("SeqReportCellResult Start");
|
|
|
|
_InitParam = param.Param as SeqReportCellResult_InitParam;
|
|
_SystemParameter = context.GetSetting<SystemParameter>(CommonSettingIds.SystemParameter);
|
|
_EDC = _InitParam.EDC_Interface;
|
|
|
|
InitDev(context);
|
|
if (!CheckDeviceReady(context)) { //Check Device
|
|
AlarmManager.Alarm(AlarmCode.ALARM_SEQUENCE_ReportCellResult_DeviceNotReady);
|
|
Log.E("The devices are not active.");
|
|
return null;
|
|
}
|
|
|
|
if (InitSequenceVariable(context) == false) {
|
|
AlarmManager.Alarm(AlarmCode.ALARM_SEQUENCE_ReportCellResult_InitVariableError);
|
|
return null;
|
|
}
|
|
|
|
return SequenceAction.Ok();
|
|
}
|
|
|
|
private bool InitSequenceVariable(SequenceContext context)
|
|
{
|
|
//_SelectedDrawObjectList = Status.GetProcessingWeldingData().SelectedDrawObjectList;
|
|
return true;
|
|
}
|
|
|
|
private void InitDev(SequenceContext context)
|
|
{
|
|
//Device Init
|
|
_CellTracker = context.GetCellTracker();
|
|
_PLC = context.GetPLC();
|
|
//_OCT = context.GetOCT(); 미사용으로 주석처리 함
|
|
}
|
|
|
|
private bool CheckDeviceReady(SequenceContext context)
|
|
{
|
|
List<string> deviceListToCheck = new List<string>() { CommonDeviceIds.CellTracker, CommonDeviceIds.PLCDevice };
|
|
bool isAllDeviceActivated = true;
|
|
foreach (string item in deviceListToCheck) {
|
|
if (!context.Devices[item].IsActivated) {
|
|
isAllDeviceActivated = isAllDeviceActivated && false;
|
|
}
|
|
}
|
|
|
|
return isAllDeviceActivated;
|
|
}
|
|
|
|
private bool CheckCondition()
|
|
{
|
|
if (CheckCondition_Interlock()) {
|
|
if (InitializeDeviceStatus()) {
|
|
return true;
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
|
|
private bool CheckCondition_Interlock()
|
|
{
|
|
// PLC, Data, IO 등 Interlock checking
|
|
return true;
|
|
}
|
|
|
|
private bool InitializeDeviceStatus()
|
|
{
|
|
// format 유지, ReceiveCellInfo 없음
|
|
return true;
|
|
}
|
|
|
|
private string CheckInitCondition(SequenceContext context, string id, ICollection<string> branches, SequenceActionResult param)
|
|
{
|
|
if (!CheckCondition()) {
|
|
AlarmManager.Alarm(AlarmCode.ALARM_SEQUENCE_ReportCellResult_CheckInitCondition);
|
|
Log.E("Condition is not in state to start sequence.");
|
|
context.PutValue(ContextKey.KEY_SEQUENCE_RESULT, false);
|
|
return SEQ_COMPLETE;
|
|
}
|
|
|
|
var startTime = DateTime.Now;
|
|
context.PutValue(ContextKey.KEY_SEQUENCE_START_TIME, startTime);
|
|
|
|
Log.D("ReportCellResult Sequence CheckInitCondition");
|
|
return SEQ_READ_CELL_RESULT;
|
|
}
|
|
|
|
private SequenceActionResult ReadCellResult(SequenceContext context, string id, SequenceActionResult param)
|
|
{
|
|
if (_EDC == null) {
|
|
Log.W("EDC is null");
|
|
return SequenceAction.Ok();
|
|
}
|
|
|
|
_StrCellData = _EDC?.ReadCellResult(context) ?? string.Empty;
|
|
|
|
return SequenceAction.Ok();
|
|
}
|
|
|
|
private SequenceActionResult ReadEquipmentData(SequenceContext context, string id, SequenceActionResult param)
|
|
{
|
|
// 2025.03.06 PLC 보고 용으로 사용하는데, PLC 보고가 없어짐, 삭제 가능
|
|
//string strRecipeID = Status.GetProcessingWeldingData().ActivatedRecipeId;
|
|
// _EDC를 쓰면 될 것. 정지명
|
|
//_EDC?.ReportResultToPLC(context, strRecipeID, SelectedDrawObjects);
|
|
// ReportResultToPLC(strRecipeID);
|
|
return SequenceAction.Ok();
|
|
}
|
|
|
|
private SequenceActionResult ReportCellResult(SequenceContext context, string id, SequenceActionResult param)
|
|
{
|
|
if (_EDC == null) {
|
|
Log.W("EDC is null");
|
|
return SequenceAction.Ok();
|
|
}
|
|
|
|
string strPath = "";
|
|
Log.I(string.Format("Cell Data {0}", _StrCellData));
|
|
|
|
List<string> Datalist = _EDC?.SendData(context, _StrCellData, ref strPath) ?? new List<string>();
|
|
|
|
_EDC.GetSaveDataStr(out string strItem, out string strData, Datalist);
|
|
|
|
ExcelManagementUnit.AppendStringInCSV(strPath, strItem, strData);
|
|
return SequenceAction.Ok();
|
|
}
|
|
|
|
|
|
private SequenceActionResult SaveResultData(SequenceContext context, string id, SequenceActionResult param)
|
|
{
|
|
context.PutValue(ContextKey.KEY_SEQUENCE_RESULT, true);
|
|
return SequenceAction.Ok();
|
|
}
|
|
|
|
private SequenceActionResult WriteCompletionPLCBit(SequenceContext context, string id, SequenceActionResult param)
|
|
{
|
|
// 완료 비트 write 하는 Node 추가 필요. format 유지, ReceiveCellInfo 없음
|
|
|
|
Log.D("ReportCellResult Sequence WriteCompletionPLCBit");
|
|
return SequenceAction.Ok();
|
|
}
|
|
|
|
private SequenceActionResult Complete(SequenceContext context, string id, SequenceActionResult param)
|
|
{
|
|
RestoreDeviceStatus();
|
|
Log.I("ReportCellResult Complete");
|
|
|
|
context.TryGetValue(ContextKey.KEY_SEQUENCE_RESULT, out bool seqResult);
|
|
SeqReportCellResult_OutParam result = new SeqReportCellResult_OutParam() { Success = seqResult };
|
|
|
|
if (seqResult == false) {
|
|
AlarmManager.Alarm(AlarmCode.ALARM_SEQUENCE_ReportCellResult_ResultFailed);
|
|
}
|
|
|
|
Log.D("ReportCellResult Sequence Complete");
|
|
return SequenceAction.Ok(result);
|
|
}
|
|
|
|
private bool RestoreDeviceStatus()
|
|
{
|
|
return true;
|
|
}
|
|
|
|
private void OnForceError(SequenceContext arg1, string arg2)
|
|
{
|
|
Log.I("SequenceAction Ok : OnForceError");
|
|
}
|
|
|
|
private void OnStopped(SequenceContext obj)
|
|
{
|
|
Log.I("SequenceAction Ok : OnStopped");
|
|
}
|
|
|
|
}
|
|
|
|
public class SeqReportCellResult_InitParam : InitParam
|
|
{
|
|
public IEDC EDC_Interface { get; set; }
|
|
}
|
|
|
|
public class SeqReportCellResult_OutParam : OutParam
|
|
{
|
|
|
|
}
|
|
} |