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 Thu Jul 18, 2019 6:10 pm

All times are UTC+01:00




Post new topic  Reply to topic  [ 42 posts ]  Go to page Previous 1 2 3
Author Message
PostPosted: Mon Oct 17, 2011 3:03 pm 
Offline
Frequent User
Frequent User
User avatar

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

Sorry for the delay in answering, but I was busy with high priority issues, and had no time to check here in the forum.

I'm clad that you could finish the issue yourself. :D

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

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


Top
   
PostPosted: Wed Oct 19, 2011 8:07 am 
Offline

Joined: Tue Oct 04, 2011 9:21 am
Posts: 27
Hi M. Schaber,

is there any command which close CoDeSys after exporting the project?


Top
   
PostPosted: Wed Oct 19, 2011 8:12 am 
Offline
Frequent User
Frequent User
User avatar

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

You can use system.exit(exitcode). The exitcode is optional, 0 (which means success) is the default.

If you just want to terminate the script execution without exitting the platform, call sys.exit() or raise a SystemExitException.

HTH,
Markus

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

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


Top
   
PostPosted: Wed Oct 19, 2011 9:58 am 
Offline
Frequent User
Frequent User
User avatar

Joined: Fri Mar 18, 2011 4:12 pm
Posts: 266
One of our customers works with "prototype projects". They want to slice the prototype projects into single objects, and then use those pieces to re-assemble different projects using scripts.

While assisting our customer, the following example script was written. It exports all POUs of the project - each of them into a single file containing just that POU including its children (Actions, Properties etc.), and the parent folders to preserve the folder structure.

Other scripts can then use the native import to import those objects under an Application, and the folder structure is recreated.

(There is a Bug with native import that can lead to duplicated folders, the fix is scheduled for 3.4 SP4 Patch 2.)

Code:
# Tests CoDeSys native import/export functionality.
from __future__ import print_function

proj = projects.primary

# We're interested in POU nodes:
POUGuid = Guid("6f9dac99-8de1-4efc-8465-68ac443b7d08")

# We collect all POU nodes in that list.
pous = []

# From the parent node on, we recursively add POU nodes:
def CollectPous(node):
    if node.type == POUGuid:
        pous.append(node)
    else:
        for child in node.get_children():
            CollectPous(child)

# Now we collect all the leaf nodes.
for node in proj.get_children():
    CollectPous(node)

# We print everything just to know what's going on.
for i in pous:
    print("found: ", i.type, i.guid, i.get_name())

# And now we export the files.
for candidate in pous:
    # We create a list of objects to export:
    # The object itsself
    objects = [candidate]
   
    # And sub-objects (POUs can have actions, properties, ...)
    objects.extend(candidate.get_children())
   
    # And the parent folders.
    parent = candidate.parent
    while ((not parent.is_root) and parent.is_folder):
        objects.append(parent)
        parent = parent.parent
   
    # Create an unique file name:
    filename = "d:\\test\\%s__%s.export" % (candidate.get_name(), candidate.guid)
   
    # print some user information
    print("exporting ", len(objects), " objects to: ", filename)
   
    # and actually export the project.
    proj.export_native(objects, filename)

print ("script finished.")

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

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


Top
   
PostPosted: Wed Oct 19, 2011 10:40 am 
Offline

Joined: Tue Oct 04, 2011 9:21 am
Posts: 27
Hi Hi,

one more request :D
After exporting the project as XML-File, CoDeSys schows usually a message, that the exporting was successfull (Exportieren erfolgreich abgeschlossen) and waits for the user to press the "OK" button.

Is it possible to tell CoDeSys to continue executing the script without waiting for the "OK" button?


Top
   
PostPosted: Wed Oct 19, 2011 11:05 am 
Offline
Frequent User
Frequent User
User avatar

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

First, we should stop discussing questions in this thread - it was only meant to present examples. We should create a new thread in this forum. :-)

Currently, it is not possible to suppress this dialog. We have system.prompt_answers which allows catching and auto-answering of dialogs - however, this currently works only for dialogs which have a so-defined "MessageKey", and it seems that the export dialogs don't offer such MessageKeys.

I created issue CDS-25228 in our tracker so this will be fixed eventually.

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

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


Top
   
PostPosted: Tue Jul 14, 2015 7:07 am 
Offline

Joined: Fri Jul 10, 2015 10:52 am
Posts: 35
Hi

I'm currently trying to make this script execution work (using the "ScriptEnginePluginAPIReference" and "CoDeSys" help)
with the examples given in help files, and seems to work but ran into some unexpected trouble.

I wanted to store my project settings and code in PLCopenXML so I made a project, exported everything,
using the example script I imported the XML to an empty project (so far it worked) but when I tried to upload
and login I got an error: gateway is not configured.

So I wrote a simple script:
Code:
    def _setGateway(self):
        objects = self.proj.get_children(recursive=True)       

        for dev in objects:
            if dev.get_name() == 'Device':
                proj_device = dev
       
        gateway_guid = proj_device.get_gateway()
        #gateway_guid = '3261a15d-434d-4868-9e1f-1bfa38e92408'
        gateway_dev_addr = 'some-hardcoded-value'
        proj_device.set_gateway_and_address(gateway_guid, gateway_dev_addr)

The script had been checked and its working _under a preset project file_.
Problems:
1st) when I execute it on a newly (script) created empty project file (after XML import)
the gateway GUID is NULL (00000-000-0000-0000), if I set the gateway (manually) in that project
and save the project and than re-execute this script I get a valid GUID.

2nd) Even if I hardcode the correct GUID and the correct address (I can see the script setting itt correctly,
because I set the addr to a wrong value before) the login command throws me an error that the device
could not be reached because of connection problems. Again if I set it manually and save the project,
login works perfectly.

Another major problem that I came across with is the following (either my python knowledge is limited here
or just a simple explanation can solve this), using a python script through command line will only grant
that and only that python script the visibility to codesys supplemented interfaces, once another script is
used from that script (using sys.path.append) that script will no longer have the ability to resolve these interface names.

- I have a few python script under (let say) C:\python_scripts, these are mostly helpers and classes (e.g. ImporterReporter)
- I have another python script under C:\codesys_python\execute.py that should do some testing (or loggin in, etc)

execute.py:
Code:
 sys.path.append('C:\\python_scripts')
 from python_importer import *


This line gives me an error/exception that undefined name is
-> execute.py line 2 "Unknown name"
-> python_scripts\codesys_importer.py line 16 "ImporterReporter"

Is there any way to grant access/visibility to script outside the runtime frame?
If I copy these scripts near my "execute.py" it works, but I have a reason for separating them
so that is not an option.

Thank you very much for your help!


Top
   
PostPosted: Tue Oct 06, 2015 7:42 am 
Offline

Joined: Mon Jul 06, 2015 3:57 am
Posts: 1
Quote:
"projects" is an object imported into the namespace for scripts running in CoDeSys, so it is only available if your script is being started in CoDeSys directly (either via the "Execute Script" menu command or button, or via the "--runscript" command line parameter.)


Is there any documents or manuals including these 'namespace' in CoDeSys?

I can't find it on my PC and internet.

Thanks a lot.


Top
   
PostPosted: Thu Dec 17, 2015 9:24 am 
Offline

Joined: Fri Jul 10, 2015 10:52 am
Posts: 35
Mystic wrote:
Quote:
"projects" is an object imported into the namespace for scripts running in CoDeSys, so it is only available if your script is being started in CoDeSys directly (either via the "Execute Script" menu command or button, or via the "--runscript" command line parameter.)


Is there any documents or manuals including these 'namespace' in CoDeSys?

I can't find it on my PC and internet.

Thanks a lot.


Yes it is documented in the online manual and also 3S CODESYS\CODESYS\Online Help\ScriptEngine.chm


Top
   
PostPosted: Thu Dec 17, 2015 9:25 am 
Offline

Joined: Fri Jul 10, 2015 10:52 am
Posts: 35
Is there a way to read the device log using the scripting interface?
E.g. when an exception happens and I retreive that the application has been stopped but would like to know the reason.


Top
   
PostPosted: Thu Dec 17, 2015 9:36 am 
Offline
Frequent User
Frequent User

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

etamgul wrote:
Is there a way to read the device log using the scripting interface?
E.g. when an exception happens and I retreive that the application has been stopped but would like to know the reason.

Right now, this is not yet possible, but this improvement is already listed in our Jira tracker CDS-31928, so it will be implemented eventually.

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: Fri Jan 22, 2016 10:18 am 
Offline

Joined: Fri Jul 10, 2015 10:52 am
Posts: 35
In my case onlineapp.application_state does not work properly when script is executed with --noUI switch.

I wanted to test that in case of an exception (thrown because the runtime got a wrong UDP packet) the application is stopped,
thus I needed a python script to send the proper UDP packets when I realized that using the --noUI switch influences the result of the
execution and this was because the onlineapp.application always returned me 'run'.

Could somebody confirm this?


Top
   
Display posts from previous:  Sort by  
Post new topic  Reply to topic  [ 42 posts ]  Go to page Previous 1 2 3

All times are UTC+01:00


Who is online

Users browsing this forum: No registered users and 3 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:  
cron
Powered by phpBB® Forum Software © phpBB Limited