gpt4 book ai didi

python - 如何编写使用其他 C 程序的父程序?

转载 作者:行者123 更新时间:2023-11-30 20:53:00 26 4
gpt4 key购买 nike

我正在制作一个 CAN 总线网络,该网络将调查一些传感器来收集数据,以便更好地了解我们想要分析和控制的环境。为此,我们使用 candump 来监控流量,并可以向 sen 发送信息(来自可以在此地址中找到的 CAN-BUS 文件: https://github.com/linux-can/can-utils.git )。我修改了一些代码并且它们编译得很好,现在我想做的是制作一个可以编排这个C程序的父代码以控制环境。我想使用 python 或 c++ 来执行此操作。

示例算法

while(sys == on){

if (everything is in place && security) then
{candump -l -t -n nb_of_max_cycle can0}
else { puts("error")}

if (user_id == permited_id && authentification) then
{ cansend can0 tram=[hexID_arbitration+data] }
else { puts("denied") }

}

预先感谢所有类型的建议。

我尝试使用 IDE,但无法编译任何内容,因为使用的 makefile 是专门为具有 CANBUS iso 标准的 CAN 程序制作的。

我想使用 c 函数调用并放置或获取基本信息,就像我在使用此代码的终端上一样。

最佳答案

您可以使用std::system来运行其他程序。

类似于:

if (std::system("candump -l -t -n nb_of_max_cycle can0") != 0) {
puts("error");
}

总的来说,这是一种糟糕的完成工作的方式。如果您想对此执行任何操作,则需要将这些较低级别程序的输出 (candump more_params >output.txt) 重定向到文件。如果您只想要简单的东西可能就足够了。

更好的方法是为这些东西提供适当的接口(interface)并将它们链接到您的二进制文件中。查看 candumpcansend 实现了什么并调用类似的函数。这应该可以让您更好地控制系统的整体工作方式。

关于python - 如何编写使用其他 C 程序的父程序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54365522/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com