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:
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'
The script had been checked and its working _under a preset project file_.
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)
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!