81 lines
2.8 KiB
C#
81 lines
2.8 KiB
C#
using Aurora;
|
|
using Aurora.Api;
|
|
using Aurora.Util.HislogPlus;
|
|
using CoreUnit.Control.UserControl.Canvas;
|
|
using CoreUnit.Scanner.UserControl.ScannerCanvas;
|
|
using DB.Recipe;
|
|
using Hermes;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Reactive.Linq;
|
|
using System.Text;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
using WeldingCommon.Alarm;
|
|
using WeldingCommon.Data;
|
|
using WeldingCommon.Devices;
|
|
using WeldingCommon.Settings;
|
|
using WeldingCommon.Utils;
|
|
using static AuroraPLC.PLCBase;
|
|
using static WeldingCommon.Devices.PLCController;
|
|
|
|
namespace WeldingCommon.RMS
|
|
{
|
|
public abstract class RMSHandler
|
|
{
|
|
protected Logger Log = new Logger("RMSHandler", "RMS_Evnet");
|
|
protected IAuroraEnvironment _aurora;
|
|
protected IRecipeEntry _recipeEntry;
|
|
private PLCController _plc;
|
|
protected SettingRmsDataList _setting;
|
|
|
|
protected List<PLCReportData> RmsDataList = new List<PLCReportData>();
|
|
private const int TimeOut = 3000;
|
|
|
|
public virtual void RegistryDeviceHandler(IAuroraEnvironment aurora)
|
|
{
|
|
_aurora = aurora;
|
|
_recipeEntry = aurora.RecipeManager;
|
|
_plc = aurora.DeviceManager[CommonDeviceIds.PLCDevice] as PLCController;
|
|
|
|
_setting = aurora.SettingEntry[CommonSettingIds.RmsDatas] as SettingRmsDataList;
|
|
foreach (var item in _setting.UploadList)
|
|
RmsDataList.Add(item.Clone() as PLCReportData);
|
|
}
|
|
public void Start()
|
|
{
|
|
_aurora.EventObservable.AsObservable(CommonEventIds.EVENT_RMS_PARAMETER_READ_REQUEST)
|
|
.ObserveOnDispatcher()
|
|
.Subscribe(OnParameterReadRequest);
|
|
}
|
|
|
|
// 레시피 데이터 변경 요청 응답
|
|
public abstract void OnParameterReadRequest(EventMessage message);
|
|
|
|
public PLCReportData getReportData(string id) => RmsDataList.Where(t => t.DataName == id).FirstOrDefault();
|
|
|
|
protected int UpdateRmsParameter() => _plc.UpdateReportDatas(RmsDataList);
|
|
protected int UploadRmsParameter() => _plc.UploadReportDatas(RmsDataList);
|
|
protected bool ReportChangeConfirm()
|
|
{
|
|
// Request
|
|
_plc.WriteBit(eCommonBitOutput.PC_RMS_PARAMETER_READ_REQUEST_ACK, true);
|
|
|
|
var timeout = TimeSpan.FromMilliseconds(TimeOut);
|
|
var start = DateTime.UtcNow;
|
|
|
|
while (DateTime.UtcNow - start < timeout) {
|
|
if (!_plc.ReadBit(eCommonBitInput.PLC_RMS_PARAMETER_READ_REQUEST).data) {
|
|
_plc.WriteBit(eCommonBitOutput.PC_RMS_PARAMETER_READ_REQUEST_ACK, false);
|
|
return true;
|
|
}
|
|
Thread.Sleep(10);
|
|
}
|
|
|
|
_plc.WriteBit(eCommonBitOutput.PC_RMS_PARAMETER_READ_REQUEST_ACK, false);
|
|
return false;
|
|
}
|
|
}
|
|
}
|