Welcome to our new forum
All users of the legacy CODESYS Forums, please create a new account at account.codesys.com. But make sure to use the same E-Mail address as in the old Forum. Then your posts will be matched. Close

Codesys Crash with Python

labview
2013-10-30
2013-10-30
  • labview - 2013-10-30

    Hi there,

    Hi there,

    I am running ctypes command in Test Manager which is calling external DLL, and it crashes! I have no idea why?

    I have attached the Crash screenshot for your reference.

    In addition, there is no issue for Python 2.7 and 3.3

    Kindly refer to the part of the python code as below,

    import ctypes
    import time, sys
    DLLHANDLE=ctypes.cdll.LoadLibrary("C:\\INSTRDLL\\builds\\DCSOURCEDLL\\B2902A.dll")
    INPUTSCRIPT="SYSTEM{DCSOURCE1|INIT}"
    INPUTVOLTAGE=0.0
    c_INPUTSCRIPT=ctypes.c_char_p(INPUTSCRIPT)
    c_INPUTVOLTAGE=ctypes.c_double(INPUTVOLTAGE)
    SOURCEHANDLE=DLLHANDLE.DCSOURCE(c_INPUTSCRIPT,c_INPUTVOLTAGE)
    time.sleep(1)
    

    Basically, The DLL is calling instrument to perform initialization once INPUTSCRIPT is issued.

    I have attached the Crash screenshot and another screenshot with no crash using Python 2.7 after executed full script. Please help...

    Please advise!

    IMG: Python_2.7.jpg

    IMG: IpyCrash.jpg

     
  • Anonymous - 2013-10-30

    Originally created by: M.Schaber

    Hi, Labview,

    As this issue seems to also happen with pure IronPython (the screenshot mentions the ipy.exe), it is not related to CODESYS.

    Maybe there is a bug in the cTypes implementation of IronPython, or maybe the signature for the call is slightly wrong, and cPython just tolerates the mismatch due to some implementation details, while .NET does not tolerate the problem.

    I don't know whether LabView provides debugging assistance for those cases (headers, debug symbols etc.), but I guess that you will need to debug deeper to solve the problem. You will need Visual Studio, the IronPython source code, and the debug symbols, so you can get more details of the crash.

    Without access to the B2902A.dll and as much debug material (headers, symobols etc.) as possible, noone will be able to help you.

     
  • labview - 2013-10-30

    Hi M.Schaber,

    I can share B2902A.dll file if you want.

    Meantime, there is no issue on Python 2.7 and 3.3 so it is very hard to convince as customers/users stand point

    My next question is Test Manager has been tested using cPython before released to market?

    Anyway, do you have any workaround solution?

     
  • Anonymous - 2013-10-30

    Originally created by: M.Schaber

    Hi, Labview,

    IronPython is a different product than CPython which just tries to implement the same language. IronPython is a complete re-implementation of the Python core in C# with a completely different internal architecture, using the Dynamic Language Runtime of the .NET Framework, while the original CPython is a Bytecode Interpreter implemented in C.

    The Jython follows a similar goal with a pure Java implementation of Python. See Why Are There So Many Pythons? for an explanation of (some of) the different implementations of Python.

    All the parts of the standard library which CPython implements in C were reimplemented in C# for the IronPython project (or are still missing / not supported). The cTypes module is one of them. Thus, it is naturally that it contains a different set of quirks and bugs compared to the CPython cTypes module.

    Additionally, IronPython is not as widespread as CPython, and thus not that well tested in those corner areas like cTypes.

    CODESYS and the CODESYS Test Manager include IronPython, because the CODESYS V3 IDE is implemented in .NET, and IronPython naturally fits there. It is not easily possible to just replace IronPython by CPython in CODESYS, because the internal structures of the interpreter are completely different. CPython code cannot call into .NET objects, thus it would be impossible to call into any CODESYS function, rendering it completely useless for that purpose.

    We did investigate alternatives, like the Python for .NET project which aims to provide a bridge between CPython and .NET, but this project seems to be unmaintained since 2007, and thus is not suitable base for a script engine for CODESYS.

    As for the workaround solutions, I think I did already mention most of them via E-Mail, including:

     
  • Anonymous - 2013-10-30

    Originally created by: M.Schaber

    Hi,

    I did post an example python script in the store products part of this forum (which is appropriate for the Test Manager):
    http://forum.codesys.com/viewtopic.php?f=20&t=5480

    This example script shows how to generate a PLCOpenXML for a function block which implements the IEC Unit Test interface.

     

Log in to post a comment.