是否可以在 UHF RFID 标签中写入和读取 ASCII 字符?
Is it possible to write and read ASCII character in UHF RFID tag?
我正在为摩托罗拉 MC9190 RFID 手持设备开发应用程序 reader。
我需要在 UHF RFID 标签中读写人类可读的信息。所以我决定用ASCII字符写信息。
在做一些研究时,我发现可以在RFID标签内存中写入ASCII字符,但它支持的字符较少。不超过10个字符我不介意。
参考文献:
http://blog.atlasrfidstore.com/types-of-memory-in-gen-2-uhf-rfid-tags
现在,我有点困惑如何在 reader 中直接写入和读取 ASCII 字符。
这是十六进制字符写入的代码。
private void writeButton_Click(object sender, EventArgs e)
{
string dataToWrite="ABCDEF9876";
Symbol.RFID3.TagAccess.WriteAccessParams m_WriteParams;
m_WriteParams.AccessPassword = 0;
m_WriteParams.MemoryBank = MEMORY_BANK.MEMORY_BANK_USER;
m_WriteParams.ByteOffset = 0;
m_WriteParams.WriteDataLength = 6;
byte[] writeData = new byte[m_WriteParams.WriteDataLength];
for (int index = 0; index < m_WriteParams.WriteDataLength; index += 2)
{
writeData[index] = byte.Parse(dataToWrite.Substring(index * 2, 2),
System.Globalization.NumberStyles.HexNumber);
writeData[index + 1] = byte.Parse(dataToWrite.Substring((index + 1) * 2, 2),
System.Globalization.NumberStyles.HexNumber);
}
m_WriteParams.WriteData = writeData;
string m_SelectedTagID = "0123456789ABCDEF"; //for example
RunWriteOperation(m_SelectedTagID,m_WriteParams);
}
void RunWriteOperation(string m_SelectedTagID,Symbol.RFID3.TagAccess.WriteAccessParams m_WriteParams)
{
if (m_SelectedTagID != String.Empty)
{
m_ReaderAPI.Actions.TagAccess.WriteWait(m_SelectedTagID,m_WriteParams, null);
}
}
如果我想用ASCII 写,我想它应该被编码为ASCII 字节。所以不用for循环,如果我换成下面的代码,能写成功吗?
string dataToWrite="HELLOWORLD";
byte[] writeData = ASCIIEncoding.ASCII.GetBytes(dataToWrite);
因为我没有reader,所以现在无法测试。
如果成功,在读取标签时,如何配置 reader 解码为 ASCII 字符并显示它,还是需要以编程方式转换?
由于我是 RFID 技术的新手,我不确定我是否正确地进行了研究。如有不妥请指正
void hex2dec(unsigned adchex,unsigned value)
{
unsigned value[4];
for(i=0;i<4;i++)
{
value[i]=adchex%10;
// value[i]=adchex%10+0x30; //for ASCII presentation
adchex=adchex/10;
}
}
您也可以在这里查看此 SDK:
http://www.tsl.uk.com/2013/07/tsls-ios-uhf-ascii-2-0-sdk-v0-8-1-now-available/
TSLAsciiCommands.framework - 一组易于使用的 Objective C 类 封装 TSL UHF ASCII 2.0 协议作为通用静态框架提供,可与 iOS 设备和 iOS 模拟器
- TSL ASCII 2.0 SDK 文档——作为文档集提供,用于 Xcode 和 HTML 格式的集成
- 快速入门示例 Xcode 项目
如果你使用 TSLAsciiCommands 框架,你可以做这样的事情。
-(void)initAndShowConnectedReader
{
if( _commander.isConnected )
{
// Display the serial number of the successfully connected unit
[self.selectReaderButton setTitle:_currentAccessory.serialNumber forState:UIControlStateNormal];
// Ensure the reader is in a known (default) state
// No information is returned by the reset command
TSLFactoryDefaultsCommand * resetCommand = [TSLFactoryDefaultsCommand synchronousCommand];
[_commander executeCommand:resetCommand];
// Notify user device has been reset
if( resetCommand.isSuccessful )
{
self.resultsTextView.text = [self.resultsTextView.text stringByAppendingString:@"Reader reset to Factory Defaults\n"];
}
else
{
self.resultsTextView.text = [self.resultsTextView.text stringByAppendingString:@"!!! Unable to reset reader to Factory Defaults !!!\n"];
}
// Update the version information for the connected reader
[_commander executeCommand:self.versionInformationCommand];
if( [self.class comparableVersionValue:self.versionInformationCommand.asciiProtocol] < [self.class comparableVersionValue:MINIMUM_ASCII_PROTOCOL_VERSION_FOR_LICENCE_KEY_COMMAND] )
{
[self updateResults:[NSString stringWithFormat:@"Reader does not support licence keys\nRequires ASCII protocol: %@\nReader ASCII protocol: %@\n",
MINIMUM_ASCII_PROTOCOL_VERSION_FOR_LICENCE_KEY_COMMAND,
self.versionInformationCommand.asciiProtocol
]];
}
[self validateReader];
}
else
{
[self.selectReaderButton setTitle:@"Tap to select reader..." forState:UIControlStateNormal];
[self updateUIState];
}
}
或
// Write data to general tag memory
string tagDataStr = "HELLO WORLD!";
byte[] tagData = ASCIIEncoding.ASCII.GetBytes(tagDataStr);
byte memBank = 0; // Different memory banks serve different purposes. See MC9190 specifications.
int addr = 0;
byte words = (byte)(tagData.Length / 2); // Words = length of msg / 2
if (UHFWriteTagData(theHandle, readerType, memBank,addr, tagData, (byte)tagData.Length, out errValue) == 0)
{
// Handle Error
}
// Read data from tag memory
byte[] readTagData = new byte[512];
int bytesRead;
if (UHFReadTagData(theHandle, readerType, memBank, addr, words, readTagData,
readTagData.Length, out bytesRead, out errValue) == 0)
{
// Handle Error
}
// Display Results
string results =
"Input tag ID: " +
tagIDStr +
Environment.NewLine +
"Read tag ID: " +
ASCIIEncoding.ASCII.GetString(readTagID).Replace('[=12=]','-') +
Environment.NewLine +
"Input tag data: " +
tagDataStr +
Environment.NewLine +
"Read tag data: " +
ASCIIEncoding.ASCII.GetString(readTagData).Replace('[=12=]', '-').Substring(0,bytesRead) +
Environment.NewLine;
MessageBox.Show(results);
我正在为摩托罗拉 MC9190 RFID 手持设备开发应用程序 reader。
我需要在 UHF RFID 标签中读写人类可读的信息。所以我决定用ASCII字符写信息。
在做一些研究时,我发现可以在RFID标签内存中写入ASCII字符,但它支持的字符较少。不超过10个字符我不介意。
参考文献:
http://blog.atlasrfidstore.com/types-of-memory-in-gen-2-uhf-rfid-tags
现在,我有点困惑如何在 reader 中直接写入和读取 ASCII 字符。
这是十六进制字符写入的代码。
private void writeButton_Click(object sender, EventArgs e)
{
string dataToWrite="ABCDEF9876";
Symbol.RFID3.TagAccess.WriteAccessParams m_WriteParams;
m_WriteParams.AccessPassword = 0;
m_WriteParams.MemoryBank = MEMORY_BANK.MEMORY_BANK_USER;
m_WriteParams.ByteOffset = 0;
m_WriteParams.WriteDataLength = 6;
byte[] writeData = new byte[m_WriteParams.WriteDataLength];
for (int index = 0; index < m_WriteParams.WriteDataLength; index += 2)
{
writeData[index] = byte.Parse(dataToWrite.Substring(index * 2, 2),
System.Globalization.NumberStyles.HexNumber);
writeData[index + 1] = byte.Parse(dataToWrite.Substring((index + 1) * 2, 2),
System.Globalization.NumberStyles.HexNumber);
}
m_WriteParams.WriteData = writeData;
string m_SelectedTagID = "0123456789ABCDEF"; //for example
RunWriteOperation(m_SelectedTagID,m_WriteParams);
}
void RunWriteOperation(string m_SelectedTagID,Symbol.RFID3.TagAccess.WriteAccessParams m_WriteParams)
{
if (m_SelectedTagID != String.Empty)
{
m_ReaderAPI.Actions.TagAccess.WriteWait(m_SelectedTagID,m_WriteParams, null);
}
}
如果我想用ASCII 写,我想它应该被编码为ASCII 字节。所以不用for循环,如果我换成下面的代码,能写成功吗?
string dataToWrite="HELLOWORLD";
byte[] writeData = ASCIIEncoding.ASCII.GetBytes(dataToWrite);
因为我没有reader,所以现在无法测试。
如果成功,在读取标签时,如何配置 reader 解码为 ASCII 字符并显示它,还是需要以编程方式转换?
由于我是 RFID 技术的新手,我不确定我是否正确地进行了研究。如有不妥请指正
void hex2dec(unsigned adchex,unsigned value)
{
unsigned value[4];
for(i=0;i<4;i++)
{
value[i]=adchex%10;
// value[i]=adchex%10+0x30; //for ASCII presentation
adchex=adchex/10;
}
}
您也可以在这里查看此 SDK: http://www.tsl.uk.com/2013/07/tsls-ios-uhf-ascii-2-0-sdk-v0-8-1-now-available/
TSLAsciiCommands.framework - 一组易于使用的 Objective C 类 封装 TSL UHF ASCII 2.0 协议作为通用静态框架提供,可与 iOS 设备和 iOS 模拟器 - TSL ASCII 2.0 SDK 文档——作为文档集提供,用于 Xcode 和 HTML 格式的集成 - 快速入门示例 Xcode 项目
如果你使用 TSLAsciiCommands 框架,你可以做这样的事情。
-(void)initAndShowConnectedReader
{
if( _commander.isConnected )
{
// Display the serial number of the successfully connected unit
[self.selectReaderButton setTitle:_currentAccessory.serialNumber forState:UIControlStateNormal];
// Ensure the reader is in a known (default) state
// No information is returned by the reset command
TSLFactoryDefaultsCommand * resetCommand = [TSLFactoryDefaultsCommand synchronousCommand];
[_commander executeCommand:resetCommand];
// Notify user device has been reset
if( resetCommand.isSuccessful )
{
self.resultsTextView.text = [self.resultsTextView.text stringByAppendingString:@"Reader reset to Factory Defaults\n"];
}
else
{
self.resultsTextView.text = [self.resultsTextView.text stringByAppendingString:@"!!! Unable to reset reader to Factory Defaults !!!\n"];
}
// Update the version information for the connected reader
[_commander executeCommand:self.versionInformationCommand];
if( [self.class comparableVersionValue:self.versionInformationCommand.asciiProtocol] < [self.class comparableVersionValue:MINIMUM_ASCII_PROTOCOL_VERSION_FOR_LICENCE_KEY_COMMAND] )
{
[self updateResults:[NSString stringWithFormat:@"Reader does not support licence keys\nRequires ASCII protocol: %@\nReader ASCII protocol: %@\n",
MINIMUM_ASCII_PROTOCOL_VERSION_FOR_LICENCE_KEY_COMMAND,
self.versionInformationCommand.asciiProtocol
]];
}
[self validateReader];
}
else
{
[self.selectReaderButton setTitle:@"Tap to select reader..." forState:UIControlStateNormal];
[self updateUIState];
}
}
或
// Write data to general tag memory
string tagDataStr = "HELLO WORLD!";
byte[] tagData = ASCIIEncoding.ASCII.GetBytes(tagDataStr);
byte memBank = 0; // Different memory banks serve different purposes. See MC9190 specifications.
int addr = 0;
byte words = (byte)(tagData.Length / 2); // Words = length of msg / 2
if (UHFWriteTagData(theHandle, readerType, memBank,addr, tagData, (byte)tagData.Length, out errValue) == 0)
{
// Handle Error
}
// Read data from tag memory
byte[] readTagData = new byte[512];
int bytesRead;
if (UHFReadTagData(theHandle, readerType, memBank, addr, words, readTagData,
readTagData.Length, out bytesRead, out errValue) == 0)
{
// Handle Error
}
// Display Results
string results =
"Input tag ID: " +
tagIDStr +
Environment.NewLine +
"Read tag ID: " +
ASCIIEncoding.ASCII.GetString(readTagID).Replace('[=12=]','-') +
Environment.NewLine +
"Input tag data: " +
tagDataStr +
Environment.NewLine +
"Read tag data: " +
ASCIIEncoding.ASCII.GetString(readTagData).Replace('[=12=]', '-').Substring(0,bytesRead) +
Environment.NewLine;
MessageBox.Show(results);