|
I2CBridge.h:
- #ifdef I2CBRIDGE_EXPORTS
- #define I2CBRIDGE_API __declspec(dllexport)
- #else
- #define I2CBRIDGE_API __declspec(dllimport)
- #endif
- class CI2CBridge
- {
- public:
- static I2CBRIDGE_API BOOL InitI2CBridge(DWORD nWriteAddress, DWORD nReadAddress, DWORD nI2CClock, DWORD nI2CPort);
- static I2CBRIDGE_API VOID DeinitI2CBridge(void);
- static I2CBRIDGE_API BOOL WriteRegisters(PBYTE pBuff, DWORD nRegs);
- static I2CBRIDGE_API BOOL ReadRegisters(PBYTE pBuff, PBYTE pAddr, DWORD nAddrLength, DWORD nRegs);
- };
复制代码
I2CBridge.cpp: 上述函数的具体实现
Invoker.cs:
- using System;
- using System.Collections.Generic;
- using System.Runtime.InteropServices;
- using System.Text;
- namespace I2CUtility
- {
- class I2CInvoke
- {
- [DllImport("I2CBridge.dll", EntryPoint = "InitI2CBridge", CharSet = CharSet.Auto)]
- public static extern bool InitI2CBridge(Int32 nWriteAddress, Int32 nReadAddress, Int32 nI2CClock, Int32 nI2CPort);
- [DllImport("I2CBridge.dll", EntryPoint = "DeinitI2CBridge", CharSet = CharSet.Auto)]
- public static extern void DeinitI2CBridge();
- [DllImport("I2CBridge.dll", EntryPoint = "WriteRegisters", CharSet = CharSet.Auto)]
- public static extern bool WriteRegisters(Byte[] pBuff, Int32 nRegs);
- [DllImport("I2CBridge.dll", EntryPoint = "ReadRegisters", CharSet = CharSet.Auto)]
- public static extern bool ReadRegisters(Byte[] pBuff, Byte[] pAddr, Int32 nAddrLength, Int32 nRegs);
- }
- }
复制代码
|
|