gpt4 book ai didi

python - 如何在Python中将结构体传递给Linux设备节点?

转载 作者:太空宇宙 更新时间:2023-11-04 04:33:08 25 4
gpt4 key购买 nike

我的/dev/中有一个fpga设备节点。为了与其驱动程序通信,我需要使用以下 C 代码。

struct pci_cmd {
unsigned int bar_id;
unsigned int command;
void *device_addr;
void *user_addr;
};

ssize_t f = open ("/dev/de4", O_RDWR);
unsigned short val;
struct pci_cmd read_cmd = { 0, 0, 0x2, &val };
read (f, &read_cmd, sizeof(val));

我发现python中有struct class,但是os.read(fd, n)只接受两个参数。有想法在 python 中执行此操作吗?

最佳答案

如果设备节点是tty I/O,则可以使用python的termios库进行通信。引用:https://docs.python.org/2/library/termios.html

此外,您可以使用 os.popen() 或 os.system() 直接编写系统命令。

关于python - 如何在Python中将结构体传递给Linux设备节点?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45339990/

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