【发布时间】:2014-06-21 05:42:14
【问题描述】:
我希望能够将 NDEF 格式的 URI 发送到我的 Arduino UNO,它连接到 Sony 的 RC-S801 动态 NFC 标签。我使用 Hercules 设置实用程序发送
"100101000300000000000000001b0030d102165370d1011255017374757474676172742e736f6e792e64650000000000"
作为http://www.stuttgart.sony.de 的十六进制字符串,我能够从启用 NFC 的手机中读取它。但是当我使用以下python代码时,它不起作用:
import serial
import time
arduino = serial.Serial('COM6', 115200)
arduino.parity = 'M'
print arduino
print("writing")
input = ("100101000300000000000000001b0030d102165370d1011255017374757474676172742e736f6e792e64650000000000")
arduino.write(input)
time.sleep(5)
print("stopped writing")
arduino.close()
它显示为一个空记录。任何人都可以建议我应该对我的 python 代码进行更改以检测 NDEF 消息吗?这是我从手机读取标签时收到的消息的屏幕截图:
这是我的arduino代码:
#include <EEPROM.h>
#define BUTTON_PIN 8 // Arduino Digital I/O pin where button is connected
#define NUM_OF_BLOCKS 14 // capacity of NFC Tag in 16-byte blocks
#include "FeliCaPlug.h"
#include <avr/pgmspace.h> <
#include <inttypes.h>
FeliCaPlug plug;
volatile byte dataStorage[NUM_OF_BLOCKS*16] = {
// TT3 Attribute block + NDEF Message Text Message
0x10, 0x04, 0x01, 0x00, 0x0d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x03, 0x00, 0x26,
0xd0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
};
uint8_t blockData[NUM_OF_BLOCKS*16];
volatile uint8_t blinkCount = 1;
uint16_t numOfBlocks = NUM_OF_BLOCKS;
volatile boolean dataChanged = false;
void setup()
{
Serial.begin(115200);
uint8_t dfc[2] = {0xff, 0xe0};
uint8_t userParam[4] = {0x01, 0x23, 0x45, 0x67};
plug.initPort();
plug.setParam(FELICA_PLUG_MODE_TYPE3, dfc, userParam);
plug.setLEDPin(FELICA_PLUG_LED_PIN);
for(int i = 0; i< NUM_OF_BLOCKS*16; i++)
blockData[i] = dataStorage[i];
plug.setBlockData(blockData, numOfBlocks, 0);
plug.setFTWriteCallback(ftWriteCallback); // initialize write callback
}
void loop()
{
getFromUart();
plug.doLoop();
Serial.print(":");
if(dataChanged){
while(dataChanged)
{
Serial.println("NFC WRITING IN PROGRESS");
// if the WriteF flag is OFF, writing type3 tag data has completed
if(blockData[9] == 0x00)
{
Serial.println("NFC WRITING IS DONE"); //let's print complete memory written by external writer
Serial.println("Recieved data from External writer:");
Serial.println("<RAW_MEM>");
for(int i = 0; i< NUM_OF_BLOCKS*16; i++)
{
Serial.print(blockData[i], HEX);
}
Serial.println("</RAW_MEM>");
}
//let's blink
digitalWrite(FELICA_PLUG_LED_PIN, LOW);
delay(50);
digitalWrite(FELICA_PLUG_LED_PIN, HIGH);
if(--blinkCount==0) dataChanged = false;
}
digitalWrite(FELICA_PLUG_LED_PIN, HIGH);
delay(50);
}
}
byte index = 0;
void getFromUart()
{
if(Serial.available() > 0)
{
while(Serial.available() > 0)
{
byte data = Serial.read();
dataStorage[index] = data;
blockData[index] = dataStorage[index];
plug.setBlockData(blockData, numOfBlocks, 0);
index++;
}
Serial.flush();
Serial.println("Recieved data from UART:");
Serial.println("<RAW_MEM>");
for(int i = 0; i< NUM_OF_BLOCKS*16; i++)
{
Serial.print(blockData[i], HEX);
}
Serial.println("</RAW_MEM>");
}
index = 0;
}
void ftWriteCallback(uint16_t blockNum, uint8_t* data)
{
// if the WriteF flag is 0x00, writing type3 tag data has started
if(blockData[9] == 0x00)
{
Serial.println("NFC WRITING STARTED");
}
dataChanged=true;
blinkCount=1;
memcpy(blockData+blockNum*16, data, 16);
}
【问题讨论】:
-
在 Hercules 设置实用程序中发送时使用哪些参数?
-
我只发送十六进制数据,比如“100101000300000000000000001b0030d102165370d1011255010000000000676f6f676c652e636f6d00000000000000000000”。 i.imgur.com/8W3gBKP.jpg[/IMG] - 这是 hercules 设置工具的截图
标签: python arduino format nfc ndef