locked
MagTek swipe card reader RRS feed

  • Question

  • User-1082374796 posted

    Hello,

    I hve recently purhased a Magnetic Swipe card reader (http://www.buy.com/prod/magtek-magnetic-stripe-swipe-card-reader-dual-track-50in-s-usb/q/loc/101/202355937.html)

    I have followed all required steps to get card data into my web page written in c#.net. But its not displaying any data in my application's textboxes when i swipe the card. On page load it asks for installing ActiveX, but after installation nothing happens when i swipe card.

    I hav set the focus on first textbox also. Pls help me I have gone thru http://forums.asp.net/t/1139917.aspx also but no help. Along with this its not working at all on FireFox (but i m leaving this issue for later)

    The code i have written is attached. 

    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="test1.aspx.cs" EnableTheming="false" Inherits="test1" %>
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
    <head runat=server id=head1>
    <title>Test Reader Code H</title>
    
    
    
        <SCRIPT LANGUAGE="JavaScript">
    
        function activate() 
        {
            USBHID.PortOpen = true;
            if(USBHID.PortOpen==false)
            {
              document.getElementById("txtCommand").value = "Could not open MagTek reader";
            }
            else
            {
              document.getElementById("txtCommand").value = "Please Swipe a card";
            }
        }
    
    
        function deactivate() 
        {
    
    	if (USBHID.PortOpen) 
            {  
                USBHID.PortOpen=false;
            }
        }
        function sendButton()
        {
    	var sendButtonIn, sendButtonOut, sendButtonSend;
    	sendButtonIn = document.getElementById("txtcommand").value;
            sendButtonOut = "";
            sendButtonSend = USBHID.USBswipe_Command(sendButtonIn,sendButtonOut);
            document.getElementById("txtCommand").value = USBHID.SwipeCommandOutput; //fix for the JavaScript's not able to pass by reference problem.
        }
            window.onload=activate; 
    
    </SCRIPT>
    
    
    </head>
    <BODY onunload="deactivate()" style=" font-family:arial; font-size:smaller">
    
      <form id="form1" runat=server method="post">
      Demo/Test MagTek Swipe Card
        <table> 
                <tr>
                    <td>CardData</td>
                    <td><asp:Textbox   id="txtCardData" runat=server /></td>
                </tr>
    	        <tr>
    	            <td>CardDataMasked</td>
    	            <td><asp:Textbox   id="txtCardDataMasked" runat=server /></td>
    	        </tr>
    	        <tr>
    	            <td>PAN</td>
    	            <td><asp:Textbox   id="txtPAN" runat=server  /></td>
    	        </tr>
    	        <tr>
    	            <td>First</td>
    	            <td><asp:Textbox   id="txtFirst" runat=server /></td>
    	        </tr>
    	        <tr>
    	            <td>Last</td>
    	            <td><asp:Textbox   id="txtLast" runat=server /></td>
    	        </tr>
    
    	        <tr>
    	            <td>Month</td>
    	            <td><asp:Textbox   id="txtMonth" runat=server /></td>
    	        </tr>
    	        <tr>
    	            <td>Year</td>
    	            <td><asp:Textbox   id="txtYear" runat=server /></td>
    	        </tr>
    	        <tr>
    	            <td>Track1Length</td>
    	            <td><asp:Textbox   id="txtTrack1Length" runat=server /></td>
    	        </tr>
    		    <tr>
    		        <td>Track2Length</td>
    		        <td><asp:Textbox   id="txtTrack2Length" runat=server /></td>
    		    </tr>
    		    <tr>
    		        <td>Track3Length</td>
    		        <td><asp:Textbox   id="txtTrack3Length" runat=server /></td>
    		    </tr>
    	        
    	        <tr>
    	            <td>Track1Data</td>
    	            <td><asp:Textbox   id="txtTrack1Data" runat=server /></td>
    	        </tr>
    	        <tr>
    	            <td>Track2Data</td>
    	            <td><asp:Textbox   id="txtTrack2Data" runat=server /></td>
    	        </tr>
    	        <tr>
    	            <td>Track3Data</td>
    	            <td><asp:Textbox   id="txtTrack3Data" runat=server /></td>
    	        </tr>
    	        
    	        
    	       
    	        
    	        <tr>
    	            <td>Reader ID</td>
    	            <td><asp:Textbox   id="txtReaderID" runat=server /></td>
    	        </tr>
    	       
    	       
    	        
    	        <tr>
    	            <td>Status</td>
    	            <td><asp:Textbox   id="txtStatus" runat=server /></td>
    	        </tr>
    
    	        <tr>
    	            <td>Target Application</td>
    	            <td><asp:Textbox   id="txtApplication"  Text="Untitled - NotePad" runat=server /></td>
    	        </tr>
    	        <tr>
    	            <td>Output</td>
    	            <td><asp:Textbox   id="txtOutput" runat=server /></td>
    	        </tr>
    	        <tr>
    	            <td>Command/Response/Status</td>
    	            <td><asp:Textbox   id="txtCommand" runat=server /></td>
    	            <td><INPUT TYPE="button" SIZE="20" NAME="Send Button" VALUE="Send" onClick="sendButton()"></td>
    	        </tr>
         </table>
      </form>
      
      <OBJECT ID="USBHID" CLASSID="CLSID:22571E97-956A-4CDD-AF8D-AE9C26597683" CODEBASE="magtek/99510060.CAB#version=1,13,0,2">
        <param name="CardDataMasked" value="" />
        <param name="Track1Length" value="0" />
        <param name="Track2Length" value="0" />
        <param name="Track3Length" value="0" />
        <param name="Track1LengthMasked" value="0" />
        <param name="Track2LengthMasked" value="0" />
        <param name="Track3LengthMasked" value="0" />
        <param name="CardData" value="" />
        <param name="PortOpen" value="0" />
        <param name="MPrintLen" value="0" />
    
        <param name="SequenceNumber" value="0" />
        <param name="MPrintStatus" value="0" />
        <param name="DeviceSerialNum" value="" />
        <param name="CardEncodeType" value="" />
        <param name="DUKPTKSN" value="" />
        <param name="ReaderID" value="" />
      </OBJECT>
    
    <OBJECT ID="SendKeys" 
    CLASSID="CLSID:A6CB1285-C23D-11D5-9FC8-0000F87AB538"
    CODEBASE="magtek/99510076.CAB#version=1,3,0,6">
    </OBJECT>
    
      <SCRIPT LANGUAGE="JavaScript" FOR="USBHID" EVENT="CardDataChanged()">
    
         document.getElementById("txtCardData").value = USBHID.CardData
         document.getElementById("txtCardDataMasked").value = USBHID.CardDataMasked;
         if(document.getElementById("txtCardDataMasked").value !="")
         {
            document.getElementById("txtPAN").value = USBHID.FindElementMasked(2,";",0,"=");
            document.getElementById("txtFirst").value = USBHID.GetFNameMasked();
            document.getElementById("txtLast").value = USBHID.GetLNameMasked();
            document.getElementById("txtMonth").value = USBHID.FindElementMasked(2,"=",2,"2");
            document.getElementById("txtYear").value = USBHID.FindElementMasked(2,"=",0,"2");
            document.getElementById("txtOutput").value =  USBHID.CardDataMasked;
         }
         else
         {
            document.getElementById("txtPAN").value = USBHID.FindElement(2,";",0,"=");
            document.getElementById("txtFirst").value = USBHID.GetFName();
            document.getElementById("txtLast").value = USBHID.GetLName();
            document.getElementById("txtMonth").value = USBHID.FindElement(2,"=",2,"2");
            document.getElementById("txtYear").value = USBHID.FindElement(2,"=",0,"2");
            document.getElementById("txtOutput").value =  USBHID.CardData;
         }
         
         document.getElementById("txtTrack1Length").value = USBHID.Track1Length;
         document.getElementById("txtTrack2Length").value = USBHID.Track2Length;
         document.getElementById("txtTrack3Length").value = USBHID.Track3Length;
        
         document.getElementById("txtTrack1Data").value = USBHID.GetTrack(1);
         document.getElementById("txtTrack2Data").value = USBHID.GetTrack(2);
         document.getElementById("txtTrack3Data").value = USBHID.GetTrack(3);
         
         
         
        
         document.getElementById("txtReaderID").value = USBHID.ReaderID;
         
         
         
         SendKeys.WaitForApp = false;
         SendKeys.WaitForKeys = false;
         SendKeys.TargetApp = document.getElementById("txtApplication").value 
         Status = SendKeys.SendData(document.getElementById("txtOutput").value)
         switch(Status)
         {
           case 0:
              document.getElementById("txtStatus").value = "OK";
           break;
           case 5:
              document.getElementById("txtStatus").value = document.getElementById("txtApplication").value  + " Not Running";
           break;
    	 default:
              document.getElementById("txtStatus").value = "Failed";
           break;
    
         };
    
      </SCRIPT>
    
      <SCRIPT LANGUAGE="JavaScript" FOR="USBHID" EVENT="CardDataError()">
         document.getElementById("txtCommand").value = "Error Reading Card Data";
      </SCRIPT>
    
    </BODY>
    </HTML>
    
    
    							
    
    <script type="text/javascript">
        var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
        document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
    </script>
    <script type="text/javascript">
        try {
            var pageTracker = _gat._getTracker("UA-11402486-1");
            pageTracker._trackPageview();
        } catch (err) { }</script>	  
    
    
    



    Tuesday, August 10, 2010 6:22 AM

Answers

  • User-1082374796 posted

    I think I am the most intelligent member here in this forum........ No replies yet & i solve the problem myself.

    All the code above written by is not required at all. Magtek card reader uses "Keyboard Emulation" so it catches the string as soon as we will swipe the card.......... Simple isn't it. All we have to do now is to parse that string & place values in textboxes. Laughing

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, August 20, 2010 2:30 AM

All replies

  • User-19459743 posted

    One thing, Firefox doesn't support ActiveX so it will never work using Firefox.

    Tuesday, August 17, 2010 2:45 PM
  • User-1082374796 posted

    I think I am the most intelligent member here in this forum........ No replies yet & i solve the problem myself.

    All the code above written by is not required at all. Magtek card reader uses "Keyboard Emulation" so it catches the string as soon as we will swipe the card.......... Simple isn't it. All we have to do now is to parse that string & place values in textboxes. Laughing

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, August 20, 2010 2:30 AM
  • User1737558460 posted

    Hello,

    Were you able to use magtek swipe reader in HID mode on firefox?

    Can we read the web pages accept input from magtek swipe reader(HID mode) in linux ?


    thanks

    Friday, November 12, 2010 1:36 PM
  • User-1082374796 posted

    [I hope HID mode means hidden mode]

    The MagTek reader will write the magnetic strip data on any editor which currently has focus. If you open a notepad and swipe ur card it will write data on that notepad window. So if u want to get data in firefox's hidden mode u some how need to set focus on the textbox of ur firefox application on which u want to get data.

    Monday, December 6, 2010 2:06 AM