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 Tue Sep 17, 2019 11:51 am

All times are UTC+01:00




Post new topic  Reply to topic  [ 12 posts ] 
Author Message
 Post subject: External Debugger
PostPosted: Wed Mar 25, 2015 2:17 pm 
Offline

Joined: Thu Jul 10, 2014 3:04 pm
Posts: 9
Hello, I visited the CDS Users Conference ... I saw there is a way to debug scipts with e.g. Pydevd, PyCharm, PyDev or LiClipse ... do you know if any of a free versions like PyCharm Community Edition is working :?:


You do not have the required permissions to view the files attached to this post.


Top
   
 Post subject: Re: External Debugger
PostPosted: Wed Mar 25, 2015 2:34 pm 
Offline
Frequent User
Frequent User
User avatar

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

The Debugging functionality currently relies on "remote debugging" capabilities.

According to PyCharm Editions Comparison, remote debugging is only supported in the professional edition of PyCharm. I don't know the details of other IDEs and their feature policies.

Personally, I did switch to PTVS and the .NET based debugging approach, because that one "just works" without any further effort by attaching to a running CODESYS process. (In theory, it should also work with SharpDevelop or MonoDevelop / Xamarin Studio, but I never tried them.)

The python based debugging approach currently requires that one starts CODESYS with special command line parameters, and needs an active "connection" script to be maintained, so the ScriptEngine can actually connect to the debugger.

We will most likely improve on that situation in the future, but (also most likely) it will stay a "remote debugging" mechanism. Everything else would require the CODESYS installation to more closely emulate a traditional python distribution (which requires quite some architectural work including changing the installation directory layout which has some constraints due to our OEMs), and additionally each script run would need a fresh CODESYS instance to be started from scratch.

We also have some plans to integrate an IronPython debugger right into CODESYS itself, but unfortunately, such issues are handled with low priority.

HTH,
Markus

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

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


Top
   
 Post subject: Re: External Debugger
PostPosted: Thu Mar 26, 2015 12:06 pm 
Offline

Joined: Thu Jul 10, 2014 3:04 pm
Posts: 9
Hello, thank you for the fast Feedback ... hope the CDS Python Debugger will coming soon :D


Top
   
 Post subject: Re: External Debugger
PostPosted: Mon Mar 30, 2015 12:56 pm 
Offline

Joined: Thu Jul 31, 2014 12:57 pm
Posts: 2
Hello,

i have a question concerning debugging Python scripts in Visual Studio:

i have installed PTVS 2.1 and try to debug the script example of the Codesys user's conference. I opened a script file, attached it to running Codesys.exe. Then i started the script from Codesys, but i cannot get Visual Studio to hit the breakpoint:

Attachment:
Aufnahme2.jpg


Do i miss something? Thx...


You do not have the required permissions to view the files attached to this post.


Top
   
 Post subject: Re: External Debugger
PostPosted: Mon Apr 06, 2015 4:59 pm 
Offline
Frequent User
Frequent User
User avatar

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

To be honest, I have no idea what's going wrong.

Just some thoughts:
- Are you sure the file path is the same?
- What happens if you call the System.Diagnostics.Debugger.Launch() or System.Diagnostics.Debugger.Break() functions?

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

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


Top
   
 Post subject: Re: External Debugger
PostPosted: Thu Apr 23, 2015 1:48 pm 
Offline

Joined: Thu Jul 31, 2014 12:57 pm
Posts: 2
I figured out the problem. When attaching the script to the Codesys.exe process, i have to select code type 'Python' to make it work


You do not have the required permissions to view the files attached to this post.


Top
   
 Post subject: Re: External Debugger
PostPosted: Mon Apr 27, 2015 8:40 am 
Offline
Frequent User
Frequent User
User avatar

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

I always tried using "Managed" rsp. ".NET" code, and it also worked. Glad you got it to work.

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

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


Top
   
 Post subject: Re: External Debugger
PostPosted: Wed Aug 26, 2015 5:08 pm 
Offline

Joined: Wed Aug 26, 2015 3:26 pm
Posts: 8
M.Schaber wrote:
The python based debugging approach currently requires that one starts CODESYS with special command line parameters, and needs an active "connection" script to be maintained, so the ScriptEngine can actually connect to the debugger.


Hello!

What is the special command line option? And what sort of script is needed?

Is it just the option to run the script, and is the script just any script that waits a little at the beginning before doing its work?

Also, how does the attach to process work, do I just have the same python script file open in Visual Studio and say "attach to process"? I have Visual Studio Tools for Python installed.

Also, I noticed with a script I was running that it was blocking the GUI. Do you have the python interpreter running in the UI thread, so if I run a python script I cannot control the UI anymore? I would like to do both, run python script and control UI at same time.

Thanks, best
Andreas Reiff


Top
   
 Post subject: Re: External Debugger
PostPosted: Thu Aug 27, 2015 9:09 am 
Offline
Frequent User
Frequent User
User avatar

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

Just to recall, there are two debugging approaches possible with IronPython in CODESYS:
- The .NET based approach using the .NET debugging APIs
- The Python (settrace) based approach

andipandi wrote:
M.Schaber wrote:
The python based debugging approach currently requires that one starts CODESYS with special command line parameters, and needs an active "connection" script to be maintained, so the ScriptEngine can actually connect to the debugger.

What is the special command line option? And what sort of script is needed?

Is it just the option to run the script, and is the script just any script that waits a little at the beginning before doing its work?


The python debugger based approach is a little more complicated. You need an Python IDE with "remote debugging" enabled and waiting for connections, and then the connection script needs to hook into sys.settrace() and open the connection to the debugger.

For example, we successfully got it working with PyCharm using the following command line:
Code:
CODESYS.exe --profile="CODESYS V3.5 SP5" --scriptDebugger="D:\test\charmdebug\initdebug.py"

The file "initdebug.py" itself looks like:
Code:
from __future__ import print_function
from __future__ import unicode_literals

import sys
sys.path.append(r"D:\test\Env2\Lib\site-packages\pycharm-debug.egg")

import pydevd

def scriptdebuggersetup():
    pydevd.settrace('localhost', port=51234, stdoutToServer=True, stderrToServer=True)

def scriptdebuggershutdown():
    pydevd.stoptrace()


You will need to adapt the pathes (and possible hostname and port) to match your own installation.


andipandi wrote:
Also, how does the attach to process work, do I just have the same python script file open in Visual Studio and say "attach to process"? I have Visual Studio Tools for Python installed.


If you're using Python Tools for Visual Studio, I'd suggest you use the .NET based debugger approach, as it is much less troublesome.

You just use "Attach to process" to the running CODESYS instance _before_ you start the script, and select "Python" as well as "Managed (V4.0)". (It may also be "Managed (V4.0, V4.5)" or similar depending on the installed VS and .NET versions, just make sure you don't select the "Managed (V2.0/3.0/3.5)" instead. Then you simply open the script in Visual studio, set the breakpoint, and start it in CODESYS, that should work (and did in all my tests).

andipandi wrote:
Also, I noticed with a script I was running that it was blocking the GUI. Do you have the python interpreter running in the UI thread, so if I run a python script I cannot control the UI anymore? I would like to do both, run python script and control UI at same time.


Yes, the python interpreter is running in the main thread. A technical reason is that the CODESYS architecture is inherentily bound to the UI thread for most API calls for historical reasons, so for running the scripts in a background thread, each interaction between the script and CODESYS would have to be marshalled to the UI thread. Another reason is that the focus of the ScriptEngine is to automate tasks which the user also can do manually - user interaction during those automated tasks would very likely disturb the script due to side-effects.

Depending on your exact use case, the solution may be:
  • If you want the script to interact with the user, you can use the methods available in system.ui which provide some simple pre-cooked prompts, or you can use System.Windows.Forms to open more complex dialog windows. (You can also create those Dialogs in Visual Studio, compile them to an assembly, and then load the assembly from IronPython.)
  • If you want to automate tests of CODESYS and thus control the UI of codesys (e. G. by using the UI Automation Framework), you should look into the CODESYS Test Manager - it is meant for test automation, and there exists an extended variant which allows user interaction during script execution.
  • If you want to extend CODESYS with functionality currently not present, the CODESYS Automation Platform is the right solution for you - it allows you to hook into events, have background tasks, and much more extensions and customizations.

HTH,
Markus

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

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


Top
   
 Post subject: Re: External Debugger
PostPosted: Thu Aug 27, 2015 6:46 pm 
Offline

Joined: Wed Aug 26, 2015 3:26 pm
Posts: 8
Many thanks for the answer, Markus.

The python debugging part looks good, I will try this.

As for the testing, I think I want to go for option 2, the CODESYS Test Manager.

My main goal is to automate codesys (actually a program that is built on/extends codesys) but find many UI controls not to adhere to MSAA or MSUIA standards and thus I am looking for another way to be able to do what I want. (Right now I am using Silktest.)

What sort of control do I have with Test Manager? Can I integrate test manager into test running in another context, like any test runner?


Top
   
 Post subject: Re: External Debugger
PostPosted: Wed Sep 02, 2015 11:16 am 
Offline
Frequent User
Frequent User
User avatar

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

andipandi wrote:
Many thanks for the answer, Markus.

The python debugging part looks good, I will try this.

As for the testing, I think I want to go for option 2, the CODESYS Test Manager.

My main goal is to automate codesys (actually a program that is built on/extends codesys) but find many UI controls not to adhere to MSAA or MSUIA standards and thus I am looking for another way to be able to do what I want. (Right now I am using Silktest.)

What sort of control do I have with Test Manager? Can I integrate test manager into test running in another context, like any test runner?


The execution of Test Manager Scripts can be triggered via Command Line arguments, this way, it can be included in CI systems (we use it in-house, where we integrated CODESYS into the Jenkins build server using both Script Engine (for build tasks) and the Test Manager (for automated test execution).

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

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


Top
   
 Post subject: Re: External Debugger
PostPosted: Thu Sep 03, 2015 7:03 am 
Offline
Frequent User
Frequent User
User avatar

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

there's some additional information about the test manager in the store:
http://store.codesys.com/codesys-test-manager.html

You can also use a free trial license to try it out before buying (but you'll need a dongle even for the trial license).

HTH,
Markus

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

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


Top
   
Display posts from previous:  Sort by  
Post new topic  Reply to topic  [ 12 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