如何在Python中转换复杂的嵌套Ctypes联合和结构

2024-05-08 17:14:01 发布

您现在位置:Python中文网/ 问答频道 /正文

如何将其转换为在Python中使用?在

下面的代码是一个复杂的嵌套Union和Struct。 很容易错误地将其转换为Python。在

typedef struct {
    unsigned char       enable;
    unsigned short      x;
    unsigned short      y;
    unsigned char       local;
    unsigned char       em;
    unsigned char       tr;
    short               at;
    unsigned char       reserved[6];
} IRF_SPOT;


typedef union strSAVEDATA
{
    struct
    {
        uint32_t    crc;
        uint8_t     ver;
        uint8_t     id;
        uint8_t     baudrate;
        int16_t     level;
        uint16_t    span;
        uint8_t     tv;
        uint8_t     agc;
        uint8_t     invert;
        uint8_t     mirror;
        uint8_t     flip;
        uint8_t     colorbar;
        uint8_t     showinfo;
        uint8_t     indicator;
        uint8_t     unit;
        uint8_t     dhcp;
        uint8_t     color;
        uint8_t     alpha;
        uint8_t     zoom;
        uint8_t     sharp;
        uint8_t     noise;          // new
        uint16_t    nuc;
        uint32_t    ipaddr;
        uint32_t    netmask;
        uint32_t    gateway;
        uint32_t    dns;
        uint8_t     alarm1_func;    // new
        uint8_t     alarm1_cond;    // new
        uint16_t    alarm1_value;   // new
        uint8_t     alarm2_func;    // new
        uint8_t     alarm2_cond;    // new
        uint16_t    alarm2_value;   // new
        uint8_t     temp_mode;      // reserved
        uint8_t     down_filter;    // reserved
        uint8_t     show_center;
        uint8_t     show_spot;
        uint8_t     show_correction;
        uint8_t     show_isotherm;
        uint8_t     reserved1[70];      
        uint8_t     limit9;
        uint8_t     enable_high;    
        uint8_t     correction;
        uint8_t     emissivity;
        uint8_t     transmission;
        int16_t atmosphere;
        struct {
            uint8_t     enable;
            uint16_t    x;
            uint16_t    y;
            uint8_t     local;
            uint8_t     em;
            uint8_t     tr;
            int16_t at;
            uint8_t     reserved[6];
        } spot[10];
        struct {
            uint8_t     enable;
            uint32_t    seed_color;
            int16_t     top;
            int16_t     bottom;
            uint8_t     reserved[3];
        } iso[3];
    };
    char padding[512];
} IRF_SAVEDATA_T;



typedef struct 
{
    unsigned short* ir_image;   
    DWORD image_buffer_size;    
    LPBYTE lpNextData;          
    DWORD dwSize;               
    DWORD dwPosition;           
    IRF_MESSAGE_TYPE_T      msg_type;
    IRF_SAVEDATA_T          save_data;      
    unsigned int            fw_ver;         
    unsigned short PMSGTYPE;    // Primary Message Type Code
    unsigned short RCODE;       // Response Code
} IRF_IR_CAM_DATA_T;

这太复杂了。我用这个连接一个互联网摄像头,但摄像头不回复信息。请教我如何正确地转换它。在

我的Python代码:

^{pr2}$

Tags: newenableshowstructshortreservedcharuint32