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 6:32 am

All times are UTC+01:00




Post new topic  Reply to topic  [ 3 posts ] 
Author Message
PostPosted: Tue Jul 23, 2019 6:04 pm 
Offline

Joined: Mon Jul 22, 2019 1:03 pm
Posts: 5
Hi,

I have started to setup a continuous integration for our project using the python api and get a login failure if project gets loaded a second time. A made a reproducer:

Code:
import scriptengine
import os
import time


for attempt, _ in enumerate(range(2), start=1):
    print('*' * 100)
    print('Load and login attempt: {0}'.format(attempt))
    print('*' * 100)
    if projects.primary:
        print('Closing previously open project')
        projects.primary.close()

    path_project = os.path.join(os.getcwd(), r'codesys_dummy.project')
    print('Opening project: {0}'.format(path_project))
    project = projects.open(path_project)

    gw = online.gateways['Gateway-1']
    print('Gateway: {0}'.format(gw))
    dev = projects.primary.find('Device', False)[0]
    print('Device: {0}'.format(dev))
    pc = os.environ['COMPUTERNAME']
    print('PC: {0}'.format(pc))


    dev.set_gateway_and_device_name(gateway=gw, device_name=pc)

    proj = projects.primary
    app = proj.active_application
    onlineapp = online.create_online_application(app)

    onlineapp.login(OnlineChangeOption.Never, False)
    onlineapp.start()


time.sleep(10)


The first time through the loop it finds device and logs in without a problem. The second time it fails. This is 100% reproducible.

I am guessing that there is something that needs to be done to clean up the environment before the second iteration in addition the project close.

Script is run as follows:
Code:
start /b /wait CoDeSys.exe --profile="CoDeSys V3.5 SP14 Patch 2" --runscript="'C:\svn\CommonTest\Resources\CodesysEnvironment\test_load_project_and_login.py" --noUI

Here is the output from running the script:
Quote:
****************************************************************************************************
Load and login attempt: 1
****************************************************************************************************
Opening project: C:\svn\CommonTest\Resources\CodesysEnvironment\codesys_dummy.project
Gateway: <_3S.CoDeSys.ScriptDriverOnline.ScriptGateway object at 0x000000000000006C [_3S.CoDeSys.ScriptDriverOnline.ScriptGateway]>
Device: ScriptObject{ScriptDeviceObject, NoExplicitConnectorObject, NoSymbolConfigObject, NoLibManObject, ScriptNoProjectInfoMarker, NoScriptApplicationObject, ScriptNonTextualObject, ScriptExternalFileObjectContainer, NoTaskConfigOb
ject, NoTaskObject, NoImagePoolObject, NoTextListObject, NoScriptApplicationComposerObject, NoScriptApplicationComposerObject, SvnScriptObjectExtender}(Project=0, Name=Device, guid=e996c1ab-272b-4343-8cca-c366568b651a)
PC: ZLUKEPC0JNGFY
Build: Text: C0: ------ Build started: Application: Device.Application -------
Build: Text: C0: typify code ...
Build: Text: C0: Compile complete -- 0 errors, 0 warnings
Build: Text: C0: ------ Build started: Application: Device.Application -------
Build: Text: C0: The application is up to date
Build: Information: Number of published variables...
Build: Information: - total: 9
Build: Information: - with read access: 9
Build: Information: - with write access: 9
Build: Information: - with execute right: 0
Build: Information: Number of published types...
Build: Information: - types: 2
Build: Information: - members: 0
Build: Information: Number of published symbols: 9
Build: Information: Generated XML file: C:\svn\CommonTest\Resources\CodesysEnvironment\codesys_dummy.Device.Application.xml
Build: Text: C0: generate code...
Build: Text: C0: generate global initializations ...
Build: Text: C0: generate code initialization ...
Build: Text: C0: generate relocations ...
Build: Information: C0: Size of generated code: 438916 bytes
Build: Information: C0: Size of global data: 70611 bytes
Build: Information: C0: Total allocated memory size for code and data: 549040 bytes
Build: Information: C0: Memory area 0 contains Data, Input, Output, Memory and Nonsafe Data: size: 1048576 bytes, highest used address: 110120, largest contiguous memory gap: 938456 bytes (89 %)
Build: Information: C0: Memory area 3 contains Code: size: 1048576 bytes, highest used address: 438920, largest contiguous memory gap: 609656 bytes (58 %)
Build: Text: C0: Build complete -- 0 errors, 0 warnings : ready for download!
****************************************************************************************************
Load and login attempt: 2
****************************************************************************************************
Closing previously open project
Opening project: C:\svn\CommonTest\Resources\CodesysEnvironment\codesys_dummy.project
Gateway: <_3S.CoDeSys.ScriptDriverOnline.ScriptGateway object at 0x000000000000006C [_3S.CoDeSys.ScriptDriverOnline.ScriptGateway]>
Device: ScriptObject{ScriptDeviceObject, NoExplicitConnectorObject, NoSymbolConfigObject, NoLibManObject, ScriptNoProjectInfoMarker, NoScriptApplicationObject, ScriptNonTextualObject, ScriptExternalFileObjectContainer, NoTaskConfigOb
ject, NoTaskObject, NoImagePoolObject, NoTextListObject, NoScriptApplicationComposerObject, NoScriptApplicationComposerObject, SvnScriptObjectExtender}(Project=54, Name=Device, guid=e996c1ab-272b-4343-8cca-c366568b651a)
PC: ZLUKEPC0JNGFY
Build: Text: C0: ------ Build started: Application: Device.Application -------
Build: Text: C0: typify code ...
Build: Text: C0: Compile complete -- 0 errors, 0 warnings
Error: Running script 'C:\svn\CommonTest\Resources\CodesysEnvironment\test_load_project_and_login.py' caused exception System.Exception: Traceback (most recent call last):
File "C:\svn\CommonTest\Resources\CodesysEnvironment\test_load_project_and_login.py", line 32, in <module>
Exception: Login failed...


Some other observations:

- We get same issue when using svn to load a project
- It seems that some environment information is saved in the project file: if the IDE run up with UI and the project opened, network scan and go online, then the project saved - then the same script run again it logs in Ok both times...

Any help with identifying how to reset/clean the environment between iterations (without exiting the python script ) would be welcome.

Kind Regards
Varley


Top
   
PostPosted: Mon Jul 29, 2019 10:00 am 
Offline
Frequent User
Frequent User

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

You can try to use "system.delay(100)" instead of "time.sleep(100)" because the system.delay() also pumps the message queue. Some stuff in CODESYS are queue and without pumping the message queue they will not be done.

If that does not help you can try to increase the time to 500 or even 1000.

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: Wed Aug 14, 2019 3:26 pm 
Offline

Joined: Mon Jul 22, 2019 1:03 pm
Posts: 5
Hi Martin,

Thanks for your post. Unfortunately just adding system.delay (tried up to several seconds) in the loop does not fix it.

We did dig into this and eventually managed to get something that would run in a loop but it is not very satisfactory. Also the issue is not just whether it can run multiple times but also in circumstances with a very "clean" setup it would not manage to setup gateway and login the first time.

So to make it work we had to:

1. Run it in UI mode - behaviour seems to be different to headless
2. Clean out all old .opt files from the work area
3. Copy a "golden" .opt file with the name formatted as follows:
Code:
        user_name = getpass.getuser()
        domain_name = socket.getfqdn().split('.', 1)[-1].replace('.group', '').upper()
        opt_file_name = '{0}-{1}-{2}.opt'.format(project_name, user_name, domain_name)
        shutil.copy('default.opt', os.path.join(target, opt_file_name))

This opt file is one copied from an environment where the gateway scanning page has been opened.

4. Checkout project
5. Then run this bit of code:
Code:
            gw = online.gateways['Gateway-1']
            devices = self.project.find('Device', False)
            dev = devices[0]
            dev.set_gateway_and_device_name(gateway=gw, device_name=dev_name)
            system.commands["devicecommunication", "setactivepath"].execute()
            system.commands["file", "save"].execute()

The key seems to be the "setactivepath" which is also a dialogue box that you have to OK the very first time the IDE is used.

So all a bit clunky and surly there is an easier way to do this? - or perhaps not ...
Eventually we want to be able to create the codesys installation from scratch as part of build process which is why we make the effort to be able reliably load and run the project in reliable way without having had to interact manually with the IDE.

Another issue we have is there does not seem to be an easy way via python to make an svn update to a particular revision. The default for svn.checkout() is head and there are no arguments to specify revision. Did not find anything like svn.update() available (at least I could not find it anywhere)
All I found was perhaps using:

Code:
system.commands["svn", "update"].execute()


but I could not work out (or find any documentation) of how to call this method with the svn revision number.
Do you happen to know ?

Thanks in advance and
Kind Regards
Varley


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

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:  
Powered by phpBB® Forum Software © phpBB Limited