Ejemplo n.º 1
0
        string LoadXMLDefinition(string pFile)
        {
            string path = TheCommonUtils.cdeFixupFileName(pFile);

            TheBaseAssets.MySYSLOG.WriteToLog(500, new TSM(MyBaseEngine.GetEngineName(), $"Trying to open Modbus configuration file: {pFile}"));

            ModbusConfiguration config = null;

            try
            {
                config = ModbusConfiguration.ReadFromFile(path);
            }
            catch (IOException)
            {
                return("File not found or parsing failed");
            }

            List <TheThing> tDevList = TheThingRegistry.GetThingsOfEngine(MyBaseThing.EngineName);

            foreach (var dd in config.Devices)
            {
                var tDev = tDevList.Find((t) => t.FriendlyName == dd.Name);
                if (tDev == null || !tDev.HasLiveObject)
                {
                    TheBaseAssets.MySYSLOG.WriteToLog(500, new TSM(MyBaseEngine.GetEngineName(), $"Adding Modbus Device {dd.Name}"));
                    var pm = new ModbusTCPDevice(tDev, this, dd);
                    TheThingRegistry.RegisterThing(pm);
                }
            }

            return("XML Definition loaded correctly.");
        }
Ejemplo n.º 2
0
        void InitServices()
        {
            List <TheThing> tDevList = TheThingRegistry.GetThingsOfEngine(MyBaseThing.EngineName);

            if (tDevList.Count > 0)
            {
                foreach (TheThing tDev in tDevList)
                {
                    if (tDev.DeviceType != "IBaseEngine")
                    {
                        if (!tDev.HasLiveObject)
                        {
                            try
                            {
                                switch (tDev.DeviceType)
                                {
                                case eModbusType.ModbusTCPDevice:
                                {
                                    var tS = new ModbusTCPDevice(tDev, this, null);
                                    TheThingRegistry.RegisterThing(tS);
                                }
                                break;

                                case eModbusType.ModbusRTUDevice:
                                {
                                    var tS = new ModbusRTUDevice(tDev, this, null);
                                    TheThingRegistry.RegisterThing(tS);
                                }
                                break;
                                }
                            }
                            catch (Exception)
                            {
                                TheBaseAssets.MySYSLOG.WriteToLog(500, new TSM(MyBaseEngine.GetEngineName(), $"Failed to start Modbus Device {tDev.FriendlyName}", eMsgLevel.l1_Error));
                                MyBaseThing.StatusLevel = 2;
                            }
                        }
                    }
                }
            }
            MyBaseEngine.SetStatusLevel(-1); //Calculates the current statuslevel of the service/engine
        }