這是一個後續問題要my question,這是沒有答案
修改,然後從我的模塊組織訪問字節
:
class t_data_block(Structure):
_fields_ = [("current_readings",c_ulong * PORTS_NUM),
("power_reading",c_ulong)]
class t_sys_flags(Structure):
"System flags"
_fields_ = [("Alarm1",c_ulong,1),
("Alarm2",c_ulong,1),
("reserved",c_ulong,30)]
class t_input_buff(Structure):
"Input buffer from the board"
_fields_ = [("header",c_ulong),
("sys_flags", t_sys_flags),# t_sys_flags is another structure
("data_block", t_data_block * CHIP_NUM)] # t_data_block is another structure
我需要遍歷buff中的每個字節,我試過以下內容:
from pc_memory import*
def calc_formula(buff,len):
sum = 0
for curChar in buff:
numericByteValue = ord(curChar)
sum += numericByteValue
return sum
def main:
input_buff = t_input_buff()
calc_formula(input_buff,len)
,我也得到了時命令
我也嘗試使用str(buff)
沒有運氣
任何建議執行「錯誤:‘t_input_buff’對象不是可迭代:類型錯誤」?
請,也給介紹「data_block」結構,所以我可以幫助 –
我更新我的問題與data_block和sys_flags結構定義 –