using System; using System.Reflection; using System.Runtime.InteropServices; using System.Text; namespace PACNET { /// Memory Access API public partial class Memory { /// SRAM public const int PAC_MEM_SRAM = 0; /// EEPROM public const int PAC_MEM_EEPROM = 1; /// NVRAM public const int PAC_MEM_NVRAM = 2; //4.1. PAC_API DWORD pac_GetMemorySize(int mem_type) /// /// This function retrieves the size of the specified memory. /// /// [in] Handle to a currently type memory. /// 0: pac_MEM_SRAM, 1: pac_MEM_EEPROM /// The return value specifies the memory size. [DllImport("PACSDK.dll", EntryPoint = "pac_GetMemorySize")] public static extern uint GetMemorySize(int mem_type); //4.2. PAC_API bool pac_ReadMemory(DWORD address, LPBYTE lpBuffer, DWORD dwLength, int mem_type) /// /// This function retrieves the size of the specified memory. /// /// [in] Specifies the memory address where read from. /// [in] A pointer to a buffer that receives the memory data. /// [in] Number of characters to be read. /// [in] Handle to a currently type memory. /// 0: pac_MEM_SRAM, 1: pac_MEM_EEPROM /// Return true if success, otherwise false. [DllImport("PACSDK.dll", EntryPoint = "pac_ReadMemory")] [return: MarshalAs(UnmanagedType.I1)] unsafe public static extern bool ReadMemory(uint address, byte* lpBuffer, uint dwLength, int mem_type); /// /// This function retrieves the size of the specified memory. /// /// [in] Specifies the memory address where read from. /// [in] A pointer to a buffer that receives the memory data. /// [in] Number of characters to be read. /// [in] Handle to a currently type memory. unsafe public static void ReadMemory(uint index, byte[] Buffer, uint Length, int mem_type) { fixed (byte* pBuffer = Buffer) ReadMemory(index, pBuffer, Length, mem_type); } //4.3. PAC_API bool pac_WriteMemory(DWORD address, LPBYTE lpBuffer, DWORD dwLength, int mem_type) /// /// This function retrieves the size of the specified memory. /// /// [in] Specifies the memory address where write from. /// [in] A pointer to the buffer containing the data to be written to the memory. /// [in] Number of characters to be written. /// [in] Handle to a currently type memory. /// 0: pac_MEM_SRAM, 1: pac_MEM_EEPROM /// Return true if success, otherwise false. [DllImport("PACSDK.dll", EntryPoint = "pac_WriteMemory")] [return: MarshalAs(UnmanagedType.I1)] unsafe public static extern bool WriteMemory(uint address, byte* lpBuffer, uint dwLength, int mem_type); /// /// This function retrieves the size of the specified memory. /// /// [in] Specifies the memory address where write from. /// [in] A pointer to the buffer containing the data to be written to the memory. /// [in] Number of characters to be written. /// [in] Handle to a currently type memory. /// 0: pac_MEM_SRAM, 1: pac_MEM_EEPROM unsafe public static void WriteMemory(uint address, byte[] lpBuffer, uint dwLength, int mem_type) { fixed (byte* pBuffer = lpBuffer) WriteMemory(address, pBuffer, dwLength, mem_type); } //4.4. PAC_API void pac_EnableEEPROM(bool bEnable) /// /// This function turns on/off EEPROM. /// /// [in] To turn on or protect EEPROM. /// True: To turn on EEPROM, False: To protect EEPROM. [DllImport("PACSDK.dll", EntryPoint = "pac_EnableEEPROM")] public static extern void EnableEEPROM(bool bEnable); } }