【发布时间】:2021-10-08 18:37:24
【问题描述】:
我想使用在 esp-32 板上完美运行的 micropython 运行我的 C++ 程序。现在我想使用 micropython 运行它。为此我指的是
https://github.com/stinos/micropython-wrap这个包装器。
我创建了 foo.cpp 和 test.py
#include <micropython-wrap-master/functionwrapper.h>
//function we want to call from within a MicroPython script
std::vector< std::string > FunctionToBeCalled ( std::vector< std::string > vec )
{
for( auto& v : vec )
v += "TRANSFORM";
return vec;
}
//function names are declared in structs
struct CppFunction
{
func_name_def( TransformList )
};
extern "C"
{
void RegisterMyModule(void)
{
//register a module named 'foo'
auto mod = upywrap::CreateModule( "foo" );
//register our function with the name 'TransformList'
//conversion of a MicroPython list of strings is done automatically
upywrap::FunctionWrapper wrapfunc( mod );
wrapfunc.Def< CppFunction::TransformList >( FunctionToBeCalled );
}
}
test.py
import foo
print(foo.TransformList(['a', 'b'])) # Prints ['aTRANSFORM', 'bTRANSFORM']
但无论我尝试什么方法都会得到
ERROR thonny.plugins.micropython.backend: Problem adding Expr handlers
Traceback (most recent call last):
File "/Applications/Thonny.app/Contents/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/thonny/plugins/micropython/backend.py", line 1235, in _add_expression_statement_handlers
root = ast.parse(source)
File "/Applications/Thonny.app/Contents/Frameworks/Python.framework/Versions/3.9/lib/python3.9/ast.py", line 50, in parse
return compile(source, filename, mode, flags,
File "<unknown>", line 1
python test1.py
^
SyntaxError: invalid syntax
Traceback (most recent call last):
File "<stdin>", line 1
SyntaxError: invalid syntax
据我所知,在我可以运行 cpp 程序之前,我需要运行 makefile。但是没有可用的步骤可以解释我如何在 esp-32 上使用 micropython 构建 makefile
任何帮助表示赞赏
【问题讨论】:
标签: c++ esp32 micropython