2015-07-25 9 views
5

Sto sviluppando un'applicazione per il lettore portatile RFID Motorola MC9190.E 'possibile scrivere e leggere caratteri ASCII nel tag RFID UHF?

Ho bisogno di leggere e scrivere le informazioni come leggibile dall'uomo nel tag RFID UHF. Così ho deciso di scrivere informazioni in caratteri ASCII.

Durante alcune ricerche, ho scoperto che è possibile scrivere caratteri ASCII nella memoria dei tag RFID ma supporta meno caratteri. Non mi dispiacerebbe finché non sarà inferiore a 10 caratteri.

riferimenti:

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

Ora, io sono po 'confuso come faccio a scrivere e leggere di caratteri ASCII direttamente nel lettore.

Questo è il codice per la scrittura in caratteri esadecimali.

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 = "ABCDEF";  //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); 
    } 
} 

Se voglio scrivere in ASCII, dovrebbe essere codificato come byte ASCII credo. Quindi, invece di for loop, se sostituisco il codice seguente, scriverò correttamente?

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

Dal momento che non ho il lettore con me, non potevo in grado di testare ora.

Se si ottiene il successo, durante la lettura del tag, come posso configurare il lettore per decodificare come carattere ASCII e visualizzarlo o devo convertire a livello di programmazione?

Dato che sono nuovo della tecnologia RFID, non sono sicuro di aver svolto correttamente la ricerca. Perfavore, correggimi se sbaglio.

+1

Il codice si mostra non funziona, si aspetta 'dataToWrite' di essere una stringa esadecimale, che "CIAOMONDO" non è. Il metodo Encoding.GetBytes() ti darà i byte che formano la stringa nella codifica data, sì. Il contrario viene fatto tramite Encoding.GetString(), usando la stessa codifica usata per la codifica. – CodeCaster

+0

Oops. hai ragione. Vedi la mia modifica. –

+0

Allora, hai letto il resto del mio commento? Qual è la tua domanda? – CodeCaster

risposta

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

Si può anche dare un'occhiata a questo SDK qui: http://www.tsl.uk.com/2013/07/tsls-ios-uhf-ascii-2-0-sdk-v0-8-1-now-available/

TSLAsciiCommands.framework - una serie di facili da utilizzare le classi C Obiettivo incapsulare l'ASCII TSL UHF protocollo 2.0 fornito come un universale quadro statico che può essere utilizzato con entrambi i dispositivi iOS e il simulatore iOS - TSL ASCII 2.0 SDK Documentazione - disponibile come Documentation Index per l'integrazione all'interno di Xcode e in formato HTML - Quick-start campione progetti Xcode


Se si utilizza il framework TSLAsciiCommands è possibile fare qualcosa di simile.

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

o

// 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); 
+0

vuoi dire che dovrei includere tilde prima dei dati come string dataToWrite = "~ HELLOWORLD"; –

+0

Si prega di consultare la modifica. – tymac

+0

Non capisco il tuo primo codice. E non sto usando il framework TSLAsciiCommands. puoi spiegare la risposta chiaramente? Questo è ciò di cui ho bisogno Desidero alimentare le informazioni come carattere ASCII nei tag UHF –

Problemi correlati