[討論] 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