此款ID读卡器提供两个dll文件:IDUSB.DLL、OUR_IDR.dll
========================================================
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;
namespace Attend
{
public class IdCardHelper
{
/// <summary>
/// 蜂鸣
/// </summary>
/// <param name="comport"></param>
/// <returns></returns>
[DllImport("OUR_IDR.dll")]
public static extern byte idr_beep(UInt32 beepTime);
/// <summary>
/// 读卡,返回卡的信息
/// </summary>
/// <param name="comport"></param>
/// <returns></returns>
[DllImport("OUR_IDR.dll")]
public static extern byte idr_read([MarshalAs(UnmanagedType.LPArray)] byte[] serial);
/// <summary>
/// 读卡,返回卡的信息
/// </summary>
/// <param name="comport"></param>
/// <returns></returns>
[DllImport("OUR_IDR.dll")]
public static extern byte pcdgetdevicenumber([MarshalAs(UnmanagedType.LPArray)] byte[] devicenumbe);
}
}
===============================================================================
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Attend
{
public class CardOperate
{
/// <summary>
/// 蜂鳴
/// </summary>
/// <param name="beepTime"></param>
/// <returns></returns>
public static byte DeviceBeep(UInt32 beepTime)
{
try
{
return IdCardHelper.idr_beep(beepTime);
}
catch
{
return 0;
}
}
/// <summary>
/// 讀取設備號
/// </summary>
/// <returns></returns>
public static string DeviceRead()
{
try
{
string deviceNo = "";
byte[] btDevice = new byte[4];
byte readInfo = IdCardHelper.pcdgetdevicenumber(btDevice);
for (int i = 0; i < btDevice.Length; i++)
{
string strTemp = btDevice[i].ToString("x");
if (strTemp.Length == 1)
strTemp = "0" + strTemp;
deviceNo += strTemp;
}
return deviceNo;
}
catch
{
return null;
}
}
/// <summary>
/// 讀取卡號
/// </summary>
/// <returns></returns>
public static string CardRead()
{
try
{
byte[] cardNo = new byte[5];
byte readInfo = IdCardHelper.idr_read(cardNo);
string strCard = "";
for (int i = 0; i < cardNo.Length; i++)
{
string strTemp = cardNo[i].ToString("x");
if (strTemp.Length == 1)
strTemp = "0" + strTemp;
strCard += strTemp;
}
strCard = strCard.Substring(2, 8);
int intTemp = Convert.ToInt32(strCard, 16);
strCard = intTemp.ToString();
intTemp = strCard.Length;
for (int i = 0; i < 10 - intTemp; i++)
{
strCard = "0" + strCard;
}
//if (strCard == "0000000000")
//{
// DeviceBeep(800);
//}
//else
//{
// DeviceBeep(200);
//}
return strCard;
}
catch
{
return null;
}
}
}
}