I'm using the PN532 RFID Library. I'm trying this snippet of code in the Arduino IDE to read a value off of the card. I can see it in the Serial Monitor, but I can't work out how to store it in a variable, I've tried different variations of int, char, uint8_t,uint16_t and they all resolve to 0.
nfc.PrintChar(data, 4);
This is the function being referenced in the C++ Library:
so data is a pointer to a byte buffer
the PrintChar() method receives that pointer and a number of byte to print as ASCII characters. Not all values of the ASCII table have a visual representation that's why the code checks if the byte is less or equal than 0x1F because as you can see in the table those are control codes.
(you could argue that >= 07F it's also not always printable)
so you would get a dot for those otherwise you get the ASCII representation.
so the question now is what do you want to get? a c-string equivalent to what would be printed out, a String, a shorter byte buffer? what do you want to do with it? does it hold an int or something you need to parse?
so when you call nfc.PrintChar(data, 4); you see 1001 for example and you would want to get that number
You could create a small function that gets you that number, something like
long readTagID(const byte *data, const uint32_t numBytes) {
char tempBuffer[numBytes + 1]; // create a temporary buffer enough bytes including for a trailing null char
memcpy(tempBuffer, data, numBytes); // copy the bytes
tempBuffer[numBytes] = '\0'; // add the trailing null char
return atol(tempBuffer); // parse the content as a long number and return it
}
and you would use it like this
long theTagID = readTagID(testData, 4); // testData being the payload you got from the tag