1. how to read from a magnetic card reader

Hi everybody I have the next issue: I have a magnetic card reader connected to a windows xp computer via usb
I have to read 2 tracks each time I swipe a card the problem I face is that
some cards comes with 2 tracks while other comes with 3 tracks
I have tried to read it char by char with the next code

-- wait until there is something to read  
while get_key()=-1 do 
end while 
-- start reading 
while 1=1 do 
   vca=get_key() 
   if vca=-1 then 
      exit 
   else 
      linea=linea&vca 
   end if 
end while 

but as soon as it read the first character it stops
maybe it is a simple question but i have not solved it yet
any idea
thanks in advance

new topic     » topic index » view message » categorize

2. Re: how to read from a magnetic card reader

Use:

integer vca = -1 
sequence linea = {} 
-- wait until there is something to read   
while vca = -1 do  
   vca = get_key() 
end while  
linea &= vca 
-- start reading  
while 1 do  
   vca = get_key()  
   if vca = '\n' then  
      exit  
   elsif vca != -1 then  
      linea = linea & vca  
   end if  
end while  

Or:

include std/console.e 
-- start reading  
linea = {} 
while 1 do  
   vca = wait_key()  
   if vca = '\n' then 
      exit  
   else  
      linea = linea & vca  
   end if  
end while  
new topic     » goto parent     » topic index » view message » categorize

3. Re: how to read from a magnetic card reader

Thanks for your answer I try it, and I don't know why, but it didn't worked either

new topic     » goto parent     » topic index » view message » categorize

4. Re: how to read from a magnetic card reader

It does not work because get_key() returns -1 when the keyboard buffer is empty, does not wait for the next key.

new topic     » goto parent     » topic index » view message » categorize

5. Re: how to read from a magnetic card reader

Generally a magnetic card reader is no more than a keyboard stuffer. They will return 1 or more lines of data, each line generally ends with a linefeed or '\n'. So, what you need is a program that reads a number of lines of data and can determine how many which lines belong where because, you state some cases you get 2 lines and others you get 3.

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu