Class: Device

Device

Spacecode Device class. Allows operating remote device(s).

Constructor

new Device(ipAddress, tcpPort)

Device default constructor.
Parameters:
Name Type Description
ipAddress string IP (v4) address of the device.
tcpPort number TCP port number (default to 8081).

Members

(static, readonly) TEMPERATURE_ERROR :number

Default value provided in case of error.
Type:
  • number

Methods

addAlert(callback, alert)

Ask the remote device to add a new alert.

Provide a boolean result to the given callback: true if the operation succeeded, false otherwise (invalid alert provided, communication failed...).
Parameters:
Name Type Description
callback function Function to call once a response is received.
alert Alert | AlertTemperature Alert to be added.

addUser(callback, user)

Ask the remote device to add a new user.

Provide a boolean result to the given callback: true if the operation succeeded, false otherwise (invalid user provided, or username already known).
Parameters:
Name Type Description
callback function Function to call once a response is received.
user User User to be added.

connect()

Connect to the remote device.

enrollFinger(callback, username, fingerIndex, masterReader)

Start finger enrollment (on the remote device).

Provide a boolean result to the given callback: true if the operation succeeded, false otherwise (invalid parameter, unknown user, communication error).
Parameters:
Name Type Description
callback function Function to call once a response is received.
username string User enrolling a fingerprint.
fingerIndex FingerIndex Index of the finger to be enrolled.
masterReader boolean If true, use the master reader, otherwise use the slave.

getAlertReports(callback, startDate, endDate, alerts)

Get alert reports (if any) made during a certain period.

Provide an array of AlertReport to the given callback.
Parameters:
Name Type Description
callback function Function to call once a response is received.
startDate Date Start date of the reports period.
endDate Date End date of the reports period.
alerts Array.<Alert> Alerts to be used for the reports research.

getAlertsList(callback)

Get the list of alerts added to the remote device (empty if none, or if an error occurred).

Provide an array of Alert to the given callback.
Parameters:
Name Type Description
callback function Function to call once a response is received.

getAuthentications(callback, startDate, endDate)

Get all the authentications recorded during a certain period.

Provide an array of Authentication to the given callback.
Parameters:
Name Type Description
callback function Function to call once a response is received.
startDate Date Start date of the inventories period.
endDate Date End date of the inventories period.

getCurrentTemperature(callback)

Get the current temperature measure.

Provide a number (temperature in °C) to the given callback, or TEMPERATURE_ERROR.
Parameters:
Name Type Description
callback function Function to call once a response is received.

getDbConfiguration(callback)

Get the configuration of the remote device database. The password is never provided (left empty).

An instance of DbConfiguration is given to the callback, or null in case of error.
Parameters:
Name Type Description
callback function Function to call once a response is received.

getDeviceType() → {DeviceType}

Returns:
Device type.
Type
DeviceType

getHardwareVersion() → {string}

Returns:
Hardware version of the device.
Type
string

getImmediateStatus(callback)

Provide the "real time" status of the Device. The Device object is supposed to automatically internally update its status, however, it may fails in case of communication error (i.e. temporary disconnection).
Parameters:
Name Type Description
callback function Function to call once a response is received.

getInventories(callback, startDate, endDate)

Get the inventories available over a given period.

Provide an array of Inventory to the given callback.
Parameters:
Name Type Description
callback function Function to call once a response is received.
startDate Date Start date of the inventories period.
endDate Date End date of the inventories period.

getInventoryById(callback, id)

Parameters:
Name Type Description
callback function Function to call once a response is received.
id number ID for the expected Inventory.
Deprecated:
  • Internal usage [DEPRECATED] Get an Inventory with provided ID (or null in case of failure, or if no result matches).

getIpAddress() → {string}

Returns:
Ip address of the device.
Type
string

getLastAlertReport(callback)

Get an AlertReport for the last alert raised, or null (if no alert was raised, or any error occurred).
Parameters:
Name Type Description
callback function Function to call once a response is received.

getLastInventory(callback)

Get the last Inventory made by the device (or null, if none).
Parameters:
Name Type Description
callback function Function to call once a response is received.

getProbeSettings(callback)

Get the configuration of the temperature probe. Delay and Delta can be equal to -1 if not set.
Parameters:
Name Type Description
callback function Function to call once a response is received.

getSerialNumber() → {string}

Returns:
Device serial (unique) number.
Type
string

getSmtpServer(callback)

Get the configuration of the SMTP server used to send the emails of alert notifications.

An instance of SmtpServer is given to the callback, or null if no server is set, or if any error occurred.
Parameters:
Name Type Description
callback function Function to call once a response is received.

getSoftwareVersion() → {string}

Returns:
Version of the device firmware.
Type
string

getStatus() → {DeviceStatus}

Returns:
Current status (internally, automatically updated).
Type
DeviceStatus

getTagToDrawerNumber(callback)

Spacecode Devices equipped with many drawers memorize (for each tag) by which drawer a given UID has been scanned for the last time.
The result given to the callback is a Map (string, number) with keys as UID and values as drawer number, or null if any error occurred.
Parameters:
Name Type Description
callback function Function to call once a response is received.

getTemperatureMeasures(callback, startDate, endDate)

Get the temperature measures recorded during a certain period.

Results (measurements) are provided in a Map, which keys are dates of type Date, and values of type number.
Parameters:
Name Type Description
callback function Function to call once a response is received.
startDate Date Start date of the measurement period.
endDate Date End date of the measurement period.

getUnregisteredUsers(callback)

Get the name of each unregistered user.
Provide an array of string (usernames) to the given callback.
Parameters:
Name Type Description
callback function Function to call once a response is received.

getUserByName(callback, username)

Get a User with provided username (or null in case of failure, or if no result matches).
Parameters:
Name Type Description
callback function Function to call once a response is received.
username string Username.

getUsers(callback)

Get the list of Authorized Users recorded on the remote device.

Provide an array of Users to the given callback.
Parameters:
Name Type Description
callback function Function to call once a response is received.

isConnected() → {boolean}

Returns:
True if the TCP socket is connected, false otherwise.
Type
boolean

isInitialized() → {boolean}

Returns:
True if the initialization (on connection) succeeded.
Type
boolean

off(eventName, callback)

Used by subscribers to remove a listener on an event.
Parameters:
Name Type Description
eventName string Event that 'callback' is linked to.
callback function Callback to be removed for event 'eventName'.

on(eventName, callback)

Used by subscribers to add a listener on an event.
Parameters:
Name Type Description
eventName string Event to be listened.
callback function Function to call once the event is raised.

one(eventName, callback)

Allow adding a listener (see method on) which will execute only one time.
Parameters:
Name Type Description
eventName string Event to be listened.
callback function Function to call once the event is raised.

release()

Close connection the to remote device.

removeAlert(callback, alert)

Ask the remote device to remove an alert.

Provide a boolean result to the given callback: true if the operation succeeded, false otherwise (invalid alert, communication error...).
Parameters:
Name Type Description
callback function Function to call once a response is received.
alert Alert | AlertTemperature Alert to be removed.

removeFingerprint(callback, username, fingerIndex)

Remove a fingerprint.

Provide a boolean result to the given callback: true if the operation succeeded, false otherwise (invalid parameter, unknown user, communication error).
Parameters:
Name Type Description
callback function Function to call once a response is received.
username string User to whom the fingerprint is attached.
fingerIndex FingerIndex Index of the finger which fingerprint has to be removed.

removeUser(callback, username)

Ask the remote device to remove an user. The device will remove the permission of the given user and not the user himself.

Provide a boolean result to the given callback: true if the operation succeeded, false otherwise (invalid or unknown username provided).
Parameters:
Name Type Description
callback function Function to call once a response is received.
username string User to be removed.

requestScan(optionsopt)

Send a request to start a scan.
The operation can be monitored by subscribing to scan events like scanstarted and scancompleted.
Parameters:
Name Type Attributes Description
options Array.<ScanOption> <optional>
Array of ScanOptions desired for the scan operation. Optional parameter.

rewriteUid(callback, oldUid, newUid)

Ask the remote device to proceed to a UID rewriting operation.

Provide a RewriteUidResult value to the given callback.
Parameters:
Name Type Description
callback function Function to call once a response is received.
oldUid string UID of the tag to be rewritten.
newUid string New UID to be written.

setDbConfiguration(callback, dbConfiguration)

Ask the remote device to update its database settings with the given DbConfiguration object.

Provide a boolean result to the given callback: true if the operation succeeded, false otherwise.
Parameters:
Name Type Description
callback function Function to call once a response is received.
dbConfiguration DbConfiguration DbConfiguration object containing the new settings.

setLightIntensity(callback, intensity)

Set the embedded LED's light intensity (for devices equipped with embedded LED's, like the SAS).
Provide a boolean result to the given callback: true if the operation succeeded, false otherwise (order not sent or not executed).
Parameters:
Name Type Description
callback function Function to call once a response (boolean) is received.
intensity number [0;300] (0 - turn off, 300 - maximal intensity).

setProbeSettings(callback, probeSettings)

Ask the remote device to update its Probe Settings with the given ProbeSettings object.

Provide a boolean result to the given callback: true if the operation succeeded, false otherwise.
Parameters:
Name Type Description
callback function Function to call once a response is received.
probeSettings ProbeSettings ProbeSettings object containing the new settings.

setSmtpServer(callback, smtpServer)

Ask the remote device to update its SMTP server with the given SmtpServer object.

Provide a boolean result to the given callback: true if the operation succeeded, false otherwise.
Parameters:
Name Type Description
callback function Function to call once a response is received.
smtpServer SmtpServer SmtpServer object containing the new settings.

startLightingTagsLed(callback, tags)

Send a "Start Tags-Lighting" request to the remote device.
If the operation is successful, an event lightingstarted will be raised with UID's of tags which could not be lighted.

Provide a boolean result to the given callback: true if the operation succeeded, false otherwise (invalid or unknown username provided).
Parameters:
Name Type Description
callback function Function to call once a response is received.
tags Array.<string> Array of tags UID's to be lighted.

stopLightingTagsLed(callback)

Send a "Stop Tags-Lighting" request to the remote device.

Provide a boolean result to the given callback: true if the operation succeeded, false otherwise (invalid or unknown username provided).
Parameters:
Name Type Description
callback function Function to call once a response is received.

stopScan()

Ask the remote device to stop the current scan process (if any).

updateAlert(callback, alert)

Ask the remote device to update an alert. Provide a boolean result to the given callback: true if the operation succeeded, false otherwise (invalid alert, communication error...).
Parameters:
Name Type Description
callback function Function to call once a response is received.
alert Alert | AlertTemperature Alert to be updated.

updateBadgeNumber(callback, username, badgeNumber)

Update a user's badge number. Provide a boolean result to the given callback: true if the operation succeeded, false otherwise (invalid username or badge number, communication error).
Parameters:
Name Type Description
callback function Function to call once a response (true/false) is received.
username string User to be modified.
badgeNumber string New badge number.

updatePermission(callback, username, permission)

Update the given user's permission on the remote device.

Provide a boolean result to the given callback:
true if the operation succeeded, false otherwise (invalid username or permission, communication error).
Parameters:
Name Type Description
callback function Function to call once a response is received.
username string User to be modified.
permission string New permission.

Events

alert

An alert has been raised by the device.
Parameters:
Name Type Description
alert Alert The Alert which has been raised.
extraData string Extra data provided by the Alert Center (Temperature value, Username...).

authenticationfailure

A user failed in authenticating himself to open the device.
Parameters:
Name Type Description
module AuthenticationModule Module which triggered the event.
user User User who failed authenticating himself.

authenticationsuccess

A user successfully authenticated himself and unlocked the device.
Parameters:
Name Type Description
module AuthenticationModule Module which triggered the event.
user User User authenticated.

badgescanned

A badge has been scanned (it may or may not belongs to an existing user).
Parameters:
Name Type Description
badgeNumber string Unique identifier of the badge just scanned.

connected

The device is connected. Most of the time, using method isInitialized() after catching this event is a safe way to make sure that the device has been fully instantiated.

connectionaborted

The connection with the remote device has been aborted. Potential reasons:
  • The remote device encountered a critical error.
  • The TCP/IP communication has been interrupted or the network is unstable.

connectionfailed

The connection with the remote device has failed. Event emitted when a connection could not be established.

disconnected

The device has been disconnected. Can be fired when:
  • The connection has been aborted
  • The device has been released (see method release)

doorclosed

The device has been closed.

dooropendelay

The device door has been open for too long (Fridges / Freezers only).

dooropened

The device has been opened.

enrollmentsample

A new sample has been recorded for the current fingerprint enrollment process.
Parameters:
Name Type Description
sampleNumber number Number of the sample just enrolled (over the 4 samples required).

fingertouched

A fingerprint reader has been touched.
Parameters:
Name Type Description
isMaster boolean If true, the master door has been unlocked. Otherwise, the slave door.

lightingstarted

The LEDs-lighting process has been started.
Parameters:
Name Type Description
tags Array.<string> Array containing the UID's of tags which could not be lighted (if any).

lightingstopped

The LEDs-lighting process has been stopped.

scancancelledbydoor

The scan has been cancelled because the door of the device has been open.

scancancelledbyhost

The scan failed has been manually interrupted.

scancompleted

The scan completed. The new inventory is available with method getLastInventory()

scanfailed

The scan failed to start.

scanstarted

The scan started.

statuschanged

The status of the device changed.
Parameters:
Name Type Description
status DeviceStatus New status.

tagadded

Emitted during a scan, when a tag has been detected.
Parameters:
Name Type Description
tag string Tag UID.

temperaturemeasure

Emitted when a new temperature value is triggered by the device.
Parameters:
Name Type Description
measure string Temperature value (dot as separator, i.e. "24.5").