Example #1
0
        /// <summary>
        /// 系统资源初始化
        /// </summary>
        public static void Startup(string processName, string moduleName = "")
        {
            ConfigPath  = Path.GetFullPath($"{BasePath}../../Cfg");
            ProcessName = processName;
            ModuleName  = moduleName;

            if (!Directory.Exists(ConfigPath))
            {
                Directory.CreateDirectory(ConfigPath);
            }

            MainConfigFile   = Path.Combine(ConfigPath, $"Main.json");
            DeviceConfigFile = Path.Combine(ConfigPath, $"{ProcessName}.device.xml");

            Logger.Main.Info($"加载主配置文件{SysConf.MainConfigFile}");
            Main = JsonExtension.GetDefKey(SysConf.MainConfigFile, "MAIN", new SysConfModel());

            if (File.Exists(SysConf.DeviceConfigFile))
            {
                var dc = XmlExtension.LoadXMLFile <DeviceConfig>(SysConf.DeviceConfigFile);
                if (dc.IsSuccess)
                {
                    Logger.Main.Info($"加载设备配置文件: {SysConf.DeviceConfigFile} 成功");
                    Device = dc.Data;
                    Device.Recombine();
                    //foreach (var d in Device.Devices)
                    //{
                    //    foreach (var p in d.Value.Properties)
                    //    {
                    //        System.Console.WriteLine(p.Value.Id);
                    //    }
                    //}
                }
                else
                {
                    Logger.Main.Error($"加载设备配置文件: {SysConf.DeviceConfigFile} 失败");
                }
            }

            if (SysConf.Main.RunEnv != "EVOC")
            {
                RunInEvoc = false;
            }

            KeyPlant        = $"LD:{Main.Factory.Id}:{Main.Plant.Id}";
            KeyAssemblyLine = $"{KeyPlant}:{Main.AssemblyLine.Id}";

            SysBootStrapper.Initialize("");
            ServiceManager.Start();
        }
Example #2
0
        public override void BeforeStartup()
        {
            // 创建消息监听服务
            ServiceManager.Services.Add(new MsgRecvService());

            //注册日志
            WorkFlowEngine.Loged      += Logger.Device.Info;
            WorkFlowEngine.ErrorLoged += Logger.Device.Error;

            //加载设备配置
            var device = Path.Combine(SysConf.ConfigPath, $"{SysConf.ProcessName}.device.json");

            ModbusConf.CnfModel = JsonExtension.GetDefKey(device, "Modbus", new ModbusConfModel[] { });
            //加载配置文件
            var plccfgPath   = Path.Combine(SysConf.ConfigPath, "PLCConfig.xml");
            var workflowPath = Path.Combine(SysConf.ConfigPath, "WorkFlow.xml");

            if (File.Exists(plccfgPath) && File.Exists(workflowPath))
            {
                var plc  = XmlExtension.LoadXMLFile <PlcConfig>(plccfgPath);
                var work = XmlExtension.LoadXMLFile <WorkFolwConfig>(workflowPath);
                if (!plc.IsSuccess)
                {
                    Logger.Main.Info("加载modbusplc配置失败");
                }
                if (!work.IsSuccess)
                {
                    Logger.Main.Info("加载modbusworkflow配置失败");
                }
                if (plc.IsSuccess && work.IsSuccess)
                {
                    ModBusDataFactory.Initialization(plc.Data, work.Data);
                }
            }
            else
            {
                Example();
            }
        }