roccomuso / node-ads Goto Github PK
View Code? Open in Web Editor NEWNodeJS Twincat ADS protocol implementation
NodeJS Twincat ADS protocol implementation
Hi @PLCHome ,
I was trying to use the the write array handle to pass the array to the beckhoff machine.
But when I pass the array I got an exception of 'Property value not available on handle!'
Here is the handle that I pass through:
var myHandle = {
symname: 'LLC.arrayOperationToolId',
bytelength: ads.array(ads.INT,0,9),
value: [0,1,2,3,4,5,6,7,8],
propname: 'value'
}
The low index and high index is the same register in the twincat and the name is the same as well.
Other than array everything works fine.
Did I do something wrong?
I have my laptop(192.168.0.120) connected over local network to a Win10 PC (192.168.0.208) running TwinCAT 3.
I am trying to do a readDeviceInfo
as described in the documentation ("Hello Machine") with options set like this:
var options = {
host: "192.168.0.208",
amsNetIdTarget: "192.168.0.208.1.1",
amsNetIdSource: "10.0.75.1.1.1",
amsPortTarget: 801,
timeout: 10000
}
I tried to add the route on the target PC via the Router UI, but it would silently fail (TwinCAT beginner here). So I ended up adding a static route to the StaticRoutes.xml file and it looks like this:
<Route>
<Name>RemoteClient</Name>
<Address>192.168.0.120</Address>
<NetId>10.0.75.1.1.1</NetId>
<Type>TCP_IP</Type>
<Flags>32</Flags>
</Route>
When I run the simple js to execute read the device info, I get
{ Error: read ECONNRESET
at TCP.onread (net.js:622:25) errno: 'ECONNRESET', code: 'ECONNRESET', syscall: 'read' }
or timeout
Wireshark shows that the laptop (RemoteClient) sends the DeviceInfoRequest, but the target PC promptly closes the connection.
From what I understand, add the route on the target PC essentially authorizes the client to connect. I am guessing that's where my problem lies, but I am unable to solve it.
Any ideas?
Thanks!
Hi @roccomuso ,
I'm trying to use node-ads to read values from beckhoff machine but I couldn't able to read array values , it gives me only the value at position 0, in the array (only displays var[0]).
As you say in the project, creating two ADS connections needs another IP address bound to the second process.
But how do I do that? I can't seem to find a way to bind the TCP connection to another IP address anywhere. Is there a way to do that?
Thank you! Other than that, I enjoy this implementation a lot!
Typescript is mentioned in another issues here #14 (comment) and it's suggested that it would take a complete rewrite.
Not necessarily. The non-typing syntax of TypeScript is JavaScript. I've changed many projects (mostly non-OSS) over from JS to TS and it's relatively painless (especially if they are smaller, e.g. <10kLOC). I find that the only things I end up changing, other than adding types, are things that should have changed anyway, but weren't apparent without the types.
I think there is a significant benefit to both provide typing for end users as well as maintaining types in the project for future maintenance.
TypeScript can also address older node compliance (also mentioned in other issues/PR) by have TS compile to an earlier version of JS for publishing on NPM while allowing the source code to be maintained with the latest syntax.
I'd also like to see the addition of unit testing and linting to the project.
Would any or all of these changes (typing, testing, linting) be entertained?
When I tried notifications, I could read the value with a handle, but I was never notified of changes.
Apparently, at line 198, there's a condition that never gets satisfied for notifications:
if (ads.pending[invokeId]) {
It isn't invoked from the library, so there's no pending object and no callback.
Adding these two lines made the notifications work.
if (commandId == ID_NOTIFICATION) {
getNotificationResult.call(this, data)
} else if (ads.pending[invokeId]) //...
Some additional cleanup (like the removing the case and check referencing ID_NOTIFICATION
) might be needed.
Hi there,
I am using the notify method this to read position feedback from axes, however i am finding that the socket connection closes after approx 10 seconds.
const options = {
host: '10.4.4.1',
amsNetIdTarget: '10.4.4.1.1.1',
amsNetIdSource: '10.4.4.2.1.1',
};
// Reading this...
var myHandle = {
symname: 'GVL.fbRevolve.rPosition',
bytelength: ads.LREAL,
};
var client = ads.connect(options, function() {
this.notify(myHandle);
});
client.on('notification', function(handle) {
console.log(handle.value);
});
client.on('close', function(data) {
console.log('CLOSE', data);
});
client.on('error', function(err) {
console.log('Error: ', err);
});
This works correctly for about 10 seconds before the socket is closed.
I thought it may have been a timeout somewhere, maybe the client not sending data frequently enough(?), so have added the following:
var client = ads.connect(options, function() {
this.notify(myHandle);
setInterval(() => {
this.readDeviceInfo(function(err, result) {
if (err) console.log('Error: ', err);
console.log('\nreadDeviceInfo: ', result);
// this.end();
});
}, 1000);
});
however after about 10 seconds the following gets thrown:
Error: Error: This socket has been ended by the other party
at Socket.writeAfterFIN [as write] (net.js:407)
at Object.runCommand (ads.js:1014)
at Object.readDeviceInfo (ads.js:295)
at EventEmitter.ads.adsClient.readDeviceInfo (ads.js:60)
at renderer.js:153
Any Ideas how to keep the connect open?
Thanks,
Jon
Was wondering when you'd have time to publish the latest version to npm.
Thanks :)
Hi, i have a problem by using the multiRead
method, i tried different things and also only one value, but it's returning every time only the error message Error: parameter size not correct
. What i'm doing wrong?
The communication itself is working well so far. Single values are working as expected.
I'm using a Beckhoff TwinCAT v2.11.
var ads = require('node-ads')
var options = {
host: "192.168.1.174",
amsNetIdTarget: "10.0.0.105.1.1",
amsNetIdSource: "192.168.137.50.1.1",
}
var client = ads.connect(options, function() {
this.notify({
symname: '.AI_Light_Sensor',
bytelength: ads.INT
});
this.notify({
symname: '.PT_Temp_Sensor',
bytelength: ads.INT
});
this.read({
symname: '.AI_Light_Sensor',
bytelength: ads.INT,
}, function(err, handle) {
if (err) console.log(err)
console.log(handle.value)
});
this.read({
symname: '.PT_Temp_Sensor',
bytelength: ads.INT,
}, function(err, handle) {
if (err) console.log(err)
console.log(handle.value)
});
this.multiRead([
{
symname: '.DO_Lamp_1',
bytelength: ads.BOOL,
}, {
symname: 'MAIN.test',
bytelength: ads.BOOL,
}, {
symname: '.DI_Button',
bytelength: ads.BOOL,
}, {
symname: '.AI_Light_Sensor',
bytelength: ads.INT,
}, {
symname: '.PT_Temp_Sensor',
bytelength: ads.INT,
}, {
symname: '.DIM_Lamp_2',
bytelength: ads.INT,
}, {
symname: '.GLOBAL_Dimmer_1',
bytelength: ads.INT,
}
],
function(err, handle) {
if (err) console.log(err)
console.log(handle)
});
});
client.on('notification', function(handle){
console.log(handle)
})
process.on('exit', function () {
console.log("exit")
})
process.on('SIGINT', function() {
client.end(function() {
process.exit()
})
})
client.on('error', function(error) {
console.log(error)
})
This is the error message on the console:
{ options:
{ host: '192.168.1.174',
amsNetIdTarget: '10.0.0.105.1.1',
amsNetIdSource: '192.168.137.50.1.1',
port: 48898,
amsPortSource: 32905,
amsPortTarget: 801,
verbose: 0 },
invokeId: 9,
pending:
{ '6': { cb: [Function], timeout: [Object] },
'7': { cb: [Function], timeout: [Object] },
'8': { cb: [Function], timeout: [Object] },
'9': { cb: [Function], timeout: [Object] } },
symHandlesToRelease:
[ <Buffer 44 00 00 f7>,
<Buffer 44 00 00 f7>,
<Buffer 63 02 00 f7>,
<Buffer a3 00 00 f7> ],
notificationsToRelease: [],
notifications: {},
dataStream: null,
tcpHeaderSize: 6,
amsHeaderSize: 32,
adsClient:
EventEmitter {
connect: [Function],
end: [Function],
readDeviceInfo: [Function],
read: [Function],
write: [Function],
notify: [Function],
writeRead: [Function],
getSymbols: [Function],
multiRead: [Function],
_eventsCount: 2 },
tcpClient:
Socket {
connecting: false,
_hadError: false,
_handle:
TCP {
reading: true,
owner: [Circular],
onread: [Function: onread],
onconnection: null,
writeQueueSize: 0 },
_parent: null,
_host: null,
_readableState:
ReadableState {
objectMode: false,
highWaterMark: 16384,
buffer: [Object],
length: 0,
pipes: null,
pipesCount: 0,
flowing: true,
ended: false,
endEmitted: false,
reading: false,
sync: false,
needReadable: true,
emittedReadable: false,
readableListening: false,
resumeScheduled: false,
destroyed: false,
defaultEncoding: 'utf8',
awaitDrain: 0,
readingMore: false,
decoder: null,
encoding: null },
readable: true,
domain: null,
_events:
{ end: [Object],
finish: [Function: onSocketFinish],
_socketEnd: [Function: onSocketEnd],
data: [Function],
timeout: [Function],
error: [Function] },
_eventsCount: 6,
_maxListeners: undefined,
_writableState:
WritableState {
objectMode: false,
highWaterMark: 16384,
finalCalled: false,
needDrain: false,
ending: false,
ended: false,
finished: false,
destroyed: false,
decodeStrings: false,
defaultEncoding: 'utf8',
length: 0,
writing: false,
corked: 0,
sync: false,
bufferProcessing: false,
onwrite: [Function: bound onwrite],
writecb: null,
writelen: 0,
bufferedRequest: null,
lastBufferedRequest: null,
pendingcb: 3,
prefinished: false,
errorEmitted: false,
bufferedRequestCount: 0,
corkedRequestsFree: [Object] },
writable: true,
allowHalfOpen: false,
_bytesDispatched: 595,
_sockname: null,
_pendingData: null,
_pendingEncoding: '',
server: null,
_server: null,
read: [Function],
_consuming: true,
[Symbol(asyncId)]: 6,
[Symbol(bytesRead)]: 0 },
dataCallback: [Function] }
Error: parameter size not correct
at getError (/Users/oVi/dev/src-one/homecontrol/node_modules/node-ads/lib/ads.js:1245:13)
at Object.getWriteReadResult (/Users/oVi/dev/src-one/homecontrol/node_modules/node-ads/lib/ads.js:760:13)
at Object.analyseResponse (/Users/oVi/dev/src-one/homecontrol/node_modules/node-ads/lib/ads.js:235:28)
at Object.checkResponseStream (/Users/oVi/dev/src-one/homecontrol/node_modules/node-ads/lib/ads.js:173:25)
at Object.analyseResponse (/Users/oVi/dev/src-one/homecontrol/node_modules/node-ads/lib/ads.js:241:23)
at Object.checkResponseStream (/Users/oVi/dev/src-one/homecontrol/node_modules/node-ads/lib/ads.js:173:25)
at Object.analyseResponse (/Users/oVi/dev/src-one/homecontrol/node_modules/node-ads/lib/ads.js:241:23)
at Object.checkResponseStream (/Users/oVi/dev/src-one/homecontrol/node_modules/node-ads/lib/ads.js:173:25)
at Object.analyseResponse (/Users/oVi/dev/src-one/homecontrol/node_modules/node-ads/lib/ads.js:241:23)
at Object.checkResponseStream (/Users/oVi/dev/src-one/homecontrol/node_modules/node-ads/lib/ads.js:173:25)
Hello Mister Musolino
When I do an update with npm I do receive version 1.4.3 of node-ads but unfortunately the getSymbols bugfix you did at 25 Sep 2018 is not contained. Could you please have a look at this.
Thanks for your help and another thanks for your library. It looks much better to me than the TcAdsWebService stuff from Beckhoff. Good job!
Best regards
Markus Hardardt
I have successfully accessed remote ads target. But if I want to access target on the same machine(node app and target are same PC), then I get timeout.
var options = {
host: "10.10.2.100",
amsNetIdTarget: "10.10.2.100.1.1",
amsNetIdSource: "10.10.2.100.1.1",
amsPortTarget: 801
}
var myHandle = {
symname: '.NoBeam',
bytelength: ads.BOOL,
propname: 'value'
}
var client = ads.connect(options, function() {
this.read(myHandle, function(err, handle) {
if (err) console.log(err)
else console.log(handle.value)
this.end()
})
})
yields to timeout
message printed only.
10.10.2.100 (and I also tried 127.0.0.1) added into static routing table.
Using TC2.
Hello @roccomuso ,
I use a CX5020 for my trials and also have problems to connect. I tried a several times different combinations of Adresses NetIds and ports but no success. Here are the error messages I face:
"Error ADS: Error: connect ECONNREFUSED 192.168.137.235:48898"
"Error readDeviceInfo: timeout"
"Ads Register Notification live tick timeout"
"Ads Register Notification Sym Tab timeout"
the ECONNREFUSED message sometimes dissappears suddenly but also suddenly comes back without having made any config changes.
Originally posted by @Wolfskammer04 in #1 (comment)
The pull request from sanders17 seems to be ok...
when does it come on the master branch and npm install?
It would be nice to be able to create a handle using an index group and offset.
For example:
When connecting to port 100 (logger), you can do an Add Device Notification on 0x1 / 0xffff to get notifications of the ADSLOGSTR(), the ones that are normally logged to the event viewer.
I have an app which is periodically writing few variables in PLC. The period is every 5 minute.
var options = {
host: "127.0.0.1",
amsNetIdTarget: "10.10.2.100.1.1",
amsNetIdSource: "10.10.2.100.1.15",
amsPortTarget: 801
}
var client = ads.connect(options, function() {
WriteAds(client, values[0]).
then(() => WriteAds(client, values[1])).
then(() => WriteAds(client, values[2])).
then(() => WriteAds(client, values[3])).
then(() => WriteAds(client, values[4])).
then(() => WriteAds(client, values[5])).
then(() => WriteAds(client, values[6])).
then(() => WriteAds(client, validityHandle)).
catch((err) => {
log.error("Error writing to ADS: ", err);
}).
finally(() => ReleaseAndDisconnect(client))
})
function ReleaseAndDisconnect(client)
{
return new Promise(function(resolve, reject){
client.end(function (){ resolve() })
resolve()
})
}
function WriteAds(client, h)
{
return new Promise(function(resolve, reject){
client.write(h, function(err) {
if (err)
{
reject(err)
}
else
{
resolve()
}
})
})
}
As you can see, there are 6 handles in array and 1 standalone handle. This is the exception
Error writing to ADS: symbol not found
Error: symbol not found
at getError (C:\pkg\node_modules\node-ads\lib\ads.js:1290:13)
at Object.getWriteResult (C:\pkg\node_modules\node-ads\lib\ads.js:792:13)
at Object.analyseResponse (C:\pkg\node_modules\node-ads\lib\ads.js:224:24)
at Object.checkResponseStream (C:\pkg\node_modules\node-ads\lib\ads.js:177:25)
at Socket.<anonymous> (C:\pkg\node_modules\node-ads\lib\ads.js:116:25)
at emitOne (events.js:116:13)
at Socket.emit (events.js:211:7)
at addChunk (_stream_readable.js:263:12)
at readableAddChunk (_stream_readable.js:250:11)
at Socket.Readable.push (_stream_readable.js:208:10)
It happens on standalone variable. Variables before are written just fine.
I captured ADS traffic and can see that ADSIGRP_SYM_HNDBYNAME
is called for all variables following ADSIGRP_SYM_VALBYHND
, except last one. The last one only received ADSIGRP_SYM_VALBYHND
without prior ADSIGRP_SYM_HNDBYNAME
. Not sure where index/offset was discovered, but there is some value. Is it cached somewhere?
Hi
Maybe a stupid question. Can this module work on a non windows machine? Can it directly connect to Beckhoff ADS server?
Thank you in advance
Hi @roccomuso,
I am thinking about using your module to talk to a Beckhoff PLC. Do you use this module yourself and is it considered to be stable?
I tried to connect to TwinCAT3 on my Virtual Machine but wasn't very successfull. Wireshark said the connection was established successfully. I also added a project route and set the amsPortTarget to 851 (due to TwinCAT3) but no luck. I always experience a timeout in the error handler.
Hi there
I have following problem:
i have set up a Project, that have around 350 ads nodes. (ADS Notification and ADS Outputs). -->i mean, thats under the Limit of the readme..
When i restart the PLC, everything is ok. But from the 1st or 2nd Deploy in Node-RED i have following Errors: (@every Deploy and peridically)
"Ads Register Notification timeout".
Sometimes followed by:
"Ads write timeout" and / or "This socket has been ended by the other party"
I have tried to set the timeout in the ads config node to 2000ms with the same result.
Node-RED: v1.0.3
Nodejs: 11.9.0
ADS: 1.1.22
My Node-RED is Running in a Docker Container on a Raspberry Pi and the PLC is Running on a CX5120 in the same Network.
It seems as the connection doesn't close correctly or something like that. Do you have an idea what can be wrong?
--> You can see here the start discussion: PLCHome/node-red-contrib-ads#25 (comment)
maybe, you can fix that problem in the api..?
Hi @PLCHome ,
I was trying to use multiWrite to pass the array to the beckhoff machine.
But when I pass the array I got an exception of 'parameter size not correct'
Here is the handle that I pass through:
var myHandle = [{
symname: 'Main.b',
bytelength: ads.INT,
value: 200
}, {
symname: 'Main.c',
bytelength: ads.BOOL,
value: true
}]
Did I do something wrong?
Hi
How can I use the multi read function? Tried to pass the handle as array, but didn't work.
Thank's for your advice.
Regards Heleon
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.