2017-02-27 15 views
1

我想實現一個python接口。我對c結構的定義有問題。如何在主結構中生成內部結構(LinV)?python:c結構和wintypes

從曼努埃爾定義:

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', ???????)] 

THX 馬庫斯

回答

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