在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
今天写了个RFID的封装类,主要实现c#调用c++中的函数。如果大家有需要,可以当个参考: 接口文档如下:
c++中的Struct 如下:
typedef struct { int deviceID; //阅读器逻辑ID char address[20]; //IP地址或串口;如"COM1","10.86.10.56" int status; //0-未链接;1-已链接,未初始化;2-已链接,已初始化 int style; //0-网络客户端;1-网络服务端;2-串口 } ReaderItem; typedef struct { int length; unsigned char tagData[2048]; //标签长度1byte(lenth字)+标签epc码(lenth*2)byte+标签长度1byte+标签epc码 } InventoryResult; c#的类如下:
public class RFIDBaseManage { [DllImport("xxx.dll")] public static extern int Connect(string dev, ref int devid); [DllImport("xxx.dll")] public static extern int Disconnect(int devid); [DllImport("xxx.dll", EntryPoint = "GetReaders")] public static extern int GetReaders(ref ReaderItem item,int maxCount,ref int count); } public class RFIDInfoManage { [DllImport("xxx.dll", EntryPoint = "EPC1G2_Inventory")] public static extern int EPC1G2_Inventory(int DeviceID, short antennalID, ref InventoryResult result); } [StructLayout(LayoutKind.Sequential)] public struct ReaderItem { public int deviceID; [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 20)] public string address; //IP地址或串口;如"COM1","10.86.10.56" public int status; public int style; } [StructLayout(LayoutKind.Sequential)] public struct InventoryResult { public int length; [MarshalAs(UnmanagedType.ByValArray, SizeConst = 2048)] public byte[] tagData; } 另外,也可以参考这几篇文章: http://hi.baidu.com/yun0216/blog/item/37a463106b575ffec3ce7913.html http://blog.csdn.net/xqf222/archive/2010/09/11/5877795.aspx 对于Byte[]的处理 可以参考
|
请发表评论