title: making a ctypes structure iterable
body: <p>Hi just need some guidance with python as I am still a noob, I converted the following snippet of C source code to python.</p>
  
  <p>C snippet:</p>
  
  <pre><code>Typedef struct packet_s {
  union {
    uint16_t fcf;
    struct {
      uint16_t type:3;
      uint16_t security:1;
      uint16_t framePending:1;
      uint16_t ack:1;
      uint16_t ipan:1;
      uint16_t reserved:3;
      uint16_t destAddrMode:2;
      uint16_t version:2;
      uint16_t srcAddrMode:2;
    } fcf_s;
  };
  
  uint8_t seq;
  uint16_t pan;
  locoAddress_t destAddress;
  locoAddress_t sourceAddress;
  
  uint8_t payload[128];
  } __attribute__((packed)) packet_t;
  </code></pre>
  
  <p>python:</p>
  
  <pre><code>class fcf_s(Structure):
      _fields_ = [
          ("type", c_uint, 3),
          ("security", c_uint, 1),
          ("framePending", c_uint, 1),
          ("ack", c_uint, 1),
          ("ipan", c_uint, 1),
          ("reserved", c_uint, 3),
          ("destAddrMode", c_uint, 2),
          ("version", c_uint, 2),
          ("srcAddrMode", c_uint, 2)
          ]
  
   class fcf_union(Union):
      _fields_ = [
         ("fcf", c_uint),
         ("fcf_s", fcf_s)
         ]
  
   class packet_s(Structure):
      _fields_ = [
         ("fcf_union", fcf_union),
         ("seq", c_uint),
         ("pan", c_uint),
         ("destAddress", c_uint64 * 8),
         ("sourceAddress", c_uint64 * 8),
         ("payload", c_uint * 128)
         ]
  </code></pre>
  
  <p>edit 1: The Function used to convert to bytes</p>
  
  <pre><code>def writeValueToBytes(data, val, n):
  """
  This function writes the value specified and convert it into bytes to 
   write in the array
  
  Args:
          data: The array you want to write the value into.
          val: The value you want to write in the array.
          n: The size of the array.
  
  Return:
          The modified array of bytes.
  """
  for i in range(0, n):
      data[i] = int(((val &gt;&gt; (i * 8)) &amp; C.MASK_LS_BYTE))
  return data
  </code></pre>
  
  <p>once the packet_s structure has been populated with the correct data, I need to pass it to function with splits it into bytes to be written via spi to the DWM1000 UWB radio.</p>
  
  <p>The type error I get is " TypeError: packet_s is not iterable", how do I fix this ?</p>
  
  <p>Thanks in advance.</p>