我无法可靠地获得PN532来响应固件信息命令以外的命令。我正在Windows上使用HSU,并使用从Adafruit及其开发板的v1.6获得的FTDI电缆。
黑色读数来自ReadFile
呼叫超时,它设置为20,并且禁用了所有流控制内容。
我不认为这是电缆,因为唤醒和固件版本的内容是有效的,并且每次都可以工作。
串行端口开放代码:
// Open the COM port
HANDLE commHandle = CreateFile(
"\\\\.\\COM5",
GENERIC_READ | GENERIC_WRITE,
0,
null,
OPEN_EXISTING,
0,
null
);
// Get the existing settings
DCB serialSettings;
GetCommState(
commHandle,
&serialSettings
);
// Page 26 of the User Manual specifies these settings
serialSettings.BaudRate = CBR_115200;
serialSettings.ByteSize = 8;
serialSettings.StopBits = ONESTOPBIT;
serialSettings.Parity = NOPARITY;
// These did not make it any better or worse
serialSettings.fParity = false;
serialSettings.fOutxCtsFlow = false;
serialSettings.fOutxDsrFlow = false;
serialSettings.fDtrControl = DTR_CONTROL_DISABLE;
serialSettings.fDsrSensitivity = false;
serialSettings.fTXContinueOnXoff = true;
serialSettings.fOutX = false;
serialSettings.fInX = false;
serialSettings.fErrorChar = false;
serialSettings.fNull = false;
serialSettings.fRtsControl = RTS_CONTROL_DISABLE;
serialSettings.fAbortOnError = false;
// Setup the state
SetCommState(
commHandle,
&serialSettings
);
// Clean out any buffers or flags
PurgeComm(
commHandle,
PURGE_RXCLEAR | PURGE_RXCLEAR | PURGE_TXABORT | PURGE_TXCLEAR
);
使用从输出参数获得的大小来写入HANDLE
和从中读取数据。
Write: 55 55 00 00 00 00 00 00 00 00 FF 02 FE D4 02 2A 00
Read: 00 00 FF 00 FF 00 00 00 FF 06 FA D5 03 32 01 06 07 E8 00
Write: 00 00 FF 00 FF 00
Write: 00 00 FF 05 FB D4 14 01 14 01 02 00
Read:
Write: 00 00 FF 05 FB D4 14 01 14 01 02 00
Read:
Write: 00 00 FF 05 FB D4 14 01 14 01 02 00
Read:
Write: 00 00 FF 05 FB D4 14 01 14 01 02 00
Read:
Write: 00 00 FF 05 FB D4 14 01 14 01 02 00
Read:
Write: 00 00 FF 05 FB D4 14 01 14 01 02 00
Read:
Write: 00 00 FF 05 FB D4 14 01 14 01 02 00
Read:
Write: 00 00 FF 05 FB D4 14 01 14 01 02 00
Read:
Read:
编辑: 这似乎仅在Windows上发生,我在Debian上尝试了相同的过程,并且运行良好。我为此使用Java,因此我只需要重写本机,这样通信本身就可以正常工作。这对我来说很奇怪。