[讨论] ctypes POINTER

楼主: waynezen (Wayne)   2016-02-23 22:32:28
原始码:
==============================================================
from ctypes import*
class TParamStruct(Structure):
_fields_= [('CSFlag',c_int),
('Price',c_int),
('Limit',c_int),
('TigValue',c_int),
('ShutFlag',c_int),
('Limit',c_int),
('ShutTime1',c_int),
('ShutTime2',c_int),
('ShutTime3',c_int),
('Alarm',c_int),
('WorkFlag',c_int),
('TickMoney',c_int),
('ReMoney',c_int),
('MeterID',c_int),
('JDQ',c_int)]
class TCardDataStruct(Structure):
_fields_= [('CardKind',c_int),
('AreaCode',c_int),
('iParamStruct',POINTER(TParamStruct))]
CardDataStruct = TCardDataStruct()
dll = windll.LoadLibrary("xtdll_tw_mw.dll")
PortId = 0
result = dll.xtRead(PortId,byref(CardDataStruct))
print CardDataStruct.AreaCode
print CardDataStruct.iParamStruct.CSFlag
==============================================================
回应:
25381111
print CardDataStruct.iParamStruct.CSFlag
AttributeError: 'LP_TParamStruct' object has no attribute 'CSFlag'
==============================================================
第一条有读出来但是用POINTER指向CSFlag就不行了,有确认过DLL档内有这条参数
我是参考:http://blog.csdn.net/magictong/article/details/3075478
感谢!!
作者: darkgerm (黑骏)   2016-02-23 22:46:00
CardDataStruct.iParamStruct[0].CSFlag或是 CardDataStruct.iParamStruct.contents.CSFlag
作者: umaga76 (U76)   2016-02-23 23:21:00
谢…但是出来的值print不出来??
作者: blueleo (静下心来练字m)   2016-03-01 15:14:00
把 pointer(TParamStruct)的pointer 拿掉即可

Links booklink

Contact Us: admin [ a t ] ucptt.com