是否可以在UHF RFID标签中写入和读取ASCII字符?

时间:2015-07-25 19:57:49

标签: c# encoding rfid windows-embedded motorola-emdk

我正在开发摩托罗拉MC9190 RFID手持阅读器的应用程序。

我需要在UHF RFID标签中读取和写入人类可读的信息。所以我决定用ASCII字符写信息。

在进行一些研究时,我发现可以在RFID标签存储器中写入ASCII字符,但它支持较少的字符。我不介意,直到它少于10个字符。

的引用:

https://support.tracerplus.com/index.php?/Knowledgebase/Article/View/199/15/encoding-rfid-tags-with-ascii-values-vs-hexadecimal-values-whats-the-difference

http://blog.atlasrfidstore.com/types-of-memory-in-gen-2-uhf-rfid-tags

现在,我有点困惑如何直接在阅读器中编写和读取ASCII字符。

这是用十六进制字符书写的代码。

background-size: cover; 

如果我想用ASCII编写,我猜它应该编码为ASCII字节。因此,如果我替换以下代码而不是for循环,它会成功写入吗?

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字符并显示它或我是否需要以编程方式进行转换?

由于我是RFID技术的新手,我不确定我是否正确地进行了研究。如果我错了,请纠正我。

1 个答案:

答案 0 :(得分:0)

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格式集成的docset提供 - 快速启动示例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('\0','-') +
Environment.NewLine +
"Input tag data: " +
tagDataStr +
Environment.NewLine +
"Read tag data: " +
ASCIIEncoding.ASCII.GetString(readTagData).Replace('\0', '-').Substring(0,bytesRead) +
Environment.NewLine;

MessageBox.Show(results);