日期:2014-05-18  浏览次数:21130 次

求救: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,