⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 hit.cs

📁 HIT读卡器操作代码 读取RFID芯片
💻 CS
字号:
/********************************************************************
	created:	2007/11/04
	created:	4:11:2007   3:07
	filename: 	G:\PPC\PPC_WX\Core\modHIT.cs
	file path:	G:\PPC\PPC_WX\Core
	file base:	modHIT
	file ext:	cs
	Company:	ItsFuture.Co.Ltd.
	author:		ANSWER
	
	purpose:	ItsFuture.PPC.
*********************************************************************/
using System;
using System.Security.Permissions;
using System.Runtime.InteropServices;

namespace ItsFuture.PPC.Core
{
	/// <summary>
	/// Summary description for CHIT.
	/// </summary>
	public class HIT
    {
        #region $ Consts Declare $

        // PlaySound declarations
		public enum Flags: int
		{
			SND_SYNC = 0x0,				// play synchronously (default) 
			SND_ASYNC = 0x1,			// play asynchronously 
			SND_NODEFAULT = 0x2,		// silence (!default) if sound not found 
			SND_MEMORY = 0x4,			// pszSound points to a memory file 
			SND_LOOP = 0x8,				// loop the sound until next sndPlaySound 
			SND_NOSTOP = 0x10,			// don't stop any currently playing sound 
			SND_NOWAIT = 0x2000,		// don't wait if the driver is busy 
			SND_ALIAS = 0x10000,		// name is a registry alias 
			SND_ALIAS_ID = 0x110000,	// alias is a predefined ID 
			SND_FILENAME = 0x20000,		// name is file name 
			SND_RESOURCE = 0x40004		// name is resource name or atom 
		}
		
		public const string cst_BeepPath = "\\Windows\\default.wav";


	
		// STATUS WORDS DEFINITION
		public const int STATUS_OK				= 0x9000;
		public const int STATUS_RESET_OK		= 0x3B00;
		public const int STATUS_ERR_P3			= 0x6700;
		public const int STATUS_ERR_P1_P2		= 0x6B00;
		public const int STATUS_ERR_INS			= 0x6D00;
		public const int STATUS_ERR_CLA			= 0x6E00;
		public const int STATUS_ERR_AUTH		= 0x6982;
		public const int STATUS_ERR_FLOW		= 0x9835;
		public const int STATUS_ERR_DETECTION	= 0x6A82;
		public const int STATUS_ERR_EEPROM		= 0x6200;
		
		// RS232 port speed (for Connect and ChangeSpeed)
		public const byte SPEED_9600	= 0x00;
		public const byte SPEED_19200	= 0x01;
		public const byte SPEED_38400	= 0x02;
		public const byte SPEED_57600	= 0x03;
		public const byte SPEED_115200	= 0x04;

		// ISO 7816-4 command set format
		public const byte CMD_CLA = 0;
		public const byte CMD_INS = 1;
		public const byte CMD_P1  = 2;
		public const byte CMD_P2  = 3;
		public const byte CMD_P3  = 4;

		// T=0 protocol direction
		public const byte ISO_NONE	 = 0x00;
		public const byte ISO_IN	 = 0x01;
		public const byte ISO_OUT	 = 0x02;
		public const byte ISO_IN_OUT = 0x03;

		// Selection Options (for CLib_w_SelectCard) 
		public const byte SELECT_NO_AUTH = 0x00;
		public const byte SELECT_AUTH_KC = 0x10;
		public const byte SELECT_AUTH_KD = 0x30;
		public const byte SELECT_LOOP	 = 0x01;
		public const byte SELECT_HALT	 = 0x02;
		public const byte SELECT_PRE	 = 0x08;

		// Chip types to select (for CLib_w_SelectCard)
		public const byte SELECT_CHIP_PICOPASS	= 0x01;
		public const byte SELECT_CHIP_PICOTAG	= 0x02;
		public const byte SELECT_CHIP_PICOCRYPT = 0x04;
		public const byte SELECT_CHIP_USER		= 0x08;
		public const byte SELECT_CHIP_ALL		= 0x0F;

		// Authentification key (for page selection, authentication and key loading)
		public const byte KEY_EXCHANGE	= 0x00;
		public const byte KEY_PAGE0_KD	= 0x01;
		public const byte KEY_PAGE0_KC	= 0x02;
		public const byte KEY_PAGE1_KD	= 0x03;
		public const byte KEY_PAGE1_KC	= 0x04;
		public const byte KEY_PAGE2_KD	= 0x05;
		public const byte KEY_PAGE2_KC	= 0x06;
		public const byte KEY_PAGE3_KD	= 0x07;
		public const byte KEY_PAGE3_KC	= 0x08;
		public const byte KEY_PAGE4_KD	= 0x09;
		public const byte KEY_PAGE4_KC	= 0x0A;
		public const byte KEY_PAGE5_KD	= 0x0B;
		public const byte KEY_PAGE5_KC	= 0x0C;
		public const byte KEY_PAGE6_KD	= 0x0D;
		public const byte KEY_PAGE6_KC	= 0x0E;
		public const byte KEY_PAGE7_KD	= 0x0F;
		public const byte KEY_PAGE7_KC	= 0x10;
		public const byte KEY_TRANSPORT = 0x11;
		public const byte KEY_NO_AUTH	= 0x18;
		public const byte KEY_HOST		= 0x83;
		public const byte KEY_PASSWORD	= 0xC3;

		// Protocol (for High-level functions & commands)
		public const byte PROTOCOL_PICO_14443_B = 0x00;
		public const byte PROTOCOL_PICO_15693	= 0x01;
		public const byte PROTOCOL_PICO_14443_A = 0x02;
		public const byte PROTOCOL_USER			= 0x03;	// Not available for SelectAuthPage and Authentify

		// User Protocol (for CLib_w_SetUserProtocol)
		public const byte USER_PROTOCOL_15693_3	  = 0x00;
		public const byte USER_PROTOCOL_14443_A_3 = 0x01;
		public const byte USER_PROTOCOL_14443_B_3 = 0x02;

		// Default INSIDE key values
		public const string DEFKEY_EXCHANGE = "$5C$BC$F1$DA$45$D5$FB$5F";
		public const string DEFKEY_DEBIT	= "$F0$E1$D2$C3$B4$A5$96$87";
		public const string DEFKEY_CREDIT	= "$76$65$54$43$32$21$10$00";

		// Key Loading Mode (for CLib_w_KeyLoading)
		public const byte KEY_LOADING_XOR_KE = 0x00;
		public const byte KEY_LOADING_XOR_KO = 0x01;

		// Data Location (for coupler Status handling)
		public const int COUPLER_EEPROM = 0x00;
		public const int COUPLER_IO		= 0x01;
		public const int COUPLER_RAM	= 0x03;

        #endregion

        #region $ HITLib-2G API Declare $

        [DllImport("CoreDll.dll", EntryPoint = "PlaySound")]
        unsafe public static extern int WCE_PlaySound(string szSound, IntPtr hMod, int flags);


		[DllImport("HITLib-2G.dll", EntryPoint = "HIT_Connect")]
		public static extern bool Connect();

		[DllImport("HITLib-2G.dll", EntryPoint = "HIT_ConnectTo")]
		public static extern bool ConnectTo(string p_sComPort, byte p_iSpeed);

		[DllImport("HITLib-2G.dll", EntryPoint = "HIT_ChangeSpeed")]
		public static extern bool SetSpeed(byte p_iSpeed);

		[DllImport("HITLib-2G.dll", EntryPoint = "HIT_Disconnect")]
		public static extern bool Disconnect();

		[DllImport("HITLib-2G.dll", EntryPoint = "HIT_SendISOCommand")]
		public static extern int SendISOCommand	(byte p_bIsoType,
												 byte p_iOutLength,
												 byte p_bCLA,
												 byte p_bINS,
												 byte p_bP1,
												 byte p_bP2,
												 byte p_bP3,
												 string p_sSentData,
												 string p_sResponse);

		[DllImport("HITLib-2G.dll", EntryPoint = "HIT_SelectCard")]
		public static extern int SelectCard	(byte p_bSelectMode, byte p_bChipTypes, string p_sTypeSN);

		[DllImport("HITLib-2G.dll", EntryPoint = "HIT_Halt")]
		public static extern int Halt(byte p_bProtocol);

		[DllImport("HITLib-2G.dll", EntryPoint = "HIT_Reselect")]
		public static extern int Reselect(byte p_bProtocol, string p_sSerialNumber);

		[DllImport("HITLib-2G.dll", EntryPoint = "HIT_EASDetect")]
		public static extern int EASDetect(byte p_bProtocole, string p_sSerialNumber);

		[DllImport("HITLib-2G.dll", EntryPoint = "HIT_AskRandom")]
		public static extern int AskRandom(string p_sRandom);

		[DllImport("HITLib-2G.dll", EntryPoint = "HIT_Transmit")]
		public static extern int Transmit	(byte p_bP1,
											 byte p_bP2,
											 byte p_bP3, 
											 string p_sDataIn, 
											 string p_sDataOut);

		[DllImport("HITLib-2G.dll", EntryPoint = "HIT_GetResponse")]
		public static extern int GetResponse(byte p_bOutLength, string p_sResponse);

		[DllImport("HITLib-2G.dll", EntryPoint = "HIT_SelectCurrentKey")]
		public static extern int SelectCurrentKey(byte p_bKey);

		[DllImport("HITLib-2G.dll", EntryPoint = "HIT_DiversifyKey")]
		public static extern int DiversifyKey(byte p_bKey, string p_sSN, string p_sKeyDiv);

		[DllImport("HITLib-2G.dll", EntryPoint = "HIT_Disable")]
		public static extern int Disable();
		
		[DllImport("HITLib-2G.dll", EntryPoint = "HIT_Enable")]
		public static extern int Enable();
		
		[DllImport("HITLib-2G.dll", EntryPoint = "HIT_ResetField")]
		public static extern int ResetField();

		[DllImport("HITLib-2G.dll", EntryPoint = "HIT_GetStatus")]
		public static extern int GetStatus(byte p_bLocation, byte p_bAddress, byte p_bData);

		[DllImport("HITLib-2G.dll", EntryPoint = "HIT_SetStatus")]
		public static extern int SetStatus(byte p_bLocation, byte p_bAddress, byte p_bData);

		[DllImport("HITLib-2G.dll", EntryPoint = "HIT_LoadKeyFile")]
		public static extern int LoadKeyFile(byte p_bKeyOperation, byte p_bKeyNumber, string p_sSentData);

		[DllImport("HITLib-2G.dll", EntryPoint = "HIT_KeyLoading")]
		public static extern int KeyLoading (byte p_bKeyNum, 
											 byte p_bLoadingMode, 
											 string p_sExchangeKey,
											 string p_sKeyValue);

		[DllImport("HITLib-2G.dll", EntryPoint = "HIT_SelectAuthPage")]
		public static extern int SelectAuthPage	(byte p_bKeyNum, 
												 byte p_bPage, 
												 byte p_bProtocol, 
												 string p_sSN, 
												 string p_sConfBlock);

		[DllImport("HITLib-2G.dll", EntryPoint = "HIT_Authentify")]
		public static extern int Authentify(byte p_bKeyNum, byte p_bProtocol, byte p_sSN);

		[DllImport("HITLib-2G.dll", EntryPoint = "HIT_ReadBlock")]
		public static extern int ReadBlock(byte p_bNumBlock, byte p_bNbBlocks, byte p_bProtocol, string p_sData);

		[DllImport("HITLib-2G.dll", EntryPoint = "HIT_ReadBlock4")]
		public static extern int ReadBlock4(byte p_bNumBlock, byte p_bNbBlocks, byte p_bProtocol, string p_sData);

		[DllImport("HITLib-2G.dll", EntryPoint = "HIT_WriteBlock")]
		public static extern int WriteBlock	(byte p_bNumBlock, 
											 byte p_bNbBlocks, 
											 byte p_bProtocol, 
											 bool p_isAuthentified, 
											 string p_sData);

		[DllImport("HITLib-2G.dll", EntryPoint = "HIT_DecreaseCounter")]
		unsafe public static extern int DecreaseCounter(int p_wUnitToDecrease, byte p_bProtocol, int *p_wCounterNew);

		[DllImport("HITLib-2G.dll", EntryPoint = "HIT_IncreaseCounter")]
		unsafe public static extern int IncreaseCounter(int p_wNewValue, byte p_bProtocol, int *p_wRechargingCounterNew);

		[DllImport("HITLib-2G.dll", EntryPoint = "HIT_EASActivate")]
		public static extern int EASActivate(byte p_bProtocol);
		
		[DllImport("HITLib-2G.dll", EntryPoint = "HIT_EASDeactivate")]
		public static extern int EASDeactivate(byte p_bProtocol);

		[DllImport("HITLib-2G.dll", EntryPoint = "HIT_SetUseProtocol")]
		public static extern int SetUserProtocol(byte p_bUserProtocol);

		[DllImport("HITLib-2G.dll", EntryPoint = "HIT_ConvertHexaToBytes")]
		unsafe public static extern void ConvertHexaToBytes(string p_sHexa, byte *p_abBytes, int p_wSize);
		
		[DllImport("HITLib-2G.dll", EntryPoint = "HIT_ConvertBytesToHexa")]
		unsafe public static extern void ConvertBytesToHexa(byte *p_abBytes, string p_sHexa, int p_wSize);

		[DllImport("HITLib-2G.dll", EntryPoint = "HIT_GetCOMName")]
		public static extern void GetComName(string p_sComPortName);

        #endregion
               
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -