ads-client 1.12.1 → 1.13.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +21 -0
- package/README.md +58 -2
- package/package.json +1 -1
- package/src/ads-client-ads.js +7 -1
- package/src/ads-client.js +33 -29
package/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,27 @@ All notable changes to this project will be documented in this file.
|
|
|
4
4
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
5
5
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
6
6
|
|
|
7
|
+
## [1.13.1] - 04.04.2022
|
|
8
|
+
### Changed
|
|
9
|
+
- Bug fix: Undefined variable `message` [See issue #89](https://github.com/jisotalo/ads-client/issues/89)
|
|
10
|
+
- Updated ADS error codes with new ones [See issue #88](https://github.com/jisotalo/ads-client/issues/88)
|
|
11
|
+
- Updated README
|
|
12
|
+
|
|
13
|
+
## [1.13.0] - 27.02.2022
|
|
14
|
+
### Added
|
|
15
|
+
- Added new setting `bareClient`. If it's set, the client will only connect to the target, nothing else
|
|
16
|
+
- No system manager, symbol version, device info and upload info are read
|
|
17
|
+
- Can be used to connect to non-PLC systems such as [ads-server](https://github.com/jisotalo/ads-server) targets and other ADS supported devices
|
|
18
|
+
- Only requirement is that ADS route is available
|
|
19
|
+
|
|
20
|
+
### Changed
|
|
21
|
+
- Updated README
|
|
22
|
+
|
|
23
|
+
## [1.12.2] - 12.02.2022
|
|
24
|
+
### Changed
|
|
25
|
+
- Bug fix: `TOD` data type was not regonized on TwinCAT 2 and TwinCAT 3 (TC3 builds <= 4020)
|
|
26
|
+
- [See issue #83](https://github.com/jisotalo/ads-client/issues/83)
|
|
27
|
+
|
|
7
28
|
## [1.12.1] - 17.01.2022
|
|
8
29
|
### Changed
|
|
9
30
|
- Updated dependecies to latest versions
|
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
|
|
4
4
|
[](https://www.npmjs.org/package/ads-client)
|
|
5
|
-
[](https://www.paypal.com/donate/?business=KUWBXXCVGZZME&no_recurring=0¤cy_code=EUR)
|
|
6
6
|
[](https://github.com/jisotalo/ads-client)
|
|
7
7
|
[](https://choosealicense.com/licenses/mit/)
|
|
8
8
|
|
|
@@ -13,10 +13,15 @@ Coded from scratch using [TwinCAT ADS specification](https://infosys.beckhoff.co
|
|
|
13
13
|
There is automatically created documentation available at https://jisotalo.github.io/ads-client/
|
|
14
14
|
|
|
15
15
|
# Project status
|
|
16
|
-
This project is currently "ready". It's maintained actively and used in projects by the author and others
|
|
16
|
+
This project is currently "ready". It's maintained actively and used in projects by the author and others (also lot's of commercial projects)
|
|
17
17
|
|
|
18
18
|
Bugs are fixed if found and new features can be added. Please let me know if you have any ideas!
|
|
19
19
|
|
|
20
|
+
And if you want you can buy me a beer using PayPal :)
|
|
21
|
+
|
|
22
|
+
[](https://www.paypal.com/donate/?business=KUWBXXCVGZZME&no_recurring=0¤cy_code=EUR)
|
|
23
|
+
|
|
24
|
+
|
|
20
25
|
# Using Node-RED?
|
|
21
26
|
Check out the [node-red-contrib-ads-client](https://www.npmjs.com/package/node-red-contrib-ads-client) package. It's an `ads-client` wrapper for Node-RED to get the same functionality.
|
|
22
27
|
|
|
@@ -29,6 +34,7 @@ Check out the [node-red-contrib-ads-client](https://www.npmjs.com/package/node-r
|
|
|
29
34
|
- [Enabling localhost support on TwinCAT 3](#enabling-localhost-support-on-twincat-3)
|
|
30
35
|
- [IMPORTANT: Writing STRUCT variables](#important-writing-struct-variables)
|
|
31
36
|
- [IMPORTANT: Things to know when using with TwinCAT 2](#important-things-to-know-when-using-with-twincat-2)
|
|
37
|
+
- [Connecting to systems without PLC runtime](#connecting-to-systems-without-plc-runtime)
|
|
32
38
|
- [Getting started](#getting-started)
|
|
33
39
|
* [Data types used in getting started](#data-types-used-in-getting-started)
|
|
34
40
|
* [Creating a new Client instance](#creating-a-new-client-instance)
|
|
@@ -336,6 +342,26 @@ await client.readSymbol('.ExampleSTRUCT') //TwinCAT 2
|
|
|
336
342
|
This is the only one non-working feature as there are no methods in TC2.
|
|
337
343
|
|
|
338
344
|
|
|
345
|
+
# Connecting to systems without PLC runtime
|
|
346
|
+
|
|
347
|
+
Since version 1.13.0 it's possible to connect to systems without PLC runtime and/or system manager using `ads-client`.
|
|
348
|
+
|
|
349
|
+
In previous versions, the client always checked the system state (RUN, CONFIG). However when connecting to different systems (non-PLC systems), there might be no system manager service. With default configuration this causes an error:
|
|
350
|
+
```
|
|
351
|
+
ClientException: Connection failed: Device system manager state read failed
|
|
352
|
+
```
|
|
353
|
+
|
|
354
|
+
By providing `bareClient` setting, the client connects to the router or target and nothing else. After that, the client can be used to read/write data. However, connection losses etc. need to be handled by the user.
|
|
355
|
+
|
|
356
|
+
|
|
357
|
+
```js
|
|
358
|
+
const client = new ads.Client({
|
|
359
|
+
targetAmsNetId: '192.168.5.131.3.1',
|
|
360
|
+
targetAdsPort: 1002,
|
|
361
|
+
bareClient: true //NOTE
|
|
362
|
+
})
|
|
363
|
+
```
|
|
364
|
+
|
|
339
365
|
# Getting started
|
|
340
366
|
|
|
341
367
|
This chapter includes some short getting started examples. See the JSDoc [documentation](#documentation) for detailed description of library classes and methods.
|
|
@@ -1623,6 +1649,36 @@ For example, when copying a variable name from TwinCAT online view using CTRL+C,
|
|
|
1623
1649
|
|
|
1624
1650
|
If you have problems, try to read the variable information using `readSymbolInfo()`. The final solution is to read all data types using `readAndCacheDataTypes()` and manually finding the correct type.
|
|
1625
1651
|
|
|
1652
|
+
### ClientException: Connection failed: Device system manager state read failed
|
|
1653
|
+
|
|
1654
|
+
This error indicates that the given AmsnetId didn't contain system manager service (port 10000). If you connect to the PLC system, there is always system manager and PLC runtime(s). However, when connecting to other systems than PLC, it might be that there is no system manager service.
|
|
1655
|
+
|
|
1656
|
+
Solution:
|
|
1657
|
+
- Double check AmsNetId settings (if connecting directly to PLC)
|
|
1658
|
+
- [Set `bareClient` setting to skip all system manager and PLC runtime checks](#connecting-to-systems-without-plc-runtime) (version 1.13.0 ->)
|
|
1659
|
+
|
|
1660
|
+
### Connection failed (error EADDRNOTAVAIL)
|
|
1661
|
+
This could happen if you have manually provided `localAddress` or `localTcpPort` that don't exist.
|
|
1662
|
+
For example, setting localAddress to 192.168.10.1 when the computer has only ethernet interface with IP 192.168.1.1.
|
|
1663
|
+
|
|
1664
|
+
See https://github.com/jisotalo/ads-client/issues/82
|
|
1665
|
+
|
|
1666
|
+
### Problems running ads-client with docker
|
|
1667
|
+
|
|
1668
|
+
- EADDRNOTAVAIL: See above and https://github.com/jisotalo/ads-client/issues/82
|
|
1669
|
+
|
|
1670
|
+
### How to connect to PLC that is in CONFIG mode?
|
|
1671
|
+
As default, the ads-client checks if the target has PLC runtime at given port. However, when target system manager is at config mode, there is none. The client will throw an error during connecting.
|
|
1672
|
+
|
|
1673
|
+
`Target and system manager found but couldn't connect to the PLC runtime (see settings allowHalfOpen and bareClient)`
|
|
1674
|
+
|
|
1675
|
+
You can disable the check by providing setting `allowHalfOpen: true`. After that, it's possible to start the PLC by `setSystemManagerToRun()`. However, when using this setting internal subscription like symbol version etc. might not work properly.
|
|
1676
|
+
|
|
1677
|
+
Another option is to use setting `bareClient: true` (since v.1.13.0). However, when using this option, the ads-client does not handle anything automatically - it's just a bare client (duh).
|
|
1678
|
+
|
|
1679
|
+
I would suggest to use ads-client normally without any special settings. If the target is at config mode, use separate client instance to start it, and the again the normal instance to connect to a running system. This way the client works the best.
|
|
1680
|
+
|
|
1681
|
+
|
|
1626
1682
|
|
|
1627
1683
|
# Documentation
|
|
1628
1684
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ads-client",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.13.1",
|
|
4
4
|
"description": "Beckhoff TwinCAT ADS client library for Node.js (unofficial). Connects to Beckhoff TwinCAT automation systems using ADS protocol.",
|
|
5
5
|
"main": "./src/ads-client.js",
|
|
6
6
|
"scripts": {
|
package/src/ads-client-ads.js
CHANGED
|
@@ -352,6 +352,8 @@ const ADS_ERROR = {
|
|
|
352
352
|
26: 'TCP send error',
|
|
353
353
|
27: 'Host unreachable',
|
|
354
354
|
28: 'Invalid AMS fragment',
|
|
355
|
+
29: 'TLS send error – secure ADS connection failed.',
|
|
356
|
+
30: 'Access denied – secure ADS access denied.',
|
|
355
357
|
1280: 'No locked memory can be allocated',
|
|
356
358
|
1281: 'The size of the router memory could not be changed',
|
|
357
359
|
1282: 'The mailbox has reached the maximum number of possible messages. The current sent message was rejected',
|
|
@@ -363,6 +365,9 @@ const ADS_ERROR = {
|
|
|
363
365
|
1288: 'The maximum number of Ports reached',
|
|
364
366
|
1289: 'Invalid port',
|
|
365
367
|
1290: 'TwinCAT Router not active',
|
|
368
|
+
1291: 'The mailbox has reached the maximum number for fragmented messages.',
|
|
369
|
+
1292: 'A fragment timeout has occurred.',
|
|
370
|
+
1293: 'The port is removed.',
|
|
366
371
|
1792: 'General device error',
|
|
367
372
|
1793: 'Service is not supported by server',
|
|
368
373
|
1794: 'Invalid index group',
|
|
@@ -420,6 +425,7 @@ const ADS_ERROR = {
|
|
|
420
425
|
1862: 'Error in win32 subsystem',
|
|
421
426
|
1863: 'Invalid client timeout value',
|
|
422
427
|
1864: 'Ads-port not opened',
|
|
428
|
+
1865: 'No AMS address.',
|
|
423
429
|
1872: 'Internal error in ads sync',
|
|
424
430
|
1873: 'Hash table overflow',
|
|
425
431
|
1874: 'Key not found in hash',
|
|
@@ -1011,7 +1017,7 @@ const BASE_DATA_TYPES = {
|
|
|
1011
1017
|
fromBuffer: buffer => buffer.readInt32LE(0)
|
|
1012
1018
|
},
|
|
1013
1019
|
{
|
|
1014
|
-
name: ['UDINT', 'DWORD', 'TIME', 'TIME_OF_DAY', 'BITARR32', 'UINT32'],
|
|
1020
|
+
name: ['UDINT', 'DWORD', 'TIME', 'TIME_OF_DAY', 'TOD', 'BITARR32', 'UINT32'],
|
|
1015
1021
|
adsDataType: ADS_DATA_TYPES.ADST_UINT32,
|
|
1016
1022
|
size: 4,
|
|
1017
1023
|
toBuffer: (value, buffer) => buffer.writeUInt32LE(value),
|
package/src/ads-client.js
CHANGED
|
@@ -74,6 +74,7 @@ class Client extends EventEmitter {
|
|
|
74
74
|
* @property {number} [connectionDownDelay=5000] - Time (milliseconds) after no successful reading of the system manager state the connection is determined to be lost - Optional (**default**: 5000 ms)
|
|
75
75
|
* @property {boolean} [allowHalfOpen=false] - If true, connect() is successful even if no PLC runtime is found (but target and system manager are available) - Can be useful if it's ok that after connect() the PLC runtime is not immediately available (example: connecting before uploading PLC code and reading data later) - WARNING: If true, reinitializing subscriptions might fail after connection loss.
|
|
76
76
|
* @property {boolean} [disableBigInt=false] - If true, 64 bit integer PLC variables are kept as Buffer objects instead of converting to Javascript BigInt variables (JSON.strigify and libraries that use it have no BigInt support)
|
|
77
|
+
* @property {boolean} [bareClient=false] - If true, only direct ads connection is established (no system manager etc) - Can be used to connect to systems without PLC runtimes etc.
|
|
77
78
|
*/
|
|
78
79
|
|
|
79
80
|
|
|
@@ -102,7 +103,8 @@ class Client extends EventEmitter {
|
|
|
102
103
|
checkStateInterval: 1000,
|
|
103
104
|
connectionDownDelay: 5000,
|
|
104
105
|
allowHalfOpen: false,
|
|
105
|
-
disableBigInt: false
|
|
106
|
+
disableBigInt: false,
|
|
107
|
+
bareClient: false
|
|
106
108
|
}
|
|
107
109
|
}
|
|
108
110
|
|
|
@@ -3126,7 +3128,7 @@ class ClientException extends Error {
|
|
|
3126
3128
|
if (typeof Error.captureStackTrace === 'function') {
|
|
3127
3129
|
Error.captureStackTrace(this, this.constructor)
|
|
3128
3130
|
} else {
|
|
3129
|
-
this.stack = (new Error(
|
|
3131
|
+
this.stack = (new Error(messageOrError)).stack
|
|
3130
3132
|
}
|
|
3131
3133
|
|
|
3132
3134
|
/**
|
|
@@ -3396,43 +3398,45 @@ function _connect(isReconnecting = false) {
|
|
|
3396
3398
|
this._internals.socketErrorHandler = _onSocketError.bind(this)
|
|
3397
3399
|
socket.on('error', this._internals.socketErrorHandler)
|
|
3398
3400
|
|
|
3399
|
-
|
|
3400
|
-
//Try to read system manager state - If it's OK, connection is successful to the target
|
|
3401
|
-
await this.readSystemManagerState()
|
|
3402
|
-
_systemManagerStatePoller.call(this)
|
|
3403
|
-
|
|
3404
|
-
} catch (err) {
|
|
3401
|
+
if (this.settings.bareClient !== true) {
|
|
3405
3402
|
try {
|
|
3406
|
-
|
|
3403
|
+
//Try to read system manager state - If it's OK, connection is successful to the target
|
|
3404
|
+
await this.readSystemManagerState()
|
|
3405
|
+
_systemManagerStatePoller.call(this)
|
|
3406
|
+
|
|
3407
3407
|
} catch (err) {
|
|
3408
|
-
|
|
3408
|
+
try {
|
|
3409
|
+
await _disconnect.call(this, false, isReconnecting)
|
|
3410
|
+
} catch (err) {
|
|
3411
|
+
debug(`_connect(): Reading target system manager failed -> Connection closed`)
|
|
3412
|
+
}
|
|
3413
|
+
this.connection.connected = false
|
|
3414
|
+
|
|
3415
|
+
return reject(new ClientException(this, '_connect()', `Connection failed: ${err.message}`, err))
|
|
3409
3416
|
}
|
|
3410
|
-
this.connection.connected = false
|
|
3411
3417
|
|
|
3412
|
-
return reject(new ClientException(this, '_connect()', `Connection failed: ${err.message}`, err))
|
|
3413
|
-
}
|
|
3414
3418
|
|
|
3419
|
+
try {
|
|
3420
|
+
await _reInitializeInternals.call(this)
|
|
3415
3421
|
|
|
3416
|
-
|
|
3417
|
-
|
|
3422
|
+
} catch (err) {
|
|
3423
|
+
if (this.settings.allowHalfOpen !== true) {
|
|
3424
|
+
try {
|
|
3425
|
+
await _disconnect.call(this, false, true)
|
|
3426
|
+
} catch (err) {
|
|
3427
|
+
debug(`_connect(): Connecting to target PLC runtime failed -> Connection closed`)
|
|
3428
|
+
}
|
|
3429
|
+
this.connection.connected = false
|
|
3418
3430
|
|
|
3419
|
-
|
|
3420
|
-
if (this.settings.allowHalfOpen !== true) {
|
|
3421
|
-
try {
|
|
3422
|
-
await _disconnect.call(this, false, true)
|
|
3423
|
-
} catch (err) {
|
|
3424
|
-
debug(`_connect(): Connecting to target PLC runtime failed -> Connection closed`)
|
|
3431
|
+
return reject(new ClientException(this, '_connect()', `Target and system manager found but couldn't connect to the PLC runtime (see settings allowHalfOpen and bareClient): ${err.message}`, err))
|
|
3425
3432
|
}
|
|
3426
|
-
this.connection.connected = false
|
|
3427
3433
|
|
|
3428
|
-
|
|
3434
|
+
//Todo: Redesign this
|
|
3435
|
+
if (this.metaData.systemManagerState.adsState !== ADS.ADS_STATE.Run)
|
|
3436
|
+
_console.call(this, `WARNING: Target is connected but not in RUN mode (mode: ${this.metaData.systemManagerState.adsStateStr}) - connecting to runtime (ADS port ${this.settings.targetAdsPort}) failed`)
|
|
3437
|
+
else
|
|
3438
|
+
_console.call(this, `WARNING: Target is connected but connecting to runtime (ADS port ${this.settings.targetAdsPort}) failed - Check the port number and that the target system state (${this.metaData.systemManagerState.adsStateStr}) is valid.`)
|
|
3429
3439
|
}
|
|
3430
|
-
|
|
3431
|
-
//Todo: Redesign this
|
|
3432
|
-
if (this.metaData.systemManagerState.adsState !== ADS.ADS_STATE.Run)
|
|
3433
|
-
_console.call(this, `WARNING: Target is connected but not in RUN mode (mode: ${this.metaData.systemManagerState.adsStateStr}) - connecting to runtime (ADS port ${this.settings.targetAdsPort}) failed`)
|
|
3434
|
-
else
|
|
3435
|
-
_console.call(this, `WARNING: Target is connected but connecting to runtime (ADS port ${this.settings.targetAdsPort}) failed - Check the port number and that the target system state (${this.metaData.systemManagerState.adsStateStr}) is valid.`)
|
|
3436
3440
|
}
|
|
3437
3441
|
|
|
3438
3442
|
//Listening connection lost events
|