读书人

:C# 实现明华读卡器

发布时间: 2012-07-24 17:47:58 作者: rapoo

求救:C# 实现明华读卡器
当我使用C# 实现对明华读卡器操作时出现问题
//对设备进行初始化

[DllImport("mwrf32.dll", EntryPoint = "rf_init", SetLastError = true, CharSet = CharSet.Ansi, ExactSpelling = true, CallingConvention = CallingConvention.StdCall)]

public static extern int rf_init(int port, long baud);
这部可以实现设备的连接
当我进行寻卡操作时就出错了
//返回卡的序列号---- 寻卡
[DllImport("mwrf32.dll", EntryPoint = "rf_card", SetLastError = true, CharSet = CharSet.Ansi, ExactSpelling = true, CallingConvention = CallingConvention.StdCall)]
public static extern int rf_card(int icdev, byte m, ulong* kahao);
求帮助。可以提供API QQ:360392776
谢谢!!

[解决办法]
参数kahao要传地址 out
[解决办法]
大概数据结构的长短和C不一样吧?
[解决办法]
int rf_card(int icdev, byte m, ulong* kahao);
文档上是怎么声明的?
[解决办法]
C#代码上 int 改成Int32, ulong改成UInt32 呢? 也是一样吗?
[解决办法]
寻卡函数构造的有问题,应该这么写
public static extern int rf_card(int icde, string model,out byte pTagType);
[解决办法]
对用你的调用的DLL可以是这样:
public static extern int rf_card(int icde, string model,out uint pTagType);
[解决办法]
读卡器不在手边...
但安装光盘里有C#的demo的吧?

[解决办法]
明华的有自己的C#例子,我这边也是用的明华的,我公司就是明华刚成立的系统集成公司,我在api中没有发现有rf_card这个方法,现在把我这边这款读卡机的代码发一下

[DllImport("mwrf32.dll", EntryPoint="rf_request", SetLastError=true,
CharSet=CharSet.Auto, ExactSpelling=false,
CallingConvention=CallingConvention.StdCall)]
//说明: 返回设备当前状态
public static extern Int16 rf_request(int icdev, int mode, out UInt16 tagtype);

[DllImport("mwrf32.dll", EntryPoint="rf_request_std", SetLastError=true,
CharSet=CharSet.Auto, ExactSpelling=false,
CallingConvention=CallingConvention.StdCall)]
//说明: 返回设备当前状态
public static extern Int16 rf_request_std(int icdev, int mode, out UInt16 tagtype);

[DllImport("mwrf32.dll", EntryPoint="rf_anticoll", SetLastError=true,
CharSet=CharSet.Auto, ExactSpelling=false,
CallingConvention=CallingConvention.StdCall)]
//说明: 返回设备当前状态
public static extern Int16 rf_anticoll(int icdev, int bcnt,out uint snr);

[DllImport("mwrf32.dll", EntryPoint="rf_select", SetLastError=true,
CharSet=CharSet.Auto, ExactSpelling=false,
CallingConvention=CallingConvention.StdCall)]
//说明: 返回设备当前状态
public static extern Int16 rf_select(int icdev, uint snr,out byte size);

[DllImport("mwrf32.dll", EntryPoint="rf_authentication", SetLastError=true,
CharSet=CharSet.Auto, ExactSpelling=false,
CallingConvention=CallingConvention.StdCall)]
//说明: 返回设备当前状态
public static extern Int16 rf_authentication(int icdev, int mode,int secnr);

[DllImport("mwrf32.dll", EntryPoint="rf_authentication_2", SetLastError=true,
CharSet=CharSet.Auto, ExactSpelling=false,
CallingConvention=CallingConvention.StdCall)]
//说明: 返回设备当前状态
public static extern Int16 rf_authentication_2(int icdev, int mode,int keynr,int blocknr);

[DllImport("mwrf32.dll", EntryPoint="rf_read", SetLastError=true,


CharSet=CharSet.Auto, ExactSpelling=false,
CallingConvention=CallingConvention.StdCall)]
//说明: 返回设备当前状态
public static extern Int16 rf_read(int icdev,int blocknr, [MarshalAs(UnmanagedType.LPArray)]byte[] databuff);

[DllImport("mwrf32.dll", EntryPoint="rf_read_hex", SetLastError=true,
CharSet=CharSet.Auto, ExactSpelling=false,
CallingConvention=CallingConvention.StdCall)]
//说明: 返回设备当前状态
public static extern Int16 rf_read_hex(int icdev,int blocknr, [MarshalAs(UnmanagedType.LPArray)]byte[] databuff);

[DllImport("mwrf32.dll", EntryPoint="rf_write_hex", SetLastError=true,
CharSet=CharSet.Auto, ExactSpelling=false,
CallingConvention=CallingConvention.StdCall)]
//说明: 返回设备当前状态
public static extern Int16 rf_write_hex(int icdev,int blocknr, [MarshalAs(UnmanagedType.LPArray)]byte[] databuff);

[DllImport("mwrf32.dll", EntryPoint="rf_write", SetLastError=true,
CharSet=CharSet.Auto, ExactSpelling=false,
CallingConvention=CallingConvention.StdCall)]
//说明: 返回设备当前状态
public static extern Int16 rf_write(int icdev, int blocknr, [MarshalAs(UnmanagedType.LPArray)]byte[] databuff);

[DllImport("mwrf32.dll", EntryPoint="rf_halt", SetLastError=true,
CharSet=CharSet.Auto, ExactSpelling=false,
CallingConvention=CallingConvention.StdCall)]
//说明: 返回设备当前状态
public static extern Int16 rf_halt(int icdev);

[DllImport("mwrf32.dll", EntryPoint="rf_initval", SetLastError=true,
CharSet=CharSet.Auto, ExactSpelling=false,
CallingConvention=CallingConvention.StdCall)]
//说明: 返回设备当前状态
public static extern Int16 rf_initval(int icdev,int blocknr, uint val);

[DllImport("mwrf32.dll", EntryPoint="rf_readval", SetLastError=true,
CharSet=CharSet.Auto, ExactSpelling=false,
CallingConvention=CallingConvention.StdCall)]
//说明: 返回设备当前状态
public static extern Int16 rf_readval(int icdev,int blocknr, out uint val);

[DllImport("mwrf32.dll", EntryPoint="rf_increment", SetLastError=true,
CharSet=CharSet.Auto, ExactSpelling=false,
CallingConvention=CallingConvention.StdCall)]
//说明: 返回设备当前状态
public static extern Int16 rf_increment(int icdev,int blocknr, uint val);

[DllImport("mwrf32.dll", EntryPoint="rf_decrement", SetLastError=true,
CharSet=CharSet.Auto, ExactSpelling=false,
CallingConvention=CallingConvention.StdCall)]
//说明: 返回设备当前状态
public static extern Int16 rf_decrement(int icdev,int blocknr,uint val);

[DllImport("mwrf32.dll", EntryPoint="rf_restore", SetLastError=true,
CharSet=CharSet.Auto, ExactSpelling=false,
CallingConvention=CallingConvention.StdCall)]
//说明: 返回设备当前状态
public static extern Int16 rf_restore(int icdev,int blocknr);

[DllImport("mwrf32.dll", EntryPoint="rf_transfer", SetLastError=true,
CharSet=CharSet.Auto, ExactSpelling=false,
CallingConvention=CallingConvention.StdCall)]
//说明: 返回设备当前状态
public static extern Int16 rf_transfer(int icdev,int blocknr);

[DllImport("mwrf32.dll", EntryPoint="rf_reset", SetLastError=true,
CharSet=CharSet.Auto, ExactSpelling=false,
CallingConvention=CallingConvention.StdCall)]
//说明: 返回设备当前状态
public static extern Int16 rf_reset(int icdev,int msec);
[解决办法]
int

读书人网 >C#

热点推荐