Read data from computer to arduino

Hi,

I am using arduino mega hookup adafruit RFID PN532. for detail.

Assuming i have data "TEST" keyword pass from computer to arduino hardware, how to detect the value as "TEST"
How to get the data "TEST"? I need to pass the value "TEST" to data[16] variable.

/**************************************************************************/

#define IRQ (2)
#define RESET (3) // Not connected by default on the NFC Shield

Adafruit_NFCShield_I2C nfc(IRQ, RESET);

void setup(void) {
Serial.begin(115200);

nfc.begin();

uint32_t versiondata = nfc.getFirmwareVersion();
if (! versiondata) {
Serial.print("Didn't find PN53x board");
while (1); // halt
}

// configure board to read RFID tags
nfc.SAMConfig();

}

void loop() {
uint8_t success;
uint8_t uid = { 0, 0, 0, 0, 0, 0, 0 }; // Buffer to store the returned UID
uint8_t uidLength; // Length of the UID (4 or 7 bytes depending on ISO14443A card type)

success = nfc.readPassiveTargetID(PN532_MIFARE_ISO14443A, uid, &uidLength);

if (success) {
// Display some basic information about the card
Serial.println("Found an ISO14443A card");
Serial.print(" UID Length: ");Serial.print(uidLength, DEC);Serial.println(" bytes");
Serial.print(" UID Value: ");
nfc.PrintHex(uid, uidLength);
Serial.println("");

if (uidLength == 4)
{
// Now we need to try to authenticate it for read/write access
// Try with the factory default KeyA: 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF
uint8_t keya[6] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };

// Start with block 4 (the first block of sector 1) since sector 0
// contains the manufacturer data and it's probably better just
// to leave it alone unless you know what you're doing
success = nfc.mifareclassic_AuthenticateBlock(uid, uidLength, 4, 0, keya);

if (success)
{
Serial.println("Sector 1 (Blocks 4..7) has been authenticated");
uint8_t data[16];

// If you want to write something to block 4 to test with, uncomment
// the following line and this text should be read back in a minute
//data = { 'a', 'd', 'a', 'f', 'r', 'u', 'i', 't', '.', 'c', 'o', 'm', 0, 0, 0, 0};
success = nfc.mifareclassic_WriteDataBlock (4, data);

// Try to read the contents of block 4
//success = nfc.mifareclassic_ReadDataBlock(4, data);

if (success)
{
// Data seems to have been read ... spit it out
Serial.println("Reading Block 4:");
nfc.PrintHexChar(data, 16);
Serial.println("");

// Wait a bit before reading the card again
delay(1000);
}
else
{
Serial.println("Ooops ... unable to read the requested block. Try another key?");
}
}
else
{
Serial.println("Ooops ... authentication failed: Try another key?");
}
}

}
}

Assuming i have data "TEST" keyword pass from computer to arduino hardware

I don't understand what this means. What does it have to do with the RFID? What 16 element array?

The data is array for 16 and i can define in code. But how to pass this data from .net application into here?
data = { 'a', 'd', 'a', 'f', 'r', 'u', 'i', 't', '.', 'c', 'o', 'm', 0, 0, 0, 0};

Amendment: WHen RFID card touch the RFID reader, The .net application get the value from card and passed the value to arduino .Does it make sense?

But how to pass this data from .net application

What language is the .net application written in? With C#, it's trivially simple to open the serial port at the proper baud rate, and send data to the Arduino.

What type is data?

Feel free to offer more information.

It is written in C# .net application. The communicate at 115200 baud.
I can read the data from arduino when i touch the card at arduino RFID reader/Writer. However When i key in value
"test" or "1000.00", I am sure i need to write the code to received this value in arduino right? Just gimme hint about c code to receive data. Let

However When i key in value
“test” or “1000.00”, I am sure i need to write the code to received this value in arduino right?

Having a reason to send random junk to the Arduino would be good. If you have one, state what it is.

Delimiting the packet that you send makes it easier to know when the full packet has been received. If you have start and end delimiters, you can use code like this to receive data from the serial port:

#define SOP '<'
#define EOP '>'

bool started = false;
bool ended = false;

char inData[80];
byte index;

void setup()
{
   Serial.begin(57600);
   // Other stuff...
}

void loop()
{
  // Read all serial data available, as fast as possible
  while(Serial.available() > 0)
  {
    char inChar = Serial.read();
    if(inChar == SOP)
    {
       index = 0;
       inData[index] = '\0';
       started = true;
       ended = false;
    }
    else if(inChar == EOP)
    {
       ended = true;
       break;
    }
    else
    {
      if(index < 79)
      {
        inData[index] = inChar;
        index++;
        inData[index] = '\0';
      }
    }
  }

  // We are here either because all pending serial
  // data has been read OR because an end of
  // packet marker arrived. Which is it?
  if(started && ended)
  {
    // The end of packet marker arrived. Process the packet

    // Reset for the next packet
    started = false;
    ended = false;
    index = 0;
    inData[index] = '\0';
  }
}

Where it says “Process the packet”, you’d add code to deal with the random data sent (stored in inData).