SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Member
    Join Date
    Mar 2007
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Javascript..middleware questions.

    Well our company has involved us in a learning project. We have purchased a Kiosk and are responsible for creating an application to work with this kiosk.

    We are starting at square one. Trying to talk to the middleware/devices.

    This kiosk came with a javascript reference to talk with the devices. We need some guidance and help of where to start. Some examples of the reference file.

    function _CardAction( Action, MediaStatus );

    Parameters
    Action : Number (a value in CardReaderCardAction)
    Description of Action
    MediaStatus : Number (a value in CardReaderMediaStatus)
    Description of MediaStatus

    function _CashInComplete( pNoteNumberList );

    Parameters
    pNoteNumberList : CashAcceptorNoteNumberCollection
    Description of pNoteNumberList


    Could someone help us out and get us started in the right direction. We can create the application but do not know how to get the application to talk with the devices. Any help is appreciated.

    Thanks

  2. #2
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,053
    Mentioned
    187 Post(s)
    Tagged
    2 Thread(s)

    talk path

    Hi dailygrind, welcome to the forums,
    Do you know the path to the files you need to transfer data with?
    Are you sure javascript is the language you want to use?
    It seems to me that something like this would be best using the Operating System's language.

  3. #3
    SitePoint Member
    Join Date
    Mar 2007
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Mittineague,

    Thanks for the reply. We are pretty sure we want to do it in JavaScript unless someone can change our mind otherwise.

    We have more information on this project now. We have some sample js code sent to us by the company that made the ActiveX objects and the kiosk itself.

    The sample code:

    Code:
    //var _BarcodeScanner = external.GetGlobalVariable( "CardReader" );
    //var _CardReaderData = external.GetGlobalVariable( "CardReaderData" );
    var _bDeviceReady = true;
    var bWorking = false;
    		
    function CardReader_DeviceError(Function, Error )
    {
    	OnScanError( Function, Error );
    	window.status = "Device Error (" + Function + ")";
    }
    
    function CardReader_DeviceReady()
    {
    	window.status = "Device Ready";
    	_bDeviceReady = true;
    //	HandleButtons();
    }
    
    function CardReader_DeviceUnavailable()
    {
    	alert( "Device Unavailable" );
    	_bDeviceReady = false;
    	OnClose();
    }
    
    function CardReader_DeviceCommandError(Command, Error)
    {
    	bWorking = false;
    	OnScanError( Command, Error );
    	window.status = "Device Command Error";
    }
    
    function CardReader_CommandTimeout(Command)
    {
    	CardReader_TimeOut( Command );
    }
    
    function CardReader_TimeOut(Function)
    {
    	window.status = "Timeout (" + Function + ")";
    	bWorking = false;	
    	
    	try
    	{
    		_CardReader.UnlockDevice();
    	}
    	catch(e)
    	{
    	}
    
    	OnScanTimeout();
    }
    
    function CardReader_TrackData(pTrackData)
    {
    	// unlock it
    	try
    	{
    		_CardReader.UnlockDevice();
    	}
    	catch(e)
    	{
    	}
    	var CardYear = 0000;
    	var CardMonth = 00;
    	bWorking = false;	
    
    	// init these so that we will fall back to track2 if necessary.
    	document.DisplayInput.DisplayInput_CardReaderData_CardNumber.value = "";
    	document.DisplayInput.DisplayInput_CardReaderData_Expiration_Year.value = "";
    	document.DisplayInput.DisplayInput_CardReaderData_Expiration_Month.value = "";
    
    	//	var result = "<table border=1><tr><th colspan=2>Results</th></tr>";
    	var tracks = new Enumerator(pTrackData);
    	for(;!tracks.atEnd();tracks.moveNext())
    	{
    		var track = tracks.item();
    //		result += "<tr><th colspan=2>" + track.Track + "</th></tr>";
    //		result += "<tr><th>Name</th><th>Value</th></tr>";
    		var nvs = new Enumerator(track.Data);
    		for(;!nvs.atEnd();nvs.moveNext())
    		{
    			var nv = nvs.item();
    			
    			switch( track.Track )
    			{
    				case "TRACK1":
    				{
    					switch( nv.Name )
    					{
    						case "ALL":
    						{
    							document.DisplayInput.DisplayInput_CardReaderData_RawData_Track1.value = nv.Value;
    							break;
    						}
    						
    						case "ACCOUNT":
    						{
    							document.DisplayInput.DisplayInput_CardReaderData_CardNumber.value = nv.Value;
    							break;
    						}
    						
    						case "NAME":
    						{
    							document.DisplayInput.DisplayInput_CardReaderData_Name.value = nv.Value;
    							break;
    						}
    						
    						case "YEAR":
    						{
    							document.DisplayInput.DisplayInput_CardReaderData_Expiration_Year.value = nv.Value;
    							
    							// ASSUMPTION: If the Year is a number higher than 50 it's a 19xx year...anything else is 20xx
    							if( CardYear == 0 )
    							{
    								CardYear = parseInt(nv.Value, 10);
    								if( CardYear >= 50 )
    									CardYear = CardYear + 1900;
    								else
    									CardYear = CardYear + 2000;
    							}
    							break;
    						}
    
    						case "MONTH":
    						{
    							document.DisplayInput.DisplayInput_CardReaderData_Expiration_Month.value = nv.Value;
    							
    							if( CardMonth == 0 )
    							{
    								CardMonth = parseInt(nv.Value, 10 );
    							}							
    							break;
    						}
    						
    						case "EXTRADATA":
    						{
    							document.DisplayInput.DisplayInput_CardReaderData_ExtraData.value = nv.Value;
    							break;
    						}																																			
    					}
    					
    					break;
    					
    				} // TRACK1
    				
    				case "TRACK2":
    				{
    					switch( nv.Name )
    					{
    						case "ALL":
    						{
    							document.DisplayInput.DisplayInput_CardReaderData_RawData_Track2.value = nv.Value;
    							break;
    						}
    						
    						case "ACCOUNT":
    						{
    							// only use the track2 account number if I did not find it in track1
    							if( document.DisplayInput.DisplayInput_CardReaderData_CardNumber.value == "" )
    								document.DisplayInput.DisplayInput_CardReaderData_CardNumber.value = nv.Value;
    							break;
    						}
    						
    						case "YEAR":
    						{
    							if( document.DisplayInput.DisplayInput_CardReaderData_Expiration_Year.value == "" )
    							{
    								document.DisplayInput.DisplayInput_CardReaderData_Expiration_Year.value = nv.Value;
    								
    								// ASSUMPTION: If the Year is a number higher than 50 it's a 19xx year...anything else is 20xx
    								if( CardYear == 0 )
    								{
    									CardYear = parseInt(nv.Value, 10);
    									if( CardYear >= 50 )
    										CardYear = CardYear + 1900;
    									else
    										CardYear = CardYear + 2000;
    								}								
    							}
    							break;
    						}
    						
    						case "MONTH":
    						{
    							if( document.DisplayInput.DisplayInput_CardReaderData_Expiration_Month.value == "" )
    							{
    								document.DisplayInput.DisplayInput_CardReaderData_Expiration_Month.value = nv.Value;
    								
    								if( CardMonth == 0 )
    								{
    									CardMonth = parseInt(nv.Value, 10 );
    								}															
    							}
    							break;
    						}						
    					}
    
    					break;
    
    				} // TRACK2
    
    				case "TRACK3":
    				{
    					if( nv.Name == "ALL" )
    						document.DisplayInput.DisplayInput_CardReaderData_RawData_Track3.value = nv.Value;
    
    					break;
    
    				} // TRACK3
    			}
    
    /*
    input.CardReaderData.RawData.FullLine= document.Input.Input_CardReaderData_RawData_FullLine.value;
    */
    			
    //			result += "<tr height=20><td>" + nv.Name + "</td><td nowrap>" + nv.Value + "</td></tr>";
    		}
    	}
    
    	var Today = new Date();
    	var TodayYear = Today.getFullYear();
    	var TodayMonth = Today.getMonth(); // This is 1 less than the traditional way (ie. Jan. = 0)
    	TodayMonth += 1;
    	if( CardYear < TodayYear )
    		OnExpiredCardScanned(CardMonth, CardYear);
    	else if( (CardYear == TodayYear) && (CardMonth < TodayMonth) )
    		OnExpiredCardScanned(CardMonth, CardYear);
    	else
    		OnCardScanned();
    
    }
    
    function CardReader_MediaDetected(Action)
    {
    	window.status = "Media Detected";
    }
    
    function CardReader_InvalidMedia()
    {
    	window.status = "Invalid Media";
    }
    
    function CardReader_InvalidTrackData(Error, Track, Data)
    {
    	window.status = "Invalid Track Data";
    }
    				
    function HandleButtons()
    {
    	if( _CardReader != null )
    	{
    		if( _bDeviceReady == true )
    		{
    			return;
    		}
    	}
    	
    }
    
    function OnClose()
    {
    	if( _CardReader != null )
    	{
    		delete _CardReader;
    		_CardReader = null;
    	}
    }
    
    function OpenCardReader()
    {
    	if( _CardReader != null )
    	{
    		_CardReader.OnDeviceError = CardReader_DeviceError;
    		_CardReader.OnDeviceReady = CardReader_DeviceReady;
    		_CardReader.OnDeviceUnavailable = CardReader_DeviceUnavailable;
    		_CardReader.OnDeviceCommandError = CardReader_DeviceCommandError;
    		_CardReader.OnCommandTimeOut = CardReader_CommandTimeout;
    		_CardReader.OnTimeOut = CardReader_TimeOut;
    		_CardReader.OnTrackData = CardReader_TrackData;
    		_CardReader.OnMediaDetected = CardReader_MediaDetected;
    		_CardReader.OnInvalidMedia = CardReader_InvalidMedia;
    		_CardReader.OnInvalidTrackData = CardReader_InvalidTrackData;
    		return true;
    	}
    	return false;
    }
    
    function OnScan()
    {
    	if( _CardReader != null )
    	{
    		if( _bDeviceReady == true )
    		{
    			//HandleButtons();
    			try
    			{
    				try
    				{
    					_CardReader.LockDevice();
    				}
    				catch(e)
    				{
    				}
    				
    				_CardReader.ExecuteTimeout = (30 * 1000);
    				_CardReader.ReadTrack( "Default" );
    				bWorking = true;
    				return true;
    			}
    			catch(x)
    			{
    				return false;
    			}
    		}
    	}
    	return false;
    }
    		
    /// End rmw changes 8-10-2006
    
    // Submit Implementation
    function Submit()
    {
        OnSubmit();
        //Save Action Inputs
        var input = window.parent.StateMachine.CurrentState.Input;
        input.Attempts=parseInt( document.Input.Input_Attempts.value);
        input.Cancel= document.Input.Input_Cancel.checked;
        input.CardReaderData.Name= document.Input.Input_CardReaderData_Name.value;
        input.CardReaderData.CardNumber= document.Input.Input_CardReaderData_CardNumber.value;
        input.CardReaderData.Expiration.Year= document.Input.Input_CardReaderData_Expiration_Year.value;
        input.CardReaderData.Expiration.Month= document.Input.Input_CardReaderData_Expiration_Month.value;
        input.CardReaderData.ExtraData= document.Input.Input_CardReaderData_ExtraData.value;
        input.CardReaderData.RawData.Track1= document.Input.Input_CardReaderData_RawData_Track1.value;
        input.CardReaderData.RawData.Track2= document.Input.Input_CardReaderData_RawData_Track2.value;
        input.CardReaderData.RawData.Track3= document.Input.Input_CardReaderData_RawData_Track3.value;
        input.CardReaderData.RawData.FullLine= document.Input.Input_CardReaderData_RawData_FullLine.value;
        input.CardReaderError= document.Input.Input_CardReaderError.checked;
        input.Back= document.Input.Input_Back.checked;
        input.PINLessIsOption= document.Input.Input_PINLessIsOption.checked;
        input.CardScanError= document.Input.Input_CardScanError.checked;
        window.parent.StateMachine.CompleteState();
    }
    // Initialize Implementation
    function Initialize()
    {
        var input = window.parent.StateMachine.CurrentState.Input;
        document.Input.Input_Attempts.value=input.Attempts;
        document.Input.Input_Cancel.checked=false;
        document.Input.Input_CardReaderData_Name.value=input.CardReaderData.Name;
        document.Input.Input_CardReaderData_CardNumber.value=input.CardReaderData.CardNumber;
        document.Input.Input_CardReaderData_Expiration_Year.value=input.CardReaderData.Expiration.Year;
        document.Input.Input_CardReaderData_Expiration_Month.value=input.CardReaderData.Expiration.Month;
        document.Input.Input_CardReaderData_ExtraData.value=input.CardReaderData.ExtraData;
        document.Input.Input_CardReaderData_RawData_Track1.value=input.CardReaderData.RawData.Track1;
        document.Input.Input_CardReaderData_RawData_Track2.value=input.CardReaderData.RawData.Track2;
        document.Input.Input_CardReaderData_RawData_Track3.value=input.CardReaderData.RawData.Track3;
        document.Input.Input_CardReaderData_RawData_FullLine.value=input.CardReaderData.RawData.FullLine;
        document.Input.Input_CardReaderError.checked=input.CardReaderError;
        document.Input.Input_Back.checked=false;
        document.Input.Input_PINLessIsOption.checked=input.PINLessIsOption;
        document.Input.Input_CardScanError.checked=input.CardScanError;
        var output = window.parent.StateMachine.CurrentState.Output;
        document.Output.Output_Language.value=output.Language;
        document.Output.Output_PaymentAmount.value=output.PaymentAmount;
        document.Output.Output_AccountBalance.value=output.AccountBalance;
        document.Output.Output_AcctBalLabel.value=output.AcctBalLabel;
        document.Output.Output_PaymentAmtLabel.value=output.PaymentAmtLabel;
        document.Output.Output_InsertCardInstruction.value=output.InsertCardInstruction;
        document.Output.Output_CurrentBalance.value=output.CurrentBalance;
        document.Output.Output_BalanceAmount.value=output.BalanceAmount;
    
        CardReader = external.GetGlobalVariable('CardReader');
        
        // Make sure we have a card reader to play with
        OpenCardReader();
        	
        OnInitialize();
    }
    // Unload Implementation
    function Unload()
    {
    	if( bWorking == true )
    		CardReader.CancelLast();
    
        //Release the devices
        CardReader = null;
        // Unhook all of the check readers events
        OnUnload();
    }
    If you would like to see the JavaScript Help file sent along with the sample code please PM me.

    Can anybody write a htm page to work with this sample code just by looking at this and the help file?

    Thank you.

  4. #4
    SitePoint Wizard gRoberts's Avatar
    Join Date
    Oct 2004
    Location
    Birtley, UK
    Posts
    2,439
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Without the hardware etc it'd be quite hard to successfully create an example. Surely if the company is willing to provide javascript capabilties for their hardware, then they will have some sort of example to show you how it works.



Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •