DIAdem

cancel
Showing results for 
Search instead for 
Did you mean: 

Debugging Python Scripts in Diadem 2020

Is there a way to debug a python script file similar to the VBS debuging in Diadem 2020 SP1?

I am able to run the scripts, but the debuging is all "greyed out". Do i need to use the external debug function?

0 Kudos
Message 1 of 10
(4,032 Views)

Hi dm999,

 

Yes, for python debugging in DIAdem, R&D has decided not to try to rebuild all the features of PyCharm or Visual Studio Code and instead try to make it as easy as possible to debug externally to DIAdem.  In DIAdem 2020 the integration still involves a number of manual steps to set up properly, but that will get progressively more automatic and easy in subsequent DIAdem versions.

 

Brad Turpin

Principal Technical Support Engineer

NI

0 Kudos
Message 2 of 10
(3,930 Views)

Hi Brad,

thanks for your response. Can you explain me how to debug externally to diadem, apart from copying everything to Pycharm ;).? Is there any documentation available how to do this steps in Diadem 2020.

0 Kudos
Message 3 of 10
(3,925 Views)

Hi Brad,

 

Is there any documentation about external debugging?

Is there a way integrate an external tool to debug python scripts through diadem interface?

 

Best regards,

Kerem

0 Kudos
Message 4 of 10
(3,627 Views)

Hi Kerem,

 

External python debugging in DIAdem is progressing in small steps with each version, so the answer to this question depends quite strongly on what DIAdem version you are using right now.  R&D is prioritizing external debugging support with Visual Studio Code, because the debugging functionality there is free.  In DIAdem 2020 you had to have a "caller" script that programmatically reloaded your to-debug script.  In all DIAdem versions you need to declare the debugging module "debugpy", which in DIAdem 2021 shows up in the automatic header of any new python script you create in the SCRIPT panel.  You then use the debugpy object to configure the just-in-time connection, execute the "listen(5678)" command (on port 5678), then "wait_for_client()" for the just-in-time response.  There's also a step in Visual Studio Code to receive the just-in-time debugging request in DIAdem, once you've started the debugging of the script in DIAdem SCRIPT.

 

There are further incremental improvements to external debugging coming in the DIAdem 2021 SP1 release due out later this year, but external editing is never going to be a cleanly integrated with DIAdem as the VBScript debugger is in the SCRIPT panel.  The good news is that once the debugging connection is achieved, the debugging tools in Visual Studio Code are superior to those in DIAdem for VBScripts.

 

Brad Turpin

Principal Technical Support Engineer

NI

0 Kudos
Message 5 of 10
(3,609 Views)

Hi All,

 

Here is an example that works with DIAdem 2020, using python 3.7.  It is invoking the ptvsd module instead of the debugpy module.

 

Make sure you end each debugging session in VSC by selecting the "Continue" debug mode to finish the script.  If you keep selecting "Next step" all the way to the end, it will spoil the connection, and you'll need to restart DIAdem and try again.

 

Brad Turpin

Principal Technical Support Engineer

NI

0 Kudos
Message 6 of 10
(3,602 Views)

Hi Brad,

 

Thank you for your answer. I will try to write my python code a on Spyder IDE nd implement it on Diadem Script. I will do my debugging on Spyder IDE. 

I could not import ptvsd module that was given in example.

import ptvsd

 Unfortunately I am unfamiliar with Visual Studio. I will try to find a way to implement python code that is written on a different software. It would make things very easy for me if I utilize python scripting opportunity of Diadem. This will enhance my data process ability on Diadem.

 

I use Diadem Professional 2020 edition

Apart from debugging issue, how can I see what python modules I have? Numpy, pandas, matplotlib, keras, tensorflow? Or is there a way to add new modules to Diadem python library? If so, how? 

These has already been too many questions 🙂 thanks for your attention.

0 Kudos
Message 7 of 10
(3,566 Views)

Hi All,

 

Here are the instructions from the DIAdem 2021 Help, which unfortunately are not yet available online.  The part where you have to load the folder into VSC that the python script is in will also be required when trying this in DIAdem 2020 (forgot to mention that).

 

Brad

0 Kudos
Message 8 of 10
(3,578 Views)

Hi, thank you for your answer.

 

How can I see the available python modules? Does diadem 2020 have numpy and pandas modules?

0 Kudos
Message 9 of 10
(3,572 Views)

You can list the installed modules with this short script:

for modul in sys.modules:
    print(modul)

If you install new modules make sure that you do it in the correct folder. The DIAdem standard installation of python can be found here:

C:\Program Files\National Instruments\Shared\Skyline\Python\3.8
If you use a user defined installation you have to install it in that folder. You can enter the path of a user defined installtion in the settings dialog of SCRIPT.

Hope this helps.

Winfried

0 Kudos
Message 10 of 10
(3,559 Views)