5

I am developing an application for Motorola MC9190 RFID handheld reader.

I am in need of reading and writing information as human-readable in UHF RFID tag. So I decided to write information in ASCII characters.

On doing some research, I found that it is possible to write ASCII character in RFID tag memory but it supports less characters. I wouldn't mind until it is less than 10 characters.

references:

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

Now, I am little bit confused how do I write and read ASCII character directly in reader.

This is the code for writing in hexadecimal character.

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);
    }
 }

If I want to write in ASCII, it should be encoded as ASCII bytes I guess. So instead of for loop, if I replace the following code, will it write successfully?

string dataToWrite="HELLOWORLD";
byte[] writeData = ASCIIEncoding.ASCII.GetBytes(dataToWrite);

Since I don't have the reader with me, I could not able to test now.

If it gets success, when reading the tag, how can I configure the reader to decode as ASCII character and display it or should I need to convert programmatically?

Since I am new to RFID technology, I am not sure I have done the research correctly. Please correct me if I am wrong.

CST RAIZE
  • 428
  • 1
  • 5
  • 18
  • 1
    The code you show won't work, it expects `dataToWrite` to be a hex string, which "HELLOWORLD" is not. The Encoding.GetBytes() method will give you the bytes that form the string in the given encoding, yes. The reverse is done through Encoding.GetString(), using the same Encoding as used for encoding. – CodeCaster Jul 26 '15 at 22:59
  • Oops. you are right. See my edit. – CST RAIZE Jul 27 '15 at 05:24
  • So, did you read the rest of my comment? What is your question? – CodeCaster Jul 27 '15 at 06:19
  • Same answer given by @tymac I will check with the reader and will tell you soon. – CST RAIZE Jul 27 '15 at 07:28

1 Answers1

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; 
}
}

You can also take a look at this SDK here: http://www.tsl.uk.com/2013/07/tsls-ios-uhf-ascii-2-0-sdk-v0-8-1-now-available/

TSLAsciiCommands.framework - a set of easy-to-use Objective C classes encapsulating the TSL UHF ASCII 2.0 protocol provided as a universal static framework that can be used with both iOS devices and the iOS simulator - TSL ASCII 2.0 SDK Documentation – available as a docset for integration within Xcode and in HTML format - Quick-start Sample Xcode Projects


If you use the TSLAsciiCommands framework you can do something like this.

-(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];
}
}

or

// 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);
Edison
  • 11,881
  • 5
  • 42
  • 50
  • do you mean I should include tilde before the data like string dataToWrite="~HELLOWORLD"; – CST RAIZE Jul 25 '15 at 20:39
  • I don't understand your first code. And I am not using TSLAsciiCommands framework. can you please explain the answer clearly? This is what is my need I want to feed information as ASCII character in UHF tags – CST RAIZE Jul 26 '15 at 15:41
  • That makes sense. let me try and will tell the result soon. – CST RAIZE Jul 27 '15 at 05:29
  • Yes. It is working. string tagDataStr = "HELLO WORLD!"; byte[] writeData = ASCIIEncoding.ASCII.GetBytes(tagDataStr); m_WriteParams.WriteData = writeData; To retrieve ASCII string from HEX Value. Referred this link http://stackoverflow.com/questions/5613279/c-sharp-hex-to-ascii And yeah. It is working fine. :) – CST RAIZE Jul 31 '15 at 17:16