Tuesday, April 01, 2014

taking mifare card data and importing the UID into equitrac express

So this is not really going to appeal to many people as its kind of specific, but at my work we use MiFare cards to log onto our printers and print out work. The printers are Ricoh machines and we use their software (equitrac) to run the system and database.

We needed a way to automatically assign the UID number from the card to the user that it is assigned to in the equitrac database. I wrote the code in AutoIt because its awesome.

Here it is

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <MsgBoxConstants.au3>

; create GUI window
$Form1 = GUICreate("Test Gui", 269, 150, 193, 115)
;create two labels for the input boxes
GUICtrlCreateLabel("Card UID", 20, 16, 50, 21)
GUICtrlCreateLabel("Username", 20, 50, 50, 21)
; create two input controls
$Input1 = GUICtrlCreateInput("", 72, 16, 121, 21)
$Input2 = GUICtrlCreateInput("", 72, 50, 121, 21)
; create a button which says "press me"
$Button1 = GUICtrlCreateButton("Press Me", 96,80, 75, 25, 0)
; set the GUI to to show, so you can see it
GUISetState(@SW_SHOW)

While 1 ; loop until expression is false
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE ; if the user clicks on X (closes the window)
            Exit ;  the script will exit.
         Case $button1 ; the user clicks on the button
            $sString = GUICtrlRead($Input1);UID added to variable
            $username = GUICtrlRead($Input2);username added to variable
            $sString1 = StringStripWS($sString,8) ;remove spaces from UID
            $sReversed = StringRegExpReplace($sString1, "(.{2})(.{2})(.{2})(.{2})", "$4$3$2$1") ;rearrange the hex value
                   
                     Local $iDec = Dec($sReversed, 2) ;convert hex to decimal
                     Run(@comspec & ' /c "c:\program Files\equitrac\Express\Tools\eqcmd.exe" -sSERVERNAME modify ur '& $username &' ! ! ! ! '& $iDec) ;run the command prompt to add to equitrac
                   
                   
    EndSwitch
WEnd; end of loop


So after the include section you have the part that builds the GUI. Then comes the code. What it does is take the UID, move it around, convert into hex and then add it into the database. The only bit you'll need to change is the line after the 'run' command where i've put SERVERNAME. You put your database server name in there (there is NO space between the -s and the name) and that's that.

Hope this help someone!