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