python:c-struct 和 wintypes

标签 python c struct

我正在尝试实现一个 python 接口(interface)。我对 c 结构的定义有疑问。如何在主结构中生成内部结构(LinV)?

手册中的定义:

typedef struct
{
float MaxExcitation;

struct LinVal
    {
    double MeasValue;
    double RefValue;
    } LinV[SEN_LIN_DATA_MAX];
} Data;

python 代码:

class LinV(Structure):
    _fields_ = [('NeasValue', c_double),
                ('RefValue', c_double)]


class Data(Structure):
    _fields_ = [('MaxExcitation', c_float),
                ('LinV', ???????)]

谢谢 马库斯

最佳答案

你只需乘以指定数组:

from ctypes import *

SEN_LIN_DATA_MAX = 3

class LinV(Structure):
    _fields_ = [('NeasValue', c_double),
                ('RefValue', c_double)]


class Data(Structure):
    _fields_ = [('MaxExcitation', c_float),
                ('LinV', LinV * SEN_LIN_DATA_MAX)]

d = Data(2.0,
   (LinV(1.2, 3.2),
    LinV(2.2, 2.2), 
    LinV(3.2, 1.2),
))  

关于python:c-struct 和 wintypes,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42490021/

相关文章:

c - 如何将执行命令的结果从服务器发送到客户端?

c - 指针如何在 C 上工作

c - 为什么在下面的编程中结构显示的内存比实际内存少

python - ModelCluster ParentalManyToManyField 上的左外连接?

python - 在 setup.py 中包含直接依赖下载链接

python - 使用 plot.ly Dash 在等待结果时显示加载符号

c - 从声明为 void 的函数返回整数值

python - 如何有效地对 Pandas 数据框的一行值求和

c - 读取并解码 jpg 图片

objective-c - 具有 Swift 结构的 C API - 作为 inout 参数的不可变值