0.0.4 • Published 9 years ago

ads-node-client v0.0.4

Weekly downloads
3
License
MIT
Repository
github
Last release
9 years ago

adsNodeClient

ADS TWINCAT Client for Node.js

A Node.js implementation for the TWINCAT protocol oriented event.

This library is for the moment not really operational only write and read method can be used. Please be patient :)

How to use

var AdsNodeClient = require('ads-node-client');
 
var options = {
    host: "192.168.2.4", 
    amsTargetNetID: "5.27.156.9.1.1", 
    amsSourceNetID: "192.168.2.2.0.0", 
}; 
 
var ads = new AdsNodeClient(options);
ads.open();
 
ads.on('connect', function() {
    console.log('#ADS new Connection');
});

API

Class

exposed by require('ads-node-client');

Constructor(options)

var AdsNodeClient = require('ads-node-client');
var ads = new AdsNodeClient(options);

Parameter:

  • options: Object contain the client options
NameDescriptionDefaultRequired
hostthe ip adress of the targetyes
portthe tcp port of the target48898no
amsTargetNetIDAMS Net ID of the targetyes
amsSourceNetIDAMS Net ID of the sourceyes
amsPortSource:AMS port of the source32905no
amsPortTarget:AMS port of the target801no
keepAlive:maintain the connection openfalseno
verbose:display debug messagesfalseno

Return:

Object | an instance of the adsNodeClient class

Method open()

open the connection

ads.open();

Parameter:

none

Return:

Socket the socket used for the connection

Method close()

close the connection

Not yet implemented

Method readDeviceInfo(cb)

close the connection

ads.readDeviceInfo();

Parameter:

  • cb executed when the response is received

Return:

Integer the id of the transaction

Method readState(cb)

read the state of the PLC

ads.readState();

Parameter:

  • cb: Function executed when the response is received

Return:

Integer the id of the transaction

Method read(options, cb)

read the value of a variable

var handle = {
	symname:".START"
}
ads.read(handle,function(response){
    console.log(response.data.value);
});

Parameter:

  • options: Object containing the request option
NameDescriptionDefaultRequired
symnamethe symbol nameif indexGroup and indexOffset are not defined
indexGroupthe tcp port of the target48898if symname not defined
indexOffsetAMS Net ID of the targetif symname not defined
bytelengthAMS Net ID of the sourceyes
  • cb: Function executed when the response is received

Return:

Integer the id of the transaction

Method write(options, cb)

assign a value to a variable

var handle = {
	symname:".START",
    value: true
}
ads.write(handle,function(response){
    console.log("write request sended");
});

Parameter:

  • options: Object containing the request option
NameDescriptionDefaultRequired
symnamethe symbol nameif indexGroup and indexOffset are not defined
indexGroupthe tcp port of the target48898if symname not defined
indexOffsetAMS Net ID of the targetif symname not defined
bytelengthAMS Net ID of the sourceyes
  • cb: Function executed when the response is received

Return:

Integer the id of the transaction

Method subscribe(options, cb)

subscribe to be notified when a value change

var handle = {
	symname:".START"
}
var notifHandle = ads.subscribe(handle,function(response){
    console.log("start listen");
});

ads.on("valueChange", function(response){
	if(response.data.notifHandle == notifHandle){
    	console.log(response.data.value);
    }
}

Parameter:

  • options: Object containing the request option
NameDescriptionDefaultRequired
symnamethe symbol nameif indexGroup and indexOffset are not defined
indexGroupthe tcp port of the target48898if symname not defined
indexOffsetAMS Net ID of the targetif symname not defined
bytelengthAMS Net ID of the sourceyes
  • cb: Function executed when the response is received

Return:

Integer the id of the transaction

Method unsubscribe()

stop be notified when a value change

Not yet implemented

Events

ads.on("valueChange", function(response){
    console.log(response.data.value);
}
NameDescription
openthe connection is open
closethe connection is closed
endThe other end close the socket
receiveSome data has been received
errorThere is an error
deviceInfoResponseDevice Information received
readWriteResponseRead Write response received
readResponseRead response received
deleteNotifResponseDelete notification response received
writeControlResponseWrite control response received
writeResponseWrite response received
readStateResponseRead state response received
addNotifResponseAdd notification response received
valueChangeA variable value changed
newNotificationNew notification request received
0.0.4

9 years ago

0.0.3

9 years ago

0.0.2

9 years ago

0.0.1

9 years ago