Has anybody done a C# wrapper for the BSL430 DLL, the DLL that controls loading of the application to the MPS430 by using its on-board BSL?
I call BSL_setFamily and BSL_setCom from C# OK which I use to set up for a USB download.
BSL_initialize_BSL is also OK. However, something that uses the DataBlock, for example, BSL_RX_Password generates exceptions in C#. I have the structure like this in C#:
[ StructLayout(LayoutKind.Sequential)] The function like this:
public unsafe struct DataBlock
{
public fixed byte data[10240];
public uint numberOfBytes;
public uint startAddr;
};
[ DllImport("BSL430.dll", EntryPoint = "BSL_RX_Password", CallingConvention = CallingConvention.Cdecl)] I have tried many combinations of the structure including various "MarshallAs" and "FieldOffset" but everything I try either gives a memory use exception (reading or writing to protected memory) or a mixed managed/unmanaged exception. Below I have given examples of two C# wrappers for DataBlock and text comments above them for the exceptions I get when using them:
private static extern byte BSL_RX_Password(DataBlock data);
// System.AccessViolationException: Attempted to read or write protected memory. [ StructLayout(LayoutKind.Sequential)] // Cannot marshal field 'data' of type 'DataBlock': Invalid managed/unmanaged type [StructLayout(LayoutKind.Explicit, Size = 10248)] [MarshalAs(UnmanagedType.U4)] [MarshalAs(UnmanagedType.U4)]
// This is often an indication that other memory is corrupt
public unsafe struct DataBlock
{
public fixed byte data[10240];
public uint numberOfBytes;
public uint startAddr;
};
// combination (this value type must be paired with Struct)
public unsafe struct DataBlock
{
[FieldOffset(0), MarshalAs(UnmanagedType.ByValArray, SizeConst=10240)]
public fixed byte data[10240];
[FieldOffset(10240)]
public uint numberOfBytes;
[FieldOffset(10244)]
public uint startAddr;
};
So, does anybody have a C# wrapper for this DLL API?