دوست عزیز
یک پروژه ایجاد کنید .
سپس مراحل ذیل را انجام دهید:
1. کلاسی به اسم MifareAPIClass.cs ایجاد کنید . کد کلاس :
class MifareAPIClass
{
[DllImport("MF_API.dll")]
public static extern short MF_GetDLL_Ver(ref Byte rVER);
[DllImport("MF_API.dll")]
public static extern int MF_InitComm(String portname, int baud);
[DllImport("MF_API.dll")]
public static extern int MF_ExitComm();
[DllImport("MF_API.dll")]
public static extern int MF_DeviceReset(int DeviceAddr);
[DllImport("MF_API.dll")]
public static extern int MF_SetDeviceSNR(int DeviceAddr, string snr);
[DllImport("MF_API.dll")]
public static extern int MF_GetDeviceSNR(int DeviceAddr, ref byte snr);
[DllImport("MF_API.dll")]
public static extern int MF_Halt(int DeviceAddr);
//
//'''''''''''''''''''''''''''''''''''card reading functions''''''''''''''''''''''''''''''''''''''''' '
[DllImport("MF_API.dll")]
public static extern int MF_Request(short DeviceAddr, short mode, ref Byte CardType);
[DllImport("MF_API.dll")]
public static extern int MF_Anticoll(short DeviceAddr, ref Byte snr);
[DllImport("MF_API.dll")]
public static extern int MF_Select(short DeviceAddr, ref Byte snr);
[DllImport("MF_API.dll")]
public static extern int MF_LoadKey(short DeviceAddr, ref Byte key);
[DllImport("MF_API.dll")]
public static extern int MF_LoadKeyFromEE(short DeviceAddr, short KeyType, short KeyNum);
[DllImport("MF_API.dll")]
public static extern int MF_Authentication(short DeviceAddr, short AuthType, short block, ref Byte snr);
[DllImport("MF_API.dll")]
public static extern int MF_Read(short DeviceAddr, short block, short numbers, ref Byte databuff);
[DllImport("MF_API.dll")]
public static extern int MF_Write(short DeviceAddr, short block, short numbers, ref Byte databuff);
[DllImport("MF_API.dll")]
public static extern int MF_Value(short DeviceAddr, short valoption, ref Byte value);
[DllImport("MF_API.dll")]
public static extern int MF_transfer(short DeviceAddr, short block);
[DllImport("MF_API.dll")]
public static extern int MF_ControlBuzzer(short DeviceAddr, short BeepTime);
}
2. کلاسی ایجاد کنید به اسم MifareClass.cs . کد کلاس :
class MifareClass
{
public static Byte[] DLL_version = new Byte[32];
public static Byte[] portN = new Byte[4];
public static Byte[] Dver = new Byte[32];
public static Byte Daddress = new Byte();
public static Byte[] Dsn = new Byte[7];
public static Byte[] cardT = new Byte[3];
public static Byte[] cardSN = new Byte[5];
public static Byte[] Ckey = new Byte[6];
public static Byte[] databuffer = new Byte[16];
public static Byte[] value = new Byte[3];
public static Byte[] Dbuffer = new Byte[63];
static Byte[] bHexKey = new Byte[32];
public static int hex2dec(string inpt)
{
//On Error Resume Next
if (inpt.Length == 1)
{
inpt = "0" + inpt;
}
int temp = 0;
switch (inpt.Substring(0, 1))
{
case "A": temp = temp + 10 * 16; break;
case "a": temp = temp + 10 * 16; break;
case "B": temp = temp + 11 * 16; break;
case "b": temp = temp + 11 * 16; break;
case "C": temp = temp + 12 * 16; break;
case "c": temp = temp + 12 * 16; break;
case "D": temp = temp + 13 * 16; break;
case "d": temp = temp + 13 * 16; break;
case "E": temp = temp + 14 * 16; break;
case "e": temp = temp + 14 * 16; break;
case "F": temp = temp + 15 * 16; break;
case "f": temp = temp + 15 * 16; break;
default: temp = temp + int.Parse((inpt.Substring(1, 1))) * 16; break;
}
switch (inpt.Substring(1, 1))
{
case "A": temp = temp + 10; break;
case "a": temp = temp + 10; break;
case "B": temp = temp + 11; break;
case "b": temp = temp + 11; break;
case "C": temp = temp + 12; break;
case "c": temp = temp + 12; break;
case "D": temp = temp + 13; break;
case "d": temp = temp + 13; break;
case "E": temp = temp + 14; break;
case "e": temp = temp + 14; break;
case "F": temp = temp + 15; break;
case "f": temp = temp + 15; break;
default: temp = temp + int.Parse((inpt.Substring(2, 1))); break;
}
return temp;
}
public static string GetMifarePort()
{
AppSettings1 appSettings1 = new AppSettings1();
return appSettings1.MifarePort;
}
}
3. اگر دستگاه شما از نوع USB میباشد اعلام کنید.
4. فایلهای ذیل را به به آدرس Debug پروژه کپی کنید :
EasyD12.dll
MF_API.dll
MF_API.h
MF_API.lib
5. در این مرحله باید خود دستگاه آماده خواندن نوشتن کنیم :
در فرم اصلی برنامه یک تایمر بگذارید و رویداد آن کد ذیل را بنویسید :
MifareAPIClass.MF_Request(0, 1, ref MifareClass.cardT[0]).ToString();
MifareAPIClass.MF_Anticoll(0, ref MifareClass.cardSN[0]).ToString();
MifareAPIClass.MF_Select(0, ref MifareClass.cardSN[0]).ToString();
MifareAPIClass.MF_LoadKeyFromEE(0, 0, 0);
MifareAPIClass.MF_Authentication(0, 0, 2, ref MifareClass.cardSN[0]).ToString();
- این کد دستگاه را بطور مداوم روشن نگه میدارد که هر زمانی کارتی در محدوده فرکانسی دستگاه قرار گرفت ،دستگاه شروع به خواندن و بررسی اطلاعات کارت نماید
تا این مرحله کار رو جلو ببرید ، سپس نتیجه رو اعلام کنید.