python:c-struct和wintypes

时间:2017-02-27 15:51:06

标签: python c struct

我试图实现python接口。我对c结构的定义有疑问。如何在main-struct中生成内部结构(LinV)?

manuel的定义:

ListView3.Items[i].Controls.Add(img);

python代码:

typedef struct
{
float MaxExcitation;

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

THX 马库斯

1 个答案:

答案 0 :(得分:0)

您只需乘以指定数组:

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),
))