Home > Back-end >  Excuse me, this function is a function of read and write about ACR122?
Excuse me, this function is a function of read and write about ACR122?

Time:09-26

I want to be a member to identify the software to use, so buy the ACR122 NFC, speaking, reading and writing. In the simple example of a function, I think it is to read and write, but the case after the operation, you really can't find out to write a value, and then read the value, trouble the good teacher to give me see this function, to teach me how to write a number, then read this value. This function can also be found in baidu, I just don't understand. SCardTransmit I copy the code below.

The function SendAPDU () : integer;
Var index: integer; Tempstr: String;
The begin

IoRequest. DwProtocol:=dwActProtocol;
IoRequest. CbPciLength:=sizeof (SCARD_IO_REQUEST);

Tempstr:=';
For the index:=0 to do SendLen - 1
Tempstr: tempstr=+ Format (' x %. 02 ', [SendBuff [index]]).
DisplayOut (tempstr, 3);

RetCode:=SCardTransmit (putting,
@ ioRequest,
@ SendBuff,
SendLen,
Nil,
@ RecvBuff,
@ RecvLen);
If retcode & lt;> SCARD_S_SUCCESS then begin
DisplayOut (GetScardErrMsg (retcode), 2);
SendAPDU:=retcode;
The Exit;
end;

Tempstr:=';
For the index:=0 to do RecvLen - 1
Tempstr: tempstr=+ Format (' x %. 02 ', [RecvBuff [index]]).

DisplayOut (tempstr, 4);

SendAPDU:=retcode;

end;

CodePudding user response:

Here is the example code.

The unit MiFareProg;

Interface

USES the
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, AcsModule StdCtrls ComCtrls;

Const MAX_BUFFER_LEN=256;

Type
TfrmMifare=class (TForm)
Label1: TLabel;
CbReader: TComboBox;
RbOutput: TRichEdit;
BtnInit: TButton;
BtnConnect: TButton;
LoadGroup: TGroupBox;
Label2: TLabel;
Label3: TLabel;
TbKeyNum: TEdit;
TbKeyVal1: TEdit;
TbKeyVal2: TEdit;
TbKeyVal3: TEdit;
TbKeyVal4: TEdit;
TbKeyVal5: TEdit;
TbKeyVal6: TEdit;
BtnLoad: TButton;
AuthenGroup: TGroupBox;
Label4: TLabel;
Label5: TLabel;
KeyGroup: TGroupBox;
RKeyA: TRadioButton;
RKeyB: TRadioButton;
TbBlockNum: TEdit;
BtnAuthen: TButton;
TbAuthenKeyNum: TEdit;
BinaryGroup: TGroupBox;
Label6: TLabel;
TbBinaryBlockNum: TEdit;
TbLen: TEdit;
Label7: TLabel;
Label8: TLabel;
TbData: TEdit;
TbRead: TButton;
TbUpdate: TButton;
ValueGroup: TGroupBox;
Label9: TLabel;
Label10: TLabel;
Label11: TLabel;
Label12: TLabel;
TbValueBlockNum: TEdit;
TbSource: TEdit;
TbTarget: TEdit;
BtnStore: TButton;
BtnInc: TButton;
BtnDec: TButton;
BtnReadValue: TButton;
BtnRestore: TButton;
TbValue: TEdit;
BtnClear: TButton;
BtnReset: TButton;
BtnQuit: TButton;
Procedure btnInitClick (Sender: TObject);
Procedure btnConnectClick (Sender: TObject);
Procedure tbKeyNumKeyPress (Sender: TObject; Var Key: Char);
Procedure tbKeyVal1KeyPress (Sender: TObject; Var Key: Char);
Procedure tbKeyVal2KeyPress (Sender: TObject; Var Key: Char);
Procedure tbKeyVal3KeyPress (Sender: TObject; Var Key: Char);
Procedure tbKeyVal4KeyPress (Sender: TObject; Var Key: Char);
Procedure tbKeyVal5KeyPress (Sender: TObject; Var Key: Char);
Procedure tbKeyVal6KeyPress (Sender: TObject; Var Key: Char);
Procedure btnLoadClick (Sender: TObject);
Procedure btnAuthenClick (Sender: TObject);
Procedure tbReadClick (Sender: TObject);
Procedure tbUpdateClick (Sender: TObject);
Procedure btnStoreClick (Sender: TObject);
Procedure btnReadValueClick (Sender: TObject);
Procedure btnIncClick (Sender: TObject);
Procedure btnDecClick (Sender: TObject);
Procedure btnRestoreClick (Sender: TObject);
Procedure btnQuitClick (Sender: TObject);
Procedure btnClearClick (Sender: TObject);
Procedure btnResetClick (Sender: TObject);
Procedure FormActivate (Sender: TObject);
Private
{Private declarations}
Public
{Public declarations}
end;

Var
FrmMifare: TfrmMifare;
HContext: SCARDCONTEXT;
Putting: SCARDCONTEXT;
IoRequest: SCARD_IO_REQUEST;
RetCode: Integer;
DwActProtocol BufferLen: dwords.
SendBuff RecvBuff: an array of Byte [0.. 262];
SendLen, RecvLen, nBytesRet: DWORD;
Buffer: array [0.. MAX_BUFFER_LEN] of char;
ATRVal: an array of byte [0.. 128];
ATRLen: ^ dwords;

Implementation

{$R *. DFM}

Procedure DisplayOut (output: String; Mode: integer);
The begin

The case mode of
1: frmMifare. RbOutput. SelAttributes. Color:=clBlue;
2: frmMifare. RbOutput. SelAttributes. Color:=clRed;
3: the begin
FrmMifare. RbOutput. SelAttributes. Color:=clBlack;
Output:='& lt; <'+ output;
end;
4: the begin
FrmMifare. RbOutput. SelAttributes. Color:=clBlack;
Output:='& gt;> '+ output;
end;
end;

FrmMifare. RbOutput. Lines. The Add (output);
FrmMifare. RbOutput. SelAttributes. Color:=clBlack;
FrmMifare. RbOutput. SetFocus;

end;

Procedure ClearBuffers ();
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related