CODESYS - the IEC 61131-3 automation software

Welcome to the official CODESYS Forum by 3S-Smart Software Solutions GmbH | A member of the CODESYS Group
Deutsche Version English version russian version 
It is currently Sun Aug 18, 2019 11:51 am

All times are UTC+01:00




Post new topic  Reply to topic  [ 6 posts ] 
Author Message
 Post subject: Install library in V3
PostPosted: Tue Jun 07, 2011 8:49 am 
Offline
User avatar

Joined: Mon Jun 06, 2011 8:42 am
Posts: 47
Hi,

Is there a way to install new libraries in CoDeSys V3 from the script engine?

The documentation states that it is possible to add_library to a project, but I cannot find a command to install the libraries so they can be added afterwards.

I am using CoDeSys V3.4 SP3 Patch 1.

Best regards,
Frank Jepsen
kk-electronic a/s


Top
   
PostPosted: Tue Jun 07, 2011 9:28 am 
Offline
Frequent User
Frequent User
User avatar

Joined: Fri Mar 18, 2011 4:12 pm
Posts: 266
Hi,

Currently, this functionality is not available.

But there is a workaround: Pack the library into a project archive, and open that archive using open_archive. This should install all libraries contained in the archive.

This workaround should solve some of the use cases.

Regards,
Markus

_________________
Check out the CODESYS store: http://store.codesys.com/

CODESYS® a trademark of 3S-Smart Software Solutions GmbH
Inspiring Automation Solutions


Last edited by M.Schaber on Tue Jun 07, 2011 9:40 am, edited 1 time in total.

Top
   
PostPosted: Tue Jun 07, 2011 9:34 am 
Offline
User avatar

Joined: Mon Jun 06, 2011 8:42 am
Posts: 47
Ok. That sounds like a reasonable workaround. Thank you.

// Frank


Top
   
PostPosted: Mon Apr 23, 2012 1:14 pm 
Offline
User avatar

Joined: Mon Jun 06, 2011 8:42 am
Posts: 47
Hi,

I have upgraded to V3.5 Patch 3 now and I can see that more objects has become available.

Could you provide an example using the ILibManager to install a library?

I would like to install e.g. "c:\myfunction.library" into the CoDeSys IDE, so I can add it to other projects.

Regards,
Frank


Top
   
PostPosted: Mon Apr 23, 2012 1:31 pm 
Offline
Frequent User
Frequent User
User avatar

Joined: Fri Mar 18, 2011 4:12 pm
Posts: 266
Hi, Frank,

Frank Jepsen wrote:
I have upgraded to V3.5 Patch 3 now and I can see that more objects has become available.

Could you provide an example using the ILibManager to install a library?

I would like to install e.g. "c:\myfunction.library" into the CoDeSys IDE, so I can add it to other projects.


I stripped one of my internal test scripts a little bit, here's the code. It demonstrates displaying all libraries, creating and deleting library repositories, and installation and uninstallation of libraries.

Code:
from __future__ import print_function

import os

for repo in librarymanager.repositories:
    print(repo.name, "(", repo.root_folder, ", ", repo.editable, ")")
    for lib in librarymanager.get_all_libraries(repo):
        print("    ", lib.displayname)
        print("        Cats: ", ", ".join(map(str, lib.categories)))
        print("        Deps: ", ", ".join(map(str, lib.dependencies)))

print("")

oldrepocount = len(librarymanager.repositories)

print("Trying to create repo")

repopath = "C:\\Path\\to\\temporary\\dir\\REPO"
os.makedirs(repopath)
   
newrepo = librarymanager.insert_repository(repopath, "Script_Test_Repo")

assert(len(librarymanager.repositories) == oldrepocount + 1)

print("Trying to install library")
libpath = "C:\\Path\\to\\Testlib.library"

installedlib = librarymanager.install_library(libpath, repo, overwrite=True)

print("Trying to find library")

foundlib, repo = librarymanager.find_library("MSch Test library, 3.4.4.0 (3S Smart Software GmbH)")

assert(repo == newrepo, "repo does not match!")
assert(foundlib == installedlib, "lib does not match!")

print("Uninstalling library")
librarymanager.uninstall_library(repo, foundlib)

print("Removing repository")
librarymanager.remove_repository(newrepo, delete_on_disk=True)

assert(not os.path.isdir(repopath), "repo deletion failed")
print("script finished.")


Here's a second script which installs all librarie swhich are found in a given directory. Our test department sometimes uses it to install all libraries which were ever released with CoDeSys into a fresh installation (for example, in a Virtual Machine).

Code:
# -*- coding: utf-8 -*.
from __future__ import print_function
import os

# The directory we want to install libraries from.
LIBDIRS = (r"D:\WorkingCopies\LibrariesV3Tags",)

# Search order (compiled vs. source libraries)
EXTENSIONS = (".compiled-library", ".library")

# disabling prompts for storage version upgrade
system.prompt_answers["UnserializableDataError2"] = PromptResult.Cancel
system.prompt_answers["LossOfDataWarning2"] = PromptResult.No

print("searching libraries to install")

repo = librarymanager.repositories[0]

for libdir in LIBDIRS:
    for extension in EXTENSIONS:
        for dir, subdirs, files in os.walk(libdir):
            for filename in files:
                if filename.endswith(extension):
                    fullpath = os.path.join(dir, filename)
                    print("installing: ", fullpath)
                    try:
                        librarymanager.install_library(fullpath, repo, overwrite=True)
                    except Exception as e:
                        print("exception: ", e)
               
print("script finished.")


Warning: I cleaned both scripts by removing some internals, and did not re-test them in their new shape, but they should still be useful for you to get the idea. :wink:

I hope that helps you a little...

_________________
Check out the CODESYS store: http://store.codesys.com/

CODESYS® a trademark of 3S-Smart Software Solutions GmbH
Inspiring Automation Solutions


Top
   
PostPosted: Mon Apr 23, 2012 1:45 pm 
Offline
User avatar

Joined: Mon Jun 06, 2011 8:42 am
Posts: 47
Thanks Markus. Those examples really helped. :)


Top
   
Display posts from previous:  Sort by  
Post new topic  Reply to topic  [ 6 posts ] 

All times are UTC+01:00


Who is online

Users browsing this forum: No registered users and 5 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Limited