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 Mon Sep 23, 2019 8:41 am

All times are UTC+01:00




Post new topic  Reply to topic  [ 5 posts ] 
Author Message
PostPosted: Wed Oct 30, 2013 12:52 pm 
Offline

Joined: Thu Sep 12, 2013 9:54 am
Posts: 12
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,

Code:
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!


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


Top
   
PostPosted: Wed Oct 30, 2013 1:20 pm 
Offline
Frequent User
Frequent User
User avatar

Joined: Fri Mar 18, 2011 4:12 pm
Posts: 266
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.

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

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


Top
   
PostPosted: Wed Oct 30, 2013 1:39 pm 
Offline

Joined: Thu Sep 12, 2013 9:54 am
Posts: 12
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?


Top
   
PostPosted: Wed Oct 30, 2013 2:15 pm 
Offline
Frequent User
Frequent User
User avatar

Joined: Fri Mar 18, 2011 4:12 pm
Posts: 266
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:
  • Generate interop assemblies for the DLL, and load those via the Python script.
  • Use Labview directly (or CPython and the generated DLL) to generate a reference table containing the input and output values (e. G. CSV or XML), and then use the IronPython script in CODESYS to read that reference table.
  • Use the reference table from above to generate IEC code which represents the test cases, and import said Code into the Test Manager for the IEC Unit Test functionality.
  • Use C++/CLI or C# and P/Invoke to generate a .NET wrapper code which can be used from IronPython via clr.AddReference().
  • Use P/Invoke from IronPython instead of cTypes.

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

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


Top
   
PostPosted: Wed Oct 30, 2013 6:44 pm 
Offline
Frequent User
Frequent User
User avatar

Joined: Fri Mar 18, 2011 4:12 pm
Posts: 266
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.

_________________
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  [ 5 posts ] 

All times are UTC+01:00


Who is online

Users browsing this forum: No registered users and 4 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