Getting a data structure

Michael Peuser mpeuser at web.de
Thu Aug 14 02:50:39 EDT 2003


"Mike solem" <msolem at firstlinux.net> schrieb im Newsbeitrag
news:1103_1060820563 at news-server.optonline.net...
>
> I need to pass a data structures from a C program, to a python program
over RS232.
> I'm not quite sure how to recreate a data structure from a string of
serial data.
> In C I would do it like this:



(1) What do you mean by "data structure" in Python?
(2) Are you fully aware of the binary/marshalled/encoded format of the RS232
string?
(3) Don't forget  plausibilibility checks!

Depending on (2) - you might find hints in the std lib module struct - you
will probably have to decode it item by item. This is very straightforward.
I am not aware of any trick that could simplify it.

Kindly
Michael P

P.S.: The C-example is no good ;-)
>
> ---------------------- This compiles under gcc ----------
> #include <stdio.h>
>
> typedef struct{
>     int  a;
>     char b;
> }myStruct;
>
> int main()
> {
>     char data[]= {1,2,3,4,5,6,7,8,9};
>     myStruct* s1;
>
>     s1 = (myStruct*)&data;
>     printf("%x %d\n", s1->a, s1->b);
>     return 0;
> }
> --------------------------------------------
>
> The 'data' array above would be a buffer which receives data from the
serial link.
> So the questions are, what type of python data stucture to use, and how to
> initialize it from the buffer.
> The struct I'm using is a lot more complex than the one I used here.  It's
built up of a couple
> of other structs.
>
> Thanks
> Mike
>
>
>
>
>






More information about the Python-list mailing list