python ctype recursive structures

You almost certainly want to declare next_command as a pointer. Having a structure that contains itself isn’t possible (in any language).

I think this is what you want:

class EthercatDatagram(Structure):
    pass
EthercatDatagram._fields_ = [
    ("header", EthercatDatagramHeader),
    ("packet_data_length", c_int),
    ("packet_data", c_char_p),
    ("work_count", c_ushort),
    ("next_command", POINTER(EthercatDatagram))]

Leave a Comment