Hello all. I'm having a bit of trouble trying to figure out how to access data I input into a ctypes array object. This is used with a hardware SDK, so I can't really change the data format at all. Here's the code:
from ctypes import *
MsgDataType = c_uint8 * 8
msg = MsgDataType()
msg[0] = 1
msg[1] = 2
msg[2] = 3
msg[3] = 4
msg[4] = 5
msg[5] = 6
msg[6] = 7
msg[7] = 8
So basically what I would like is to type for example "msg[0]" and get out 1 as the value, but what I'm getting only 0's instead for "msg[0]", "msg[1]", etc.
Typing "msg" outputs:
<__main__.c_ubyte_Array_8 object at 0x00F58A80>
I also tried creating a pointer via "pt = pointer(msg)" and then tried to access the value using "pt[0]" but I obtain:
<__main__.c_ubyte_Array_8 object at 0x00F58AD0>
Typing "pt" outputs:
<ctypes.LP_c_ubyte_Array_8 object at 0x00F58A80>
I've also tried typing "for i in msg: print i", for which I get the error:
Traceback (most recent call last):
File "<pyshell#55>", line 1, in <module>
for i in msg: print i
TypeError: 'function' object is not iterable
Any ideas how I can resolve this problem? I'm probably missing something very simple, but it's beyond me as a Python/C newbie. Thanks!