Frequently Asked Question

How to Modify PC Value in UHF Tags?
Last Updated 1 days ago

⚠️ WARNING: Incorrectly modifying the PC (Protocol Control) value can lead to severe consequences.
If an incorrect length is set or data overwrites wrong memory addresses (e.g., CRC or EPC data body), the tag may become unreadable/unidentifiable by reader devices, or cause tag data corruption and loss.
Before proceeding with modifications, please verify that the write offset and PC value calculations are correct!

1. Important Notes

  • start / offset unit is Word (2 Bytes): When modifying the PC value, you MUST set this parameter to 1. Passing an incorrect value will overwrite the CRC or the EPC data body.
  • epc parameter is used to "target/locate the tag": Passing an incorrect EPC value will result in a "Tag Not Found" error.
  • Modifying PC does NOT automatically clear/pad EPC data: After extending the declared length, the reader will read residual data following the tag memory. If full rewriting is required, separately write data starting at offset = 2.

2. Parameter Comparison Table

Parameter Data Type V1 Support V2 Support Description & Notes
password byte[] Access Password
• Fixed length of 4 bytes.
• Pass new byte[4] (all zeroes) or null if the tag is not password-locked.
epc byte[] Current EPC of the target tag
• Used to send Select commands to locate the tag over the air.
• ⚠️ Must match the actual current EPC of the tag.
bank RFIDMemoryBank Target Memory Bank
• Always pass RFIDMemoryBank.EPC when modifying PC.
• ⚠️ Do NOT pass RFIDMemoryBank.Err.
start (or offset) int Starting Word Offset
• Measured in 16-bit Words (2 bytes), NOT Bytes!
0 = CRC-16 (Do not modify)
1 = PC Value (Fixed at 1 for PC modifications)
2 or higher = EPC Data Body
retry int Retry Count
• Automatic retry attempts upon weak communication. Recommended setting: 1 ~ 3 times.
data (or pcData) byte[] PC Value to Write (2 bytes)
• Big-Endian format.
• Example: For 96-bit length, pass {0x30, 0x00}.
• Safe calculation formula: (wordCount << 11) | (oldPC & 0x07FF)
timeoutMilliseconds int Single Operation Timeout (ms)
• Exclusive to V2.
• Recommended setting: 3000 ~ 5000 (3–5 seconds).

3. API V1 vs V2 Core Method Comparison

Item API V1 API V2
Class Name com.cipherlab.rfidapi.RfidManager com.cipherlab.rfidapi2.RfidManager2
Method Name RFIDDirectWriteTagByEPC (PascalCase) rfidDirectWriteTagByEPC (camelCase)
Return Type DeviceResponse (OperationSuccess indicates success) int (0 indicates success)
Error Message mRfidManager.GetLastError() mRfidManager2.getLastError()
Timeout N/A timeoutMilliseconds (ms)

4. API V1 Complete Method & Example

Method Signature

public DeviceResponse RFIDDirectWriteTagByEPC(
    byte[] password, 
    byte[] epc, 
    RFIDMemoryBank bank, 
    int start, 
    int retry, 
    byte[] data
);

Example Code (Setting PC Length to 96-bit)

// 1. Prepare parameters
byte[] password = new byte[4];                        // 4 zero-bytes for unlocked tag
byte[] currentEpc = hexToBytes("300833B21111222233334444"); // Target tag's actual current EPC (for targeting)
RFIDMemoryBank bank = RFIDMemoryBank.EPC;             // Specify EPC Bank (Fixed value)
int start = 1;                                        // Word Offset = 1 (Points to PC address)
int retry = 3;                                        // Retry 3 times
byte[] pcData = new byte[] {(byte)0x30, (byte)0x00};  // New PC value (0x3000 = 96-bit length)

// 2. Execute write
DeviceResponse response = mRfidManager.RFIDDirectWriteTagByEPC(
    password,
    currentEpc,
    bank,
    start,
    retry,
    pcData
);

// 3. Handle response
if (response == DeviceResponse.OperationSuccess) {
    Log.i("RFID", "V1 Write PC Successful!");
} else {
    String errorMsg = mRfidManager.GetLastError();
    Log.e("RFID", "V1 Write Failed, Reason: " + errorMsg);
}

5. API V2 Complete Method & Example

Method Signature

public int rfidDirectWriteTagByEPC(
    byte[] password, 
    byte[] epc, 
    RFIDMemoryBank bank, 
    int start, 
    int retry, 
    byte[] data, 
    int timeoutMilliseconds
);

Example Code

new Thread(new Runnable() {
    @Override
    public void run() {
        // 1. Prepare parameters
        byte[] password = new byte[4];                        // 4 zero-bytes for unlocked tag
        byte[] currentEpc = hexToBytes("300833B21111222233334444"); // Target tag's actual current EPC
        RFIDMemoryBank bank = RFIDMemoryBank.EPC;             // Specify EPC Bank
        int start = 1;                                        // Word Offset = 1 (Points to PC address)
        int retry = 3;                                        // Retry 3 times
        byte[] pcData = new byte[] {(byte)0x30, (byte)0x00};  // New PC value (0x3000)
        int timeout = 5000;                                   // Timeout set to 5000 ms (5 seconds)

        // 2. Execute write
        int result = mRfidManager2.rfidDirectWriteTagByEPC(
            password,
            currentEpc,
            bank,
            start,
            retry,
            pcData,
            timeout
        );

        // 3. Handle response
        if (result == 0) {
            Log.i("RFID", "V2 Write PC Successful!");
        } else {
            String errorMsg = mRfidManager2.getLastError();
            Log.e("RFID", "V2 Write Failed, Code: " + result + ", Reason: " + errorMsg);
        }
    }
}).start();

Please Wait!

Please wait... it will take a second!