FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour How to read data from Magnatic Card?
Posts: 1598
Joined: Fri Oct 07, 2005 05:56 PM

How to read data from Magnatic Card?

Posted: Thu May 06, 2010 06:44 AM

Dear All,

I need to get data from credit card with magnatic reader but It will read all (too much data). How can I get all data to buffer and cut unused data off before show to user.
for example
==========
"%B4907641102356613^NIRANTASUKWONG/P ^1105201133720000000000979000000?;4907641102356613=11052011337297900000?"

I need only this

"4907641102356613^NIRANTASUKWONG/P ^1105"

How can I do it?

Thx&Regards,
Dutch

Regards,

Dutch



FWH 2304 / xHarbour Simplex 1.2.3 / BCC73 / Pelles C / UEStudio

FWPPC 10.02 / Harbour for PPC (FTDN)

ADS V.9 / MySql / MariaDB

R&R 12 Infinity / Crystal Report XI R2

(Thailand)
Posts: 603
Joined: Sun May 04, 2008 08:44 PM

Re: How to read data from Magnatic Card?

Posted: Thu May 06, 2010 07:52 AM
You can try this :-)
Code (fw): Select all Collapse
function main()

 LOCAL cRegEx := "[%][B](.*)([\^][0-9]{4})"
 LOCAL cText   := "%B4907641102356613^NIRANTASUKWONG/P ^1105201133720000000000979000000?;4907641102356613=11052011337297900000?"
 LOCAL aResult := HB_RegEx( cRegEx, cText )

 if (valtype(aResult)=="A" .AND. len(aResult)>=3)
     ? aResult[2]+aResult[3] 
 else 
     ? "No match !"
 endif

return

Posts: 1598
Joined: Fri Oct 07, 2005 05:56 PM

Re: How to read data from Magnatic Card?

Posted: Thu May 06, 2010 08:43 AM

Dear laiton.webmaster,

What am I putting this HB_RegEx() to?
If I use TGET, will I put to (::bLostFocus() or ::bChange )?

Thx, I gonna try.

Regards,
Dutch

Regards,

Dutch



FWH 2304 / xHarbour Simplex 1.2.3 / BCC73 / Pelles C / UEStudio

FWPPC 10.02 / Harbour for PPC (FTDN)

ADS V.9 / MySql / MariaDB

R&R 12 Infinity / Crystal Report XI R2

(Thailand)
Posts: 603
Joined: Sun May 04, 2008 08:44 PM

Re: How to read data from Magnatic Card?

Posted: Thu May 06, 2010 03:22 PM
Dutch,

Please try this.

look:
Code (fw): Select all Collapse
#include "Fivewin.ch"

Function Main()
Local oDlg
Local cGet:=Space(50)
define dialog oDlg
@ 10,10 get oGet var cGet of oDlg
oGet:bLostFocus:={||MCard( SELF,cGet, DataCArd  ) } // DataCard you need informe how you return numbers that
                                                                                          // you show up. 
Activate dialog oDlg
Return

Function MCard( oG,cG,cData ) // <<== cData is data card
 LOCAL cRegEx := "[%][B](.*)([\^][0-9]{4})"
 LOCAL cText   := cData; 
 LOCAL aResult := HB_RegEx( cRegEx, cText )
 if (valtype(aResult)=="A" .AND. len(aResult)>=3)
     cG:= aResult[2]+aResult[3] // add result to GET
     oG:Refresh()                     // refresh Get
 else
     MsgStop("No match ER !","Not Found")
 endif
Return


:-)
Posts: 3022
Joined: Fri Oct 07, 2005 01:45 PM

Re: How to read data from Magnatic Card?

Posted: Thu May 06, 2010 05:34 PM

Dutch,

Using a card swipe device, which acts as a keyboard reader, this code is good for swiping a credit card. You can then take the resulting string and manipulate it as you wish.

FUNCTION ccSwipeCard( )

LOCAL cCrdVal := SPACE(256), lValOK := .F., cCCVal := SPACE(100)

// Define the dialog window
DEFINE DIALOG oSwnd FROM 0, 0 TO 6, 40 TITLE &quot;Credit Card Input&quot;

// Obtain the search string
@ 10, 40  SAY &quot;Swipe The Card&quot; PIXEL
@ -100, -100 GET ccobj1 VAR cCrdVal
// Define the processing buttons
@ 20, 25 BUTTON &quot;&amp;Accept&quot; SIZE 35, 12 OF oSwnd ACTION  cCCVal := TRIM(oCrdVal) PIXEL
@ 20, 75 BUTTON &quot;&amp;Cancel&quot; SIZE 35,12 OF oSwnd ACTION ( oSwnd:end() ) PIXEL

// Activate the dialog
ACTIVATE DIALOG oSwnd ON INIT ( oSwnd:center(wndmain()), ccobj1:setfocus( ) )

RETURN( cCCVal )

Tim Stone
http://www.MasterLinkSoftware.com
http://www.autoshopwriter.com
timstone@masterlinksoftware.com
Using: FWH 23.10 with Harbour 3.2.0 / Microsoft Visual Studio Community 2022-24 32/64 bit
Posts: 1598
Joined: Fri Oct 07, 2005 05:56 PM

Re: How to read data from Magnatic Card?

Posted: Fri May 07, 2010 05:03 AM
Dear Laiton&Tim,

I have got an idea to get the result that I need but the user interface is not nice.
1.) When I swipe the cr.card it show all information in cr.card but I need only some information
2.) I use :bLostFocus to cut all information that I need. It works fine.

I don't want to change text color as background, bcos this field has used many purpose. It is not cr.card information only but manual typing information also.

How can I hold the information in buffer and show on 2nd step only .or. How to don't show the information until 2nd step?
</noscript>



Code (fw): Select all Collapse
#include "Fivewin.ch"

Function Main()
Local oDlg, oGet, oBtn
Local cGet:=Space(400)
define dialog oDlg from 100,100 to 200, 1200 pixel
@ 10,10 get oGet var cGet of oDlg pixel size 500,12
oGet:bLostFocus:={|Self,nKey|MCard( Self,cGet ) } // DataCard you need informe how you return numbers that
                                                                                          // you show up. 
@ 30, 10 BUTTON oBtn PROMPT 'Ok' ACTION (oDlg:End()) PIXEL
Activate dialog oDlg
Return nil

Function MCard( oG,cG ) // <<== cData is data card
 LOCAL cText   := alltrim(oG:cText())
 local aCard, aResult
 if left(cText,1)='%'
 aCard  := HB_ATokens( cText, "^", .F. , .F. )
 aResult := { aCard[1],aCard[2], aCard[3] } // HB_RegEx( cRegEx, cText ) 
 if (valtype(aResult)=="A" .AND. len(aResult)>=2)
     oG:VarPut( right(aResult[1],len(aResult[1])-2 )+'-'+left(aResult[3],2)+'/'+subs(aResult[3],3,2) )
     oG:Refresh()                     // refresh Get
 else
     MsgStop("No match ER !","Not Found")
 endif
end
Return .t.

Thanks&Regards,
Dutch
Regards,

Dutch



FWH 2304 / xHarbour Simplex 1.2.3 / BCC73 / Pelles C / UEStudio

FWPPC 10.02 / Harbour for PPC (FTDN)

ADS V.9 / MySql / MariaDB

R&R 12 Infinity / Crystal Report XI R2

(Thailand)
Posts: 512
Joined: Mon Oct 17, 2005 10:38 AM

Re: How to read data from Magnatic Card?

Posted: Fri May 07, 2010 06:31 AM

You can change the color on the ON CHANGE clause. If the first character is always %, you can test this condition.

Posts: 782
Joined: Wed Dec 19, 2007 07:50 AM

Re: How to read data from Magnatic Card?

Posted: Fri May 07, 2010 01:41 PM
Hello Dutch:
dutch wrote:I have got an idea to get the result that I need but the user interface is not nice.

Why not to define two gets, one which has the focus and is not visible (coordinates beyond the dialog boundaries) and other visible which is updated and refreshed through clause ON CHANGE of the hidden one.

Just an idea, best regards.

Manuel Mercado Gómez.
manuelmercado at prodigy dot net dot mx
Posts: 1598
Joined: Fri Oct 07, 2005 05:56 PM

Re: How to read data from Magnatic Card?

Posted: Mon May 10, 2010 05:10 PM

Dear Manuel&Massimo,

Thank you for your idea, I think both way are working well.

Best regards,
Dutch

Regards,

Dutch



FWH 2304 / xHarbour Simplex 1.2.3 / BCC73 / Pelles C / UEStudio

FWPPC 10.02 / Harbour for PPC (FTDN)

ADS V.9 / MySql / MariaDB

R&R 12 Infinity / Crystal Report XI R2

(Thailand)

Continue the discussion