export/import devices

Nina
2017-10-20
2017-10-23
  • Nina - 2017-10-20

    Hi,
    I need to export and import devices from one repository to another. I can see the export option in codesys, but i do not find the corresponding option in ScriptDeviceDescrition

    to get the device I'm using this code:

    for id in range(0, DevRepList.__len__()):   # for some reaseon for Dev in DevRepList wont work
          if DevRepList[id].name == "X-Soft":
             XList=device_repository.get_all_devices(DevRepList[id])
             for  xDev in XList:
                pass # do export
    

    Is it possible at all to export devices?

    Thanks,
    Nina

    IMG: 1.JPG

     
  • mkeller - 2017-10-23

    Hi Nina.

    Nina hat geschrieben:

    for id in range(0, DevRepList.__len__()):   # for some reaseon for Dev in DevRepList wont work
          if DevRepList[id].name == "X-Soft":
             XList=device_repository.get_all_devices(DevRepList[id])
             for  xDev in XList:
                pass # do export
    

    About the first line of your code: Where does the come from?

    Nina hat geschrieben:
    Is it possible at all to export devices?

    The export of device descriptions was added with CODESYS V3.5 SP10 and the Scripting API does not support it yet. I added an entry to our bug tracking so it will be implemented at some point.

    BR
    Martin

     
  • Nina - 2017-10-23

    M.Keller hat geschrieben:
    About the first line of your code: Where does the come from?

    sorry, i forgot the first line:

    DevRepList=device_repository.sources
    for id in range(0, DevRepList.__len__()):   # for some reaseon for Dev in DevRepList wont work
          if DevRepList[id].name == "X-Soft":
             XList=device_repository.get_all_devices(DevRepList[id])
             for  xDev in XList:
                pass # do export
    

    Thanks for adding to jira

     
  • mkeller - 2017-10-23

    Hi Nina.

    The iteration of should work. I tested it with the following code and had no problem:

    sources = device_repository.sources
    assert(len(sources) > 0, "no repo sources")
    print("Available sources of the device repository:")
    for src in sources:
       print("- {}: {}".format(src.name, src.location_url))
    count = 0
    print("Get all device descriptions from a specific source")
    sysRepoSource = sources["System Repository"]
    devColl = device_repository.get_all_devices(sysRepoSource)
    for dev in devColl:
       printDeviceDesc(dev)
       count += 1
       if count > 100:
          break
    

    You find the complete source code as attachment.

    BTW: You can get the repo source by name. The syntax for it is . It will return the matching repo source or if there is none with that name.

    BR
    Martin

    device_repo_show_minimal.py [1.74 KiB]

     

Log in to post a comment.