Konuyu Oyla:
  • Derecelendirme: 3/5 - 1 oy
  • 1
  • 2
  • 3
  • 4
  • 5
Firemonkey Android ile OCR ve Mifare - NFC - RFID Kütüphaneleri
#5
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;
Cevapla


Bu Konudaki Yorumlar
Cvp: Firemonkey Android ile OCR ve Mifare - NFC - RFID Kütüphaneleri - Yazar: Abdullah ILGAZ - 11-12-2017, Saat: 18:07

Konu ile Alakalı Benzer Konular
Konular Yazar Yorumlar Okunma Son Yorum
  Android için comport iletişimi beklentili 7 3.712 06-05-2024, Saat: 20:57
Son Yorum: deutsch1988
Exclamation Delphi 12 - Android 14 nevez 22 1.197 26-04-2024, Saat: 22:54
Son Yorum: nevez
  Android Rehbere Kayıt Ekleme barissagir 6 444 04-04-2024, Saat: 09:36
Son Yorum: RAD Coder
  Android’de Dosya Depolama ve Paylaşma-2: And 11 SDK 30 Scoped Storage SAF MediaStore emozgun 12 5.241 19-03-2024, Saat: 22:29
Son Yorum: nguzeller
  Android 33 api sdk güncelleme [ÇÖZÜLDÜ] codder71 4 535 19-02-2024, Saat: 22:38
Son Yorum: codder71



Konuyu Okuyanlar: 1 Ziyaretçi