DIAdem

cancel
Showing results for 
Search instead for 
Did you mean: 

How to consistently connect to the external debugger( Visual Studio Code ) to debug diadem python scripts in Diadem 2023 Q2

Solved!
Go to solution

So I have been trying to use some the inbuilt of the examples to practice external debugging using Visual Studio Code. However I have been unable to get it to work consistently so far it only work once but most the time it's just fails with Visual Studio Code say it can't connect

Screenshot 2023-12-12 161547.png

 

and Diadem giving the following error see bellow:

Screenshot 2023-12-12 161525.png

 

In Visual Studio Code my json file  is as what is bellow:

{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Python: Remote Attach",
            "type": "python",
            "request": "attach",
            "connect": {
                "host": "localhost",
                "port": 5678
            },
            "pathMappings": [
                {
                    "localRoot": "${workspaceFolder}",
                    "remoteRoot": "${workspaceFolder}",
                }
            ],
            "justMyCode": true
        }
    ]
}

 

Python code :

import sys
if 'DIAdem' in sys.modules:
    from DIAdem import Application as dd

    if dd.AppEnableScriptDebugger:
        import debugpy
        debugpy.configure(python = sys.prefix + '\\python.exe')
        if not debugpy.is_client_connected():
            try:
                debugpy.listen(5678)
            except:
                pass
                debugpy.wait_for_client()
            
sPathDocuments = dd.ProgramDrv + "Examples\\Documents\\"
sPathData      = dd.ProgramDrv + "Examples\\Data\\"

dd.Data.Root.Clear()
dd.DataFileLoad(sPathData  + "Example_data.tdm", "TDM", "Load|ChnXYRelation") 

oResultChnList = dd.Data.CreateElementList()

oResultGroup = dd.Data.Root.ChannelGroups.Add("Quantize")
oResultGroup.Activate()

oSourceChn = dd.Data.GetChannel("[1]/[3]")
dMax = oSourceChn.Maximum
dMin = oSourceChn.Minimum

dResolution            = 100
sChnResultName         = oSourceChn.Name + "_Quantize_" + dd.str(dResolution, "d.")
oResultChnTempList     = dd.ChnQuantize(oSourceChn, sChnResultName, dResolution, dMin, dMax)
oResultChnList.Add(oResultChnTempList(1))

dResolution            = 2**8
sChnResultName         = oSourceChn.Name + "_Quantize_" + dd.str(dResolution, "d.")
oResultChnTempList     = dd.ChnQuantize(oSourceChn, sChnResultName, dResolution, dMin, dMax)
oResultChnList.Add(oResultChnTempList(1))

dResolution            = 2**15 - 1
sChnResultName         = oSourceChn.Name + "_Quantize_" + dd.str(dResolution, "d.")
oResultChnTempList     = dd.ChnQuantize(oSourceChn, sChnResultName, dResolution, dMin, dMax)
oResultChnList.Add(oResultChnTempList(1))

dResolution            = 2**16 - 1
sChnResultName         = oSourceChn.Name + "_Quantize_" + dd.str(dResolution, "d.")
oResultChnTempList     = dd.ChnQuantize(oSourceChn, sChnResultName, dResolution, dMin, dMax)
oResultChnList.Add(oResultChnTempList(1))

dResolution            = 2**31 - 1
sChnResultName         = oSourceChn.Name + "_Quantize_" + dd.str(dResolution, "d.")
oResultChnTempList     = dd.ChnQuantize(oSourceChn, sChnResultName, dResolution, dMin, dMax)
oResultChnList.Add(oResultChnTempList(1))

dd.CHNSUB(oSourceChn, oResultChnList(1), "Err_" + oResultChnList(1).Name)
dd.CHNSUB(oSourceChn, oResultChnList(2), "Err_" + oResultChnList(2).Name)
dd.CHNSUB(oSourceChn, oResultChnList(3), "Err_" + oResultChnList(3).Name)
dd.CHNSUB(oSourceChn, oResultChnList(4), "Err_" + oResultChnList(4).Name)
dd.CHNSUB(oSourceChn, oResultChnList(5), "Err_" + oResultChnList(5).Name)

oQChnName      = oResultGroup.Channels.Add("Quantize_ChnName", dd.DataTypeChnString)
oQChnTyp       = oResultGroup.Channels.Add("Quantize_ChnTyp", dd.DataTypeChnString)
oQChnMaxErrVal = oResultGroup.Channels.Add("Quantize_MaxErrVal", dd.DataTypeChnFloat64)

debugpy.breakpoint()
for iLoop in range(1, 6):
    oQChnName[iLoop]      = oResultGroup.Channels(iLoop + 5).Name
    oQChnMaxErrVal[iLoop] = oResultGroup.Channels(iLoop + 5).Maximum

oQChnTyp[1] = "Byte"
oQChnTyp[2] = "Byte"
oQChnTyp[3] = "Integer"
oQChnTyp[4] = "Integer"
oQChnTyp[5] = "LongInteger"

dd.Report.LoadLayout( sPathDocuments + "Channel_Quantize.TDR")
dd.Report.Refresh()

 

My Python version is 3.10 and environment was installed with Anaconda

0 Kudos
Message 1 of 2
(1,509 Views)
Solution
Accepted by topic author JamieA99

I have been able to get it to work now . i don't really know what's changed but it works so this can be closed now.

0 Kudos
Message 2 of 2
(1,448 Views)