Esempio n. 1
0
        /// <summary>
        /// Creates a communication line, communication channel and devices.
        /// </summary>
        public static CommLine Create(LineConfig lineConfig, CoreLogic coreLogic, DriverHolder driverHolder)
        {
            // create communication line
            CommLine commLine = new CommLine(lineConfig, coreLogic);

            // create communication channel
            if (string.IsNullOrEmpty(lineConfig.Channel.TypeName))
            {
                ChannelLogic channelLogic = new ChannelLogic(commLine, lineConfig.Channel);
                commLine.channel = new ChannelWrapper(channelLogic, commLine.Log);
            }
            else if (driverHolder.GetDriver(lineConfig.Channel.Driver, out DriverLogic driverLogic))
            {
                ChannelLogic channelLogic = driverLogic.CreateChannel(commLine, lineConfig.Channel);
                commLine.channel = new ChannelWrapper(channelLogic, commLine.Log);
            }
            else
            {
                throw new ScadaException(Locale.IsRussian ?
                                         "Драйвер для создания канала связи не найден." :
                                         "Driver for creating communication channel not found.");
            }

            // create devices
            foreach (DeviceConfig deviceConfig in lineConfig.DevicePolling)
            {
                if (driverHolder.GetDriver(deviceConfig.Driver, out DriverLogic driverLogic))
                {
                    DeviceLogic deviceLogic = driverLogic.CreateDevice(commLine, deviceConfig);
                    commLine.AddDevice(deviceLogic);
                }
            }

            return(commLine);
        }
Esempio n. 2
0
        private DataSourceHolder dataSourceHolder;      // holds data sources


        /// <summary>
        /// Initializes a new instance of the class.
        /// </summary>
        public CoreLogic(CommConfig config, CommDirs appDirs, ILog log)
        {
            Config      = config ?? throw new ArgumentNullException(nameof(config));
            AppDirs     = appDirs ?? throw new ArgumentNullException(nameof(appDirs));
            Log         = log ?? throw new ArgumentNullException(nameof(log));
            BaseDataSet = null;
            SharedData  = null;

            infoFileName = Path.Combine(appDirs.LogDir, CommUtils.InfoFileName);
            commLineLock = new object();

            thread             = null;
            terminated         = false;
            utcStartDT         = DateTime.MinValue;
            startDT            = DateTime.MinValue;
            serviceStatus      = ServiceStatus.Undefined;
            lastInfoLength     = 0;
            maxLineTitleLength = -1;

            commLines        = null;
            commLineMap      = null;
            deviceMap        = null;
            commandReader    = null;
            driverHolder     = null;
            dataSourceHolder = null;
        }
Esempio n. 3
0
        /// <summary>
        /// Creates a communication line, communication channel and devices.
        /// </summary>
        public static CommLine Create(LineConfig lineConfig, CoreLogic coreLogic, DriverHolder driverHolder)
        {
            // create communication line
            CommLine commLine = new CommLine(lineConfig, coreLogic);

            // create communication channel
            if (string.IsNullOrEmpty(lineConfig.Channel.Driver))
            {
                ChannelLogic channelLogic = new ChannelLogic(commLine, lineConfig.Channel); // stub
                commLine.channel = new ChannelWrapper(channelLogic, commLine.Log);
            }
            else if (driverHolder.GetDriver(lineConfig.Channel.Driver, out DriverLogic driverLogic))
            {
                ChannelLogic channelLogic = driverLogic.CreateChannel(commLine, lineConfig.Channel);
                commLine.channel = new ChannelWrapper(channelLogic, commLine.Log);
            }
            else
            {
                throw new ScadaException(Locale.IsRussian ?
                                         "Драйвер канала связи {0} не найден." :
                                         "Communication channel driver {0} not found.", lineConfig.Channel.Driver);
            }

            // create devices
            foreach (DeviceConfig deviceConfig in lineConfig.DevicePolling)
            {
                if (deviceConfig.Active && !coreLogic.DeviceExists(deviceConfig.DeviceNum))
                {
                    if (driverHolder.GetDriver(deviceConfig.Driver, out DriverLogic driverLogic))
                    {
                        DeviceLogic deviceLogic = driverLogic.CreateDevice(commLine, deviceConfig);

                        if (deviceLogic == null)
                        {
                            throw new ScadaException(Locale.IsRussian ?
                                                     "Не удалось создать устройство {0}." :
                                                     "Unable to create device {0}.", deviceConfig.Title);
                        }

                        commLine.AddDevice(deviceLogic);
                    }
                    else
                    {
                        throw new ScadaException(Locale.IsRussian ?
                                                 "Драйвер {0} для устройства {1} не найден." :
                                                 "Driver {0} for device {1} not found.",
                                                 deviceConfig.Driver, deviceConfig.Title);
                    }
                }
            }

            // prepare channel after adding devices
            commLine.channel.ChannelLogic.MakeReady();

            return(commLine);
        }
Esempio n. 4
0
        /// <summary>
        /// Initializes drivers.
        /// </summary>
        private void InitDrivers()
        {
            driverHolder = new DriverHolder(Log);

            foreach (string driverCode in Config.DriverCodes)
            {
                if (DriverFactory.GetDriverLogic(AppDirs.DrvDir, driverCode, this,
                                                 out DriverLogic driverLogic, out string message))
                {
                    Log.WriteAction(message);
                    driverHolder.AddDriver(driverLogic);
                }