Hardware Reference
In-Depth Information
Continued from opposite page.
String responseString = "";
if (lastResponse != null) {
for (int b = 0; b < lastResponse.length; b++) {
responseString += hex(lastResponse[b], 2);
responseString += " ";
}
// wrap the full text so it doesn't overflow the buttons
// and make the screen all messy:
text("Full response:\n" + responseString, 10, 150, 300, 200);
}
// print any error messages from the reader:
text(myReader.getErrorMessage(), 10, 210);
// print the last message read from the tag:
text("last message read from tag:\n" + message, 10, 230);
// print the output message:
text("type your message to write to tag:\n", 10, 300);
fill(userText);
text(outputString, 10, 320);
// show the library version:
fill(0);
text("SonMicroReader version: " + myReader.version(),
width - 300, height - 30);
}
8
TheSonMicroReader library uses
the Serial library to communicate with
the reader—like the Serial library—it
generates an event when new data
is available. sonMicroEvent() occurs
whenever there's a response from the
reader. In this sketch, you read all the
parts of the response in the sonMi-
croEvent() method, including the tag
number, tag type, any data returned
from reading a memory block, the
antenna status, and more.
/*
This function is called automatically whenever there's
a valid packet of data from the reader
*/
void sonMicroEvent(SonMicroReader myReader) {
// get all the relevant data from the last data packet:
lastCommand = myReader.getCommand();
lastTagType = myReader.getTagType();
lastPacketLength = myReader.getPacketLength();
lastTag = myReader.getTagString();
lastErrorCode = myReader.getErrorCode();
lastAntennaPower = myReader.getAntennaPower();
lastResponse = myReader.getSonMicroReading();
lastChecksum = myReader.getCheckSum();
// if the last command sent was a read block command:
if (lastCommand == 0x86) {
int[] inputString = myReader.getPayload();
message = "";
for (int c = 0; c < inputString.length; c++) {
message += char(inputString[c]);
}
}
 
Search WWH ::




Custom Search