简体   繁体   English

Galaxy S3和ACR122之间的P2P NFC通信

[英]P2P NFC Communication Between Galaxy S3 and ACR122

I'm working on a project which requires an NFC communication between an android phone and a PC. 我正在开发一个需要在Android手机和PC之间进行NFC通信的项目。 I am using Galaxy S3 as android phone and ACR122 as NFC reader. 我使用Galaxy S3作为Android手机,使用ACR122作为NFC读卡器。 I have tried the applications at here and here . 我在这里这里尝试了应用程序。

I used the sample application which found in android sdk to beam the NDEF message through NFC. 我使用在android sdk中找到的示例应用程序通过NFC发送NDEF消息。

No matter how many times I tried, I couldn't establish a connection between the phone and PC. 无论我尝试了多少次,我都无法在手机和PC之间建立连接。 Android application works fine, since it can push the NDEF message through other phones, but when it comes to connecting with the pc, it doesn't work. Android应用程序工作正常,因为它可以通过其他手机推送NDEF消息,但是当涉及到与PC连接时,它不起作用。 Led on the reader changes color from red to blinking green and orange when I touch the phone to the reader, but nothing else happens. 当我将手机触摸到阅读器时,阅读器上的颜色从红色变为闪烁的绿色和橙色,但没有其他任何事情发生。

There is the log output from the ismb-npp-java application: ismb-npp-java应用程序有日志输出:

Get factory 去工厂

Get terminals 获得终端

Terminal name: ACS ACR122 0 终端名称:ACS ACR122 0

T=1 T = 1

Called rightProcedureTarget.. 被称为rightProcedureTarget ..

[DEBUG] {sending [50 bytes]} 0xFF 0x00 0x00 0x00 0x2D 0xD4 0x8C 0x01 0x00 0x00 0x00 0x00 >0x00 0x40 0x01 0xFE 0x0F 0xBB 0xBA 0xA6 0xC9 0x89 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 >0xFF 0xFF 0x01 0xFE 0x0F 0xBB 0xBA 0xA6 0xC9 0x89 0x00 0x00 0x06 0x46 0x66 0x6D 0x01 0x01 >0x10 0x00 [DEBUG] {发送[50字节]} 0xFF 0x00 0x00 0x00 0x2D 0xD4 0x8C 0x01 0x00 0x00 0x00 0x00> 0x00 0x40 0x01 0xFE 0x0F 0xBB 0xBA 0xA6 0xC9 0x89 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00> 0xFF 0xFF 0x01 0xFE 0x0F 0xBB 0xBA 0xA6 0xC9 0x89 0x00 0x00 0x06 0x46 0x66 0x6D 0x01 0x01> 0x10 0x00

it.ismb.npp.IsmbNppException: problem with transmitting data it.ismb.npp.IsmbNppException:传输数据的问题

[DEBUG] {sending [7 bytes]} 0xFF 0x00 0x00 0x00 0x02 0xD4 0x86 [DEBUG] {发送[7字节]} 0xFF 0x00 0x00 0x00 0x02 0xD4 0x86

[DEBUG] {sending [26 bytes]} 0xFF 0x00 0x00 0x00 0x15 0xD4 0x8E 0x05 0x20 0x06 0x0F 0x63 >0x6F 0x6D 0x2E 0x61 0x6E 0x64 0x72 0x6F 0x69 0x64 0x2E 0x6E 0x70 0x70 [DEBUG] {发送[26字节]} 0xFF 0x00 0x00 0x00 0x15 0xD4 0x8E 0x05 0x20 0x06 0x0F 0x63> 0x6F 0x6D 0x2E 0x61 0x6E 0x64 0x72 0x6F 0x69 0x64 0x2E 0x6E 0x70 0x70

at it.ismb.npp.IsmbNppConnection.transceive(IsmbNppConnection.java:281) at it.ismb.npp.IsmbNppConnection.transceive(IsmbNppConnection.java:281)

at it.ismb.npp.IsmbNppConnection.rightProcedureTarget(IsmbNppConnection.java:301) at it.ismb.npp.IsmbNppConnection.rightProcedureTarget(IsmbNppConnection.java:301)

at it.ismb.npp.SenderToPhone$ThreadSender.run(SenderToPhone.java:90) at it.ismb.npp.SenderToPhone $ ThreadSender.run(SenderToPhone.java:90)

at it.ismb.npp.SenderToPhone$InitiatorTask.run(SenderToPhone.java:75) at it.ismb.npp.SenderToPhone $ InitiatorTask.run(SenderToPhone.java:75)

at java.util.TimerThread.mainLoop(Unknown Source) at java.util.TimerThread.mainLoop(Unknown Source)

at java.util.TimerThread.run(Unknown Source) 在java.util.TimerThread.run(未知来源)

it.ismb.npp.IsmbNppException: problem with transmitting data it.ismb.npp.IsmbNppException:传输数据的问题

at it.ismb.npp.IsmbNppConnection.transceive(IsmbNppConnection.java:281) at it.ismb.npp.IsmbNppConnection.transceive(IsmbNppConnection.java:281)

at it.ismb.npp.IsmbNppConnection.rightProcedureTarget(IsmbNppConnection.java:306) at it.ismb.npp.IsmbNppConnection.rightProcedureTarget(IsmbNppConnection.java:306)

at it.ismb.npp.SenderToPhone$ThreadSender.run(SenderToPhone.java:90) at it.ismb.npp.SenderToPhone $ ThreadSender.run(SenderToPhone.java:90)

at it.ismb.npp.SenderToPhone$InitiatorTask.run(SenderToPhone.java:75) at it.ismb.npp.SenderToPhone $ InitiatorTask.run(SenderToPhone.java:75)

at java.util.TimerThread.mainLoop(Unknown Source) at java.util.TimerThread.mainLoop(Unknown Source)

at java.util.TimerThread.run(Unknown Source) 在java.util.TimerThread.run(未知来源)

Exception in thread "Timer-0" java.lang.IllegalStateException: Card has been removed 线程“Timer-0”中的异常java.lang.IllegalStateException:卡已被删除

at sun.security.smartcardio.CardImpl.checkState(Unknown Source) at sun.security.smartcardio.CardImpl.checkState(Unknown Source)

at sun.security.smartcardio.ChannelImpl.checkClosed(Unknown Source) 在sun.security.smartcardio.ChannelImpl.checkClosed(未知来源)

at sun.security.smartcardio.ChannelImpl.transmit(Unknown Source) 在sun.security.smartcardio.ChannelImpl.transmit(未知来源)

at it.ismb.npp.IsmbNppConnection.transceive(IsmbNppConnection.java:263) at it.ismb.npp.IsmbNppConnection.transceive(IsmbNppConnection.java:263)

at it.ismb.npp.IsmbNppConnection.rightProcedureTarget(IsmbNppConnection.java:317) at it.ismb.npp.IsmbNppConnection.rightProcedureTarget(IsmbNppConnection.java:317)

at it.ismb.npp.SenderToPhone$ThreadSender.run(SenderToPhone.java:90) at it.ismb.npp.SenderToPhone $ ThreadSender.run(SenderToPhone.java:90)

at it.ismb.npp.SenderToPhone$InitiatorTask.run(SenderToPhone.java:75) at it.ismb.npp.SenderToPhone $ InitiatorTask.run(SenderToPhone.java:75)

at java.util.TimerThread.mainLoop(Unknown Source) at java.util.TimerThread.mainLoop(Unknown Source)

at java.util.TimerThread.run(Unknown Source) 在java.util.TimerThread.run(未知来源)

I've used all of the drivers I could find (Including the latest driver) but the problem persists. 我已经使用了我能找到的所有驱动程序(包括最新的驱动程序),但问题仍然存在。

Could there be a problem with the device? 该设备可能有问题吗? Or am I missing something here? 或者我在这里遗漏了什么?

What version of Android are you running? 您运行的是哪个版本的Android? NPP only works on older versions of Android (pre ICS, I believe). NPP仅适用于旧版本的Android(我认为是ICS之前的版本)。

For ICS and JellyBean, try using the SNEP protocol. 对于ICS和JellyBean,请尝试使用SNEP协议。 The author of the project you are using has a version for SNEP here: 您正在使用的项目的作者在这里有一个SNEP版本:

http://code.google.com/p/ismb-snep-java/ http://code.google.com/p/ismb-snep-java/

try this to get NfcAdapter 试试这个来获得NfcAdapter

nfcP2PAdapter = NfcAdapter.getDefaultAdapter(recentContext.getApplicationContext()); nfcP2PAdapter = NfcAdapter.getDefaultAdapter(recentContext.getApplicationContext());

// recentContext is activity(this) // recentContext是活动(这个)

It will work for you, it works for me 它适合你,它适合我

The error you stated is from the transceive method in NppConnection.java. 您声明的错误来自NppConnection.java中的收发方法。 I would suggest that you first place the phone on the reader (let the reader's LED turn to green), then run the application again. 我建议您先将手机放在阅读器上(让阅读器的LED变为绿色),然后再次运行应用程序。 See if this works. 看看这是否有效。 If not, put a breakpoint in the transceive method and check the values of SW1 and SW2 (if the command is successful, you would expect sw1 = 0x90 and sw2 = 0x00). 如果没有,在收发方法中放置一个断点并检查SW1和SW2的值(如果命令成功,你会期望sw1 = 0x90和sw2 = 0x00)。 In case of errors, you would get either sw2 not equal to 0x00 or sw1 = 0x63. 如果出现错误,您将获得sw2不等于0x00或sw1 = 0x63。

From my understanding, even if you are using a newer version of android and if snep is not supported by either of your devices, they will fall back to NPP. 根据我的理解,即使你使用更新版本的android,如果你的任何一个设备都不支持snep,它们也会回归到NPP。

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

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