Winsoft'un örneklemesine göre;
Okuma İşlemi
procedure TFormMain.ReadTag(NfcTag: TNfcTag);
var
NfcA: TNfcA;
NfcV: TNfcV;
NdefFormatable: TNdefFormatable;
Ndef: TNdef;
MifareClassic: TMifareClassic;
MifareUltralight: TMifareUltralight;
TechList: TArray<string>;
I, PageCount, PageSize, BlockCount, BlockSize: Integer;
NdefRecords: TArray<TNdefRecord>;
NdefRecord: TNdefRecord;
Blocks: TArray<TArray<Byte>>;
Data: TArray<Byte>;
begin
ClearLines;
AddLine('ID: ' + NfcTag.Id);
// TechList
AddLine('');
TechList := NfcTag.TechList;
for I := Low(TechList) to High(TechList) do
AddLine('Tech ' + IntToStr(I) + ': ' + TechList[I]);
// NFC A
NfcA := NfcTag.NfcA;
if NfcA <> nil then
begin
AddLine('');
AddLine('NFC-A');
AddLine(' SAK/SEL_RES: $' + IntToHex(NfcA.Sak, 4));
AddLine(' ATQA: $' + BytesToHexReverse(NfcA.Atqa));
AddLine(' Max transceive length: ' + IntToStr(NfcA.MaxTransceiveLength));
AddLine(' Timeout: ' + IntToStr(NfcA.Timeout));
end;
// NFC V
NfcV := NfcTag.NfcV;
if NfcV <> nil then
begin
AddLine('');
AddLine('NFC-V');
AddLine(' DSF ID: $' + IntToHex(NfcV.DsfId, 2));
AddLine(' Response flags: $' + IntToHex(NfcV.ResponseFlags, 2));
AddLine(' Max transceive length: ' + IntToStr(NfcV.MaxTransceiveLength));
BlockCount := NfcV.BlockCount;
BlockSize := NfcV.BlockSize;
AddLine(' Block count: ' + IntToStr(BlockCount));
AddLine(' Block size: ' + IntToStr(BlockSize));
for I := 0 to BlockCount - 1 do
AddLine(' Block $' + IntToHex(I, 2) + ': ' + BytesToHex(NfcV.ReadBlock(I)));
end;
// NDEF Formatable
NdefFormatable := NfcTag.NdefFormatable;
if NdefFormatable <> nil then
begin
AddLine('');
AddLine('NDEF Formatable');
end;
// NDEF
Ndef := NfcTag.Ndef;
if Ndef <> nil then
begin
AddLine('');
AddLine('NDEF');
AddLine(' Type: ' + Ndef.&Type);
AddLine(' Max size: ' + IntToStr(Ndef.MaxSize));
if Ndef.IsWritable then
AddLine(' Is writable');
if Ndef.CanMakeReadOnly then
AddLine(' Can make read-only');
NdefRecords := Ndef.Records;
for I := 0 to Length(NdefRecords) - 1 do
begin
NdefRecord := NdefRecords[I];
AddLine(' Record ' + IntToStr(I));
AddLine(' Top level type: ' + NdefRecord.TnfDescription);
if NdefRecord.IsText then
begin
AddLine(' Language code: ' + NdefRecord.TextLanguageCode);
AddLine(' Text: ' + NdefRecord.Text)
end
else if NdefRecord.IsUri then
AddLine(' URI: ' + NdefRecord.Uri)
else if NdefRecord.IsExternalType then
AddLine(' External text: ' + NdefRecord.ExternalText)
else
AddLine(' Payload: ' + BytesToHex(NdefRecord.Payload));
end;
end;
// MIFARE Classic
MifareClassic := NfcTag.MifareClassic;
if MifareClassic <> nil then
begin
AddLine('');
AddLine(MifareClassic.TypeDescription);
AddLine(' Block size: ' + IntToStr(MifareClassic.BlockSize));
AddLine(' Block count: ' + IntToStr(MifareClassic.BlockCount));
AddLine(' Sector count: ' + IntToStr(MifareClassic.SectorCount));
AddLine(' Size: ' + IntToStr(MifareClassic.Size));
AddLine(' Max transceive length: ' + IntToStr(MifareClassic.MaxTransceiveLength));
AddLine(' Timeout: ' + IntToStr(MifareClassic.Timeout));
Blocks := MifareClassic.ReadBlocks;
for I := 0 to Length(Blocks) - 1 do
AddLine(' Block ' + IntToStr(I) + ': ' + BytesToHex(Blocks[I]));
end;
// MIFARE Ultralight
MifareUltralight := NfcTag.MifareUltralight;
if MifareUltralight <> nil then
begin
AddLine('');
AddLine(MifareUltralight.TypeDescription);
AddLine(' Page count: ' + IntToStr(MifareUltralight.PageCount));
AddLine(' Max transceive length: ' + IntToStr(MifareUltralight.MaxTransceiveLength));
AddLine(' Timeout: ' + IntToStr(MifareUltralight.Timeout));
Data := MifareUltralight.ReadData;
PageCount := MifareUltralight.PageCount;
PageSize := Length(Data) div PageCount;
for I := 0 to PageCount - 1 do
AddLine(' Page ' + IntToStr(I) + ': ' + BytesToHex(Data, PageSize * I, PageSize));
end;
end;
Yazma İşlemi
procedure TFormMain.WriteTag(NfcTag: TNfcTag);
var
Ndef: TNdef;
TextRecord, UriRecord, ApplicationRecord: TNdefRecord;
begin
ClearLines;
AddLine('ID: ' + NfcTag.Id);
AddLine('');
// NDEF
Ndef := NfcTag.Ndef;
if Ndef = nil then
AddLine('Unsupported tag')
else if not Ndef.IsWritable then
AddLine('Tag is not writable')
else
begin
TextRecord := TNdefRecord.CreateTextRecord('Hello, world!');
UriRecord := TNdefRecord.CreateUriRecord('http://www.winsoftxe.com');
ApplicationRecord := TNdefRecord.CreateApplicationRecord('com.adobe.reader');
if Ndef.Write([TextRecord, UriRecord, ApplicationRecord]) then
AddLine('Tag written')
else
AddLine('Cannot write tag')
end;
end;
Format Belirleme İşlemi
procedure TFormMain.FormatTag(NfcTag: TNfcTag);
var NdefFormatable: TNdefFormatable;
begin
ClearLines;
AddLine('ID: ' + NfcTag.Id);
AddLine('');
NdefFormatable := NfcTag.NdefFormatable;
if NdefFormatable = nil then
AddLine('Tag is not formatable')
else if NdefFormatable.Format then
AddLine('Tag formated')
else
AddLine('Cannot format tag')
end;