Cross Point


Opening networks and locating readers example

The following JScript examples opens the first COM port, scans this network for readers and logs as installer onto the first reader it finds using the default password. It then returns the number of users that are stored in this reader's user database. To execute this sample, copy it to a empty file and name the file "Example1.js". Now execute the sample by simply double-clicking on it in Windows explorer. When you have a reader attached on the network on COM1, running on the correct baudrate and with the correct password, you will see a messagebox showing the name of the reader and the number of users of this reader.

// Variables
var iComPort = 1; // Modify this value if your network is located on another COM port
var iBaudRate = 19200; // Modify this value if your readers operate at a different baudrate
var iInstallerPassword = 123456789; // Modify this value if your reader has another installer level password

Main();

// All functionality is placed in a function to increase readability
function Main()
{
        // Create the main API application object
        var oApp = new ActiveXObject("TalosAPI.Application");
        if (oApp)
        {
                // Create/find a network
                var oNetwork  = oApp.FindReaderNetwork(iComPort);
                if (oNetwork)
                {
                        // Connect/open the network
                        if (oNetwork.Connect(iBaudRate))
                        {
                                // Scan all readers from address 0 to 32
                                // Note that we scan synchronously here, meaning that this method will block
                                // until it has scanned all readers.
                                if (oNetwork.ScanReaders(false, 0, 32))
                                {
                                        if (oNetwork.ReaderCount == 0)
                                        {
                                                WScript.Echo("No readers found from address 0 to 32!");
                                                return;
                                        }
                                
                                        // Use the first reader
                                        var oReader = oNetwork.Readers.FirstItem;
                                        if (!oReader)
                                        {
                                                WScript.Echo("Error, failed to get the first reader!");
                                                return;
                                        }
                                        
                                        // Very essential: log-on to the reader (2 = installer level, true = auto-authorize)
                                        if (!oReader.Logon(2, iInstallerPassword, true))
                                        {
                                                WScript.Echo("Error while logging on to the reader! Is the value '" + iInstallerPassword + "' a valid password?");
                                                return;
                                        }

                                        // The reader is now logged on, display the number of users
                                        WScript.Echo("Reader: '" + oReader.Name + "' contains " + oReader.UserDatabase.Count + " users.");              
                                        
                                        // Finish
                                        oReader.Logoff();
                                }
                                else
                                {
                                        WScript.Echo("Error, failed to scan readers!"); 
                                }                       
                                oNetwork.Disconnect();
                        }
                        else
                        {
                                WScript.Echo("Error, failed to connect to the network!");       
                        }
                }
                else
                {
                        WScript.Echo("Error, no network found on COM1, specify another COM port in the script!");       
                }
        }
        else
        {
                WScript.Echo("Error, failed to create the application object! Is the TalosAPI registered?");
        }
}

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