python的结构体多层_如何在Python中使用C/C++结构体等复杂类型

C封装了一个Dll,名为SpjMatlabTest.dll,暴露实现:

typedef struct{

double *Min;

double *Max;

} ST_TESTLIMIT;

typedef struct{

int NumVDIVs;

int NumPts;

double *TestedVDIVs; // Pointer to first element in array that is 1xNumVDIVs long.

double *TestPtsinFracFS; // Pointer to first element in array that is 1xNumPts long.

double *VerrinFracFS; // Pointer to first element in array that is NumVDIVs*NumPts*NumChans long.

double DCAcc;

double OffConstAcc;

double *GainErrorPct; // Pointer to first element in array of NumVDIVs*NumChans long.

double *OffsetErrorFracFS; // Pointer to first element in array of NumVDIVs*NumChans long.

double *MaxNonLinearityFracFS; // Pointer to first element in array of NumVDIVs*NumChans long.

double GainErrorLimitPctAbs;

double TDIV;

} ST_LINACCD1M;

#include #ifndef BUILD_DLL

//Define the function prototypes to be used by the calling application.

typedef bool (__cdecl *MATLABAPPINITIALIZE)(void);

typedef bool (__cdecl *MATLABAPPTERMINATE)(void);

typedef bool (__cdecl *LINACCD1M)(ST_LINACCD1M *stOutput, const bool *Channels, const char *ScopeAddress, const int GPIBAddress);

typedef void (__cdecl *LINACCD1MCLEANUP)(void);

#endif

现在需要在py代码中使用ST_LINACCD1M结构体。

测试代码:

from ctypes import *

class C_ST_LINACCD1M(Structure):

_fields_ = [('NumVDIVs', c_int),

('NumPts', c_int),

('TestedVDIVs', c_void_p),

('TestPtsinFracFS', c_void_p),

('VerrinFracFS', c_void_p),

('DCAcc', c_double),

('OffConstAcc', c_double),

('GainErrorPct', c_void_p),

('OffsetErrorFracFS', c_void_p),

('MaxNonLinearityFracFS', c_void_p),

('GainErrorLimitPctAbs', c_double),

('TDIV', c_double)]

import sys

def visit():

info = C_ST_LINACCD1M()

#print info.sth...

dllName = "SpjMatlabTest.dll"

dllload = windll.LoadLibrary(dllName)

print dllload

py_LINACCD1M = dllload.LINACCD1M

py_LINACCD1M.argtypes = [c_void_p, c_void_p, c_char_p, c_int]

#.restypep = c_void_p

para_in_1 = True

para_in_2 = c_char_p("/0")

para_in_3 = 0

nRetVal = dllload.LINACCD1M(byref(info), para_in_1, para_in_2, para_in_3)

#print info.sth...

if __name__ == "__main__":

visit()

打完收工。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值