File

src/communication/commHmiNodeServer.ts

Description

Class that implements the communication abstract class with the specifications related to CNC 8070.

Connection is made against the main HMI NODE Server via Websocket && HTTP.

Events

This object will be emiting the following events:

emits online when connection chain has been resolved succesfully, libfagorclient is ready to operate

emits offline when any link has been disconnected, so libfagorclient is unusable.

emits model-received A full copy of the model has been received. (model will be pass as an argument)

emits model-updated Array of JSON-patches containing changes to be applied in current model

emits plcmodel-received A full copy of the plc model has been received. (model will be pass as an argument)

emits plcmodel-updated Array of JSON-patches containing changes to be applied in current plc model

emits new-authetication-token whenever a new token is fetched (token update is managed internally)

Example

const comm = new CommHmiNodeServer();

// We must listen to online event, before making the connection.
comm.on("online", () => {
console.log("Connection success!");
console.log(
`${comm.getToken()} this is the authorization token which can be used on other HMI connections.`
);
});


// Trying to connect ot localhost using usernamee & password
comm.connect({
host: "localhost",
port: "3000",
username: "anonymous",
password: "anonymous"
});


// also a valid token could be used
comm.connect({
host: "localhost",
port: "3000",
token: "valid_remote_token"
});


// Or even a valid refresh token can be issued to get a connection setup
comm.connect({
host: "localhost",
port: "3000",
username: "anonymous",
refreshToken: "valid_refresh_token"
});

Extends

EventEmitter

Index

Properties
Methods

Properties

Public clientId
Type : string

unique UUID for current WS connection

Public cncId
Type : CncIdentification
Default value : {idHW: ""}

Current cnc idenftificaion

Public cncSwOptions
Type : SwOptions[]
Default value : []

Sotfware options exported by cnc for each session

Public cncVersion
Type : CncVersion[]
Default value : []

Current cnc version

Public connected
Type : boolean
Default value : false

current connection status

Public connectedCncNodes
Type : number
Default value : 0

Connected cnc nodes

Public connecting
Type : boolean
Default value : false

is connection on progress?

httpClient
Type : any
Public online
Type : boolean
Default value : false

Flag that indicates whether cnc system is accesible and fully operative

Methods

Public canCloseCnc
canCloseCnc(cncNodeIndex: number)

Implements the canCloseCnc service call. It calls to CommHmiNodeServer to call appropiate REST API route.

Returns a promise. This promise is fulfilled with reply object if everything is ok or is rejected with CncServiceOperationException when something goes wrong.

Parameters :
Name Type Optional Default value
cncNodeIndex number No 0
Public connect
connect(connectionData: ConnectionData)

Implements the connection process with the main HMI Node Server. Assigns an unique guid number, established tjhe websocket connection and check the HTTP Endpoint.

Returns Promise resolved to true if connection success, or with custom error.

Parameters :
Name Type Optional Description
connectionData ConnectionData No

ConnectionData connection data (endpoint/authorization data) for CNC Node server

Public disconnect
disconnect()

Implements the disconnection process with the main HMI Node Server. TODO: Currently only closes ws connection.

Returns : Promise<boolean | errors.ConnectionTimeoutException | errors.ConnectionFailedException>
Public Async getCncId
getCncId()
Returns : Promise<boolean>
Public getCNCLanguage
getCNCLanguage(lang: string)

Returns the CNC language associated with the HMI elite language Return CNC language

Parameters :
Name Type Optional
lang string No
Returns : string
Public getCncProcessInfo
getCncProcessInfo(cncNodeIndex: number)

Implements the isCncRunning service call. It calls to CommHmiNodeServer to call appropiate REST API route.

Returns a promise. This promise is fulfilled with reply object if everything is ok or is rejected with CncServiceOperationException when something goes wrong.

Parameters :
Name Type Optional Default value
cncNodeIndex number No 0
Public Async getCncVersion
getCncVersion()
Returns : Promise<boolean>
Public getGlobalsParInfo
getGlobalsParInfo(cncNodeIndex: number)

Gets the CNC global parameter info data and fills CommHmiNodeServer.globalsParInfo member. This service is referenced on runtime when {CommHmiNodeServer} creates Model-s. It calls to CommHmiNodeServer to call appropiate REST API route.

Returns a promise. This promise is fulfilled with reply object if everything is ok or is rejected with CncServiceOperationException when something goes wrong.

Parameters :
Name Type Optional Default value
cncNodeIndex number No 0
Public Async getSwOptions
getSwOptions()
Returns : Promise<boolean>
Public Async pressJogKeysToCnc
pressJogKeysToCnc(jogkey: string, cncNodeIndex: number)
Parameters :
Name Type Optional Default value Description
jogkey string No

Simulate full key pressed in 1 promise

cncNodeIndex number No 0
Public reboot
reboot(undefined: literal type)

Implements the reboot service call. It calls to CommHmiNodeServer to call appropiate REST API route.

Returns a promise. This promise is fulfilled with reply object if everything is ok or is rejected with CncServiceOperationException when something goes wrong.

Parameters :
Name Type Optional
literal type No
Public sendJogKeysToCnc
sendJogKeysToCnc(jogkey: string, value: number, cncNodeIndex: number)
Parameters :
Name Type Optional Default value
jogkey string No ""
value number No
cncNodeIndex number No 0
Public sendKeysToCnc
sendKeysToCnc(keys: string[], cncNodeIndex: number)

Implements the sendKeysToCNC private service call.

Returns a promise. This promise is fulfilled with reply object if everything is ok or is rejected with CncServiceOperationException when something goes wrong.

Parameters :
Name Type Optional Default value Description
keys string[] No []

Keys to send to the CNC

cncNodeIndex number No 0
Public setMachineParameter
setMachineParameter(route: string, name: string, value: string, cncNodeIndex: number)

Implements the setMachineParameter service call. writes and validates a machine parameter by its variable name. This service is referenced on runtime when {CommHmiNodeServer} creates Model-s. It calls to CommHmiNodeServer to call appropiate REST API route.

Returns a promise. This promise is fulfilled with reply object if everything is ok or is rejected with CncServiceOperationException when something goes wrong.

Parameters :
Name Type Optional Default value Description
route string No ""

Execution route

name string No ""
value string No ""
cncNodeIndex number No 0
Public setTimeout
setTimeout(timeout: number)

Sets http request timeout

Parameters :
Name Type Optional
timeout number No
Returns : void
Public shutdown
shutdown(undefined: literal type)

Implements the shutdown service call. It calls to CommHmiNodeServer to call appropiate REST API route.

Returns a promise. This promise is fulfilled with reply object if everything is ok or is rejected with CncServiceOperationException when something goes wrong.

Parameters :
Name Type Optional
literal type No
Public shutdownServer
shutdownServer()

Sends a shutdown message to remote endpoing

Returns : boolean
Public start
start(cncNodeIndex: number)

Implements the start service call. It calls to CommHmiNodeServer to call appropiate REST API route.

Returns a promise. This promise is fulfilled with reply object if everything is ok or is rejected with CncServiceOperationException when something goes wrong.

Parameters :
Name Type Optional Default value
cncNodeIndex number No 0

results matching ""

    No results matching ""