Cross Point


Miscellaneous functionality

The following code snippet assumes you already have connected to a network and located a reader. This example consists of three different pieces. The first piece will open the door (relay) of the reader. This function is only implemented in firmware versions newer than 1.63 so make sure you have installed the latest firmware in your reader. The second piece will check if a card is within the proximity field of the reader, if it is the a messagebox will popup showing the card details. The third piece will demonstrate a 'walking' LED. It is included just for fun.

The easiest method of executing this sample is to paste the code inside the sample code of Opening networks and locating readers example, just after the number of users is displayed, but before the Logoff method is called.

// Assume that oReader holds a valid logged-on reader object.

// Open the door of the reader (will only work with firmware > 1.63)
if (oReader.GetVersion(5) > 163) // 5 = vtFirmware
{
        WScript.Echo("Now opening the door of reader '" + oReader.Name + "'");
        oReader.AccessControl.OpenDoor();
}
else
        WScript.Echo("The current firmware version does not support the OpenDoor command");


// Display the last detected card
WScript.Echo("Please present a card within the next 5 seconds after closing this messagebox");

// Wait until 5 seconds are passed, or until a card is within the field of the reader
var dtNow = (new Date()).getTime();
var dtEnd = dtNow + 5000;
while (!oReader.HardwareControl.IsCarrierInField && dtNow < dtEnd)
{
        WScript.Sleep(100);
        dtNow = (new Date()).getTime(); // Get the current time
}

// Was a card detected?
if (oReader.HardwareControl.IsCarrierInField)
{
        // Yes, card detected, get the card number
        var oUser = oReader.HardwareControl.LastUser;
        if (oUser)
                WScript.Echo("Detected card with card number: " + oUser.CardNumber + " (Username: '" + oUser.Name + "')");
}
else
        WScript.Echo("No card detected within 5 seconds.");
        

// Show some LED action
WScript.Echo("Now displaying some LED actions");

// Get the original LED state
var oOriginalLEDState = oReader.HardwareControl.LEDs;

// 'Walking' LED light:
for(var j = 0; j < 3; j++)
{
        // Downwards movement
        var iMask = 1;
        for(var i = 0; i < 7; i++)
        {       
                oReader.HardwareControl.LEDs = iMask;
                iMask = iMask << 1;
                WScript.Sleep(100);
        }
        // Upwards movement
        for(var i = 0; i < 7; i++)
        {       
                iMask = iMask >>> 1;
                oReader.HardwareControl.LEDs = iMask;
                WScript.Sleep(100);
        }
}

// Set back the original LED state
oReader.HardwareControl.LEDs = oOriginalLEDState;

© Copyright 2001 - 2006 Cross Point. Generated on Mon Mar 12 16:29:52 2007 Cross Point