CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

How to interface magnetic card reader with PC
Goto page 1, 2  Next
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
asimraufawan



Joined: 04 Jul 2008
Posts: 12
Location: Karachi Pakistan

View user's profile Send private message Send e-mail Yahoo Messenger MSN Messenger

How to interface magnetic card reader with PC
PostPosted: Sat Jul 05, 2008 3:33 am     Reply with quote

--------------------------------------------------------------------------------

HI ALL!
I am new to this forum.
Actually I want to interface the TTL magnetic card reader with computer
I have tried it with stripe snoop using game port but it does not work out
the reader i m using is TYSSO TTL MCR series which reads data from track 2 with loco magnetic cards, now i m a little bit confused how will i interface it with serial port, in the reader there is a decoder IC ET6106
which decode the magnetic head analog signal to digital form which output three signals which are CARD PRESENT(/CLS) ,DATA(/RDP) & STROBE or CLOCK PULSE (/RCP).
Kindly help me out,
Thanks,
ASIM RAUF
dyeatman



Joined: 06 Sep 2003
Posts: 1934
Location: Norman, OK

View user's profile Send private message

PostPosted: Sat Jul 05, 2008 7:14 am     Reply with quote

A search of this forum would be a good place to start.

Find the MCR.C driver that comes with the compiler then see the below links.

http://www.ccsinfo.com/forum/viewtopic.php?t=34383

http://www.ccsinfo.com/forum/viewtopic.php?t=34716


Dave
asimraufawan



Joined: 04 Jul 2008
Posts: 12
Location: Karachi Pakistan

View user's profile Send private message Send e-mail Yahoo Messenger MSN Messenger

PostPosted: Wed Jul 09, 2008 1:45 am     Reply with quote

I have gone through both the links below plus mcr.c driver
still confused what will be the hardware design.
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Wed Jul 09, 2008 11:48 am     Reply with quote

Just to make sure, do you want to connect the MCR reader to the PC or to a PIC? It's only one letter difference so it could be a typing error.

As I see you posted the same question in at least three other forums not related to the PIC my guess is you intend to read the data with a PC? Please note that this forum is dedicated to the PIC processor and that we don't know a lot about PC interfacing.

Here is a link to a website with several Tysso card readers: http://www.barcode-manufacturer.com/magnetic_card/magstripe.html#OEM_Modules
Which is the one you are using?
asimraufawan



Joined: 04 Jul 2008
Posts: 12
Location: Karachi Pakistan

View user's profile Send private message Send e-mail Yahoo Messenger MSN Messenger

PostPosted: Thu Sep 04, 2008 11:19 pm     Reply with quote

I posted the question on other forums so that i can collect many ideas
now i decided to see the result of card reader on PC by using PIC16F877A.
Simply by connecting the magnetic card reader to PIC then PIC to thePC via RS232.
can any one provide me the sample code.
n-squared



Joined: 03 Oct 2006
Posts: 99

View user's profile Send private message Send e-mail Visit poster's website

PostPosted: Fri Sep 05, 2008 8:34 am     Reply with quote

Did you purchase a CCS compiler? It contains a ready made code for reading tracks 1 and 2.
_________________
Every solution has a problem.
asimraufawan



Joined: 04 Jul 2008
Posts: 12
Location: Karachi Pakistan

View user's profile Send private message Send e-mail Yahoo Messenger MSN Messenger

PostPosted: Sat Sep 06, 2008 12:13 am     Reply with quote

Thanks,
i just want to read track 2 data,
this example for reading data from MCR hope will work fine.
Ttelmah
Guest







PostPosted: Sat Sep 06, 2008 2:23 am     Reply with quote

In terms of hardware, all you need is the normal MAX232 RS232 driver IC (or something else similar), wired just as you would to talk to a PC, _except_ with pins2,and 3 'swapped' on the DB9 connection. Basically the modules are wired to talk to a PC, so the TXD, and RXD connections need to be swapped.

Best Wishes
asimraufawan



Joined: 04 Jul 2008
Posts: 12
Location: Karachi Pakistan

View user's profile Send private message Send e-mail Yahoo Messenger MSN Messenger

PostPosted: Fri Sep 12, 2008 12:34 am     Reply with quote

Quote:

_except_ with pins2,and 3 'swapped' on the DB9 connection. Basically the modules are wired to talk to a PC, so the TXD, and RXD connections need to be swapped.


sorry i didnt get the above point
Ttelmah
Guest







PostPosted: Fri Sep 12, 2008 2:33 am     Reply with quote

The module is wired so that it's RXD line connects to a PC's TXD line, and vice versa. The normal PIC RS232, is _wired the same way_, so that it too can talk directly to a PC. To talk to the module, you either need a 'null modem' cable (that swaps these lines), or to swap the wiring on the PIC connections.

Best Wishes
asimraufawan



Joined: 04 Jul 2008
Posts: 12
Location: Karachi Pakistan

View user's profile Send private message Send e-mail Yahoo Messenger MSN Messenger

PostPosted: Fri Sep 12, 2008 9:41 pm     Reply with quote

It works fine when i connect first time to the hyper terminal but when i disconnect & then reconnect in the same window it works but show the data twice of each card some time mix the data of different magnetic cards.
Kindly explain the PARITY & LRC error regarding the magnetic cards
as well as where will i find a flow diagram for the whole process.

THANKS
asimraufawan



Joined: 04 Jul 2008
Posts: 12
Location: Karachi Pakistan

View user's profile Send private message Send e-mail Yahoo Messenger MSN Messenger

PostPosted: Fri Sep 26, 2008 12:32 am     Reply with quote

I m just reading the data from track 2 ,therefore i made the mcr.c driver
& example file for the particular task,

Code:


#include <16F877A.h>
#device adc=8

#FUSES NOWDT                    //No Watch Dog Timer
#FUSES HS                       //High speed Osc (> 4mhz)
#FUSES PUT                      //Power Up Timer
#FUSES NOPROTECT                //Code not protected from reading
#FUSES NODEBUG                  //No Debug mode for ICD
#FUSES NOBROWNOUT               //No brownout reset
#FUSES NOLVP                    //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NOCPD                    //No EE protection
#FUSES NOWRT                    //Program memory not write protected

#use delay(clock=20000000)
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8)


#ifndef MCR_CARD_PRESENT
#define MCR_CARD_PRESENT   PIN_B0
#define MCR_DATA          PIN_B4
#define MCR_STROBE        PIN_B5
#endif


#define MCR_ERR_PARITY 2
#define MCR_ERR_LRC    8

int mcr_read(char* track2)
{
   int   error    = 0;
   int1  dataBit  = 0;
   int1  ST       = 1;
   int1  ST_old   = 1;
   int1  firstOne = 0;
   int1  parity   = 0;
   int   count    = 0;
   int   index    = 0;
   int   LRC      = 0;

   // Wait for card to be present
   while(input(MCR_CARD_PRESENT));

   // Loop until a card is not present
   while(!input(MCR_CARD_PRESENT))
   {
   // Check for NULL pointer and an index less than 40
      if(track2 != 0 && index < 40)
      {
         // Get strobe
         ST = input(MCR_STROBE);

         // If the strobe was high and is now low (falling edge),
         //then data is present
         if(ST == 0 && ST_old == 1)
         {
            ST_old = 0;

            // Check if the first 1 was received
            if(firstOne == 1)
            {
               // Check if 4 bits of data were received
               if(count == 4)
               {
                  // Reset the bit counter back to 0
                  count = 0;

                  // Shift the bits right by 4
                  *(track2+index) >>= 4;

                  // Verify the LRC
                  if(*(track2+index-1) == '?' && LRC != *(track2+index))
                  {
                     error |= MCR_ERR_LRC;
                  }
                  else
                  {
                     LRC ^= *(track2+index);
                  }
                 
                  // Add 0x30 to convert to ASCII
                  *(track2+index) += 0x30;

                  // Check the parity bit. The parity on a 0 is not checked
                  // because of the trailing zeros after the LRC character
                  if(!input(MCR_DATA) != parity && *(track2+index) != '0')
                  {
                     error |= MCR_ERR_PARITY;
                  }
               
                                   
                  // Reset the parity check
                  parity = 1;
                 
               
                  // Increment the index into the array
                  ++index;
                 
               }
               else
               {
                  // Get a bit of data from the card
                  dataBit = !input(MCR_DATA);

                  // XOR the data with the parity bit
                  parity ^= dataBit;

                  // Store the new bit of data
                  shift_right(track2+index, 1, dataBit);

                  // Increment the bit counter
                  ++count;
               }
            }
            else
            {
               // Check if the first 1 has appeard on the data line
               if(!input(MCR_DATA))
               {
                  // Set the first 1 received flag
                  firstOne = 1;

                  // Store the first 1
                  shift_right(track2, 1, 1);

                  // Increment the bit counter
                  ++count;
               }
            }
         }
         else if(ST == 1)
         {
            ST_old = 1;
         }
      }
   }

   // Return any errors
   return error;
}

void main()
{

   int index;
   int error;
   char Track2[40];

   setup_adc_ports(NO_ANALOGS);
   setup_adc(ADC_OFF);
   setup_psp(PSP_DISABLED);
   setup_spi(FALSE);
   setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
   setup_timer_1(T1_DISABLED);
   setup_timer_2(T2_DISABLED,0,1);
   setup_comparator(NC_NC_NC_NC);
   setup_vref(FALSE);

   // TODO: USER CODE!!

while(TRUE)
   {
      printf("\r\n\nWaiting to read magnetic card...\r\n");

      // Read a card and get any errors
      error = mcr_read(Track2);
// Display the data in track 2
      index=0;
      printf("\r\nTrack2 Data:\r\n");

      // Loop until the end sentinel (?) is displayed.
      // This loop does not display the LRC character.
      do
      {
          //Display the character and increment the index
         putc(Track2[index++]);
      }
      while(Track2[index-1] != '?' && index<40);

      // Check for card reading errors
      if(error & MCR_ERR_PARITY)
      {
         printf("\r\nTrack 2 parity error");
      }
      if(error & MCR_ERR_LRC)
      {
         printf("\r\nTrack 2 LRC error");
      }
   }

}



In short i m drawing a flow chart for the above program
as for future reference but in function i m not getting how to
describe the flow for LRC & PARITY error verification can any
one explain me in detail.

Below is the part for LRC & PARITY error.

Code:


{
            ST_old = 0;

            // Check if the first 1 was received
            if(firstOne == 1)
            {
               // Check if 4 bits of data were received
               if(count == 4)
               {
                  // Reset the bit counter back to 0
                  count = 0;

                  // Shift the bits right by 4
                  *(track2+index) >>= 4;

                  // Verify the LRC
                  if(*(track2+index-1) == '?' && LRC != *(track2+index))
                  {
                     error |= MCR_ERR_LRC;
                  }
                  else
                  {
                     LRC ^= *(track2+index);
                  }
                 
                  // Add 0x30 to convert to ASCII
                  *(track2+index) += 0x30;

                  // Check the parity bit. The parity on a 0 is not checked
                  // because of the trailing zeros after the LRC character
                  if(!input(MCR_DATA) != parity && *(track2+index) != '0')
                  {
                     error |= MCR_ERR_PARITY;
                  }
               
                                   
                  // Reset the parity check
                  parity = 1;
                 
               
                  // Increment the index into the array
                  ++index;
                 
               }



THANKS
n-squared



Joined: 03 Oct 2006
Posts: 99

View user's profile Send private message Send e-mail Visit poster's website

PostPosted: Sun Sep 28, 2008 3:59 pm     Reply with quote

Hi,
The exact description and good explanations for magnetic card reading can be found in the ISO7811 standard.
There should be no problem getting this document on the internet.

Best regards
_________________
Every solution has a problem.
dsolorzano



Joined: 29 Mar 2011
Posts: 3

View user's profile Send private message

PostPosted: Tue Mar 29, 2011 1:56 am     Reply with quote

Hello. The mcr library is very nice. However I need to do a bidirectional code and have been unable to do it. Could anybody help me? Thanks
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Tue Mar 29, 2011 3:12 am     Reply with quote

Please, for a new question start a new thread. Do not re-open a three year old topic for a question that has almost no relation to the original question.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group