[DllImport("RC500_232.dll")]
private static extern byte RC500_232_init(int mport, int mbaud);
[DllImport("RC500_232.dll")]
private static extern byte RC500_232_config();
[DllImport("RC500_232.dll")]
private static extern byte RC500_232_exit();
[DllImport("RC500_232.dll")]
private static extern byte RC500_232_request(byte mmode, ref UInt16 mtagtype);
[DllImport("RC500_232.dll")]
private static extern byte RC500_232_anticoll(byte mbcnt, ref UInt32 msnr);
[DllImport("RC500_232.dll")]
private static extern byte RC500_232_select(UInt32 msnr, ref byte msize);
[DllImport("RC500_232.dll")]
private static extern byte RC500_232_authkey(byte mmode, byte msecnr, byte[] mkey);
[DllImport("RC500_232.dll")]
private static extern byte RC500_232_read(byte maddr, byte[] mdata);
[DllImport("RC500_232.dll")]
private static extern byte RC500_232_write(byte maddr, byte[] mdata);
[DllImport("RC500_232.dll")]
private static extern byte RC500_232_readval(byte maddr, ref Int32 value);
[DllImport("RC500_232.dll")]
private static extern byte RC500_232_writeval(byte maddr, Int32 value);
[DllImport("RC500_232.dll")]
private static extern byte RC500_232_alarm(int contrl, int opentm, int closetm, int repcnt);
[DllImport("RC500_232.dll")]
private static extern byte RC500_232_load_key(byte mmode, byte msecnr, byte[] mkey);
public static bool Init(ref string msg)
{
byteDataArea = (byte)Convert.ToInt32("29"); //选择的数据块
byteSQ = (byte)Convert.ToInt32("07"); //选择扇区
byte[] Ackey = getKey();
//byte[] Ackey = HexString2Bytes(); bool flag = false;
if (RC500_232_request(0, ref tagtype) != 0) //检查有效范围是否有卡
{ if (RC500_232_request(0, ref tagtype) != 0) //检查有效范围是否有卡
{
msg = "没有卡!";
return false;
}
else
flag = true;
}
else
flag = true; if (flag)
{
if (RC500_232_anticoll(0, ref snr) != 0) //防碰撞控制,snr返回卡的序列号
{
msg = "防碰撞错误!";
return false;
}
else if (RC500_232_select(snr, ref size) != 0) //选择某一序号的卡,size返回卡的容量大小
{
msg = "选择错误!";
return false;
}
else if (RC500_232_authkey(0, byteSQ, Ackey) != 0) //密码验证,密码存放在 key数组中- -key
{
msg = "密码验证错误!";
return false;
}
}
return true;
}
为神马老读不到数据 我用串口调试器 卡放上去 听见叫了,但串口窗口上也没数据 神马都没有 求解?
private static extern byte RC500_232_init(int mport, int mbaud);
[DllImport("RC500_232.dll")]
private static extern byte RC500_232_config();
[DllImport("RC500_232.dll")]
private static extern byte RC500_232_exit();
[DllImport("RC500_232.dll")]
private static extern byte RC500_232_request(byte mmode, ref UInt16 mtagtype);
[DllImport("RC500_232.dll")]
private static extern byte RC500_232_anticoll(byte mbcnt, ref UInt32 msnr);
[DllImport("RC500_232.dll")]
private static extern byte RC500_232_select(UInt32 msnr, ref byte msize);
[DllImport("RC500_232.dll")]
private static extern byte RC500_232_authkey(byte mmode, byte msecnr, byte[] mkey);
[DllImport("RC500_232.dll")]
private static extern byte RC500_232_read(byte maddr, byte[] mdata);
[DllImport("RC500_232.dll")]
private static extern byte RC500_232_write(byte maddr, byte[] mdata);
[DllImport("RC500_232.dll")]
private static extern byte RC500_232_readval(byte maddr, ref Int32 value);
[DllImport("RC500_232.dll")]
private static extern byte RC500_232_writeval(byte maddr, Int32 value);
[DllImport("RC500_232.dll")]
private static extern byte RC500_232_alarm(int contrl, int opentm, int closetm, int repcnt);
[DllImport("RC500_232.dll")]
private static extern byte RC500_232_load_key(byte mmode, byte msecnr, byte[] mkey);
public static bool Init(ref string msg)
{
byteDataArea = (byte)Convert.ToInt32("29"); //选择的数据块
byteSQ = (byte)Convert.ToInt32("07"); //选择扇区
byte[] Ackey = getKey();
//byte[] Ackey = HexString2Bytes(); bool flag = false;
if (RC500_232_request(0, ref tagtype) != 0) //检查有效范围是否有卡
{ if (RC500_232_request(0, ref tagtype) != 0) //检查有效范围是否有卡
{
msg = "没有卡!";
return false;
}
else
flag = true;
}
else
flag = true; if (flag)
{
if (RC500_232_anticoll(0, ref snr) != 0) //防碰撞控制,snr返回卡的序列号
{
msg = "防碰撞错误!";
return false;
}
else if (RC500_232_select(snr, ref size) != 0) //选择某一序号的卡,size返回卡的容量大小
{
msg = "选择错误!";
return false;
}
else if (RC500_232_authkey(0, byteSQ, Ackey) != 0) //密码验证,密码存放在 key数组中- -key
{
msg = "密码验证错误!";
return false;
}
}
return true;
}
为神马老读不到数据 我用串口调试器 卡放上去 听见叫了,但串口窗口上也没数据 神马都没有 求解?
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货