我试图在Python中编写结构(不要在线获取更多信息),这是在一个.py文件中定义的。我需要导入.py并获取结构信息并进行逻辑检查。
现有的C结构如下:
typedef struct
{
U16 ID;
S8 Name[32];
S8 Description[96];
S8 Units[16];
enum eType Type;
F32 Scaling;
F32 Offset;
BOOL Writeable;
}sDataInfo;
/* ID's, Name, Description, Unit, Type, Scaling, Offset, Writable */
sDataInfo data_items[] =
{
0x0202, "dtc_num_of_faults_", "Number of DTCs", "", u8, 1, 0, FALSE,
0x2007, "FlBodyVertLocSel_A_Meas_", "FL Vertical Acceleration", "m/s^2", s16, 0.05, 0, FALSE,
0x2008, "FrBodyVertLocSel_A_Meas_", "FR Vertical Acceleration", "m/s^2", s16, 0.05, 0, FALSE,
0x2022, "RlBodyVertLocSel_A_Meas_", "RL Vertical Acceleration","m/s^2", s16, 0.05, 0, FALSE
}
这是在python中定义结构的最佳方法,它将通过示例代码帮助完整一些更明确的答案。