C# Code Sequence particulars
Calling library functions in C# is very similar to the C/C++ example below from the Basic Demo Code Sequence. The only significant difference is the necessity to use the Marshal class when passing pointers.
using System.Runtime.InteropServices; //add to top of source code to include Marshal
For example, when getting the F_Report_Message() string value, it should be retrieved as follows:
String text;
text = Marshal.PtrToStringAnsi(FLASHPROARM_API.F_Report_Message());
Another commonly used example is reading and writing using byte arrays, i.e. using functions F_Read_Bytes_Block() and F_Write_Bytes_Block_to_RAM()
int response;
const Int32 size = 64;
Int32 addr;
byte []data_block = new byte[size];
IntPtr data_block_ptr = Marshal.AllocHGlobal(Marshal.SizeOf(data_block[0]) * data_block.Length);
addr = mcu.x.RAMStartAddr;//or use custom address
for(k=0; k<size; k++)
data_block[k] = (byte)(0x30 + k);
try
{
Marshal.Copy(data_block, 0, data_block_ptr, size);
unsafe
{
//----------------------------------------------------
response = FLASHPROARM_API.F_Write_Bytes_Block_to_RAM(addr, size, (byte*)data_block_ptr);
//----------------------------------------------------
}
}
finally
{
Marshal.FreeHGlobal(data_block_ptr);
}
Basic code example is compatible with C#, and can be found here: C/C++ Basic Demo Code Sequence