Ejemplo n.º 1
0
        /// <summary>
        /// Deletes the configuration file of a straton NG driver which belongs to the stated zenon Logic project.
        /// </summary>
        /// <param name="zenonLogicProjectName"></param>
        private void DeleteExistingStratonNgDriverConfigFile(string zenonLogicProjectName)
        {
            // the whitespace character between the ZenonStratonNgDriverConfigFilePrefix and the zenonLogicProjectName
            // is required
            string driverConfigFilePath = Path.Combine(ZenonProject.GetFolderPath(FolderPath.Drivers),
                                                       $"{Strings.ZenonStratonNgDriverConfigFilePrefix} {zenonLogicProjectName}{Strings.TextFileExtension}");

            if (File.Exists(driverConfigFilePath))
            {
                File.Delete(driverConfigFilePath);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Creates a StratonNG driver for the current zenon project and configures it by setting the specified parameters
        /// in the config file.
        /// </summary>
        /// <param name="zenonLogicProjectName"></param>
        /// <param name="nextFreeZenonLogicMainPort"></param>
        /// <returns>Returns the driver ID of the created StratonNG driver.</returns>
        private string CreateStratonNgDriverForZenonLogicProject(string zenonLogicProjectName, string nextFreeZenonLogicMainPort)
        {
            // If a driver configuration file with the same name as it would get created here already exists it has to be
            // deleted manually beforehand. This scenario occurs when a zenon Logic project gets deleted via the GUI as zenon
            // does not remove the driver configuration file which belongs to a driver that belongs to a zenon Logic project.
            DeleteExistingStratonNgDriverConfigFile(zenonLogicProjectName);

            IDriver newStratonNgDriver = ZenonProject.Drivers().CreateDriverEx($"zenon Logic: {zenonLogicProjectName}", "STRATONNG", false);

            newStratonNgDriver.OpenConfig();
            newStratonNgDriver.CreateDynProperty("DrvConfig.Connections");

            newStratonNgDriver.DynProperties["DrvConfig.Connections.ConnectionName"] = zenonLogicProjectName;
            newStratonNgDriver.DynProperties["DrvConfig.Connections.PrimaryTCPPort"] = nextFreeZenonLogicMainPort;

            newStratonNgDriver.DynProperties["Description"] = Strings.StratonNgDriverDescription;
            string ret = newStratonNgDriver.DynProperties["DriverId"].ToString();

            newStratonNgDriver.CloseConfig(true);
            return(ret);
        }