using Aurora; using Aurora.Api; using Aurora.Api.Manager; using Aurora.View; using AuroraChiller; using AuroraIO; using AuroraLaser; using AuroraLaserScanner; using AuroraLight; using AuroraLight.View; using AuroraPLC; using DB; using Hermes; using System; using System.Collections.Generic; using System.Reactive.Linq; using System.Threading.Tasks; using System.Windows; using System.Windows.Input; using WeldingCommon.Alarm; using WeldingCommon.Recipes; using WeldingCommon.Sequences; using WeldingCommon.Settings; using WeldingCommon.Views; using WeldingCommon.Views.DoorInterlock; using WeldingCommon.Vision.Common; using WeldingCommon.Vision.Factory; namespace WeldingCommon { public abstract class CommonEquipmentSetup { protected static Logger Log = new Logger("EquipmentSetup"); protected UCRecipe _UCRecipe; protected ResourceDictionary IconDictionary; public IAuroraEnvironment AuroraEnv { get; set; } public virtual void BuildMainStatusView(MainStatusBuilder builder) { builder .AddLanguage("en-US", "ko-KR") .AddDeviceActiveStatus(CommonDeviceIds.Scanner) .AddDeviceActiveStatus(CommonDeviceIds.Laser) .AddDeviceActiveStatus(CommonDeviceIds.IODevice) .AddDeviceActiveStatus(CommonDeviceIds.PLCDevice) //.AddDeviceActiveStatus(CommonDeviceIds.Light) .AddDeviceActiveStatus(CommonDeviceIds.SmcChiller); } public bool CanShutDown() { return true; } public virtual string GetEquipmentName() { return "ILSOS"; } public void OnResetAlarm(List codeList) { } public void OnSetAlarm(int code, bool isHeavy) { //if (isHeavy) { // AlarmManager.StopSequenceByAlarm(code); //} } public void OnShutDown() { var devices = AuroraEnv.DeviceManager.GetDevices(); foreach (var device in devices) { if (device.Deactivate() != E1.OK) { Log.E($"{device.DeviceId} connect fail."); } } } private void TestSystemEvents() { Observable.Merge( AuroraEnv.EventObservable.AsObservable(AuroraSysEvent.SYS_EQUIPMENT_LOADED), AuroraEnv.EventObservable.AsObservable(AuroraSysEvent.SYS_MENU_CHANGED), AuroraEnv.EventObservable.AsObservable(AuroraSysEvent.SYS_ALARM_SET_ALARM), AuroraEnv.EventObservable.AsObservable(AuroraSysEvent.SYS_ALARM_RESET_ALARM), AuroraEnv.EventObservable.AsObservable(AuroraSysEvent.SYS_ALARM_RESET_ALL_ALARM), AuroraEnv.EventObservable.AsObservable(AuroraSysEvent.SYS_ALARM_DESCRIPTIONS_RELOADED), AuroraEnv.EventObservable.AsObservable(AuroraSysEvent.SYS_PERMISSION_CHANGED), //AuroraEnv.EventObservable.AsObservable(AuroraSysEvent.SYS_REQ_MAIN_PROGRESS), AuroraEnv.EventObservable.AsObservable(AuroraSysEvent.SYS_REQ_SCREEN_INTERLOCK), AuroraEnv.EventObservable.AsObservable(AuroraSysEvent.SYS_REQ_MAIN_LOCK), AuroraEnv.EventObservable.AsObservable(AuroraSysEvent.SYS_REQ_MAIN_LAMP), AuroraEnv.EventObservable.AsObservable(AuroraSysEvent.SYS_REQ_MENU_CHANGE), AuroraEnv.EventObservable.AsObservable(AuroraSysEvent.SYS_REQ_MAIN_MENU_ENABLE), AuroraEnv.EventObservable.AsObservable(AuroraSysEvent.SYS_REQ_WINDOW_MODE), AuroraEnv.EventObservable.AsObservable(AuroraSysEvent.SYS_REQ_WINDOW_FULL_SCREEN), AuroraEnv.EventObservable.AsObservable(AuroraSysEvent.SYS_REQ_MANUAL_BACKUP_START), AuroraEnv.EventObservable.AsObservable(AuroraSysEvent.SYS_REQ_TOAST_MESSAGE), AuroraEnv.EventObservable.AsObservable(AuroraSysEvent.SYS_REQ_TOAST_MESSAGE_CLEAR), AuroraEnv.EventObservable.AsObservable(AuroraSysEvent.SYS_MAIN_ALARM), AuroraEnv.EventObservable.AsObservable(AuroraSysEvent.SYS_REQ_CHANGE_LANGUAGE), AuroraEnv.EventObservable.AsObservable(AuroraSysEvent.SYS_CORE_ERROR_OCCURED), //AuroraEnv.EventObservable.AsObservable(AuroraSysEvent.SYS_INGREDIENT_RELOADED), AuroraEnv.EventObservable.AsObservable(AuroraSysEvent.SYS_EQUIPMENT_LOAD_FAILED), AuroraEnv.EventObservable.AsObservable(AuroraSysEvent.SYS_SHUTDOWN), AuroraEnv.EventObservable.AsObservable(AuroraSysEvent.SYS_SETTING_CHANGED), AuroraEnv.EventObservable.AsObservable(AuroraSysEvent.SYS_DEVICE_ACTIVATED), AuroraEnv.EventObservable.AsObservable(AuroraSysEvent.SYS_DEVICE_DEACTIVATED), AuroraEnv.EventObservable.AsObservable(AuroraSysEvent.SYS_DEVICE_IS_COMM_ERROR), AuroraEnv.EventObservable.AsObservable(AuroraSysEvent.SYS_RECIPE_ACTIVATED), AuroraEnv.EventObservable.AsObservable(AuroraSysEvent.SYS_RECIPE_ENTRY_CHANGED), AuroraEnv.EventObservable.AsObservable(AuroraSysEvent.SYS_RECIPE_RELOADED), AuroraEnv.EventObservable.AsObservable(AuroraSysEvent.SYS_RECIPE_ITEM_CHANGED), //AuroraEnv.EventObservable.AsObservable(AuroraSysEvent.SYS_MODEL_CHANGED), AuroraEnv.EventObservable.AsObservable(AuroraSysEvent.SYS_ACTIVATED_RECIPE_MODEL_CHANGED), AuroraEnv.EventObservable.AsObservable(AuroraSysEvent.SYS_MODEL_ACTIVATED), AuroraEnv.EventObservable.AsObservable(AuroraSysEvent.SYS_MODEL_RELOADED), AuroraEnv.EventObservable.AsObservable(AuroraSysEvent.SYS_MODEL_ITEM_CHANGED), AuroraEnv.EventObservable.AsObservable(AuroraSysEvent.SYS_MODEL_NAME_CHANGED), AuroraEnv.EventObservable.AsObservable(AuroraSysEvent.SYS_MODEL_ENTRY_CHAGNED), //AuroraEnv.EventObservable.AsObservable(AuroraSysEvent.SYS_INGREDIENT_ENTRY_CHAGNED), //AuroraEnv.EventObservable.AsObservable(AuroraSysEvent.SYS_INGREDIENT_ITEM_CHAGNED), AuroraEnv.EventObservable.AsObservable(AuroraSysEvent.SYS_LANGUAGE_CHANGED), AuroraEnv.EventObservable.AsObservable(AuroraSysEvent.SYS_REQ_MODEL_EDITING_CHANGE) ).ObserveOnDispatcher() .Subscribe(x => { Log.V($"{x.Subject} :: Param[{x.Param?.ToString()}] From[{x.From}]"); }); } public async Task ActivateDevices() { await System.Threading.Tasks.Task.Run(() => { try { var devices = AuroraEnv.DeviceManager.GetDevices(); foreach (var device in devices) { if (device.Activate() != E1.OK) { Log.E($"{device.DeviceId} connect fail."); if (device.DeviceId.Equals("Laser")) { //Laser 연결 실패시 알람 발생 //AuroraEnv.AlarmService.SetAlarm(3); } } } } catch (Exception e) { Log.E($"An error occurred OnStartUp : {e.Message}"); } }); } public virtual async void OnStartUp() { int value = 9999; Log.I($"{ApplicationExt.CurLang}"); Log.I($"{ApplicationExt.IsSimulation}"); Log.I($"value = {value}"); Status.AuroraEnv = AuroraEnv; await Task.Run(() => ConnectDevices()).ContinueWith(x => StartProcess()); AuroraEnv.EventObservable.AsObservable(AuroraSysEvent.SYS_SETTING_CHANGED) .Select(msg => msg.Param as string) .Where(param => param == CommonSettingIds.Sequence) .Subscribe(_ => UpdateSequenceState()); #region Event AuroraEnv.EventObservable.AsObservable(CommonEventIds.EVENT_DOOR_INTERLOCK) .Subscribe(x => { if (x.Param != null && x.Param is bool isOpen) { if (isOpen) { Application.Current.Dispatcher.Invoke(delegate { DoorInterlockPopup.GetInstance().PopupMaint(CommonSettingIds.DoorInterlock); }); } else { Application.Current.Dispatcher.Invoke(delegate { DoorInterlockPopup.GetInstance().PopupMaintClose(); }); } } }); #endregion //AlarmMonitroing Seq Start AuroraEnv.SequenceEntry[CommonSequenceIds.AlarmMonitor].Start(); AuroraEnv?.EventPublisher?.Publish(new EventMessage("", EquipEvent.BOOT_COMPLETED)); Status.BOOT_COMPLETED = true; // Test, 발생 Event 확인용 TestSystemEvents(); } private void ConnectDevices() { var equipSetting = AuroraEnv.SettingEntry[AuroraSettings.Equipment] as EquipmentInfo; if (!equipSetting.AutomaticallyConnectDevices) { return; } var devMngr = AuroraEnv.DeviceManager; foreach (var device in devMngr.GetDevices()) { device.Activate(); } } private void StartProcess() { UpdateSequenceState(); } private void UpdateSequenceState() { SequenceManager.Instance.UpdateSequenceStatus(AuroraEnv.SettingEntry[CommonSettingIds.Sequence] as SequenceSetting , AuroraEnv.SequenceEntry); } public virtual void RegisterDevices(IDeviceRegistry registry) { var equipSetting = AuroraEnv.SettingEntry[AuroraSettings.Equipment] as EquipmentInfo; var isSimul = ApplicationExt.IsSimulation; var setting = AuroraEnv.SettingEntry[AuroraSettings.Equipment] as EquipmentInfo; var systemParameterILSOS = AuroraEnv.SettingEntry[CommonSettingIds.SystemParameter] as SystemParameter; //IODevice는 AjinIO가 아니라 IOUnit으로 받아오는것으로 수정해야 함 //registry.Register(CommonDeviceIds.IODevice, () => new IODevice(AuroraEnv, CommonDeviceIds.IODevice, isSimul), new IOUnitConfig()); //registry.Register(CommonDeviceIds.Laser, () => new Laser(CommonDeviceIds.Laser, isSimul), new LaserConfig(), // device => new UCLaserDevice() { DataContext = new UCLaserDeviceViewModel(AuroraEnv, CommonDeviceIds.Laser) }); registry.Register(CommonDeviceIds.Scanner, () => new Scanner(CommonDeviceIds.Scanner), new ScannerConfig()); //registry.Register(CommonDeviceIds.SmcChiller, () => new SmcChiller(CommonDeviceIds.SmcChiller, 0, isSimul), new SmcChiller.Config(), // device => new UCSMCChillerDevice() { DataContext = new UCSMCChillerDeviceViewModel(AuroraEnv, CommonDeviceIds.SmcChiller) }); registry.Register(CommonDeviceIds.SmcChiller, () => new SmcChiller(CommonDeviceIds.SmcChiller), new SmcChillerConfig(), device => new UCChiller(AuroraEnv, CommonDeviceIds.SmcChiller)); //PRIBAT은 PLC안씀??? //PLC-> 각자 장비 프로젝트가 등록하도록 Commom에서 각 장비 EquipmentSetup으로 이동 (각 PLC 마다 주소값이 다르고, API가 다른 부분이 존재해서 따로 관리하는 게 맞아보임) //var _plc = new PLCController(CommonDeviceIds.PLCDevice, ePLCNetType.MXComponent, ApplicationExt.IsSimulation, PLCMMapFileType.CSV, AuroraEnv); //registry.Register(CommonDeviceIds.PLCDevice, // () => _plc, PLCMxComponentConfig.GetDefaultConfig(), // device => new UCPLCDevice() { DataContext = new UCPLCDeviceViewModel(AuroraEnv, _plc) }); //VisionFactory.RegisterDevices(registry); VisionFactory.RegisterDevices(registry); //registry.Register(CommonDeviceIds.Light, () => new LightDevice(CommonDeviceIds.Light, eLight.ERI), new LightConfig(), // device => new UCLight() { DataContext = new UCLightViewModel(AuroraEnv, CommonDeviceIds.Light) }); // TODO: SystemParameterManager.Initialize 할 위치 찾자. 여기는 조금.... SystemParameterManager.Initialize(AuroraEnv); AlarmManager.Init(AuroraEnv); } public virtual void RegisterModels(ModelRegister register) { VisionFactory.RegisterModel(register); // Simulation Mode, Equipment Name 등 기본 세팅 load Status.Init(AuroraEnv); } public virtual void RegisterRecipes(RecipeRegister register) { //LASA 초기화 작업 GUI.Program.dao = new Dao(); GUI.Program.dao.Initialize(); //register(RecipeIds.Laser, new LaserRecipe()); //register(CommonRecipeIds.LaserScannerTeaching, new LaserScannerTeachingRecipe(), // (recipe, item) => new LaserScannerTeaching() { // DataContext = new LaserScannerTeachingViewModel(AuroraEnv, new LaserScannerTeachingToolboxViewModel(AuroraEnv)) // }); VisionFactory.RegisterRecipe(register); } public virtual void RegisterSequences(SequenceRegister register) { // Common Sequences SequenceManager.RegisterSequence(AuroraEnv, register); VisionFactory.RegisterSequences(AuroraEnv, register); } //public virtual void RegisterServices(IServiceRegistry register) //{ //} public virtual void RegisterSettings(SettingRegister register) { register(CommonSettingIds.SystemParameter, new SystemParameter()); register(CommonSettingIds.LaserPowerCalParam, new LaserPowerCalParam()); register(CommonSettingIds.Sequence, new SequenceSetting()); register(CommonSettingIds.DataLogPath, new DataLogPathSetting()); register(CommonSettingIds.DoorInterlock, new DoorInterlockSetting()); VisionFactory.RegisterSetting(AuroraEnv, register); } public virtual void RegisterViews(IViewManager manager) { if (ApplicationExt.Theme_Color.Contains("Light")) { Application.Current.Resources.MergedDictionaries.Add(new ResourceDictionary { // Light Theme Source = new Uri("pack://application:,,,/AuroraUIComponent;component/Style/GenericLightSG.xaml") //Source = new Uri("pack://application:,,,/AuroraUIComponent;component/Style/GenericLight.xaml") }); } else { Application.Current.Resources.MergedDictionaries.Add(new ResourceDictionary { // Dark Theme Source = new Uri("pack://application:,,,/AuroraUIComponent;component/Style/Generic.xaml") }); } IconDictionary = new ResourceDictionary(); IconDictionary.Source = new Uri("pack://application:,,,/AuroraUIComponent;component/Resources/IconsDic.xaml"); // Vision Theme Set if (ApplicationExt.Theme_Color.Contains("Light")) { Application.Current.Resources.MergedDictionaries.Add(new ResourceDictionary { // Light Theme //Source = new Uri("pack://application:,,,/VisionCommonUI;component/Styles/Theme/VisionLight.xaml") Source = new Uri("pack://application:,,,/VisionCommonUI;component/Styles/Theme/VisionLightSG.xaml") }); } else { Application.Current.Resources.MergedDictionaries.Add(new ResourceDictionary { // Dark Theme Source = new Uri("pack://application:,,,/VisionCommonUI;component/Styles/Theme/VisionDark.xaml") }); } // Vision Theme 적용 Application.Current.Resources.MergedDictionaries.Add(new ResourceDictionary { Source = new Uri("pack://application:,,,/VisionCommonUI;component/Styles/VisionResources.xaml") }); VisionEventManager.Instance.Init(); } public void RegisterIngredients(IngredientsRegister register) { VisionFactory.RegisterIngredient(register); } public void RegisterLanguageResource(LangResourceRegister register) { VisionFactory.RegisterLanguageResource(register); } public void RegisterShortcuts(ShortcutRegister register) { register(CommonShortcutIds.StartMain, "Start Main Desc", ModifierKeys.Alt, Key.S); register(CommonShortcutIds.ScreenCapture, "Screen Capture", ModifierKeys.Alt, Key.C); } } }