It is a waste of valuable processor embedded time to generate and transfer XML files. Instead, I would just use an array of binary bytes representing the data, but I would use structures to help interpret the data. The C # struct function makes it easy to interpret an array of bytes as meaningful data. Here is an example:
[StructLayout(LayoutKind.Sequential, Pack = 1)] public struct DeviceStatus { public UInt16 position;
Then you will have a function that converts your byte array into this structure:
public unsafe DeviceStatus getStatus() { byte[] dataFromDevice = fetchStatusFromDevice(); fixed (byte* pointer = dataFromDevice) { return *(DeviceStatus*)pointer; } }
Compared to XML, this method will save processor time on the device and on the PC, and it is easier to maintain than the XML scheme, with additional functions for building and analyzing the XML file. All you have to do is make sure that the definitions of struct and enum in your embedded device match those of your C # code so that the program and C # device agree on the protocol used.
You will probably want to use the βpackedβ attribute in both C # and the built-in side, so that all elements of the structure are arranged in a predictable way.
source share