dotnet / dotnet/iot

PN532 binding does not work correctly when configured "AsTarget"

Open
#2,029 1 comment 0 reactions 1 assignee Claimed by @Ellerbach View on GitHub
area-device-bindings bug Priority:2
Dominant language
C#
Stars
2.4k
Forks
630
Avg merge
7d 11h
Merged PRs (30d)
3

Description

The physical device is a PN532 board from Elechouse similar to [this one](https://www.elechouse.com/elechouse/images/product/PN532_module_V3/PN532_%20Manual_V3.pdf)

The code used to test the device (with a Raspberry PI) is [the one published at the binding page](https://github.com/dotnet/iot/blob/a0db92f8c766771434095662ce2a0c0e47bec24c/src/devices/Pn532/README.md#pn532-as-a-target)

The nuget packages in the test project are the following:
```




```

I made the tests using both the I2C and the RS232 connections. In both cases the communication breaks:
- the I2C communication breaks and the device needs to be reset before re-testing it
- the RS232 communication breaks after a while but still shows a timeout communication error

**Log using the I2C**
```
Mifare
08-00-00-00-00-60
feliCa
01-FE-A2-A3-A4-A5-A6-A7-C0-C1-C2-C3-C4-C5-C6-C7-FF-FF
picc
AA-99-88-77-66-55-44-33-22-11-00-00
Before WriteCommand(TgInitAsTarget)WriteCommand: CommandSet TgInitAsTarget
Bytes to send: 04-08-00-00-00-00-60-01-FE-A2-A3-A4-A5-A6-A7-C0-C1-C2-C3-C4-C5-C6-C7-FF-FF-AA-99-88-77-66-55-44-33-22-11-00-00
W> 00-FF-27-D9-D4-8C-04-08-00-00-00-00-60-01-FE-A2-A3-A4-A5-A6-A7-C0-C1-C2-C3-C4-C5-C6-C7-FF-FF-AA-99-88-77-66-55-44-33-22-11-00-00-99
Before ReadResponse(TgInitAsTarget)WriteCommand: CommandSet SetParameters
Bytes to send: 20
W> 00-FF-03-FD-D4-12-20-FA
Mifare
08-00-00-00-00-60
feliCa
01-FE-A2-A3-A4-A5-A6-A7-C0-C1-C2-C3-C4-C5-C6-C7-FF-FF
picc
AA-99-88-77-66-55-44-33-22-11-00-00
Before WriteCommand(TgInitAsTarget)WriteCommand: CommandSet TgInitAsTarget
Bytes to send: 04-08-00-00-00-00-60-01-FE-A2-A3-A4-A5-A6-A7-C0-C1-C2-C3-C4-C5-C6-C7-FF-FF-AA-99-88-77-66-55-44-33-22-11-00-00
W> 00-FF-27-D9-D4-8C-04-08-00-00-00-00-60-01-FE-A2-A3-A4-A5-A6-A7-C0-C1-C2-C3-C4-C5-C6-C7-FF-FF-AA-99-88-77-66-55-44-33-22-11-00-00-99
Before ReadResponse(TgInitAsTarget)WriteCommand: CommandSet SetParameters
Bytes to send: 20
W> 00-FF-03-FD-D4-12-20-FA
Mifare
08-00-00-00-00-60
feliCa
01-FE-A2-A3-A4-A5-A6-A7-C0-C1-C2-C3-C4-C5-C6-C7-FF-FF
picc
AA-99-88-77-66-55-44-33-22-11-00-00
Before WriteCommand(TgInitAsTarget)WriteCommand: CommandSet TgInitAsTarget
Bytes to send: 04-08-00-00-00-00-60-01-FE-A2-A3-A4-A5-A6-A7-C0-C1-C2-C3-C4-C5-C6-C7-FF-FF-AA-99-88-77-66-55-44-33-22-11-00-00
W> 00-FF-27-D9-D4-8C-04-08-00-00-00-00-60-01-FE-A2-A3-A4-A5-A6-A7-C0-C1-C2-C3-C4-C5-C6-C7-FF-FF-AA-99-88-77-66-55-44-33-22-11-00-00-99
Before ReadResponse(TgInitAsTarget)Unhandled exception. System.IO.IOException: Error 5 performing I2C data transfer.  
at System.Device.I2c.UnixI2cBus.WriteReadCore(UInt16 deviceAddress, Byte* writeBuffer, Byte* readBuffer, UInt16 writeBufferLength, UInt16 readBufferLength)   at System.Device.I2c.UnixI2cBus.Read(Int32 deviceAddress, Span`1 buffer)  
at TestNfc.Pn532.ReadResponseI2C(CommandSet commandSet, Span`1 readData) in H:\dev.git\libraries\SipLibrary\src\SipLibrarySolution\TestNfc\Pn532.cs:line 2000  
at TestNfc.Pn532.InitAsTarget(TargetModeInitialization mode, TargetMifareParameters mifare, TargetFeliCaParameters feliCa, TargetPiccParameters picc) in H:\dev.git\libraries\SipLibrary\src\SipLibrarySolution\TestNfc\Pn532.cs:line 923  
at TestNfc.Program.AsTarget(Pn532 pn532) in H:\dev.git\libraries\SipLibrary\src\SipLibrarySolution\TestNfc\Program.cs:line 68  
at TestNfc.Program.Start() in H:\dev.git\libraries\SipLibrary\src\SipLibrarySolution\TestNfc\Program.cs:line 59  
at TestNfc.Program.Main(String[] args) in H:\dev.git\libraries\SipLibrary\src\SipLibrarySolution\TestNfc\Program.cs:line 25
Aborted
```

**Log using the RS232**
```
01-FE-A2-A3-A4-A5-A6-A7-C0-C1-C2-C3-C4-C5-C6-C7-FF-FFpiccAA-99-88-77-66-55-44-33-22-11-00-00
Before WriteCommand(TgInitAsTarget)WriteCommand: CommandSet TgInitAsTarget Bytes to send: 04-08-00-00-00-00-60-01-FE-A2-A3-A4-A5-A6-A7-C0-C1-C2-C3-C4-C5-C6-C7-FF-FF-AA-99-88-77-66-55-44-33-22-11-00-00
Before ReadResponse(TgInitAsTarget)
Unhandled exception. System.TimeoutException: The operation has timed out.   at System.IO.Ports.SerialStream.Read(Byte[] array, Int32 offset, Int32 count, Int32 timeout)  
at System.IO.Ports.SerialPort.ReadByte()  
at TestNfc.Pn532.ReadResponseSerial(CommandSet commandSet, Span`1 readData) in H:\dev.git\libraries\SipLibrary\src\SipLibrarySolution\TestNfc\Pn532.cs:line 1786  
at TestNfc.Pn532.ReadResponse(CommandSet commandSet, Span`1 readData) in H:\dev.git\libraries\SipLibrary\src\SipLibrarySolution\TestNfc\Pn532.cs:line 1747  
at TestNfc.Pn532.InitAsTarget(TargetModeInitialization mode, TargetMifareParameters mifare, TargetFeliCaParameters feliCa, TargetPiccParameters picc) in H:\dev.git\libraries\SipLibrary\src\SipLibrarySolution\TestNfc\Pn532.cs:line 932  
at TestNfc.Program.AsTarget(Pn532 pn532) in H:\dev.git\libraries\SipLibrary\src\SipLibrarySolution\TestNfc\Program.cs:line 70  
at TestNfc.Program.Start() in H:\dev.git\libraries\SipLibrary\src\SipLibrarySolution\TestNfc\Program.cs:line 61  
at TestNfc.Program.Main(String[] args) in H:\dev.git\libraries\SipLibrary\src\SipLibrarySolution\TestNfc\Program.cs:line 26
Aborted
```

The logs have been instrumented with additional `Console.WriteLine`. This caused the slow to exhibit some delays and caused some improvements (the exception was visible after a while) but did not resolve the issue.

I already discussed the issue with @Ellerbach (the original author) and made multiple tests with him to verify what was going on.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.