Overview
Reads data from, and writes data to, a memory bank of a specific tag, using srfidReadTag and srfidWriteTag.
Details
The tag ID is the tag's EPC as a hexadecimal string, for example one read by an inventory. Data to write is also a hexadecimal string, with four characters per 16-bit word.
In the EPC memory bank, word 0 is the CRC and word 1 is the PC. The EPC itself starts at word 2. The read below starts at word 0, so it returns the CRC, the PC and the first six words of the EPC. The write starts at word 2, so it replaces the 96-bit EPC (six words, 24 hexadecimal characters). Do not write the EPC at word 0, because that overwrites the CRC and PC words.
The write changes the tag. Use a tag you can afford to change, and note its original EPC so you can write it back. After the write, the tag answers to its new EPC, so use the new EPC as the tag ID to address it again.
-(void)accessOperationTagReadAndWrite {
/* allocate object for storing results of access operation */
srfidTagData *access_result = [[srfidTagData alloc] init];
/* id of tag to be read (the EPC, as a hexadecimal string) */
NSString *tag_id = @"E28011B0A506007D3DD17A34";
/* an object for storage of error response received from RFID reader */
NSString *error_response = nil;
/* request to read 8 words from EPC memory bank of tag specified by tag _id */
SRFID_RESULT result = [apiInstance srfidReadTag:readerID aTagID:tag_id aAccessTagData:&access_result aMemoryBank:SRFID_MEMORYBANK_EPC aOffset:0 aLength:8 aPassword:0x00 aStatusMessage:&error_response];
if (SRFID_RESULT_SUCCESS == result) {
NSLog(@"Request succeed\n");
/* check result code of access operation */
if (NO == [access_result getOperationSucceed]) {
NSLog(@"Read operation has failed with error: %@\n", [access_result getOperationStatus]);
}
else {
NSLog(@"Memory bank data: %@", [access_result getMemoryBankData]);
}
}
else if (SRFID_RESULT_RESPONSE_ERROR == result) {
NSLog(@"Error response from RFID reader: %@\n", error_response);
}
else if (SRFID_RESULT_RESPONSE_TIMEOUT == result) {
NSLog(@"Timeout occurred\n");
}
else {
NSLog(@"Request failed\n");
}
access_result = [[srfidTagData alloc] init];
error_response = nil;
/* data to be written: a new 96-bit EPC, as 24 hexadecimal characters */
NSString *data = @"ABCDEF0123456789ABCDEF01";
/* request to write a data to a EPC memory bank of tag specified by tag_id, starting at word 2 (the EPC) */
result = [apiInstance srfidWriteTag:readerID aTagID:tag_id aAccessTagData:&access_result aMemoryBank:SRFID_MEMORYBANK_EPC aOffset:2 aData:data aPassword:0x00 aDoBlockWrite:NO aStatusMessage:&error_response];
if (SRFID_RESULT_SUCCESS == result) {
NSLog(@"Request succeed\n");
/* check result code of access operation */
if (NO == [access_result getOperationSucceed]) {
NSLog(@"Write operation has failed with error: %@\n", [access_result getOperationStatus]);
}
}
else if (SRFID_RESULT_RESPONSE_ERROR == result) {
NSLog(@"Error response from RFID reader: %@\n", error_response);
}
else if (SRFID_RESULT_RESPONSE_TIMEOUT == result) {
NSLog(@"Timeout occurred\n");
}
else {
NSLog(@"Request failed\n");
}
}