Parallax RFID Read/Write Module problem!

I got an Parallax Read/Write Module http://www.parallax.com/StoreSearchResults/tabid/768/txtSearch/rfid/List/0/SortField/4/ProductID/688/Default.aspx

How to connect it to our board. ( ex. MEGA)
I connected to the serial , but I dont know how to start , what to send to the module , to start readin tags.

Give me an example of code to read tags! Thanks..

It is a well documented and most simple serial protocol

' =========================================================================
'
'   File...... rfid_rw_test.bs2
'   Purpose... System-level test code for the Parallax RFID Read/Write Module
'   Author.... Joe Grand, Grand Idea Studio, Inc. [www.grandideastudio.com]
'   E-mail.... support@parallax.com
'   Updated... 15 Dec 2009
'
'   {$STAMP BS2}
'   {$PBASIC 2.5}
'
' =========================================================================


' -----[ Program Description ]---------------------------------------------
'
' This program performs a system-level test of the Parallax RFID Read/
' Write Module by:
' 
' 1) Reading tag's unique ID
' 2) Writing and verifying a block of data to the tag


' -----[ I/O Definitions ]-------------------------------------------------

RFID_TX            PIN      0            ' Connects to RFID R/W Module SIN
RFID_RX            PIN      1            ' Connects to RFID R/W Module SOUT


' -----[ Constants ]-------------------------------------------------------

#SELECT $STAMP
  #CASE BS2, BS2E, BS2PE
    T9600       CON     84
  #CASE BS2SX, BS2P
    T9600       CON     240
#ENDSELECT

Baud        CON     T9600

' RFID R/W Module Commands
' Number of bytes returned in ()
RFID_Read                  CON            $01      ' Read data from specified address, valid locations 1 to 33 (5)
RFID_Write                  CON            $02      ' Write data to specified address, valid locations 3 to 31 (1)
RFID_Login                  CON            $03      ' Login to tag with password (1)
RFID_SetPass            CON            $04      ' Change tag's password from old to new (1)
RFID_Protect            CON            $05      ' Enable/disable password protection (1)
RFID_Reset                  CON            $06      ' Reset tag (1)
RFID_ReadLegacy            CON            $0F      ' Read unique ID from EM4102 read-only tag (for backwards compatibility with Parallax RFID Card Reader, #28140 and #28340) (12)

' Memory map/address locations for EM4x50 tag
' Each address holds/returns a 32-bit (4 byte) value
ADDR_Password      CON            0      ' Password (not readable)
ADDR_Protect      CON            1      ' Protection Word
ADDR_Control      CON            2      ' Control Word
' ADDR 3-31 are User EEPROM area
ADDR_Serial      CON            32      ' Device Serial Number
ADDR_DeviceID      CON            33      ' Device Identification

' Status/error return codes
ERR_OK            CON            $01      ' No errors
ERR_LIW            CON            $02      ' Did not find a listen window
ERR_NAK            CON            $03      ' Received a NAK, could be invalid command
ERR_NAK_OLDPW      CON            $04      ' Received a NAK sending old password (RFID_SetPass), could be incorrect password
ERR_NAK_NEWPW      CON            $05      ' Received a NAK sending new password (RFID_SetPass)
ERR_LIW_NEWPW      CON            $06      ' Did not find a listen window after sending old password (RFID_SetPass)
ERR_PARITY            CON            $07      ' Parity error when reading data


' -----[ Variables ]-------------------------------------------------------

buf            VAR            BYTE(12)      ' data buffer

idx            VAR         BYTE         ' index
idy            VAR            BYTE

' -----[ EEPROM Data ]-----------------------------------------------------


' -----[ Initialization ]--------------------------------------------------

Initialize:
  PAUSE 250  ' let DEBUG open
  DEBUG CLS  ' clear the screen
  DEBUG "Parallax RFID Read/Write Module Test Application", CR,
        "------------------------------------------------", CR, CR


' -----[ Program Code ]----------------------------------------------------

Main:
  DEBUG "Reading tag's unique serial number..."
Read_Tag:
  SEROUT RFID_TX, Baud, ["!RW", RFID_Read, ADDR_Serial]      ' Read tag's serial number
  SERIN  RFID_RX, Baud, [STR buf\5]                              ' Get status byte and data bytes
  IF buf(0) <> ERR_OK THEN Read_Tag                        ' If we get an error, keep trying until the read is successful
  FOR idx = 1 TO 4                                                ' Print data
    DEBUG HEX2 buf(idx)
  NEXT
  DEBUG CR 

  DEBUG "Writing and verifying data to tag..."
Write_Tag:
  SEROUT RFID_TX, Baud, ["!RW", RFID_Write, 3, $FE, $ED, $BE, $EF] ' Write $FEEDBEEF into address 4 (user EEPROM area)
  SERIN RFID_RX, Baud, [buf(0)]                                           ' Wait for status byte
  IF buf(0) <> ERR_OK THEN Write_Tag                                    ' If we get an error, keep trying until the write is successful
  DEBUG "Success!", CR

  DEBUG "End of test.", CR
  END
' -----[ End of File ]----------------------------------------------------

Im new in programming .... do I need something like :

#include <SoftwareSerial.h>

int  val = 0; 
char code[10]; 
int bytesread = 0; 

#define rxPin 7
#define txPin 6
// RFID reader SOUT pin connected to Serial RX pin at 2400bps to pin8

void setup()
{ 
  Serial.begin(9600);  // Hardware serial for Monitor 2400bps

  
}


void loop()
{ 
  SoftwareSerial RFID = SoftwareSerial(rxPin,txPin); 
  RFID.begin(9600);



   RFID.println("RFID_Read");  // ????????????




  if((val = RFID.read()) == 10)
  {   // check for header 
    bytesread = 0; 
    while(bytesread<10)
    {  // read 10 digit code 
      val = RFID.read(); 
      if((val == 10)||(val == 13))
      {  // if header or stop bytes before the 10 digit reading 
        break;                       // stop reading 
      } 
      code[bytesread] = val;         // add the digit           
      bytesread++;                   // ready to read next digit  
    } 

    if(bytesread == 10)
    {  // if 10 digit read is complete 
      Serial.print("TAG code is: ");   // possibly a good TAG 
      Serial.println(code);            // print the TAG code 
    }
    bytesread = 0; 
    delay(500);                       // wait for a second
  } 
}

You know that loop is executed in an endless loop, right?

Creating a new instance of SoftwareSerial on every pass is not really a good idea.

You should be using NewSoftSerial. SoftwareSerial is obsolete.

Does your RFID reader have some capability to display messages? If not, why are you writing to it?

   RFID.println("RFID_Read");  // ????????????

code is a character array, not a string. The difference between a string and a character array is that a string is a character array THAT IS NULL TERMINATED. Your array is not NULL terminated. Therefore it is not a string, and can be treated, by Serial.println as one.

You need to make code bigger, and store '\0' in code[bytesread] after storing the value read from the serial port and incrementing bytesread.

You should be using NewSoftSerial. SoftwareSerial is obsolete.

That's what I thought too, until I tried to use it with a Mega. As far as I can tell, reading characters doesn't work on a Mega. In fact, on the Arduiniana web page they list support for Arduino Mega under "Upcoming Improvements".

--
The Quick Shield: breakout all 28 pins to quick-connect terminals

With 4 hardware serial ports on the Mega, why would you need software serial ports, too?

I want to connect more than 5 rfid modules... thats why software serial!

I can figure out what to do ...

can some one the by steps what to do.... because Im out of ideas !

Communication: asynchronous serial 9600 bps, (8N1); 5 V TTL-level, non-inverted

must send a three-byte header string of !RW (in ASCII), followed by the desired single-byte command (in hexadecimal)

the command will be RFID_Read

now , what do I have to write ? to start reading tags ? help me please , I dont know what to do ? I'm new in this stuff!

I've never used it with a Mega... but I'm pretty sure the Parallax RFID reader works at 2400 bps, not 9600 bps so that might be your first problem.

Get your read on;
http://www.arduino.cc/playground/Learning/PRFID

I'll be glad if this whas the problem, but in do doc. is written so ! http://www.parallax.com/Portals/0/Downloads/docs/prod/rf/28440-RFIDReadWrite-v1.0.pdf