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 :)
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');
});
exposed by require('ads-node-client');
var AdsNodeClient = require('ads-node-client');
var ads = new AdsNodeClient(options);
Parameter:
- options: Object contain the client options
Name | Description | Default | Required |
---|---|---|---|
host |
the ip adress of the target | yes | |
port |
the tcp port of the target | 48898 | no |
amsTargetNetID |
AMS Net ID of the target | yes | |
amsSourceNetID |
AMS Net ID of the source | yes | |
amsPortSource: |
AMS port of the source | 32905 | no |
amsPortTarget: |
AMS port of the target | 801 | no |
keepAlive: |
maintain the connection open | false | no |
verbose: |
display debug messages | false | no |
Return:
Object | an instance of the adsNodeClient class
open the connection
ads.open();
Parameter:
none
Return:
Socket the socket used for the connection
close the connection
Not yet implemented
close the connection
ads.readDeviceInfo();
Parameter:
- cb executed when the response is received
Return:
Integer the id of the transaction
read the state of the PLC
ads.readState();
Parameter:
- cb: Function executed when the response is received
Return:
Integer the id of the transaction
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
Name | Description | Default | Required |
---|---|---|---|
symname |
the symbol name | if indexGroup and indexOffset are not defined | |
indexGroup |
the tcp port of the target | 48898 | if symname not defined |
indexOffset |
AMS Net ID of the target | if symname not defined | |
bytelength |
AMS Net ID of the source | yes |
- cb: Function executed when the response is received
Return:
Integer the id of the transaction
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
Name | Description | Default | Required |
---|---|---|---|
symname |
the symbol name | if indexGroup and indexOffset are not defined | |
indexGroup |
the tcp port of the target | 48898 | if symname not defined |
indexOffset |
AMS Net ID of the target | if symname not defined | |
bytelength |
AMS Net ID of the source | yes |
- cb: Function executed when the response is received
Return:
Integer the id of the transaction
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
Name | Description | Default | Required |
---|---|---|---|
symname |
the symbol name | if indexGroup and indexOffset are not defined | |
indexGroup |
the tcp port of the target | 48898 | if symname not defined |
indexOffset |
AMS Net ID of the target | if symname not defined | |
bytelength |
AMS Net ID of the source | yes |
- cb: Function executed when the response is received
Return:
Integer the id of the transaction
stop be notified when a value change
Not yet implemented
ads.on("valueChange", function(response){
console.log(response.data.value);
}
Name | Description |
---|---|
open |
the connection is open |
close |
the connection is closed |
end |
The other end close the socket |
receive |
Some data has been received |
error |
There is an error |
deviceInfoResponse |
Device Information received |
readWriteResponse |
Read Write response received |
readResponse |
Read response received |
deleteNotifResponse |
Delete notification response received |
writeControlResponse |
Write control response received |
writeResponse |
Write response received |
readStateResponse |
Read state response received |
addNotifResponse |
Add notification response received |
valueChange |
A variable value changed |
newNotification |
New notification request received |