173 lines
6.2 KiB
C#

using Aurora.Api;
using Aurora.Api.Devices;
using Aurora.Util.HislogPlus;
using Aurora.View;
using AuroraLaser;
using AuroraLaser.Trumpf;
using AuroraMassFlowMeter;
using Hermes;
using Hermes.Collections;
using WeldingCommon.Alarm;
using WeldingCommon.Device.ACS;
using WeldingCommon.Process;
using WeldingCommon.Recipes;
using WeldingCommon.Settings;
using WeldingCommon.Tools;
using WeldingCommon.Views.Recipes;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using WeldingCommon;
using WeldingCommon.Sequences;
using WeldingCommon.Devices.ACS;
namespace WeldingCommon.Sequences
{
class SeqOneShot
{
static readonly Logger Log = new Logger("OneShotSequence");
const string SEQ_ENTER = "SEQ_ENTER";
const string SEQ_CHECK_INIT_CONDITION = "Check Init Condition";
const string SEQ_ONE_SHOT = "OneShot";
const string SEQ_ONE_SHOT_COMPLETE = "OneShot Sequence Complete";
private static IScannerACS _motion;
private static Laser _laser;
private static OneShotItem _Item; // 26.04.13
private static eStage _stage;
public static bool _LaserIOUse;
const int MOTION_TIMEOUT = 10 * 1000;
const int WELDING_TIMEOUT = 100 * 1000;
const int MOTION_INTERVAL = 20;
public static SequenceBuilder Builder()
{
SequenceBuilder sb = new SequenceBuilder(1000, true);
sb.AddAction(SEQ_ENTER, Sequence_Enter);
sb.AddAction(SEQ_CHECK_INIT_CONDITION, CheckInitCondition);
sb.AddAction(SEQ_ONE_SHOT, OneShot);
sb.AddAction(SEQ_ONE_SHOT_COMPLETE, ProcessComplete);
sb.OnStopped(OnStopped);
sb.OnForceError(OnForceError);
sb.Flows(sb.Init > sb[SEQ_ENTER] > sb[SEQ_CHECK_INIT_CONDITION] > sb[SEQ_ONE_SHOT] > sb[SEQ_ONE_SHOT_COMPLETE] > sb.Final);
//sb.Draw("SeqOneShot.pdf");
return sb;
}
public static SequenceActionResult Sequence_Enter(SequenceContext context, string id, SequenceActionResult param)
{
Log.I("SeqOneShot Start");
if (_motion is null)
_motion = context.Devices[CommonDeviceIds.ACS] as IScannerACS;
//if (_laser is null)
// _laser = context.Devices[CommonDeviceIds.Laser] as Laser;
var settingItems = (ManualLaserSetting)param.Param; // 26.04.13
_Item = settingItems.OneShots;
_LaserIOUse = settingItems.LaserIOUse;
return SequenceAction.Ok();
}
private static SequenceActionResult CheckInitCondition(SequenceContext context, string id, SequenceActionResult param)
{
Log.I("SeqOneShot CheckInitCondition");
if (!((_motion as ScannerACS).IsActivated)) {
Log.E($"[ACS activated({(_motion as ScannerACS).IsActivated})]");
return null;
}
_motion.SetLaserIOUse(_LaserIOUse);
Log.V($"LaserUse({_LaserIOUse})");
//if (!(_laser.IsActivated && _laser.GetConnected())) {
// Log.E($"[Laser activated({_laser.IsActivated}) / connected({_laser.GetConnected()})]");
// context.PutValue<int>("AlarmCode", AlarmCode_PrismaticGun.DEVICE_LASER_DEACTIVATED_DISCONNECTED);
// return null;
//}
//if (!_laser.GetLaserReady()) {
// _laser.LaserOn();
// Log.V($"Laser On");
// var res = context.RetryUntilSuccess(() => _laser.GetLaserReady(), WELDING_TIMEOUT, MOTION_INTERVAL);
// if (res == E2.TIMEOUT) {
// Log.FuncE("Laser Ready Check Timeout!");
// context.PutValue<int>("AlarmCode", AlarmCode_PrismaticGun.GET_LASER_READY);
// return null;
// } else if (res == E2.CANCELLED) {
// Log.FuncE("Laser Ready Check Cancel!");
// context.PutValue<int>("AlarmCode", 0);
// return null;
// }
//}
Log.V($"Laser Setting Complete");
return SequenceAction.Ok();
}
private static SequenceActionResult OneShot(SequenceContext context, string id, SequenceActionResult param)
{
var _shotTime = _Item.ShotTime;
var _shotPower1 = _Item.ShotPower1;
var _shotPower2 = _Item.ShotPower2;
_motion.SetLCILserOn(true);
_motion.SetOneShot(_shotTime, _shotPower1, _shotPower2);
Thread.Sleep(500);
_motion.OneShotStart();
Log.E(">> OneShot Start");
Thread.Sleep(500);
return SequenceAction.Ok();
}
private static SequenceActionResult ProcessComplete(SequenceContext context, string id, SequenceActionResult param)
{
var ret = context.RetryUntilSuccess(() => _motion.CheckOneShotComp(), MOTION_TIMEOUT, MOTION_INTERVAL);
if(ret == E2.TIMEOUT) {
Log.E("OneShot Timeout");
context.PutValue<int>("AlarmCode", AlarmCode_PrismaticGun.ACS_ONESHOT_COMP); //26.04.13 잠시 주석
return null;
} else if(ret == E2.CANCELLED) {
Log.E("OneShot Cancel");
context.PutValue<int>("AlarmCode", AlarmCode_PrismaticGun.ACS_ONESHOT_COMP); // 26.04.13 잠시 주석
return null;
}
Log.FuncV(">> OneShot Complete");
_motion.SetLCILserOn(false);
//_laser.LaserOff();
Thread.Sleep(500);
return SequenceAction.Ok();
}
private static void OnStopped(SequenceContext context)
{
_motion.SetLCILserOn(false);
//_laser.LaserOff();
MessageUtil.ShowErrorToast(">> Sequence Stop");
return;
}
private static void OnForceError(SequenceContext context, string arg2)
{
_motion.SetLCILserOn(false);
//_laser.LaserOff();
MessageUtil.ShowErrorToast(">> Sequence Fail");
return;
}
}
}