启动- SCL Simulator for IEC61850

来源:互联网 发布:淘宝外卖会员卡好用吗 编辑:程序博客网 时间:2024/05/18 03:19

- v0.0.1

  a 支持 Ironpython 脚本,嵌入

  b .net界面


2013.05.23  - start to wrap iec 61850 stack using ctypes, just for quick start.

-  Use Ctypes , if you want to wrap pure C code very easily.-  Use Boost.Python , if you want to create a more complete API for C++ that also reects the object oriented nature of your native code, including inheritance into Python, etc.
-  Use cython, if you want to easily speed up and migrate code from Python to speedier native code (Mixing is possible!).-  Use SWIG, if you want to wrap your code against several dynamic languages

---------

ironpython +.net + c/c++.dll will be very cool for your unit test, automatic test, functional acceptance test..

========  notes:  in .net with ironpython to excute python script which inject your dll c function

1.  C# need add reference : /r:IronPython.dll /r:Microsoft.Scripting.dll

2. test1 :

def welcome(name):
return "Hello '" + name + "' from IronPython"

 static void Main(string[] args)

        {          
            ScriptScope helloworld = Python.CreateRuntime().UseFile("D:\\Project\\script\\hello.py");
            var welcome = helloworld.GetVariable("welcome");
            Console.WriteLine(welcome("abc"));
            Console.ReadLine();
        }


3: errors “name 'ctypes' is not defined”  -> to solve

change  "from ctypes import *"  to  "   import ctypes "  in python script

--dll.c to compile  dll.dll

1.=====

#include <math.h>

#ifdef __cplusplus
extern "C" {
#endif

__declspec(dllexport) double testsin(double x)
{
         return sin(x);
}

#ifdef __cplusplus
}
#endif

2.==python script  file : dll.py

import ctypes
dll = ctypes.CDLL('D:\\Project\\TestSuit\\Debug\\testdll.dll')
dll.testsin.argtypes = [ctypes.c_double]
dll.testsin.restype = ctypes.c_double
print(dll.testsin(34))
MessageBox = ctypes.windll.user32.MessageBoxW
MessageBox(None, u"Hello World", u"Hi", 0)

3.==.net main function

     static void Main(string[] args)
        {
            var engine = Python.CreateEngine();
            string dir = "D:\\Project\\script\\";
            List<string> searchPaths = new List<string>(engine.GetSearchPaths());          
            if (!String.IsNullOrEmpty(dir))
            {
                searchPaths.Add("D:\\Project\\script\\");
            }
            else
            {
                searchPaths.Add(Environment.CurrentDirectory);
            }

            searchPaths.Add(Environment.CurrentDirectory);
            searchPaths.Add("C:\\Program Files\\IronPython 2.7");
            searchPaths.Add("C:\\Program Files\\IronPython 2.7\\Lib");         
            engine.SetSearchPaths(searchPaths);

            var script = engine.CreateScriptSourceFromFile("D:\\Project\\script\\dll.py");
                   
            CompiledCode code = script.Compile();
            ScriptScope scope = engine.CreateScope();
            code.Execute(scope);
        }


原创粉丝点击