CODESYS - the IEC 61131-3 automation software

Welcome to the official CODESYS Forum
Deutsche Version English version russian version 
It is currently Thu Jul 27, 2017 1:39 pm

All times are UTC+01:00




Post new topic  Reply to topic  [ 9 posts ] 
Author Message
PostPosted: Sat Jun 18, 2016 6:20 pm 
Offline

Joined: Fri Nov 23, 2012 11:42 am
Posts: 46
I want to use a python script to add and remove device descriptors. It appears that the IScriptDeviceRepository Interface added in 3.5.9.0 gives me the methods I require, but I've been unable to work out how to get an object that implements the interface.


Top
   
PostPosted: Sun Jun 19, 2016 12:27 pm 
Offline

Joined: Fri Nov 23, 2012 11:42 am
Posts: 46
I've got a bit further now, I found a global named device_repository. What I want to do is to ensure that I remove old versions of a set of device descriptors and add in new ones. I've managed to find the devices I want to remove, however either removing or importing devices is giving problems.

Code:
devices = device_repository.get_all_devices("MyUniqueText")
for device in devices:
    print("id: ", device.device_id, " info= ",device.device_info.name)
    device_repository.remove_device(device.device_id, None, True)

for file in glob.glob("artefacts/*.devdesc.xml"):
    device_repository.import_device(file, None, True)
    print("Installed "+ file)


Running this gives the error below for the line with remove_device, if I comment that line I get the same for import_device.
Code:
System.ArgumentNullException: Traceback (most recent call last):
  File "C:\Users\David\Documents\scripts\CODESYS\CheckoutProject.py", line 50, in <module>
TypeError: Value cannot be null.
Parameter name: source

However the documentation for the source parameter in import_device and remove_device both say
Quote:
Remove the device from this repository source. If null the device is removed from the default repository source.

I've spent quite a while digging through the API's and I haven't managed to work out another value that I could use for the source parameter.
Any help would be much appreciated.


Top
   
PostPosted: Mon Jun 20, 2016 10:59 am 
Offline
Frequent User
Frequent User

Joined: Tue Nov 13, 2012 9:20 am
Posts: 202
Hi DavidCozens.

DavidCozens wrote:
However the documentation for the source parameter in import_device and remove_device both say
Quote:
Remove the device from this repository source. If null the device is removed from the default repository source.

I've spent quite a while digging through the API's and I haven't managed to work out another value that I could use for the source parameter.
Any help would be much appreciated.

It is a bug. I added the Jira CDS-49921 to our bug tracking, so it will be fixed eventually.

At the moment you need to specify a repository source to import or remove a device/vendor description.

BR
Martin

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

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


Top
   
PostPosted: Mon Jun 20, 2016 2:30 pm 
Offline

Joined: Fri Nov 23, 2012 11:42 am
Posts: 46
M.Keller wrote:
Hi DavidCozens.

DavidCozens wrote:
However the documentation for the source parameter in import_device and remove_device both say
Quote:
Remove the device from this repository source. If null the device is removed from the default repository source.

I've spent quite a while digging through the API's and I haven't managed to work out another value that I could use for the source parameter.
Any help would be much appreciated.

It is a bug. I added the Jira CDS-49921 to our bug tracking, so it will be fixed eventually.

At the moment you need to specify a repository source to import or remove a device/vendor description.

BR
Martin

Hi Martin,

Thank you. I have however been unable to find an API call to give me access to any repository source. How do I find the default repository source?

regards David


Top
   
PostPosted: Mon Jun 20, 2016 5:15 pm 
Offline
Frequent User
Frequent User

Joined: Tue Nov 13, 2012 9:20 am
Posts: 202
Hi DavidCozens.

You get the list of repository sources from the property sources (see IScriptRepositorySourceList) of the device repository.

Code:
sources = device_repository.sources
mySource = sources["My Device Repository"]

BR
Martin

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

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


Top
   
PostPosted: Mon Jun 20, 2016 7:25 pm 
Offline

Joined: Fri Nov 23, 2012 11:42 am
Posts: 46
M.Keller wrote:
Hi DavidCozens.

You get the list of repository sources from the property sources (see IScriptRepositorySourceList) of the device repository.

Code:
sources = device_repository.sources
mySource = sources["My Device Repository"]

BR
Martin


Hi Martin,

Thank you - I have that part of my script working now.

regards David


Top
   
PostPosted: Mon Feb 06, 2017 12:55 pm 
Offline

Joined: Wed Jan 25, 2017 2:30 pm
Posts: 2
Hi,
sorry for capturing this topic, but my question might fit to that.

What's the best way to remove all versions of all devices from the repository, which belong
to a certain vendor?

I did not really find an interface that lists all installed devices of a specific vendor.

Regards


Top
   
PostPosted: Mon Feb 06, 2017 3:42 pm 
Offline
Frequent User
Frequent User

Joined: Tue Nov 13, 2012 9:20 am
Posts: 202
Hi jmohre.

jmohre wrote:
What's the best way to remove all versions of all devices from the repository, which belong
to a certain vendor?

The following example code iterates through the device sources, gets a list of all devices for a specific vendor and removes them from the device repository:

Code:
try:
   for src in device_repository.sources:
      devs = device_repository.get_all_devices(src)
      devsVendor = devs.get_devices_of_vendor("Some company")

      try:
         for dev in devsVendor:
            device_repository.remove_device(dev.device_id, src, False)
      except:
         print("Failed to remove device description")
finally:
   # Save the device cache because we used the remove_device without
   # saving the device cache because it is faster
   device_repository.save_device_cache()

The call of save_device_cache() is important because otherwise the devices still appear in the repository after a restart of CODESYS but the files of the device were deleted.

BR
Martin

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

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


Top
   
PostPosted: Tue Feb 07, 2017 11:37 am 
Offline

Joined: Wed Jan 25, 2017 2:30 pm
Posts: 2
Thanks Martin,

I found "get_devices_of_vendor" this morning - it is a bit hidden :-).
But I did not take care of the cache issue and the different repositories.

Regards

Jörg


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

All times are UTC+01:00


Who is online

Users browsing this forum: No registered users and 1 guest


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