ads-client 1.14.0 → 1.14.2

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 CHANGED
@@ -4,6 +4,28 @@ 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.14.2] - 02.05.2023
8
+ ### Changed
9
+ - Bug fix: `ADS_DATA_TYPE_FLAGS` (`dataType.flags`) were parsed incorrectly.
10
+ - See [issue #109](https://github.com/jisotalo/ads-client/issues/109)
11
+ - Thank you [Michael Croes](https://github.com/mycroes) for contribution!
12
+ - Bug fix: If calling `unsubcribeAll()` when client is already unsubcribing and disconnecting, an error might be thrown
13
+ - See [issue #103](https://github.com/jisotalo/ads-client/issues/103#issuecomment-1450640160)
14
+ - Bug fix: Check that subscription callback exists before calling it
15
+ - Fixes unecessary error if receiving notification data (for subscription) but it's being unsubscribed at the same time
16
+ - Bump json5 from 2.2.1 to 2.2.3
17
+ - See [pull request 101](https://github.com/jisotalo/ads-client/pull/101)
18
+ - Not used in production code, only when running tests
19
+
20
+ ### Added
21
+ - New test for [issue #103](https://github.com/jisotalo/ads-client/issues/103)
22
+
23
+ ## [1.14.1] - 13.09.2022
24
+ ### Changed
25
+ - Bug fix: Connecting to local router failed with ECONNREFUSED error on Node.js version 17 and newer
26
+ - See [https://github.com/nodejs/node/issues/40702](https://github.com/nodejs/node/issues/40702)
27
+ - Fixed by using `127.0.0.1` instead of `localhost`
28
+
7
29
  ## [1.14.0] - 23.07.2022
8
30
  ### Added
9
31
  - Created end-to-end testing for the library using Jest
package/README.md CHANGED
@@ -1713,8 +1713,6 @@ Solution:
1713
1713
  Solution:
1714
1714
  - See [this issue comment](https://github.com/jisotalo/ads-client/issues/51#issuecomment-758016428) by hansipete how to do it.
1715
1715
 
1716
-
1717
-
1718
1716
  ### A data type is not found even when it should be
1719
1717
 
1720
1718
  If you use methods like `convertFromRaw()` and `getDataType()` but receive an error similar to `ClientException: Finding data type *data type* failed`, make sure you have really written the data type correctly.
@@ -1756,6 +1754,16 @@ Another option is to use setting `bareClient: true` (since v.1.13.0). However, w
1756
1754
 
1757
1755
  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.
1758
1756
 
1757
+ ### Getting a message `Ads notification received but it has unknown notificationHandle (**). Use unsubscribe() to save resources.`
1758
+
1759
+ Possible reasons:
1760
+ * You have created notifications (subscriptions) using `subscribe()` and then closed the Node.js application without unsubscribing them first (TwinCAT still sends the data)
1761
+ * You are connecting without router (providing directly the target IP as router address) and you have other connections too like TwinCAT XAE running. See issue: https://github.com/jisotalo/ads-client/issues/85
1762
+
1763
+ Solution:
1764
+ * When closing application, first unsubscribe from all notifications using `unsubscribeAll()`
1765
+ * Use router instead of direct connection, see https://github.com/jisotalo/ads-client/issues/85#issuecomment-1193098519
1766
+
1759
1767
  # Automatic testing
1760
1768
  Since version 1.14.0 the library has automatic testing using Jest. Idea is to run the tests before updates to make sure everything works OK (this should have been done much earlier...)
1761
1769
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ads-client",
3
- "version": "1.14.0",
3
+ "version": "1.14.2",
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.js CHANGED
@@ -61,7 +61,7 @@ class Client extends EventEmitter {
61
61
  * @property {boolean} [readAndCacheDataTypes=false] - If true, all PLC data types are cached during connecting. Otherwise they are read and cached only when needed - Optional (**default**: false)
62
62
  * @property {boolean} [disableSymbolVersionMonitoring=false] - If true, PLC symbol version changes aren't monitored and cached symbols and datatypes won't be updated after PLC program download - Optional - Optional (**default**: false)
63
63
  * @property {number} [routerTcpPort=48898] - Target ADS router TCP port - Optional (**default**: 48898)
64
- * @property {string} [routerAddress=localhost] - Target ADS router IP address/hostname - Optional (**default**: localhost)
64
+ * @property {string} [routerAddress=127.0.0.1] - Target ADS router IP address/hostname - Optional (**default**: 127.0.0.1)
65
65
  * @property {string} [localAddress='(system default)'] - Local IP address to use, use this to change used network interface if required - Optional (**default**: System default)
66
66
  * @property {number} [localTcpPort='(system default)'] - Local TCP port to use for outgoing connections - Optional (**default**: System default)
67
67
  * @property {string} [localAmsNetId='(from AMS router)'] - Local AmsNetId to use - Optional (**default**: From AMS router)
@@ -91,7 +91,7 @@ class Client extends EventEmitter {
91
91
  readAndCacheDataTypes: false,
92
92
  disableSymbolVersionMonitoring: false,
93
93
  routerTcpPort: 48898,
94
- routerAddress: 'localhost',
94
+ routerAddress: '127.0.0.1',
95
95
  localAddress: null,
96
96
  localTcpPort: null,
97
97
  localAmsNetId: null,
@@ -145,6 +145,12 @@ class Client extends EventEmitter {
145
145
  this.settings.targetAmsNetId = '127.0.0.1.1.1'
146
146
  }
147
147
 
148
+ //Checking that router address is 127.0.0.1 instead of localhost
149
+ //to prevent problem like https://github.com/nodejs/node/issues/40702
150
+ if (this.settings.routerAddress.toLowerCase() === 'localhost') {
151
+ this.settings.routerAddress = '127.0.0.1'
152
+ }
153
+
148
154
  /**
149
155
  * Internal variables - Not intended for external use
150
156
  *
@@ -1218,7 +1224,11 @@ class Client extends EventEmitter {
1218
1224
  unSubCount++
1219
1225
 
1220
1226
  } catch (err) {
1221
- debug(`unsubscribeAll(): Unsubscribing from notification ${JSON.stringify(this._internals.activeSubscriptions[sub].target)} failed`)
1227
+ if (this._internals.activeSubscriptions[sub] && this._internals.activeSubscriptions[sub].target !== undefined) {
1228
+ debug(`unsubscribeAll(): Unsubscribing from notification ${JSON.stringify(this._internals.activeSubscriptions[sub].target)} failed`)
1229
+ } else {
1230
+ debug(`unsubscribeAll(): Unsubscribing from notification with handle ${sub} failed`)
1231
+ }
1222
1232
 
1223
1233
  firstError = new ClientException(this, 'unsubscribeAll()', err)
1224
1234
  }
@@ -4716,32 +4726,32 @@ async function _parseDataType(data) {
4716
4726
  dataType.adsDataTypeStr = ADS.ADS_DATA_TYPES.toString(dataType.adsDataType)
4717
4727
  pos += 4
4718
4728
 
4719
- //27..30 Flags (AdsDataTypeFlags)
4720
- dataType.flags = data.readUInt16LE(pos)
4729
+ //28..31 Flags (AdsDataTypeFlags)
4730
+ dataType.flags = data.readUInt32LE(pos)
4721
4731
  dataType.flagsStr = ADS.ADS_DATA_TYPE_FLAGS.toStringArray(dataType.flags)
4722
4732
  pos += 4
4723
4733
 
4724
- //31..32 Name length
4734
+ //32..33 Name length
4725
4735
  dataType.nameLength = data.readUInt16LE(pos)
4726
4736
  pos += 2
4727
4737
 
4728
- //33..34 Type length
4738
+ //34..35 Type length
4729
4739
  dataType.typeLength = data.readUInt16LE(pos)
4730
4740
  pos += 2
4731
4741
 
4732
- //35..36 Comment length
4742
+ //36..37 Comment length
4733
4743
  dataType.commentLength = data.readUInt16LE(pos)
4734
4744
  pos += 2
4735
4745
 
4736
- //37..40 Array dimension
4746
+ //38..39 Array dimension
4737
4747
  dataType.arrayDimension = data.readUInt16LE(pos)
4738
4748
  pos += 2
4739
4749
 
4740
- //41..42 Subitem count
4750
+ //40..41 Subitem count
4741
4751
  dataType.subItemCount = data.readUInt16LE(pos)
4742
4752
  pos += 2
4743
4753
 
4744
- //43.... Name
4754
+ //42.... Name
4745
4755
  dataType.name = _trimPlcString(iconv.decode(data.slice(pos, pos + dataType.nameLength + 1), 'cp1252'))
4746
4756
  pos += dataType.nameLength + 1
4747
4757
 
@@ -6321,7 +6331,7 @@ async function _onAdsCommandReceived(packet) {
6321
6331
  parsedValue.timeStamp = stamp.timeStamp
6322
6332
 
6323
6333
  //Then lets call the users callback
6324
- sub.callback(
6334
+ sub.callback && sub.callback(
6325
6335
  parsedValue,
6326
6336
  sub
6327
6337
  )