Main Site Documentation

How to use I2C effeciently on my FEZ spider


#1

I have a FEZ Spider which I recently purchased to for a dedicated one off application. This involves capturing a substantial quantity of analogue data, processing it, and displaying the results in graphical form to the user in near real time.

The data capture is handled by a dedicated processor connected to the FEZ spider via I2C. When sent the data consists of a stream with the following structure:-


typedef struct {
  unsigned char status1;        //1
  unsigned char status2;        //1
  short   adc[5];                     //10
  int      time_stamp;   //4
} RT_INPUT_SET_t;

I hope to send several hundred at a time and I want to efficiently format them so that they can be quickly processed. The issue I have is that on input the IC2 data is a byte array and I would like to overlay my structure in the way of a C union. In the full C# this can be done using System.Runtime.InteropServices.StructLayout(LayoutKind.Explicit but under the micro framework FieldOffset is not implemented.

Surely there must be a quicker way than copying the incoming data byte by byte into a new structure?

[italic]
For the record I am an experienced real time programmer but this was gained many many years ago.
[/italic]


#2

If it actually came to it, you could always build some support into your Hydra firmware for converting from the byte[] to the struct, since it’s all open source.


#3

What you want is Microsoft.SPOT.Reflection.Deserialize().