Getting a data structure

Mike solem msolem at firstlinux.net
Wed Aug 13 20:23:14 EDT 2003


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:

---------------------- 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