如何将C API集成在机器人框架中
How to integrate C++ APIs in Robot framework?
我已经为我的项目开发了C API。还创建了一个Linux .SO共享库。我需要使用机器人框架关键字来调用这些API。
预先感谢。
c apis可以使用python库 ctypes 轻松地调用。您可能已经知道,Python库可以集成到机器人框架中。
假设您必须使用机器人框架调用SendMesg C API。请遵循以下步骤:
1。创建C API库.SO文件
connect.cpp
extern "C"
{
int Initialize(char* ip, int port)
{
//creates socket connection with remote host
}
int SendMesg(char* msg)
{
//Send mesg code
}
}
g++ -std=c++11 -fpic -c connect.cpp
g++ -std=c++11 -shared -g -o connect.so connect.o
现在您已经创建了Connect.SO共享库在与CPP文件相同的路径中。
2。为C APIS创建Python包装器
connectWrapper.py
import ctypes
class connectWrapper:
def __init__(self, ip , port):
self.Lib = ctypes.cdll.LoadLibrary('absolute path to connect.so')
self.Lib.Initialize.argtypes = [ctypes.c_char_p, ctypes.c_int]
self.Lib.Initialize(ip, port)
def SendMessageWrapper(self, msg):
self.Lib.SendMesg.argtypes = [ctypes.c_char_p]
print self.Lib.SendMesg(msg)
创建Python包装器API时要记住的4件事。
a)python文件名与类名称相同
b)使用CTYPE调用API时,您应始终指定输入参数类型。否则,使用此Python库运行机器人文件时,您可能会遇到以下错误:
notimplemplementError:尚不支持的variadic函数;指定参数列表
在这种情况下,我们将参数指定为ctypes.c_char_p,用于字符串类型和ctypes.c_int作为整数。有关更多信息,您可以使用:
:[http://python.net/crew/theller/ctypes/tutorial.html#specifying-the-the-preired-required-argument-types-function-protypes] [1]
c)在ctypes.cdll.LoadLibrary
API中给出了connect.so
的绝对路径。
d)通过使用chmod +x connectWrapper.py
3。将python库添加到机器人文件
test.robot.txt
** * Settings * **
Library "absoulte path to connectWrapper.py" 10.250.0.1 8080
** * Test Cases * **
Send Message
SendMessageWrapper "Hello World"
您可能会注意到,在"设置"部分中添加了Python库,其中的参数以IP和端口为单位。我们已经在测试用例部分中添加了SendMessage关键字,并带有字符串消息" Hello World"。作为输入参数。
我希望运行命令后:
robot test.robot.txt
一切正常:)
- 在没有Xcode的情况下在Mac捆绑包中嵌入框架
- catch框架有没有办法比较流或文件
- 如何将不同的可执行文件合并到一个窗口框架中进行编码?像浏览器一样
- 使用Qt框架在c ++类中创建API调用
- 如何在ECS框架中更新组件数据和通知系统
- VSCode IntelliSense无法识别SDL框架的SDL_image扩展库
- 用于C++的静态二进制检测或二进制重写工具和框架
- GoogleMock是否仍然打算与任何测试框架一起使用?
- 带有框架的 QGraphicsTextItem 的 QPropertyAnimation 会使文本抖动
- 在C++中使用 Catch 测试框架编译错误"error: expected ';' at end of declaration list"
- 通过 Gazebo 世界插件将静态对象附加到机器人链接
- 我正在尝试制作一个自平衡机器人,但编译时存在错误。我不知道如何解决它
- 修改生成文件以简化框架 #include 路径
- 无敌框架并受到伤害等级
- 如何在提升构建中设置环境变量以进行提升单元测试框架?
- 使用 gtest 框架在单元测试代码中检查目标对象的私有变量的最佳实践是什么?
- Xcode 中的加速框架以获得 A 的 QR 分解,但找不到 zgeqrf
- 是否可以在 Xcode C++项目中包含框架?
- 我的精灵使用名为 ASGE 的C++框架卡在屏幕边缘
- 如何将C API集成在机器人框架中