On my i386 PC you need to reverse the "address" and "is_command" values to shift the 1 to the far left.
It's easy enough to make up a union to output what you want. It should be easy to convert any structure to a byte array but I don't know how to do that. But try this:
from ctypes import *
class myPacketHeader(Structure):
_pack_ = 1
_fields_ = [("seqnum", c_ubyte, 8),
("address", c_uint, 31),
("is_command", c_uint, 1),
("length", c_ubyte, 8)]
class myUnion(Union):
_pack_ = 1
_fields_ = [("header", myPacketHeader),
("bytes", c_uint8 * 6)]
hdr = myPacketHeader()
hdr.seqnum = 255
hdr.is_command = 1
hdr.address = 0x1234
hdr.length = 54
print "Size of hdr is: %d" % sizeof(hdr)
hun = myUnion(hdr)
["0x%02x" % x for x in hun.bytes]
To produce ['0xff', '0x34', '0x12', '0x00', '0x80', '0x36']