Discussion Groups

[WAP3]: write 240bit EPC

This question is not answered

Hi,

I'm using the Workabout Pro 3 with the CAENA528 UHF Module.

I have allready used different power levels between 50 - 500 mW.

I split the 30 byte EPC to shorter 6 byte arrays and try to write them 

with the WriteTagData_EPC_C1G2 command, 3 retrys per partial array.

After this process I try to set the PC.

The success rate is below 50% even with the CAEN Demo Application:

"RFID CAEN Demo v 3.00".

used Code:

public bool WriteTag(byte[] epc)
{
bool tagWritten = false;
if (source0 != null)
{
CAENRFIDTag readTag = GetStrongestTag();
if (readTag != null)
{
try
{
byte[] pc = new byte[2];
GetPC(epc.Length / 2, out pc[0]);

List<byte[]> totalEPC = new List<byte[]>();

for (int i = 0; i < epc.Length; i+=6)
{
if (epc.Length - i >= 6)
{
byte[] partialEPC = new byteDevil;
Array.Copy(epc, i, partialEPC, 0, 6);
totalEPC.Add(partialEPC);
}

else
{
byte[] partialEPC = new byte[epc.Length - i];
Array.Copy(epc, i, partialEPC, 0, epc.Length - i);
if (partialEPC.Length%2 != 0)
{
byte[] makeEvenHelper = partialEPC;
partialEPC = new byte[makeEvenHelper.Length +1];
Array.Copy(makeEvenHelper, partialEPC, makeEvenHelper.Length);
}
totalEPC.Add(partialEPC);
}
}

source0.WriteTagData_EPC_C1G2(readTag, 0x01, 0x02, 0x02, pc);
Thread.Sleep(100);

int counter = 0;
bool writeSuccess = false;
foreach (byte[] item in totalEPC)
{
writeSuccess = false;
for (int i = 0; i < 3; i++)
{
if (InternalWriteTag(readTag, (short)(counter*6 + 4), item))
{
CAENRFIDTag[] tags = source0.InventoryTag();
byte[] read = new byte[item.Length];
byte[] source = tags[0].GetId();
Array.Copy(source, counter * 6, read, 0, item.Length);
if (CompareByteArrays(item, read))
{
writeSuccess = true;
break;
}
}
}

if (!writeSuccess)
{
return false;
}
Thread.Sleep(100);

readTag = GetStrongestTag();
counter++;
}

tagWritten = true;
}
catch (Exception ex)
{
tagWritten = false;
}
}
}

return tagWritten;
}

private CAENRFIDTag GetStrongestTag()
{
CAENRFIDTag readTag = null;
if (source0 != null)
{
CAENRFIDTag[] tags = null;
byte[] tempMask = new byte[16];

try
{
tags = source0.InventoryTag(tempMask, 0, 0, 1);
}
catch (Exception ex)
{
throw new RFIDReaderException("Error executing Inventory.", ex);
}

if (tags != null)
{
short rssi = 0;

foreach (CAENRFIDTag tag in tags)
{
if (tag.GetRSSI() > rssi)
{
readTag = tag;
}
}
}
}

return readTag;
}

private bool InternalWriteTag(CAENRFIDTag readTag, short address, byte[] writeBytes)
{
try
{
source0.WriteTagData_EPC_C1G2(readTag, 0x01, address, (short)writeBytes.Length, writeBytes);
return true;
}
catch (Exception)
{
return false;
}
}

private static void GetPC(int wordCount, out byte pc)
{
pc = Convert.ToByte(string.Format("{0}000", Convert.ToString(wordCount, 2).PadLeft(5, '0')), 2);
}

private bool CompareByteArrays(byte[] data1, byte[] data2)
{
// If both are null, they're equal
if (data1 == null && data2 == null)
{
return true;
}
// If either but not both are null, they're not equal
if (data1 == null || data2 == null)
{
return false;
}
if (data1.Length != data2.Length)
{
return false;
}
for (int i = 0; i < data1.Length; i++)
{
if (data1Idea != data2Idea)
{
return false;
}
}
return true;
}

All Replies