简体   繁体   English

与Delphi中的Mifare DESFire通信

[英]Communication with Mifare DESFire in Delphi

I want to write application in Delphi, which can communicate with Android phones and DESFire cards. 我想用Delphi编写应用程序,它可以与Android手机和DESFire卡通信。 I know, I have to send some bytes to card and card answers me. 我知道,我必须向卡发送一些字节,卡才能回答我。 I read article about it: 我读了有关它的文章:

https://ridrix.wordpress.com/2009/09/19/mifare-desfire-communication-example/ https://ridrix.wordpress.com/2009/09/19/mifare-desfire-communication-example/

I have no idea, how can I write and read bytes from card? 我不知道如何从卡中读写字节? I wrote simple application according to Daniel Magin: 我根据Daniel Magin编写了简单的应用程序:

http://www.danielmagin.de/blog/index.php/2014/09/nfc-android-application-with-delphi-xe6-and-xe7/ http://www.danielmagin.de/blog/index.php/2014/09/nfc-android-application-with-delphi-xe6-and-xe7/

This program can only read UID from card. 该程序只能从卡中读取UID。

function TNfc.ReadNFCUID: string;
var
  Intent: JIntent;
  jIntentName: JString;
  IntentName: string;
  tagId: Androidapi.JNIBridge.TJavaArray<Byte>;
  tagFromIntent: JParcelable;
  id: string;
  i: Integer;

begin
  id := '';
  Intent := SharedActivity.getIntent;

  if Intent <> nil then
  begin
    jIntentName := Intent.getAction;
    IntentName := JStringToString(jIntentName);

    tagId := Intent.getByteArrayExtra(TJNFCAdapter.JavaClass.EXTRA_ID);

    tagFromIntent := Intent.getParcelableExtra
      (TJNFCAdapter.JavaClass.EXTRA_TAG);
    if (tagId <> nil) and (tagFromIntent <> nil) then
    begin
      for i := 0 to tagId.Length - 1 do
        id := id + IntToHex(tagId.Items[i], 2);
    end;
  end;

  Result := id;

end;

I find solution for my question: 我为我的问题找到了解决方案:

..
var
    isoNFC : JIsoDep;
    tag : JTag;
    aRawData : TJavaByteArray;
    aResponse : TJavaByteArray;

begin
  aRawData := TJavaByteArray.Create(1);

  tag := TJTag.Wrap((CurrentNFCTag as ILocalObject).GetObjectID);
  isoNFC := TJIsoDep.JavaClass.get(tag);
  isoNFC.connect();

  aRawData.Items[0] := TCmd.GetApplicationIDs;
  aResponse := isoNFC.transceive(aRawData);
..

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM