ads-client 2.0.0-beta.4 → 2.0.0-beta.6

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/README.md CHANGED
@@ -1,33 +1,137 @@
1
1
  # ads-client
2
2
 
3
-
4
3
  [![npm version](https://img.shields.io/npm/v/ads-client)](https://www.npmjs.org/package/ads-client)
5
4
  [![GitHub](https://img.shields.io/badge/View%20on-GitHub-brightgreen)](https://github.com/jisotalo/ads-client)
6
5
  [![License](https://img.shields.io/github/license/jisotalo/ads-client)](https://choosealicense.com/licenses/mit/)
7
- [![Support](https://img.shields.io/badge/Donate-PayPal-yellow)](https://www.paypal.com/donate/?business=KUWBXXCVGZZME&no_recurring=0&currency_code=EUR)
8
6
 
9
7
  Beckhoff TwinCAT ADS client library for Node.js (unofficial).
10
8
 
11
9
  Connect to a Beckhoff TwinCAT automation system using the ADS protocol from a Node.js app.
12
10
 
13
- ## v2 project status
11
+ If you are using Node-RED, check out the [node-red-contrib-ads-client](https://www.npmjs.com/package/node-red-contrib-ads-client).
12
+
13
+ # Project status
14
+
15
+ 14.12.2024 - version 2 released!
16
+
17
+ - Rewritten in Typescript
18
+ - See [CHANGELOG.md](https://github.com/jisotalo/ads-client/blob/v2-dev/CHANGELOG.md) for details.
19
+ - See [MIGRATION.md](https://github.com/jisotalo/ads-client/blob/v2-dev/MIGRATION.md) for guide of migrating v1 -> v2 (**breaking changes!**)
20
+ - See the new [documentation](https://jisotalo.fi/ads-client/classes/Client.html)
21
+
22
+ Documentation for legacy version 1.4.4 is archived at [https://archive.ph/Sswco](https://archive.ph/Sswco).
23
+
24
+ # Features
25
+ - Supports TwinCAT 2 and 3
26
+ - Supports connecting to the local TwinCAT 3 runtime
27
+ - Supports any kind of target systems with ADS protocol (local runtime, PLC, EtherCAT I/O...)
28
+ - Supports multiple connections from the same host
29
+ - Reading and writing any kind of variables
30
+ - Subscribing to variable value changes (ADS notifications)
31
+ - Automatic conversion between PLC and Javascript objects
32
+ - Calling function block methods (RPC)
33
+ - Automatic 32/64 bit variable support (PVOID, XINT, etc.)
34
+ - Automatic byte alignment support (all pack-modes automatically supported)
35
+
36
+ # Table of contents
37
+ - [ads-client](#ads-client)
38
+ - [Project status](#project-status)
39
+ - [Features](#features)
40
+ - [Table of contents](#table-of-contents)
41
+ - [Support](#support)
42
+ - [Installing](#installing)
43
+ - [Minimal example (TLDR)](#minimal-example-tldr)
44
+ - [Connection setup](#connection-setup)
45
+ - [Setup 1 - Connect from Windows](#setup-1---connect-from-windows)
46
+ - [Setup 2 - Connect from Linux/Windows](#setup-2---connect-from-linuxwindows)
47
+ - [Setup 3 - Connect from any Node.js system](#setup-3---connect-from-any-nodejs-system)
48
+ - [Setup 4 - Connect from local system](#setup-4---connect-from-local-system)
49
+ - [Setup 5 - Docker container](#setup-5---docker-container)
50
+ - [Important](#important)
51
+ - [Enabling localhost support on TwinCAT 3](#enabling-localhost-support-on-twincat-3)
52
+ - [Structured variables](#structured-variables)
53
+ - [Connecting to targets without a PLC runtime](#connecting-to-targets-without-a-plc-runtime)
54
+ - [Differences when using with TwinCAT 2](#differences-when-using-with-twincat-2)
55
+ - [Getting started](#getting-started)
56
+ - [Documentation](#documentation)
57
+ - [Available methods](#available-methods)
58
+ - [Creating a client](#creating-a-client)
59
+ - [Connecting](#connecting)
60
+ - [Reading values](#reading-values)
61
+ - [Reading any value](#reading-any-value)
62
+ - [Reading raw data](#reading-raw-data)
63
+ - [Reading reference/pointer](#reading-referencepointer)
64
+ - [Writing values](#writing-values)
65
+ - [Writing any value](#writing-any-value)
66
+ - [Writing raw data](#writing-raw-data)
67
+ - [Writing reference/pointer](#writing-referencepointer)
68
+ - [Subscribing to value changes](#subscribing-to-value-changes)
69
+ - [Any value](#any-value)
70
+ - [Raw data](#raw-data)
71
+ - [Unsubscribing](#unsubscribing)
72
+ - [Using variable handles](#using-variable-handles)
73
+ - [Reading a value using a variable handle](#reading-a-value-using-a-variable-handle)
74
+ - [Writing a value using a variable handle](#writing-a-value-using-a-variable-handle)
75
+ - [Calling function block RPC methods](#calling-function-block-rpc-methods)
76
+ - [Things to note when using RPC Methods](#things-to-note-when-using-rpc-methods)
77
+ - [About examples](#about-examples)
78
+ - [RPC method with standard data types](#rpc-method-with-standard-data-types)
79
+ - [RPC method with struct](#rpc-method-with-struct)
80
+ - [Converting data between raw data and Javascript objects](#converting-data-between-raw-data-and-javascript-objects)
81
+ - [Converting a raw value to a Javascript object](#converting-a-raw-value-to-a-javascript-object)
82
+ - [Converting a Javascript object to a raw value](#converting-a-javascript-object-to-a-raw-value)
83
+ - [Other features](#other-features)
84
+ - [ADS sum commands](#ads-sum-commands)
85
+ - [Starting and stopping a PLC](#starting-and-stopping-a-plc)
86
+ - [Starting and stopping TwinCAT system](#starting-and-stopping-twincat-system)
87
+ - [Client events](#client-events)
88
+ - [Debugging](#debugging)
89
+ - [Disconnecting](#disconnecting)
90
+ - [Common issues and questions](#common-issues-and-questions)
91
+ - [There are lot's of connection issues and timeouts](#there-are-lots-of-connection-issues-and-timeouts)
92
+ - [Getting `TypeError: Do not know how to serialize a BigInt`](#getting-typeerror-do-not-know-how-to-serialize-a-bigint)
93
+ - [Can I connect from Raspberry Pi to TwinCAT?](#can-i-connect-from-raspberry-pi-to-twincat)
94
+ - [Receiving ADS error 1808 `Symbol not found` even when it should be found](#receiving-ads-error-1808-symbol-not-found-even-when-it-should-be-found)
95
+ - [Having timeouts or 'mailbox is full' errors](#having-timeouts-or-mailbox-is-full-errors)
96
+ - [Having problems to connect from OSX or Raspberry Pi to target PLC](#having-problems-to-connect-from-osx-or-raspberry-pi-to-target-plc)
97
+ - [A data type is not found even when it should be](#a-data-type-is-not-found-even-when-it-should-be)
98
+ - [Connection failed - failed to set PLC connection](#connection-failed---failed-to-set-plc-connection)
99
+ - [Connection failed (error EADDRNOTAVAIL)](#connection-failed-error-eaddrnotavail)
100
+ - [Problems running ads-client with docker](#problems-running-ads-client-with-docker)
101
+ - [How to connect to a PLC that is in CONFIG mode?](#how-to-connect-to-a-plc-that-is-in-config-mode)
102
+ - [Issues with TwinCAT 2 low-end devices (BK9050, BC9050 etc.)](#issues-with-twincat-2-low-end-devices-bk9050-bc9050-etc)
103
+ - [External links](#external-links)
104
+ - [Library testing](#library-testing)
105
+ - [TwinCAT 3 tests](#twincat-3-tests)
106
+ - [TwinCAT 2 tests](#twincat-2-tests)
107
+ - [License](#license)
108
+
109
+
110
+ # Support
111
+
112
+ * Bugs and feature requests:
113
+ * [Github Issues](https://github.com/jisotalo/ads-client/issues)
114
+ * Help, support and discussion:
115
+ * [Github Discussions](https://github.com/jisotalo/ads-client/discussions)
116
+
117
+ If you want to support my work, you can buy me a coffee! Contact for more options.
118
+
119
+ <a href="https://www.buymeacoffee.com/jisotalo" target="_blank"><img src="https://cdn.buymeacoffee.com/buttons/v2/default-blue.png" alt="Buy Me A Coffee" style="height: 60px !important;width: 217px !important;" ></a>
14
120
 
15
- **02.10.2024:** Beta 4 released! See [CHANGELOG.md](https://github.com/jisotalo/ads-client/blob/v2-dev/CHANGELOG.md) for details.
121
+ [![Donate](https://img.shields.io/badge/Donate-PayPal-yellow)](https://www.paypal.com/donate/?business=KUWBXXCVGZZME&no_recurring=0&currency_code=EUR)
16
122
 
17
- All breaking changes are (hopefully) done.
123
+ If you need help with integrating the ads-client, I'm available for coding work with invoicing. Contact for further details.
18
124
 
19
- * See [milestone #2](https://github.com/jisotalo/ads-client/milestone/2) for tasks to be done.
20
- * See [MIGRATION.md](https://github.com/jisotalo/ads-client/blob/v2-dev/MIGRATION.md) for guide of migrating v1->v2
21
- * Clone repository and open `docs/index.html` in browser for documentation
125
+ # Installing
22
126
 
23
- ## Getting started
127
+ Install the [npm package](https://www.npmjs.com/package/ads-client):
24
128
 
25
- README is under construction.
129
+ ```
130
+ npm install ads-client
131
+ ```
26
132
 
27
- ### Install
28
- `npm install ads-client@beta`
133
+ Include the module in your code:
29
134
 
30
- ### Import the client
31
135
  ```js
32
136
  //Javascript:
33
137
  const { Client } = require('ads-client');
@@ -36,87 +140,1332 @@ const { Client } = require('ads-client');
36
140
  import { Client } from 'ads-client';
37
141
  ```
38
142
 
39
- ### Create a client and connect
143
+ You can also clone the repository and run `npm run build`. After that, the library is available at `./dist/`
144
+
145
+ # Minimal example (TLDR)
146
+
147
+ This connects to a local PLC runtime, reads a value, writes a value, reads it again and then disconnects. The value is a string and it's located in `GVL_Global.StringValue`.
148
+
149
+ ```js
150
+ const { Client } = require('ads-client');
151
+
152
+ const client = new Client({
153
+ targetAmsNetId: 'localhost',
154
+ targetAdsPort: 851
155
+ });
156
+
157
+ client.connect()
158
+ .then(async (res) => {
159
+ console.log(`Connected to the ${res.targetAmsNetId}`);
160
+ console.log(`Router assigned us AmsNetId ${res.localAmsNetId} and port ${res.localAdsPort}`);
161
+
162
+ try {
163
+ //Reading a value
164
+ const read = await client.readValue('GVL_Global.StringValue');
165
+ console.log('Value read (before):', read.value);
166
+
167
+ //Writing a value
168
+ await client.writeValue('GVL_Global.StringValue', 'This is a new value');
169
+
170
+ //Reading a value
171
+ const read2 = await client.readValue('GVL_Global.StringValue');
172
+ console.log('Value read (after):', read2.value);
173
+
174
+ } catch (err) {
175
+ console.log('Something failed:', err);
176
+ }
177
+
178
+ //Disconnecting
179
+ await client.disconnect();
180
+ console.log('Disconnected');
181
+
182
+ }).catch(err => {
183
+ console.log('Error:', err);
184
+ });
185
+ ```
186
+
187
+ # Connection setup
188
+
189
+ The ads-client can be used with multiple system configurations.
190
+
191
+ ![ads-client-setups](https://raw.githubusercontent.com/jisotalo/ads-client/refs/heads/v2-dev/img/connection_setup.png)
192
+
193
+
194
+ ## Setup 1 - Connect from Windows
195
+
196
+ This is the most common scenario. The client is running on a Windows PC that has TwinCAT Router installed (such as development laptop, Beckhoff IPC/PC, Beckhoff PLC).
197
+
198
+ **Requirements:**
199
+ - Client has one of the following installed
200
+ - TwinCAT XAE (dev. environment)
201
+ - TwinCAT XAR (runtime)
202
+ - [TwinCAT ADS](https://www.beckhoff.com/en-en/products/automation/twincat/tc1xxx-twincat-3-base/tc1000.html)
203
+ - An ADS route is created between the client and the PLC using TwinCAT router
204
+
205
+ **Client settings:**
206
+
207
+ ```js
208
+ const client = new Client({
209
+ targetAmsNetId: '192.168.1.120.1.1', //AmsNetId of the target PLC
210
+ targetAdsPort: 851,
211
+ });
212
+ ```
213
+
214
+ ## Setup 2 - Connect from Linux/Windows
215
+
216
+ In this scenario, the client is running on Linux or Windows without TwinCAT Router. The .NET based router can be run separately on the same machine.
217
+
218
+ **Requirements:**
219
+ - Client has .NET runtime installed
220
+ - Client has [AdsRouterConsoleApp](https://github.com/Beckhoff/TF6000_ADS_DOTNET_V5_Samples/tree/main/Sources/RouterSamples/AdsRouterConsoleApp) or similar running
221
+ - An ADS route is created between the client and the PLC (see [AdsRouterConsoleApp](https://github.com/Beckhoff/TF6000_ADS_DOTNET_V5_Samples/tree/main/Sources/RouterSamples/AdsRouterConsoleApp) docs)
222
+
223
+ **Client settings:**
224
+
225
+ ```js
226
+ const client = new Client({
227
+ targetAmsNetId: '192.168.1.120.1.1', //AmsNetId of the target PLC
228
+ targetAdsPort: 851,
229
+ });
230
+ ```
231
+
232
+ ## Setup 3 - Connect from any Node.js system
233
+
234
+ In this scenario, the client is running on a machine that has no router running (no TwinCAT router and no 3rd party router). For example, Raspberry Pi without any additional installations.
235
+
236
+ In this setup, the client directly connects to the PLC and uses its TwinCAT router for communication. Only one simultaneous connection from the client is possible.
237
+
238
+ **Requirements:**
239
+ - Target system (PLC) firewall has TCP port 48898 open
240
+ - Windows Firewall might block, make sure Ethernet connection is handled as "private"
241
+ - Local AmsNetId and ADS port are set manually
242
+ - Used `localAmsNetId` is not already in use
243
+ - Used `localAdsPort` is not already in use
244
+ - An ADS route is configured to the PLC (see blow)
245
+
246
+ **Setting up the route:**
247
+
248
+ 1. At the PLC, open `C:\TwinCAT\3.1\Target\StaticRoutes.xml`
249
+ 2. Copy paste the following under `<RemoteConnections>`
250
+
251
+ ```xml
252
+ <Route>
253
+ <Name>UI</Name>
254
+ <Address>192.168.1.10</Address>
255
+ <NetId>192.168.1.10.1.1</NetId>
256
+ <Type>TCP_IP</Type>
257
+ <Flags>64</Flags>
258
+ </Route>
259
+ ```
260
+
261
+ 3. Edit `Address` to IP address of the client (which runs the Node.js app), such as `192.168.1.10`
262
+ 4. Edit `NetId` to any unused AmsNetId address, such as `192.168.1.10.1.1`
263
+ 5. Restart PLC
264
+
265
+ **Client settings:**
266
+
267
+ ```js
268
+ const client = new Client({
269
+ localAmsNetId: '192.168.1.10.1.1', //Same as Address in PLC's StaticRoutes.xml (see above)
270
+ localAdsPort: 32750, //Can be anything that is not used
271
+ targetAmsNetId: '192.168.1.120.1.1',//AmsNetId of the target PLC
272
+ targetAdsPort: 851,
273
+ routerAddress: '192.168.1.120', //PLC IP address
274
+ routerTcpPort: 48898
275
+ });
276
+ ```
277
+
278
+ **See also:**
279
+ * [Issue #51](https://github.com/jisotalo/ads-client/issues/51#issuecomment-758016428)
280
+
281
+ ## Setup 4 - Connect from local system
282
+
283
+ In this scenario, the PLC is running Node.js app locally. For example, the development PC or Beckhoff PLC with a screen for HMI.
284
+
285
+ **Requirements:**
286
+ - AMS router TCP loopback enabled (see [Enabling localhost support](#enabling-localhost-support))
287
+ - Should be already enabled in TwinCAT versions >= 4024.5.
288
+
289
+ **Client settings:**
290
+
291
+ ```js
292
+ const client = new Client({
293
+ targetAmsNetId: '127.0.0.1.1.1', //or 'localhost'
294
+ targetAdsPort: 851,
295
+ });
296
+ ```
297
+
298
+ ## Setup 5 - Docker container
299
+
300
+ It's also possible to run the client in a docker containers, also with a separate router (Linux systems).
301
+
302
+ I'm available for coding work if you need help with this. See [Supporting](#supporting)
303
+
304
+ # Important
305
+
306
+ ## Enabling localhost support on TwinCAT 3
307
+
308
+ If connecting to the local TwinCAT runtime (Node.js and PLC on the same machine), the ADS router TCP loopback feature has to be enabled.
309
+
310
+ TwinCAT 4024.5 and newer already have this enabled as default.
311
+
312
+ 1. Open registery edition (`regedit`)
313
+ 2. Navigate to
314
+
315
+ ```
316
+ 32 bit operating system:
317
+ HKEY_LOCAL_MACHINE\SOFTWARE\Beckhoff\TwinCAT3\System\
318
+
319
+ 64 bit it operating system:
320
+ HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Beckhoff\TwinCAT3\System\
321
+ ```
322
+
323
+ 3. Create new DWORD registery named `EnableAmsTcpLoopback` with value of `1`
324
+ 4. Restart
325
+
326
+ ![ads-client-tcp-loopback](https://user-images.githubusercontent.com/13457157/82748398-2640bf00-9daa-11ea-98e5-0032b3537969.png)
327
+
328
+ Now you can connect to the localhost using `targetAmsNetId` address of `127.0.0.1.1.1` or `localhost`.
329
+
330
+ ## Structured variables
331
+
332
+ When writing structured variables, the object properties are handled case-insensitively. This is because the TwinCAT is case-insensitive.
333
+
334
+ In practice, it means that the following objects are equal when passed to `writevalue()` or `convertToRaw()`:
335
+
336
+ ```js
337
+ {
338
+ sometext: 'hello',
339
+ somereal: 3.14
340
+ }
341
+ ```
342
+
343
+ ```js
344
+ {
345
+ SOmeTEXT: 'hello',
346
+ SOMEreal: 3.14
347
+ }
348
+ ```
349
+
350
+ If there are multiple properties with the same name (in case-insensitive manner), the client selects probably the first one (the selection is done by `Object.find()`):
351
+
352
+ ```js
353
+ //In this case, probably the first one (sometext) is selected and the SOMEtext is skipped.
354
+ {
355
+ sometext: 'hello',
356
+ SOMEtext: 'good day'
357
+ }
358
+ ```
359
+
360
+ ## Connecting to targets without a PLC runtime
361
+
362
+ Usually the `ads-client` is used to connect to a PLC runtime. Howevever, it's also possible to connect to any device supporting ADS protocol, such as
363
+
364
+ * TwinCAT system service
365
+ * I/O devices (EtherCAT, K-bus etc.)
366
+ * [ads-server](https://github.com/jisotalo/ads-server) instances
367
+
368
+ As default, the client assumes that there should be a PLC runtime. This causes errors with non-PLC systems, as different PLC related things are initialized.
369
+ ```
370
+ Connection failed - failed to set PLC connection. If target is not PLC runtime, use setting "rawClient". If system is in config mode or there is no PLC software yet, you might want to use setting "allowHalfOpen".
371
+ ```
372
+
373
+ By using the `rawClient` setting, the client allows raw connections to any ADS supported system.
374
+
375
+ ```js
376
+ const client = new Client({
377
+ targetAmsNetId: '192.168.5.131.3.1',
378
+ targetAdsPort: 1002,
379
+ rawClient: true // <-- NOTE
380
+ })
381
+ ```
382
+
383
+ Note that when the `rawclient` setting is set, the client only connects to the target. All other background features, such as monitoring system state, PLC symbol version or connection issues, are not available.
384
+
385
+
386
+ ## Differences when using with TwinCAT 2
387
+
388
+ * ADS port for first the PLC runtime is 801 instead of 851
389
+
390
+ ```js
391
+ const client = new ads.Client({
392
+ targetAmsNetId: '...',
393
+ targetAdsPort: 801 //<-- NOTE
394
+ });
395
+ ```
396
+
397
+ * All variable and data type names are in UPPERCASE
398
+
399
+ This might cause problems if your app is used with both TC2 & TC3 systems.
400
+
401
+ ![image](https://user-images.githubusercontent.com/13457157/86540055-96df0d80-bf0a-11ea-8f94-7e04515213c2.png)
402
+
403
+
404
+ * Global variables are accessed with dot (`.`) prefix (without the GVL name)
405
+
406
+ ```js
407
+ await client.readSymbol('GVL_Test.ExampleSTRUCT') //TwinCAT 3
408
+ await client.readSymbol('.ExampleSTRUCT') //TwinCAT 2
409
+ ```
410
+
411
+ * ENUMs are always numeric values only
412
+
413
+ * Empty structs and function blocks (without members) can't be read
414
+
415
+ # Getting started
416
+
417
+ ## Documentation
418
+
419
+ The documentation is available at [https://jisotalo.fi/ads-client](https://jisotalo.fi/ads-client/classes/Client.html) and `./docs` folder.
420
+
421
+ Examples in the getting started are based on a PLC project from [https://github.com/jisotalo/ads-client-test-plc-project](https://github.com/jisotalo/ads-client-test-plc-project).
422
+
423
+ You can use the test PLC project as reference together with the [ads-client.test.js](https://github.com/jisotalo/ads-client/blob/master/test/TC3/ads-client.test.js) to see and try out all available features.
424
+
425
+ ## Available methods
426
+
427
+ Click a method to open it's documentation.
428
+
429
+ | Method | Description |
430
+ | --------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
431
+ | [`cacheDataTypes()`](https://jisotalo.fi/ads-client/classes/Client.html#cacheDataTypes) | Caches all data types from the target PLC runtime. |
432
+ | [`cacheSymbols()`](https://jisotalo.fi/ads-client/classes/Client.html#cacheSymbols) | Caches all symbols from the target PLC runtime. |
433
+ | [`connect()`](https://jisotalo.fi/ads-client/classes/Client.html#connect) | Connects to the target. |
434
+ | [`convertFromRaw()`](https://jisotalo.fi/ads-client/classes/Client.html#convertFromRaw) | Converts raw data to a Javascript object by using the provided data type. |
435
+ | [`convertToRaw()`](https://jisotalo.fi/ads-client/classes/Client.html#convertToRaw) | Converts a Javascript object to raw data by using the provided data type. |
436
+ | [`createVariableHandle()`](https://jisotalo.fi/ads-client/classes/Client.html#createVariableHandle) | Creates a handle to a variable at the target system by variable path (such as `GVL_Test.ExampleStruct`). |
437
+ | [`createVariableHandleMulti()`](https://jisotalo.fi/ads-client/classes/Client.html#createVariableHandleMulti) | Sends multiple `createVariableHandle()` commands in one ADS packet (ADS sum command). |
438
+ | [`deleteVariableHandle()`](https://jisotalo.fi/ads-client/classes/Client.html#deleteVariableHandle) | Deletes a variable handle that was previously created using `createVariableHandle()`. |
439
+ | [`deleteVariableHandleMulti()`](https://jisotalo.fi/ads-client/classes/Client.html#deleteVariableHandleMulti) | Sends multiple `deleteVariableHandle()` commands in one ADS packet (ADS sum command). |
440
+ | [`disconnect()`](https://jisotalo.fi/ads-client/classes/Client.html#disconnect) | Disconnects from the target and closes active connection. |
441
+ | [`getDataType()`](https://jisotalo.fi/ads-client/classes/Client.html#getDataType) | Returns full data type declaration for requested data type (such as `ST_Struct`). |
442
+ | [`getDataTypes()`](https://jisotalo.fi/ads-client/classes/Client.html#getDataTypes) | Returns all target PLC runtime data types. |
443
+ | [`getDefaultPlcObject()`](https://jisotalo.fi/ads-client/classes/Client.html#getDefaultPlcObject) | Returns a default (empty) Javascript object representing provided PLC data type. |
444
+ | [`getSymbol()`](https://jisotalo.fi/ads-client/classes/Client.html#getSymbol) | Returns a symbol object for given variable path (such as `GVL_Test.ExampleStruct`). |
445
+ | [`getSymbols()`](https://jisotalo.fi/ads-client/classes/Client.html#getSymbols) | Returns all symbols from the target PLC runtime. |
446
+ | [`invokeRpcMethod()`](https://jisotalo.fi/ads-client/classes/Client.html#invokeRpcMethod) | Invokes a function block RPC method on the target system. |
447
+ | [`readDeviceInfo()`](https://jisotalo.fi/ads-client/classes/Client.html#readDeviceInfo) | Reads target device information. |
448
+ | [`readPlcRuntimeState()`](https://jisotalo.fi/ads-client/classes/Client.html#readPlcRuntimeState) | Reads target PLC runtime state (`Run`, `Stop` etc.) |
449
+ | [`readPlcSymbolVersion()`](https://jisotalo.fi/ads-client/classes/Client.html#readPlcSymbolVersion) | Reads target PLC runtime symbol version. |
450
+ | [`readPlcUploadInfo()`](https://jisotalo.fi/ads-client/classes/Client.html#readPlcUploadInfo) | Reads target PLC runtime upload information. |
451
+ | [`readRaw()`](https://jisotalo.fi/ads-client/classes/Client.html#readRaw) | Reads raw data from the target system by a raw ADS address (index group, index offset and data length). |
452
+ | [`readRawByHandle()`](https://jisotalo.fi/ads-client/classes/Client.html#readRawByHandle) | Reads raw data from the target system by a previously created variable handle (acquired using `createVariableHandle()`). |
453
+ | [`readRawByPath()`](https://jisotalo.fi/ads-client/classes/Client.html#readRawByPath) | Reads raw data from the target system by variable path (such as `GVL_Test.ExampleStruct`). |
454
+ | [`readRawBySymbol()`](https://jisotalo.fi/ads-client/classes/Client.html#readRawBySymbol) | Reads raw data from the target system by a symbol object (acquired using `getSymbol()`). |
455
+ | [`readRawMulti()`](https://jisotalo.fi/ads-client/classes/Client.html#readRawMulti) | Sends multiple `readRaw()` commands in one ADS packet (ADS sum command). |
456
+ | [`readState()`](https://jisotalo.fi/ads-client/classes/Client.html#readState) | Reads target ADS state. |
457
+ | [`readTcSystemState()`](https://jisotalo.fi/ads-client/classes/Client.html#readTcSystemState) | Reads target TwinCAT system state from ADS port 10000 (usually `Run` or `Config`). |
458
+ | [`readValue()`](https://jisotalo.fi/ads-client/classes/Client.html#readValue) | Reads variable's value from the target system by a variable path (such as `GVL_Test.ExampleStruct`) and returns the value as a Javascript object. |
459
+ | [`readValueBySymbol()`](https://jisotalo.fi/ads-client/classes/Client.html#readValueBySymbol) | Reads variable's value from the target system by a symbol object (acquired using `getSymbol()`) and returns the value as a Javascript object. |
460
+ | [`readWriteRaw()`](https://jisotalo.fi/ads-client/classes/Client.html#readWriteRaw) | Writes raw data to the target system by a raw ADS address (index group, index offset) and reads the result as raw data. |
461
+ | [`readWriteRawMulti()`](https://jisotalo.fi/ads-client/classes/Client.html#readWriteRawMulti) | Sends multiple `readWriteRaw()` commands in one ADS packet (ADS sum command). |
462
+ | [`reconnect()`](https://jisotalo.fi/ads-client/classes/Client.html#reconnect) | Reconnects to the target (disconnects and then connects again). |
463
+ | [`resetPlc()`](https://jisotalo.fi/ads-client/classes/Client.html#resetPlc) | Resets the target PLC runtime. Same as reset cold in TwinCAT XAE. |
464
+ | [`restartPlc()`](https://jisotalo.fi/ads-client/classes/Client.html#restartPlc) | Restarts the PLC runtime. Same as calling `resetPlc()` and then `startPlc()`. |
465
+ | [`restartTcSystem()`](https://jisotalo.fi/ads-client/classes/Client.html#restartTcSystem) | Restarts the target TwinCAT system. |
466
+ | [`sendAdsCommand()`](https://jisotalo.fi/ads-client/classes/Client.html#sendAdsCommand) | Sends a raw ADS command to the target. |
467
+ | [`sendAdsCommandWithFallback()`](https://jisotalo.fi/ads-client/classes/Client.html#sendAdsCommandWithFallback) | Sends a raw ADS command to the target. If it fails to specific ADS error codes, sends the fallback ADS command. |
468
+ | [`setDebugLevel()`](https://jisotalo.fi/ads-client/classes/Client.html#setDebugLevel) | Sets active debug level. |
469
+ | [`setTcSystemToConfig()`](https://jisotalo.fi/ads-client/classes/Client.html#setTcSystemToConfig) | Sets the target TwinCAT system to config mode. Same as `Restart TwinCAT (Config mode)` in TwinCAT XAE. |
470
+ | [`setTcSystemToRun()`](https://jisotalo.fi/ads-client/classes/Client.html#setTcSystemToRun) | Sets the target TwinCAT system to run mode. Same as `Restart TwinCAT system` in TwinCAT XAE. |
471
+ | [`startPlc()`](https://jisotalo.fi/ads-client/classes/Client.html#startPlc) | Starts the target PLC runtime. Same as pressing the green play button in TwinCAT XAE. |
472
+ | [`stopPlc()`](https://jisotalo.fi/ads-client/classes/Client.html#stopPlc) | Stops the target PLC runtime. Same as pressing the red stop button in TwinCAT XAE. |
473
+ | [`subscribe()`](https://jisotalo.fi/ads-client/classes/Client.html#subscribe) | Subscribes to value change notifications (ADS notifications) by variable path (such as `GVL_Test.ExampleStruct`) or raw ADS address (index group, index offset and data length). |
474
+ | [`subscribeRaw()`](https://jisotalo.fi/ads-client/classes/Client.html#subscribeRaw) | Subscribes to raw value change notifications (ADS notifications) by a raw ADS address (index group, index offset and data length). |
475
+ | [`subscribeValue()`](https://jisotalo.fi/ads-client/classes/Client.html#subscribeValue) | Subscribes to value change notifications (ADS notifications) by a variable path, such as `GVL_Test.ExampleStruct`. |
476
+ | [`unsubscribe()`](https://jisotalo.fi/ads-client/classes/Client.html#unsubscribe) | Unsubscribes a subscription (deletes ADS notification). |
477
+ | [`unsubscribeAll()`](https://jisotalo.fi/ads-client/classes/Client.html#unsubscribeAll) | Unsubscribes all active subscription (deletes all ADS notifications). |
478
+ | [`writeControl()`](https://jisotalo.fi/ads-client/classes/Client.html#writeControl) | Sends an ADS `WriteControl` command to the target. |
479
+ | [`writeRaw()`](https://jisotalo.fi/ads-client/classes/Client.html#writeRaw) | Writes raw data to the target system by a raw ADS address (index group, index offset and data length). |
480
+ | [`writeRawByHandle()`](https://jisotalo.fi/ads-client/classes/Client.html#writeRawByHandle) | Writes raw data to the target system by a previously created variable handle (acquired using `createVariableHandle()`). |
481
+ | [`writeRawByPath()`](https://jisotalo.fi/ads-client/classes/Client.html#writeRawByPath) | Writes raw data to the target system by variable path (such as `GVL_Test.ExampleStruct`). |
482
+ | [`writeRawBySymbol()`](https://jisotalo.fi/ads-client/classes/Client.html#writeRawBySymbol) | Writes raw data to the target system by a symbol object (acquired using `getSymbol()`). |
483
+ | [`writeRawMulti()`](https://jisotalo.fi/ads-client/classes/Client.html#writeRawMulti) | Sends multiple `writeRaw()` commands in one ADS packet (ADS sum command). |
484
+ | [`writeValue()`](https://jisotalo.fi/ads-client/classes/Client.html#writeValue) | Writes variable's value to the target system by a variable path (such as `GVL_Test.ExampleStruct`). Converts the value from a Javascript object to a raw value. |
485
+ | [`writeValueBySymbol()`](https://jisotalo.fi/ads-client/classes/Client.html#writeValueBySymbol) | Writes variable's value to the target system by a symbol object (acquired using `getSymbol()`). Converts the value from a Javascript object to a raw value. |
486
+
487
+ ## Creating a client
488
+
489
+ Settings are passed via the [`Client`](https://jisotalo.fi/ads-client/classes/Client.html) constructor. The following settings are mandatory:
490
+ - [`targetAmsNetId`](https://jisotalo.fi/ads-client/interfaces/AdsClientSettings.html#targetAmsNetId) - Target runtime AmsNetId
491
+ - [`targetAdsPort`](https://jisotalo.fi/ads-client/interfaces/AdsClientSettings.html#targetAdsPort) - Target runtime ADS port
492
+
493
+ See other settings from the [`AdsClientSettings` documentation](https://jisotalo.fi/ads-client/interfaces/AdsClientSettings.html).
40
494
 
41
495
  ```js
42
496
  const client = new Client({
43
497
  targetAmsNetId: "localhost",
44
498
  targetAdsPort: 851
45
499
  });
500
+ ```
501
+
502
+ ## Connecting
503
+
504
+ It's a good practice to start a connection at startup and keep it open until the app is closed.
505
+ If there are connection issues or the PLC software is updated, the client will handle everything automatically.
506
+
507
+
508
+ ```js
509
+ const { Client } = require('ads-client');
510
+
511
+ const client = new Client({
512
+ targetAmsNetId: 'localhost',
513
+ targetAdsPort: 851
514
+ });
515
+
516
+ client.connect()
517
+ .then(async (res) => {
518
+ console.log(`Connected to the ${res.targetAmsNetId}`);
519
+ console.log(`Router assigned us AmsNetId ${res.localAmsNetId} and port ${res.localAdsPort}`);
520
+ //Connected
521
+
522
+ //...
523
+
524
+ //Disconnecting
525
+ await client.disconnect();
46
526
 
47
- await client.connect();
527
+ }).catch(err => {
528
+ console.log('Error:', err);
529
+ });
48
530
  ```
49
531
 
50
- ### Read a value
532
+ ## Reading values
533
+
534
+ ### Reading any value
535
+
536
+ Use [`readValue()`](https://jisotalo.fi/ads-client/classes/Client.html#readValue) to read any PLC value.
537
+
538
+ The only exception is the dereferenced value of a reference/pointer, see [Reading reference/pointer](#reading-referencepointer).
539
+
540
+ **Reading INT**
51
541
 
52
542
  ```js
53
- const res = await client.readValue('GVL_Example.StringValue');
54
- console.log(res.value);
543
+ const res = await client.readValue('GVL_Read.StandardTypes.INT_');
544
+ console.log(res.value);
545
+ // 32767
546
+ ```
55
547
 
56
- //Typescript:
57
- const res = await client.readValue<string>('GVL_Example.StringValue');
58
- console.log(res.value); //res.value is typed as string (instead of any)
548
+ **Reading STRING**
59
549
 
550
+ ```js
551
+ const res = await client.readValue('GVL_Read.StandardTypes.STRING_');
552
+ console.log(res.value);
553
+ // A test string ääöö!!@@
60
554
  ```
61
555
 
62
- ### Write a value
556
+ **Reading DT**
63
557
 
64
558
  ```js
65
- await client.writeValue('GVL_Example.StringValue', 'a new value');
559
+ const res = await client.readValue('GVL_Read.StandardTypes.DT_');
560
+ console.log(res.value);
561
+ // 2106-02-06T06:28:15.000Z (Date object)
66
562
  ```
67
- ### Subscribe to value changes
563
+
564
+ **Reading STRUCT**
68
565
 
69
566
  ```js
70
- await client.subscribe({
71
- target: 'GVL_Example.ChangingValue',
72
- cycleTime: 100,
73
- callback: (data, subscription) => console.log(`${data.timestamp}: Value changed to ${data.value}`)
567
+ const res = await client.readValue('GVL_Read.ComplexTypes.STRUCT_');
568
+ console.log(res.value);
569
+ /*
570
+ {
571
+ BOOL_: true,
572
+ BOOL_2: false,
573
+ BYTE_: 255,
574
+ WORD_: 65535,
575
+ //...and so on
576
+ }
577
+ */
578
+ ```
579
+
580
+ **Reading FUNCTION_BLOCK**
581
+
582
+ ```js
583
+ const res = await client.readValue('GVL_Read.ComplexTypes.BLOCK_2'); //TON
584
+ console.log(res.value);
585
+ // { IN: false, PT: 2500, Q: false, ET: 0, M: false, StartTime: 0 }
586
+ ```
587
+
588
+ **Reading ARRAY**
589
+
590
+ ```js
591
+ const res = await client.readValue('GVL_Read.StandardArrays.REAL_3');
592
+ console.log(res.value);
593
+ // [ 75483.546875, 0, -75483.546875 ]
594
+ ```
595
+
596
+ **Reading ENUM**
597
+
598
+ ```js
599
+ const res = await client.readValue('GVL_Read.ComplexTypes.ENUM_');
600
+ console.log(res.value);
601
+ // { name: 'Running', value: 100 }
602
+ ```
603
+
604
+ **Typescript example: Reading INT**
605
+
606
+ ```ts
607
+ const res = await client.readValue<number>('GVL_Read.StandardTypes.INT_');
608
+ console.log(res.value); //res.value is typed as number
609
+ // 32767
610
+ ```
611
+
612
+ **Typescript example: Reading STRUCT**
613
+
614
+ ```ts
615
+ interface ST_ComplexTypes {
616
+ BOOL_: boolean,
617
+ BOOL_2: boolean,
618
+ BYTE_: number,
619
+ WORD_: number,
620
+ //..and so on
621
+ }
622
+
623
+ const res = await client.readValue<ST_ComplexTypes>('GVL_Read.ComplexTypes.STRUCT_');
624
+ console.log(res.value); //res.value is typed as ST_ComplexTypes
625
+ /*
626
+ {
627
+ BOOL_: true,
628
+ BOOL_2: false,
629
+ BYTE_: 255,
630
+ WORD_: 65535,
631
+ //..and so on
632
+ }
633
+ */
634
+ ```
635
+
636
+ ### Reading raw data
637
+
638
+ Use [`readRaw()`](https://jisotalo.fi/ads-client/classes/Client.html#readRaw) or [`readRawByPath()`](https://jisotalo.fi/ads-client/classes/Client.html#readRawByPath) to read any PLC value as raw data. The raw data in this context means received bytes (a `Buffer` object).
639
+
640
+ The only exception is the dereferenced value of a reference/pointer, see [Reading reference/pointer](#reading-referencepointer).
641
+
642
+ For converting the data between raw data and Javascript object, see [Converting data between raw data and Javascript objects](#converting-data-between-raw-data-and-javascript-objects).
643
+
644
+ **readRaw()**
645
+
646
+ The `indexGroup` and `indexOffset` can be acquired by using [`getSymbol()`](https://jisotalo.fi/ads-client/classes/Client.html#getSymbol).
647
+
648
+
649
+ ```js
650
+ //Read 2 bytes from indexGroup 16448 and indexOffset 414816
651
+ const data = await client.readRaw(16448, 414816, 2);
652
+ console.log(data); //<Buffer ff 7f>
653
+ ```
654
+
655
+ **readRawByPath()**
656
+
657
+ ```js
658
+ const data = await client.readRawByPath('GVL_Read.StandardTypes.INT_');
659
+ console.log(data); //<Buffer ff 7f>
660
+ ```
661
+
662
+
663
+ ### Reading reference/pointer
664
+
665
+ The dereferenced value of a reference (`REFERENCE TO`) or a pointer (`POINTER TO`) can be read with [`readRawByPath()`](https://jisotalo.fi/ads-client/classes/Client.html#readRawByPath) or by using [variable handles](https://jisotalo.fi/ads-client/classes/Client.html#createVariableHandle).
666
+
667
+ **Reading POINTER (readRawByPath())**
668
+
669
+ ```js
670
+ //Reading a raw POINTER value (Note the dereference operator ^)
671
+ const value = await client.readRawByPath('GVL_Read.ComplexTypes.POINTER_^');
672
+
673
+ //Converting to a Javascript object
674
+ const value = await client.convertFromRaw(rawValue, 'ST_StandardTypes');
675
+ console.log(value);
676
+ /*
677
+ {
678
+ BOOL_: true,
679
+ BOOL_2: false,
680
+ BYTE_: 255,
681
+ WORD_: 65535,
682
+ //..and so on
683
+ }
684
+ */
685
+ ```
686
+
687
+ **Reading REFERENCE (readRawByPath())**
688
+
689
+ ```js
690
+ //Reading a raw REFERENCE value
691
+ const rawValue = await client.readRawByPath('GVL_Read.ComplexTypes.REFERENCE_');
692
+
693
+ //Converting to a Javascript object
694
+ const value = await client.convertFromRaw(rawValue, 'ST_StandardTypes');
695
+ console.log(value);
696
+ /*
697
+ {
698
+ BOOL_: true,
699
+ BOOL_2: false,
700
+ BYTE_: 255,
701
+ WORD_: 65535,
702
+ //..and so on
703
+ }
704
+ */
705
+ ```
706
+
707
+ **Reading POINTER (variable handle)**
708
+
709
+ ```js
710
+ //Reading a POINTER value (Note the dereference operator ^)
711
+ const handle = await client.createVariableHandle('GVL_Read.ComplexTypes.POINTER_^');
712
+ const rawValue = await client.readRawByHandle(handle);
713
+ await client.deleteVariableHandle(handle);
714
+
715
+ //Converting to a Javascript object
716
+ const value = await client.convertFromRaw(rawValue, 'ST_StandardTypes');
717
+ console.log(value);
718
+ /*
719
+ {
720
+ BOOL_: true,
721
+ BOOL_2: false,
722
+ BYTE_: 255,
723
+ WORD_: 65535,
724
+ //..and so on
725
+ }
726
+ */
727
+ ```
728
+
729
+ **Reading REFERENCE (variable handle)**
730
+
731
+ ```js
732
+ //Reading a REFERENCE value
733
+ const handle = await client.createVariableHandle('GVL_Read.ComplexTypes.REFERENCE_');
734
+ const rawValue = await client.readRawByHandle(handle);
735
+ await client.deleteVariableHandle(handle);
736
+
737
+ //Converting to a Javascript object
738
+ const value = await client.convertFromRaw(rawValue, 'ST_StandardTypes');
739
+ console.log(value);
740
+ /*
741
+ {
742
+ BOOL_: true,
743
+ BOOL_2: false,
744
+ BYTE_: 255,
745
+ WORD_: 65535,
746
+ //..and so on
747
+ }
748
+ */
749
+ ```
750
+
751
+ ## Writing values
752
+
753
+ ### Writing any value
754
+
755
+ Use [`writeValue()`](https://jisotalo.fi/ads-client/classes/Client.html#writeValue) to write any PLC value.
756
+
757
+ The only exception is the dereferenced value of a reference/pointer, see [Writing reference/pointer](#writing-referencepointer).
758
+
759
+ **Writing INT**
760
+
761
+ ```js
762
+ const res = await client.writeValue('GVL_Write.StandardTypes.INT_', 32767);
763
+ console.log(res.value);
764
+ // 32767
765
+ ```
766
+
767
+ **Writing STRING**
768
+
769
+ ```js
770
+ await client.writeValue('GVL_Write.StandardTypes.STRING_', 'This is a test');
771
+ ```
772
+
773
+ **Writing DT**
774
+
775
+ ```js
776
+ await client.writeValue('GVL_Write.StandardTypes.DT_', new Date());
777
+ ```
778
+
779
+ **Writing STRUCT (all properties)**
780
+
781
+ ```js
782
+ await client.writeValue('GVL_Write.ComplexTypes.STRUCT_', {
783
+ BOOL_: true,
784
+ BOOL_2: false,
785
+ BYTE_: 255,
786
+ WORD_: 65535,
787
+ //...and so on
74
788
  });
789
+ ```
75
790
 
76
- //Typescript:
77
- await client.subscribe<number>({
78
- target: 'GVL_Example.ChangingValue',
79
- cycleTime: 100,
791
+ **Writing STRUCT (some properties only)**
792
+
793
+ All other properties will keep their values. The client reads the active value first and then makes changes.
794
+
795
+ ```js
796
+ await client.writeValue('GVL_Write.ComplexTypes.STRUCT_', {
797
+ WORD_: 65535
798
+ }, true); //<-- NOTE: autoFill set
799
+ ```
800
+
801
+ **Writing FUNCTION_BLOCK (all properties)**
802
+
803
+ ```js
804
+ const timerBlock = {
805
+ IN: false,
806
+ PT: 2500,
807
+ Q: false,
808
+ ET: 0,
809
+ M: false,
810
+ StartTime: 0
811
+ };
812
+
813
+ await client.writeValue('GVL_Write.ComplexTypes.BLOCK_2', timerBlock);
814
+ ```
815
+
816
+ **Writing FUNCTION_BLOCK (some properties only)**
817
+
818
+ All other properties will keep their values. The client reads the active value first and then makes changes.
819
+
820
+ ```js
821
+ await client.writeValue('GVL_Write.ComplexTypes.BLOCK_2', {
822
+ IN: true
823
+ }, true); //<-- NOTE: autoFill set
824
+ ```
825
+
826
+ **Writing ARRAY**
827
+
828
+ ```js
829
+ const data = [
830
+ 75483.546875,
831
+ 0,
832
+ -75483.546875
833
+ ];
834
+
835
+ await client.writeValue('GVL_Write.StandardArrays.REAL_3', data);
836
+ ```
837
+
838
+ **Writing ENUM**
839
+
840
+ ```js
841
+ await client.writeValue('GVL_Write.ComplexTypes.ENUM_', 'Running');
842
+ //...or...
843
+ await client.writeValue('GVL_Write.ComplexTypes.ENUM_', 100);
844
+ ```
845
+
846
+ ### Writing raw data
847
+
848
+ Use [`writeRaw()`](https://jisotalo.fi/ads-client/classes/Client.html#writeRaw) or [`writeRawByPath()`](https://jisotalo.fi/ads-client/classes/Client.html#writeRawByPath) to write any PLC value using raw data. The raw data in this context means bytes (a `Buffer` object).
849
+
850
+ The only exception is the dereferenced value of a reference/pointer, see [Reading reference/pointer](#reading-referencepointer).
851
+
852
+ For converting the data between raw data and Javascript object, see [Converting data between raw data and Javascript objects](#converting-data-between-raw-data-and-javascript-objects).
853
+
854
+ **writeRaw()**
855
+ ```js
856
+ //Creating raw data of an INT
857
+ const data = await client.convertToRaw(32767, 'INT');
858
+ console.log(data); //<Buffer ff 7f>
859
+
860
+ //Writing the value to indexGroup 16448 and indexOffset 414816
861
+ await client.writeRaw(16448, 414816, data);
862
+ ```
863
+
864
+ **writeRawByPath()**
865
+
866
+ ```js
867
+ //Creating raw data of an INT
868
+ const data = await client.convertToRaw(32767, 'INT');
869
+ console.log(data); //<Buffer ff 7f>
870
+
871
+ await client.writeRawByPath('GVL_Write.StandardTypes.INT_', data);
872
+ ```
873
+
874
+ ### Writing reference/pointer
875
+
876
+ The dereferenced value of a reference (`REFERENCE TO`) or a pointer (`POINTER TO`) can be written
877
+ with [`writeRawByPath()`](https://jisotalo.fi/ads-client/classes/Client.html#writeRawByPath) or by using [variable handles](https://jisotalo.fi/ads-client/classes/Client.html#createVariableHandle).
878
+
879
+ **Writing POINTER (writeRawByPath())**
880
+
881
+ ```js
882
+ const value = {
883
+ BOOL_: true,
884
+ BOOL_2: false,
885
+ BYTE_: 255,
886
+ WORD_: 65535,
887
+ //...and so on
888
+ };
889
+ const rawValue = await client.convertToRaw(value, 'ST_StandardTypes');
890
+
891
+ //Writing a raw POINTER value (Note the dereference operator ^)
892
+ await client.writeRawByPath('GVL_Write.ComplexTypes.POINTER_^', rawValue);
893
+ ```
894
+
895
+ **Writing REFERENCE (writeRawByPath())**
896
+
897
+ ```js
898
+ const value = {
899
+ BOOL_: true,
900
+ BOOL_2: false,
901
+ BYTE_: 255,
902
+ WORD_: 65535,
903
+ //...and so on
904
+ };
905
+ const rawValue = await client.convertToRaw(value, 'ST_StandardTypes');
906
+
907
+ //Writing a raw REFERENCE value
908
+ await client.writeRawByPath('GVL_Write.ComplexTypes.REFERENCE_', rawValue);
909
+ ```
910
+
911
+ **Writing POINTER (variable handle)**
912
+
913
+ ```js
914
+ const value = {
915
+ BOOL_: true,
916
+ BOOL_2: false,
917
+ BYTE_: 255,
918
+ WORD_: 65535,
919
+ //...and so on
920
+ };
921
+ const rawValue = await client.convertToRaw(value, 'ST_StandardTypes');
922
+
923
+ //Writing a raw POINTER value (Note the dereference operator ^)
924
+ const handle = await client.createVariableHandle('GVL_Write.ComplexTypes.POINTER_^');
925
+ await client.writeRawByHandle(handle, rawValue);
926
+ await client.deleteVariableHandle(handle);
927
+ ```
928
+
929
+ **Writing REFERENCE (variable handle)**
930
+
931
+ ```js
932
+ const value = {
933
+ BOOL_: true,
934
+ BOOL_2: false,
935
+ BYTE_: 255,
936
+ WORD_: 65535,
937
+ //...and so on
938
+ };
939
+ const rawValue = await client.convertToRaw(value, 'ST_StandardTypes');
940
+
941
+ //Writing a raw REFERENCE value
942
+ const handle = await client.createVariableHandle('GVL_Write.ComplexTypes.POINTER_');
943
+ await client.writeRawByHandle(handle, rawValue);
944
+ await client.deleteVariableHandle(handle);
945
+ ```
946
+
947
+ ## Subscribing to value changes
948
+
949
+ In ads-client, subscriptions are used to handle ADS notifications. ADS notifications are data sent by PLC automatically without request. For example, the latest value of a variable every second.
950
+
951
+ By subscribing to a variable value changes, the target system (PLC) will send ADS notifications when the value changes (or every x milliseconds). The client then receives these notifications and calls the user callback function with the latest value.
952
+
953
+ More information about ADS notifications at [Beckhoff Infosys: Use of ADS Notifications](https://infosys.beckhoff.com/content/1033/tc3_ads.net/9407523595.html?id=431879546285476216).
954
+
955
+ ### Any value
956
+
957
+ Use [`subscribeValue()`](https://jisotalo.fi/ads-client/classes/Client.html#subscribeValue) or [`subscribe()`](https://jisotalo.fi/ads-client/classes/Client.html#subscribe) to subscribe to PLC variable value changes.
958
+
959
+ **Example**
960
+
961
+ Subscribing to changes of `GVL_Subscription.NumericValue_10ms`. The callback is called when the PLC value changes (at maximum every 100 milliseconds).
962
+
963
+ ```js
964
+ const onValueChanged = (data, subscription) => {
965
+ console.log(`Value of ${subscription.symbol.name} has changed: ${data.value}`);
966
+ }
967
+
968
+ const subscription = await client.subscribeValue(
969
+ 'GVL_Subscription.NumericValue_10ms',
970
+ onValueChanged,
971
+ 100
972
+ );
973
+ ```
974
+
975
+ **Example**
976
+
977
+ Subscribing to value of `GVL_Subscription.NumericValue_1000ms`. The callback is called with the latest value every 100 milliseconds (doesn't matter if the value has changed or not).
978
+
979
+ ```js
980
+ const onValueReceived = (data, subscription) => {
981
+ console.log(`Value of ${subscription.symbol.name} is: ${data.value}`);
982
+ }
983
+
984
+ const subscription = await client.subscribeValue(
985
+ 'GVL_Subscription.NumericValue_1000ms',
986
+ onValueReceived,
987
+ 100,
988
+ false
989
+ );
990
+
991
+ ```
992
+
993
+ **Typescript example**
994
+
995
+ Same as previous example, but with [`subscribe()`](https://jisotalo.fi/ads-client/classes/Client.html#subscribe) instead. A type can be provided for `subscribeValue<T>()` as well.
996
+
997
+ ```js
998
+ const subscription = await client.subscribe<number>({
999
+ target: 'GVL_Subscription.NumericValue_1000ms',
80
1000
  callback: (data, subscription) => {
81
- //data.value is typed as string (instead of any)
82
- console.log(`${data.timestamp}: Value changed to ${data.value}`);
1001
+ //data.value is typed as "number" instead of "any"
1002
+ console.log(`Value of ${subscription.symbol.name} is: ${data.value}`);
1003
+ },
1004
+ cycleTime: 100,
1005
+ sendOnChange: false
1006
+ });
1007
+ ```
1008
+
1009
+ ### Raw data
1010
+
1011
+ Use [`subscribeRaw()`](https://jisotalo.fi/ads-client/classes/Client.html#subscribeRaw) or [`subscribe()`](https://jisotalo.fi/ads-client/classes/Client.html#subscribe) to subscribe to raw value changes.
1012
+
1013
+ The `indexGroup` and `indexOffset` can be acquired by using [`getSymbol()`](https://jisotalo.fi/ads-client/classes/Client.html#getSymbol).
1014
+
1015
+ **Example**
1016
+
1017
+ Subscribing to raw address of `indexGroup` = 16448 and `indexOffset` = 414816 (2 bytes).
1018
+
1019
+ ```js
1020
+ await client.subscribeRaw(16448, 414816, 2, (data, subscription) => {
1021
+ console.log(`Value has changed: ${data.value.toString('hex')}`);
1022
+ }, 100);
1023
+ ```
1024
+
1025
+ **Example**
1026
+
1027
+ Same as previous example, but with [`subscribe()`](https://jisotalo.fi/ads-client/classes/Client.html#subscribe) instead.
1028
+
1029
+ ```js
1030
+ const onValueChanged = (data, subscription) => {
1031
+ console.log(`Value has changed: ${data.value.toString('hex')}`);
1032
+ }
1033
+
1034
+ await client.subscribe({
1035
+ target: {
1036
+ indexGroup: 16448,
1037
+ indexOffset: 414816,
1038
+ size: 2
1039
+ },
1040
+ callback: onValueChanged,
1041
+ cycleTime: 100
1042
+ });
1043
+ ```
1044
+
1045
+ ### Unsubscribing
1046
+
1047
+ Subscriptions should always be cancelled when no longer needed (to save PLC resources).
1048
+
1049
+ To unsubscribe, use [`unsubscribe()`](https://jisotalo.fi/ads-client/classes/Client.html#unsubscribe) or subscription object's [`ActiveSubscription.unsubscribe()`](https://jisotalo.fi/ads-client/interfaces/ActiveSubscription.html#unsubscribe).
1050
+
1051
+ ```js
1052
+ const subscription = await client.subscribeValue(...);
1053
+
1054
+ //Later when no longer needed
1055
+ await subscription.unsubscribe();
1056
+
1057
+ //Or alternatively
1058
+ await client.unsubscribe(subscription);
1059
+ ```
1060
+
1061
+ ## Using variable handles
1062
+
1063
+ Using variable handles is an another way to read and write raw data.
1064
+
1065
+ First, a handle is created to a specific PLC variable by the variable path. After that, read and write operations are available.
1066
+
1067
+ Handles should always be deleted after no longer needed, as the PLC has limited number of handles.
1068
+
1069
+ Handles can also be used to read/write reference and pointer values, see [Reading reference/pointer](#reading-referencepointer).
1070
+
1071
+ ### Reading a value using a variable handle
1072
+
1073
+ ```js
1074
+ //Creating a handle
1075
+ const handle = await client.createVariableHandle('GVL_Read.StandardTypes.INT_');
1076
+
1077
+ //Reading a value
1078
+ const data = await client.readRawByHandle(handle);
1079
+
1080
+ //Deleting the handle
1081
+ await client.deleteVariableHandle(handle);
1082
+
1083
+ //Converting to a Javascript value
1084
+ const converted = await client.convertFromRaw(data, 'INT');
1085
+ console.log(data); //<Buffer ff 7f>
1086
+ console.log(converted); //32767
1087
+ ```
1088
+
1089
+ ### Writing a value using a variable handle
1090
+
1091
+ ```js
1092
+ //Creating a raw value
1093
+ const data = await client.convertToRaw(32767, 'INT');
1094
+ console.log(data); //<Buffer ff 7f>
1095
+
1096
+ //Creating a handle
1097
+ const handle = await client.createVariableHandle('GVL_Write.StandardTypes.INT_');
1098
+
1099
+ //Writing the value
1100
+ await client.writeRawByHandle(handle, data);
1101
+
1102
+ //Deleting the handle
1103
+ await client.deleteVariableHandle(handle);
1104
+ ```
1105
+
1106
+ ## Calling function block RPC methods
1107
+
1108
+ If a function block method has pragma `{attribute 'TcRpcEnable'}`,
1109
+ the method can be called from ads-client.
1110
+
1111
+ Read more at [Beckhoff Infosys: Attribute 'TcRpcEnable'](https://infosys.beckhoff.com/english.php?content=../content/1033/tc3_plc_intro/7145472907.html).
1112
+
1113
+ ### Things to note when using RPC Methods
1114
+
1115
+ These are my own observations.
1116
+
1117
+ - Do not use online change if you change RPC method parameters or return data types
1118
+ - Make sure that parameters and return value have no pack-mode pragmas defined, otherwise data might be corrupted
1119
+ - Do not use `ARRAY` values directly in parameters or return value, encapsulate arrays inside struct and use the struct instead
1120
+ - The feature isn't well documented by Beckhoff, so there might be some things that aren't taken into account
1121
+
1122
+ ### About examples
1123
+
1124
+ These examples use `FB_RPC` from the test PLC project at [https://github.com/jisotalo/ads-client-test-plc-project](https://github.com/jisotalo/ads-client-test-plc-project).
1125
+
1126
+ ![](https://raw.githubusercontent.com/jisotalo/ads-client/refs/heads/v2-dev/img/fb_rpc.png)
1127
+
1128
+ There is an instance of the function block at `GVL_RPC.RpcBlock`.
1129
+
1130
+ ### RPC method with standard data types
1131
+
1132
+ The `Calculator()` method calculates sum, product and division of the input values. The method returns `true`, if all calculations were successful.
1133
+ ```
1134
+ {attribute 'TcRpcEnable'}
1135
+ METHOD Calculator : BOOL
1136
+ VAR_INPUT
1137
+ Value1 : REAL;
1138
+ Value2 : REAL;
1139
+ END_VAR
1140
+ VAR_OUTPUT
1141
+ Sum : REAL;
1142
+ Product : REAL;
1143
+ Division : REAL;
1144
+ END_VAR
1145
+
1146
+ //--- Code starts ---
1147
+
1148
+ //Return TRUE if all success
1149
+ Calculator := TRUE;
1150
+
1151
+ Sum := Value1 + Value2;
1152
+ Product := Value1 * Value2;
1153
+
1154
+ IF Value2 <> 0 THEN
1155
+ Division := Value1 / Value2;
1156
+ ELSE
1157
+ Division := 0;
1158
+ Calculator := FALSE;
1159
+ END_IF
1160
+ ```
1161
+
1162
+ Example call:
1163
+
1164
+ ```js
1165
+ const res = await client.invokeRpcMethod('GVL_RPC.RpcBlock', 'Calculator', {
1166
+ Value1: 1,
1167
+ Value2: 123
1168
+ });
1169
+
1170
+ console.log(res);
1171
+ /*
1172
+ {
1173
+ returnValue: true,
1174
+ outputs: {
1175
+ Sum: 124,
1176
+ Product: 123,
1177
+ Division: 0.008130080997943878
1178
+ }
1179
+ }
1180
+ */
1181
+ ```
1182
+
1183
+ ### RPC method with struct
1184
+
1185
+ The `Structs()` method takes a struct value as input, changes its values and then returns the result.
1186
+
1187
+ ```
1188
+ {attribute 'TcRpcEnable'}
1189
+ METHOD Structs : ST_Struct
1190
+ VAR_INPUT
1191
+ Input : ST_Struct;
1192
+ END_VAR
1193
+
1194
+ //--- Code starts ---
1195
+
1196
+ Structs.SomeText := CONCAT('Response: ', Input.SomeText);
1197
+ Structs.SomeReal := Input.SomeReal * 10.0;
1198
+ Structs.SomeDate := Input.SomeDate + T#24H;
1199
+ ```
1200
+
1201
+ Example call:
1202
+
1203
+ ```js
1204
+ const res = await client.invokeRpcMethod('GVL_RPC.RpcBlock', 'Structs', {
1205
+ Input: {
1206
+ SomeText: 'Hello ads-client',
1207
+ SomeReal: 3.14,
1208
+ SomeDate: new Date('2024-12-24T00:00:00.000Z')
83
1209
  }
84
1210
  });
1211
+
1212
+ console.log(res);
1213
+ /*
1214
+ {
1215
+ returnValue: {
1216
+ SomeText: 'Response: Hello ads-client',
1217
+ SomeReal: 31.4,
1218
+ SomeDate: 2024-12-24T01:00:00.000Z
1219
+ },
1220
+ outputs: {}
1221
+ }
1222
+ */
85
1223
  ```
86
1224
 
87
- ## Support
1225
+ ## Converting data between raw data and Javascript objects
88
1226
 
89
- * Bugs and feature requests:
90
- * [Github Issues](https://github.com/jisotalo/ads-client/issues)
91
- * Help, support and discussion:
92
- * [Github Discussions](https://github.com/jisotalo/ads-client/discussions)
93
- * Professional support:
94
- * Support and also development available
95
- * Contact me!
1227
+ The raw data in this context means sent or received bytes (a `Buffer` object).
96
1228
 
97
- If the library has been useful for you or your business, Paypal can be used to support my work. Or contact me and let's discuss the options!
1229
+ When using methods such as [`readValue()`](https://jisotalo.fi/ads-client/classes/Client.html#readValue), [`writeValue()`](https://jisotalo.fi/ads-client/classes/Client.html#writeValue) and [`subscribeValue()`](https://jisotalo.fi/ads-client/classes/Client.html#subscribeValue),
1230
+ the client converts data automatically. The conversion can be done manually as well, by using [`convertFromRaw()`](https://jisotalo.fi/ads-client/classes/Client.html#convertFromRaw) and [`convertToRaw()`](https://jisotalo.fi/ads-client/classes/Client.html#convertToRaw).
98
1231
 
99
- [![Donate](https://img.shields.io/badge/Donate-PayPal-yellow)](https://www.paypal.com/donate/?business=KUWBXXCVGZZME&no_recurring=0&currency_code=EUR)
1232
+ See my other library [iec-61131-3](https://github.com/jisotalo/iec-61131-3) for other possibilities to convert data between Javascript and IEC 61131-3 types.
100
1233
 
101
- ## TwinCAT 2
1234
+ ### Converting a raw value to a Javascript object
102
1235
 
103
- The library works also with TwinCAT 2.
1236
+ Use [`convertFromRaw()`](https://jisotalo.fi/ads-client/classes/Client.html#convertFromRaw) to convert raw data to Javascript object.
104
1237
 
105
- Please note the following things when communicating with TC2 systems:
106
- * ADS port for first PLC runtime is 801 instead of 851
107
- * All variable names are in UPPERCASE
108
- * All data type names are in UPPERCASE
109
- * Global variables are accessed with dot (`.`) prefix, without the GVL name
110
- * ENUMs are always numeric values only
111
- * Empty structs and function blocks (no members) can't be read
1238
+ **Converting INT**
1239
+
1240
+ ```js
1241
+ const data = await client.readRaw(16448, 414816, 2);
1242
+ console.log(data); //<Buffer ff 7f>
1243
+
1244
+ const converted = await client.convertFromRaw(data, 'INT');
1245
+ console.log(converted); //32767
1246
+ ```
1247
+
1248
+ **Converting STRUCT**
1249
+
1250
+ ```js
1251
+ const converted = await client.convertFromRaw(data, 'ST_StandardTypes');
1252
+ console.log(converted);
1253
+ /*
1254
+ {
1255
+ BOOL_: true,
1256
+ BOOL_2: false,
1257
+ BYTE_: 255,
1258
+ WORD_: 65535,
1259
+ //..and so on
1260
+ }
1261
+ */
1262
+ ```
1263
+
1264
+
1265
+ ### Converting a Javascript object to a raw value
1266
+
1267
+ Use [`convertToRaw()`](https://jisotalo.fi/ads-client/classes/Client.html#convertToRaw) to convert Javascript object to raw data.
1268
+
1269
+ **Converting INT**
1270
+
1271
+ ```js
1272
+ const data = await client.convertToRaw(12345, 'INT');
1273
+ console.log(data); //<Buffer 39 30>
1274
+ ```
1275
+
1276
+ **Converting STRUCT**
1277
+
1278
+ ```js
1279
+ const value = {
1280
+ BOOL_: true,
1281
+ BOOL_2: false,
1282
+ BYTE_: 255,
1283
+ WORD_: 65535,
1284
+ //...and so on
1285
+ };
1286
+
1287
+ const data = await client.convertToRaw(value, 'ST_StandardTypes');
1288
+ console.log(data); //<Buffer ...>
1289
+ ```
1290
+
1291
+ **Converting STRUCT (some properties only)**
1292
+
1293
+ All other (missing) properties are set to default values (zero / empty string).
1294
+ ```js
1295
+ const value = {
1296
+ WORD_: 65535
1297
+ };
1298
+
1299
+ const data = await client.convertToRaw(value, 'ST_StandardTypes', true); //<-- NOTE: autoFill set
1300
+ console.log(data); //<Buffer ...>
1301
+ ```
1302
+
1303
+ ## Other features
1304
+
1305
+ ### ADS sum commands
1306
+
1307
+ ADS sum commands can be used to have multiple ADS commands in one request. This can be useful for efficiency reasons.
1308
+
1309
+ See [Beckhoff Information System](https://infosys.beckhoff.com/english.php?content=../content/1033/tc3_adsdll2/9007199379576075.html&id=9180083787138954512) for more info.
1310
+
1311
+ - [`createVariableHandleMulti()`](https://jisotalo.fi/ads-client/classes/Client.html#createVariableHandleMulti)
1312
+ - [`deleteVariableHandleMulti()`](https://jisotalo.fi/ads-client/classes/Client.html#deleteVariableHandleMulti)
1313
+ - [`readRawMulti()`](https://jisotalo.fi/ads-client/classes/Client.html#readRawMulti)
1314
+ - [`writeRawMulti()`](https://jisotalo.fi/ads-client/classes/Client.html#writeRawMulti)
1315
+ - [`readWriteRawMulti()`](https://jisotalo.fi/ads-client/classes/Client.html#readWriteRawMulti)
1316
+
1317
+ ### Starting and stopping a PLC
1318
+
1319
+ - [`startPlc()`](https://jisotalo.fi/ads-client/classes/Client.html#startPlc)
1320
+ - [`stopPlc()`](https://jisotalo.fi/ads-client/classes/Client.html#stopPlc)
1321
+ - [`resetPlc()`](https://jisotalo.fi/ads-client/classes/Client.html#resetPlc)
1322
+ - [`restartPlc()`](https://jisotalo.fi/ads-client/classes/Client.html#restartPlc)
1323
+
1324
+ ### Starting and stopping TwinCAT system
1325
+
1326
+ - [`setTcSystemToConfig()`](https://jisotalo.fi/ads-client/classes/Client.html#setTcSystemToConfig)
1327
+ - [`setTcSystemToRun()`](https://jisotalo.fi/ads-client/classes/Client.html#setTcSystemToRun)
1328
+ - [`restartTcSystem()`](https://jisotalo.fi/ads-client/classes/Client.html#restartTcSystem)
1329
+
1330
+ ### Client events
1331
+
1332
+ See [`AdsClientEvents`](https://jisotalo.fi/ads-client/interfaces/AdsClientEvents.html) for all available events, their descriptions and examples.
1333
+
1334
+ ```js
1335
+ client.on('connect', (connection) => {
1336
+ console.log('Connected:', connection);
1337
+ });
1338
+ ```
1339
+
1340
+ ### Debugging
1341
+
1342
+ Use [`setDebugLevel()`](https://jisotalo.fi/ads-client/classes/Client.html#setDebugLevel) to change debug level.
1343
+
1344
+ ```js
1345
+ client.setDebugLevel(1);
1346
+ ```
1347
+
1348
+ - 0: no debugging (default)
1349
+ - 1: basic debugging (`$env:DEBUG='ads-client'`)
1350
+ - 2: detailed debugging (`$env:DEBUG='ads-client,ads-client:details'`)
1351
+ - 3: detailed debugging with raw I/O data (`$env:DEBUG='ads-client,ads-client:details,ads-client:raw-data'`)
1352
+
1353
+ Debug data is available in the console (See [Debug](https://www.npmjs.com/package/debug) library for more).
1354
+
1355
+
1356
+ ## Disconnecting
1357
+
1358
+ After the client is no more used, always use [`disconnect()`](https://jisotalo.fi/ads-client/classes/Client.html#disconnect) to release all subscription handles and other resources.
1359
+
1360
+ ```js
1361
+ await client.disconnect();
1362
+ ```
1363
+
1364
+ ## Common issues and questions
1365
+
1366
+ ### There are lot's of connection issues and timeouts
1367
+ Things to try:
1368
+ - Remove all TwinCAT routes and create them again (yes, really)
1369
+ - Increase value of [`timeoutDelay`](https://jisotalo.fi/ads-client/interfaces/AdsClientSettings.html#timeoutDelay) setting
1370
+ - Cache all data types and symbols straight after connecting using [`cacheDataTypes`](https://jisotalo.fi/ads-client/classes/Client.html#cacheDataTypes) and [`cacheSymbols`](https://jisotalo.fi/ads-client/classes/Client.html#cacheSymbols)
1371
+
1372
+ ### Getting `TypeError: Do not know how to serialize a BigInt`
1373
+ - `JSON.stringify` doesn't understand BigInt values (such as `LINT` or similar 64 bit PLC values)
1374
+ - Check [this Github issue](https://github.com/GoogleChromeLabs/jsbi/issues/30#issuecomment-953187833) for the following patch:
1375
+
1376
+ ```js
1377
+ BigInt.prototype.toJSON = function() { return this.toString() }
1378
+ ```
1379
+
1380
+ ### Can I connect from Raspberry Pi to TwinCAT?
1381
+
1382
+ Yes, for example using [Setup 3 - Connect from any Node.js system](#setup-3---connect-from-any-nodejs-system).
1383
+ 1. Open a TCP port 48898 from your PLC
1384
+ 2. Edit `StaticRoutes.xml` file from your PLC
1385
+ 3. Connect from the Raspberry Pi using the PLC IP address as `routerAddress` and the AmsNetID written to `StaticRoutes.xml` as `localAmsNetId`
1386
+
1387
+ ### Receiving ADS error 1808 `Symbol not found` even when it should be found
1388
+
1389
+ - Make sure you have updated the latest PLC software using *download*. Sometimes online change causes this.
1390
+ - If you are using TwinCAT 2, see chapter [Differences when using with TwinCAT 2](#differences-when-using-with-twincat-2)
1391
+ - Double check variable path for typos
1392
+
1393
+ ### Having timeouts or 'mailbox is full' errors
1394
+
1395
+ - The AMS router is capable of handling only limited number of requests in a certain time.
1396
+ - Other possible reason is that operating system TCP window is full because of large number of requests.
1397
+ - Solution:
1398
+ - Use structs or arrays to send data in larger packets
1399
+ - Try raw commands or sum commands to decrease data usage
1400
+
1401
+ ### Having problems to connect from OSX or Raspberry Pi to target PLC
1402
+
1403
+ - The local machine has no AMS router
1404
+ - You need to connect to the PLC's AMS router instead
1405
+ - See [this issue comment](https://github.com/jisotalo/ads-client/issues/51#issuecomment-758016428)
1406
+
1407
+ ### A data type is not found even when it should be
1408
+
1409
+ 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.
1410
+
1411
+ For example, when copying a variable name from TwinCAT online view using CTRL+C, it might not work:
1412
+ - Displayed name: `ARRAY [0..1, 0..1] OF ST_Example`
1413
+ - The value copied to clipboard `ARRAY [0..1, 0..1] OF ST_Example`
1414
+ - --> **This causes error!**
1415
+ - The real data type name that needs to be used is `ARRAY [0..1,0..1] OF ST_Example` (note no whitespace between array dimensions)
1416
+
1417
+ If you have problems, try to read the symbol object using `getSymbol()`. The final solution is to read all data types using `getDataTypes()` and manually locate the correct type.
1418
+
1419
+ ### Connection failed - failed to set PLC connection
1420
+
1421
+ - The `targetAmsNetId` didn't contain a system manager service (port `10000`)
1422
+ - The target is not a PLC and `rawClient` setting is not set
1423
+ - Solution:
1424
+ - Double-check connection settings
1425
+ - [Use `rawClient` setting ](#connecting-to-targets-without-a-plc-runtime)
1426
+
1427
+ ### Connection failed (error EADDRNOTAVAIL)
1428
+ This could happen if you have manually provided `localAddress` or `localTcpPort` that don't exist.
1429
+ For example, setting `localAddress` to `192.168.10.1` when the computer has only ethernet interface with IP `192.168.1.1`.
1430
+
1431
+ See also https://github.com/jisotalo/ads-client/issues/82
1432
+
1433
+ ### Problems running ads-client with docker
1434
+
1435
+ - EADDRNOTAVAIL: See above and https://github.com/jisotalo/ads-client/issues/82
1436
+
1437
+ ### How to connect to a PLC that is in CONFIG mode?
1438
+ 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:
1439
+
1440
+ `Connection failed - failed to set PLC connection. If target is not PLC runtime, use setting "rawClient". If system is in config mode or there is no PLC software yet, you might want to use setting "allowHalfOpen"`
1441
+
1442
+ You can disable the check by providing setting `allowHalfOpen: true`. After that, it's possible to start the PLC by `setTcSystemToRun()`.
1443
+
1444
+ Another option is to use setting `rawClient: true` - see [Connecting to targets without a PLC runtime](#connecting-to-targets-without-a-plc-runtime).
1445
+
1446
+ ### Issues with TwinCAT 2 low-end devices (BK9050, BC9050 etc.)
1447
+ * You can only use raw commands (such as `readRaw()`, `writeRaw()`, `subscribeRaw()`) as these devices provide no symbols
1448
+ * See [issue 114](https://github.com/jisotalo/ads-client/issues/114) and [issue 116](https://github.com/jisotalo/ads-client/issues/116)
1449
+
1450
+
1451
+
1452
+ ## External links
1453
+
1454
+ | Description | Link |
1455
+ | -------------------------------------------- | ------------------------------------------------------- |
1456
+ | ADS client for Node-RED | https://github.com/jisotalo/node-red-contrib-ads-client |
1457
+ | ADS server for Node.js | https://github.com/jisotalo/ads-server |
1458
+ | IEC 61131-3 PLC data type helper for Node.js | https://github.com/jisotalo/iec-61131-3/ |
1459
+ | Codesys client for Node.js | https://github.com/jisotalo/codesys-client/ |
112
1460
 
113
- See the TwinCAT 2 tests for supported and tested features.
114
1461
 
115
1462
  ## Library testing
116
1463
 
117
- Target is that library has tests for all its features, see `./test/` directory.
1464
+ All features of this library are tested using quite large test suite - see `./test/` directory.
118
1465
  This prevents regression, thus updating the ads-client should be always safe.
119
1466
 
1467
+ There are separate tests for TwinCAT 2 and TwinCAT 3.
1468
+
120
1469
  PLC projects for running test suites are located in the following repository:
121
1470
  [https://github.com/jisotalo/ads-client-test-plc-project/tree/v2-dev](https://github.com/jisotalo/ads-client-test-plc-project/tree/v2-dev).
122
1471
 
@@ -124,494 +1473,10 @@ PLC projects for running test suites are located in the following repository:
124
1473
 
125
1474
  Tests are run with command `npm run test-tc3`. TwinCAT 3 test PLC projects needs to be running in the target system.
126
1475
 
127
- **Results 28.09.2024:**
128
-
129
- <details>
130
- <summary>Click to show test results</summary>
131
- <pre>
132
- PASS test/TC3/ads-client.test.js (24.801 s)
133
- √ IMPORTANT NOTE: This test requires running a specific TwinCAT 3 PLC project (https://github.com/jisotalo/ads-client-test-plc-project) (1 ms)
134
- connection
135
- √ client is not connected at beginning (1 ms)
136
- √ checking ads client settings (1 ms)
137
- √ connecting to the target (41 ms)
138
- √ checking that test PLC project is active (13 ms)
139
- √ checking that test PLC project version is correct (10 ms)
140
- √ checking 32/64 bitness (4 ms)
141
- √ caching of symbols and data types
142
- √ reconnecting (34 ms)
143
- resetting PLC to original state
144
- √ resetting PLC (514 ms)
145
- √ checking that reset was successful (8 ms)
146
- √ checking that PLC is not running (11 ms)
147
- √ setting IsReset to false (6 ms)
148
- √ starting PLC (7 ms)
149
- √ checking that test PLC project is running (505 ms)
150
- testing PLC runtime stop, start, restart
151
- √ stopping PLC (15 ms)
152
- √ starting PLC (14 ms)
153
- √ restarting PLC (528 ms)
154
- system state, PLC runtime states and device information
155
- √ reading TwinCAT system state (5 ms)
156
- √ reading PLC runtime (port 851) state (3 ms)
157
- √ reading PLC runtime (port 852) state (3 ms)
158
- √ reading PLC runtime device info (3 ms)
159
- √ reading TwinCAT system device info (5 ms)
160
- √ reading PLC runtime symbol version (4 ms)
161
- symbols and data types
162
- √ reading upload info (4 ms)
163
- √ reading all symbols (16 ms)
164
- √ reading single symbol information (1 ms)
165
- √ reading all data type information (19 ms)
166
- √ reading single data type information (2 ms)
167
- data conversion
168
- √ converting a raw PLC value to a Javascript variable (4 ms)
169
- √ converting a Javascript value to a raw PLC value (40 ms)
170
- reading values
171
- reading standard values
172
- √ reading BOOL (16 ms)
173
- √ reading BYTE (8 ms)
174
- √ reading WORD (9 ms)
175
- √ reading DWORD (7 ms)
176
- √ reading SINT (15 ms)
177
- √ reading USINT (7 ms)
178
- √ reading INT (14 ms)
179
- √ reading UINT (7 ms)
180
- √ reading DINT (13 ms)
181
- √ reading UDINT (7 ms)
182
- √ reading REAL (31 ms)
183
- √ reading STRING (16 ms)
184
- √ reading DATE (7 ms)
185
- √ reading DT (14 ms)
186
- √ reading TOD (16 ms)
187
- √ reading TIME (8 ms)
188
- √ reading LWORD (8 ms)
189
- √ reading LINT (13 ms)
190
- √ reading ULINT (7 ms)
191
- √ reading LREAL (31 ms)
192
- √ reading WSTRING (16 ms)
193
- √ reading LDATE (---- TODO: Needs TC 3.1.4026 ----)
194
- √ reading LDT (---- TODO: Needs TC 3.1.4026 ----) (1 ms)
195
- √ reading LTOD (---- TODO: Needs TC 3.1.4026 ----)
196
- √ reading LTIME (9 ms)
197
- reading standard array values
198
- √ reading ARRAY OF BOOL (14 ms)
199
- √ reading ARRAY OF BYTE (8 ms)
200
- √ reading ARRAY OF WORD (9 ms)
201
- √ reading ARRAY OF DWORD (8 ms)
202
- √ reading ARRAY OF SINT (13 ms)
203
- √ reading ARRAY OF USINT (7 ms)
204
- √ reading ARRAY OF INT (13 ms)
205
- √ reading ARRAY OF UINT (8 ms)
206
- √ reading ARRAY OF DINT (16 ms)
207
- √ reading ARRAY OF UDINT (7 ms)
208
- √ reading ARRAY OF REAL (31 ms)
209
- √ reading ARRAY OF STRING (15 ms)
210
- √ reading ARRAY OF DATE (8 ms)
211
- √ reading ARRAY OF DT (15 ms)
212
- √ reading ARRAY OF TOD (14 ms)
213
- √ reading ARRAY OF TIME (5 ms)
214
- √ reading ARRAY OF LWORD (8 ms)
215
- √ reading ARRAY OF LINT (16 ms)
216
- √ reading ARRAY OF ULINT (7 ms)
217
- √ reading ARRAY OF LREAL (26 ms)
218
- √ reading ARRAY OF WSTRING (13 ms)
219
- √ reading ARRAY OF LDATE (---- TODO: Needs TC 3.1.4026 ----)
220
- √ reading ARRAY OF LDT (---- TODO: Needs TC 3.1.4026 ----)
221
- √ reading ARRAY OF LTOD (---- TODO: Needs TC 3.1.4026 ----)
222
- √ reading ARRAY OF LTIME (6 ms)
223
- reading complex values
224
- √ reading STRUCT (14 ms)
225
- √ reading ALIAS (7 ms)
226
- √ reading ENUM (44 ms)
227
- √ reading POINTER (address) (8 ms)
228
- √ reading SUBRANGE (8 ms)
229
- √ reading UNION (22 ms)
230
- √ reading FUNCTION_BLOCK (28 ms)
231
- √ reading INTERFACE (8 ms)
232
- reading complex array values
233
- √ reading ARRAY OF STRUCT (19 ms)
234
- √ reading ARRAY OF ALIAS (9 ms)
235
- √ reading ARRAY OF ENUM (38 ms)
236
- √ reading ARRAY OF POINTER (address) (6 ms)
237
- √ reading ARRAY OF SUBRANGE (6 ms)
238
- √ reading ARRAY OF UNION (8 ms)
239
- √ reading ARRAY OF FUNCTION_BLOCK (27 ms)
240
- √ reading ARRAY OF INTERFACE (6 ms)
241
- reading special types / cases
242
- √ reading ARRAY with negative index (9 ms)
243
- √ reading multi-dimensional ARRAY (9 ms)
244
- √ reading ARRAY OF ARRAY (7 ms)
245
- √ reading STRUCT with pragma: {attribute 'pack_mode' := '1'} (8 ms)
246
- √ reading STRUCT with pragma: {attribute 'pack_mode' := '8'} (8 ms)
247
- √ reading an empty FUNCTION_BLOCK (7 ms)
248
- √ reading an empty STRUCT (8 ms)
249
- √ reading an empty ARRAY (9 ms)
250
- √ reading a single BIT (15 ms)
251
- √ reading a struct with BIT types (8 ms)
252
- reading dereferenced POINTER and REFERENCE values
253
- √ reading POINTER (value) (8 ms)
254
- √ reading REFERENCE (value) (5 ms)
255
- reading raw data
256
- √ reading a raw value (4 ms)
257
- √ reading a raw value using symbol (3 ms)
258
- √ reading a raw value using path (4 ms)
259
- √ reading multiple raw values (multi/sum command) (5 ms)
260
- reading (misc)
261
- √ reading a value using symbol (3 ms)
262
- writing values
263
- writing standard values
264
- √ writing BOOL (22 ms)
265
- √ writing BYTE (12 ms)
266
- √ writing WORD (12 ms)
267
- √ writing DWORD (12 ms)
268
- √ writing SINT (24 ms)
269
- √ writing USINT (10 ms)
270
- √ writing INT (23 ms)
271
- √ writing UINT (11 ms)
272
- √ writing DINT (25 ms)
273
- √ writing UDINT (11 ms)
274
- √ writing REAL (46 ms)
275
- √ writing STRING (21 ms)
276
- √ writing DATE (11 ms)
277
- √ writing DT (22 ms)
278
- √ writing TOD (22 ms)
279
- √ writing TIME (11 ms)
280
- √ writing LWORD (7 ms)
281
- √ writing LINT (24 ms)
282
- √ writing ULINT (9 ms)
283
- √ writing LREAL (44 ms)
284
- √ writing WSTRING (22 ms)
285
- √ writing LDATE (---- TODO: Needs TC 3.1.4026 ----)
286
- √ writing LDT (---- TODO: Needs TC 3.1.4026 ----) (1 ms)
287
- √ writing LTOD (---- TODO: Needs TC 3.1.4026 ----)
288
- √ writing LTIME (7 ms)
289
- writing standard array values
290
- √ writing ARRAY OF BOOL (24 ms)
291
- √ writing ARRAY OF BYTE (13 ms)
292
- √ writing ARRAY OF WORD (12 ms)
293
- √ writing ARRAY OF DWORD (13 ms)
294
- √ writing ARRAY OF SINT (22 ms)
295
- √ writing ARRAY OF USINT (12 ms)
296
- √ writing ARRAY OF INT (19 ms)
297
- √ writing ARRAY OF UINT (11 ms)
298
- √ writing ARRAY OF DINT (22 ms)
299
- √ writing ARRAY OF UDINT (12 ms)
300
- √ writing ARRAY OF REAL (44 ms)
301
- √ writing ARRAY OF STRING (23 ms)
302
- √ writing ARRAY OF DATE (11 ms)
303
- √ writing ARRAY OF DT (20 ms)
304
- √ writing ARRAY OF TOD (22 ms)
305
- √ writing ARRAY OF TIME (11 ms)
306
- √ writing ARRAY OF LWORD (12 ms)
307
- √ writing ARRAY OF LINT (21 ms)
308
- √ writing ARRAY OF ULINT (12 ms)
309
- √ writing ARRAY OF LREAL (46 ms)
310
- √ writing ARRAY OF WSTRING (22 ms)
311
- √ writing ARRAY OF LDATE (---- TODO: Needs TC 3.1.4026 ----) (1 ms)
312
- √ writing ARRAY OF LDT (---- TODO: Needs TC 3.1.4026 ----) (1 ms)
313
- √ writing ARRAY OF LTOD (---- TODO: Needs TC 3.1.4026 ----)
314
- √ writing ARRAY OF LTIME (10 ms)
315
- writing complex values
316
- √ writing STRUCT (26 ms)
317
- √ writing ALIAS (11 ms)
318
- √ writing ENUM (49 ms)
319
- √ writing POINTER (address) (14 ms)
320
- √ writing SUBRANGE (17 ms)
321
- √ writing UNION (46 ms)
322
- √ writing FUNCTION_BLOCK (46 ms)
323
- √ writing INTERFACE (13 ms)
324
- writing complex array values
325
- √ writing ARRAY OF STRUCT (24 ms)
326
- √ writing ARRAY OF ALIAS (10 ms)
327
- √ writing ARRAY OF ENUM (57 ms)
328
- √ writing ARRAY OF POINTER (address) (12 ms)
329
- √ writing ARRAY OF SUBRANGE (11 ms)
330
- √ writing ARRAY OF UNION (16 ms)
331
- √ writing ARRAY OF FUNCTION_BLOCK (48 ms)
332
- √ writing ARRAY OF INTERFACE (16 ms)
333
- writing special types / cases
334
- √ writing ARRAY with negative index (14 ms)
335
- √ writing multi-dimensional ARRAY (15 ms)
336
- √ writing ARRAY OF ARRAY (16 ms)
337
- √ writing STRUCT with pragma: {attribute 'pack_mode' := '1'} (14 ms)
338
- √ writing STRUCT with pragma: {attribute 'pack_mode' := '8'} (16 ms)
339
- √ writing an empty FUNCTION_BLOCK (8 ms)
340
- √ writing an empty STRUCT (7 ms)
341
- √ writing an empty ARRAY (7 ms)
342
- √ writing a single BIT (36 ms)
343
- √ writing a struct with BIT types (11 ms)
344
- writing dereferenced POINTER and REFERENCE values
345
- √ writing POINTER (value) (22 ms)
346
- √ writing REFERENCE (value) (23 ms)
347
- writing raw data
348
- √ writing a raw value (6 ms)
349
- √ writing a raw value using symbol (7 ms)
350
- √ writing a raw value using path (11 ms)
351
- √ writing multiple raw values (multi/sum command) (20 ms)
352
- writing (misc)
353
- √ writing a value using symbol (8 ms)
354
- variable handles
355
- √ creating and deleting a varible handle (14 ms)
356
- √ reading value using a variable handle (12 ms)
357
- √ writing value using a variable handle (30 ms)
358
- √ creating and deleting multiple varible handles (multi/sum command) (9 ms)
359
- subscriptions (ADS notifications)
360
- √ subscribing and unsubscribing successfully (2033 ms)
361
- √ subscribing to a changing value (10 ms) with default cycle time (3023 ms)
362
- √ subscribing to a changing value (10 ms) with 10 ms cycle time (28 ms)
363
- √ subscribing to a constant value with maximum delay of 2000 ms (2016 ms)
364
- √ subscribing to a raw ADS address (222 ms)
365
- √ subscribing using subscribeValue() (2030 ms)
366
- √ subscribing to a raw ADS address using subscribeRaw() (219 ms)
367
- remote procedure calls (RPC methods)
368
- √ calling a RPC method (13 ms)
369
- √ calling a RPC method with struct parameters (9 ms)
370
- √ calling a RPC method without return value and without parameters (11 ms)
371
- miscellaneous
372
- √ sending read write ADS command (6 ms)
373
- √ sending multiple read write ADS commands (multi/sum command) (12 ms)
374
- issue specific tests
375
- issue 103 (https://github.com/jisotalo/ads-client/issues/103)
376
- √ calling unsubscribeAll() multiple times (should not crash to unhandled exception) (50 ms)
377
- disconnecting
378
- √ disconnecting client (9 ms)
379
- controlling TwinCAT system service
380
- √ connecting (1 ms)
381
- √ setting TwinCAT system to config (4024 ms)
382
- √ setting TwinCAT system to run (4018 ms)
383
- √ disconnecting (2 ms)
384
- handling unknown/stale ADS notifications
385
- √ connecting (27 ms)
386
- √ creating an unknown notification handle by forced disconnecting (1040 ms)
387
- √ deleting an unknown notification handle automatically (1034 ms)
388
- √ disconnecting (1 ms)
389
-
390
- Test Suites: 1 passed, 1 total
391
- Tests: 223 passed, 223 total
392
- Snapshots: 0 total
393
- Time: 24.889 s, estimated 25 s
394
- Ran all test suites matching /TC3\\ads-client.test.js/i.
395
- </pre>
396
- </details>
397
-
398
1476
  ### TwinCAT 2 tests
399
1477
 
400
1478
  Tests are run with command `npm run test-tc2`. TwinCAT 2 test PLC projects needs to be running in the target system.
401
1479
 
402
- TwinCAT 2 tests only have features that are supported by TC2.
403
-
404
- **Results 28.09.2024:**
405
-
406
- <details>
407
- <summary>Click to show test results</summary>
408
- <pre>
409
- PASS test/TC2/ads-client.test.js (26.971 s)
410
- √ IMPORTANT NOTE: This test requires running a specific TwinCAT 2 PLC project (https://github.com/jisotalo/ads-client-test-plc-project)
411
- connection
412
- √ client is not connected at beginning
413
- √ checking ads client settings
414
- √ connecting to the target (35 ms)
415
- √ checking that test PLC project is active (58 ms)
416
- √ checking that test PLC project version is correct (9 ms)
417
- √ checking 32/64 bitness (2 ms)
418
- √ caching of symbols and data types (1 ms)
419
- √ reconnecting (22 ms)
420
- resetting PLC to original state
421
- √ resetting PLC (507 ms)
422
- √ checking that reset was successful (5 ms)
423
- √ checking that PLC is not running (8 ms)
424
- √ setting IsReset to false (3 ms)
425
- √ starting PLC (5 ms)
426
- √ checking that test PLC project is running (506 ms)
427
- testing PLC runtime stop, start, restart
428
- √ stopping PLC (13 ms)
429
- √ starting PLC (10 ms)
430
- √ restarting PLC (523 ms)
431
- system state, PLC runtime states and device information
432
- √ reading TwinCAT system state (2 ms)
433
- √ reading PLC runtime (port 801) state (2 ms)
434
- √ reading PLC runtime device info (2 ms)
435
- √ reading TwinCAT system device info (2 ms)
436
- √ reading PLC runtime symbol version (2 ms)
437
- symbols and data types
438
- √ reading upload info (2 ms)
439
- √ reading all symbols (15 ms)
440
- √ reading single symbol information
441
- √ reading all data type information (33 ms)
442
- √ reading single data type information (9 ms)
443
- data conversion
444
- √ converting a raw PLC value to a Javascript variable (7 ms)
445
- √ converting a Javascript value to a raw PLC value (41 ms)
446
- reading values
447
- reading standard values
448
- √ reading BOOL (12 ms)
449
- √ reading BYTE (6 ms)
450
- √ reading WORD (6 ms)
451
- √ reading DWORD (7 ms)
452
- √ reading SINT (11 ms)
453
- √ reading USINT (7 ms)
454
- √ reading INT (11 ms)
455
- √ reading UINT (7 ms)
456
- √ reading DINT (13 ms)
457
- √ reading UDINT (6 ms)
458
- √ reading REAL (19 ms)
459
- √ reading STRING (10 ms)
460
- √ reading DATE (4 ms)
461
- √ reading DT (9 ms)
462
- √ reading TOD (8 ms)
463
- √ reading TIME (6 ms)
464
- √ reading LREAL (26 ms)
465
- reading standard array values
466
- √ reading ARRAY OF BOOL (9 ms)
467
- √ reading ARRAY OF BYTE (5 ms)
468
- √ reading ARRAY OF WORD (5 ms)
469
- √ reading ARRAY OF DWORD (4 ms)
470
- √ reading ARRAY OF SINT (10 ms)
471
- √ reading ARRAY OF USINT (6 ms)
472
- √ reading ARRAY OF INT (9 ms)
473
- √ reading ARRAY OF UINT (6 ms)
474
- √ reading ARRAY OF DINT (10 ms)
475
- √ reading ARRAY OF UDINT (3 ms)
476
- √ reading ARRAY OF REAL (18 ms)
477
- √ reading ARRAY OF STRING (9 ms)
478
- √ reading ARRAY OF DATE (7 ms)
479
- √ reading ARRAY OF DT (11 ms)
480
- √ reading ARRAY OF TOD (9 ms)
481
- √ reading ARRAY OF TIME (4 ms)
482
- √ reading ARRAY OF LREAL (24 ms)
483
- reading complex values
484
- √ reading STRUCT (15 ms)
485
- √ reading ALIAS (8 ms)
486
- √ reading ENUM (16 ms)
487
- √ reading POINTER (address) (6 ms)
488
- √ reading SUBRANGE (6 ms)
489
- √ reading FUNCTION_BLOCK (23 ms)
490
- reading complex array values
491
- √ reading ARRAY OF STRUCT (12 ms)
492
- √ reading ARRAY OF ALIAS (6 ms)
493
- √ reading ARRAY OF ENUM (20 ms)
494
- √ reading ARRAY OF POINTER (address) (5 ms)
495
- √ reading ARRAY OF SUBRANGE (3 ms)
496
- √ reading ARRAY OF FUNCTION_BLOCK (22 ms)
497
- reading special types / cases
498
- √ reading ARRAY with negative index (8 ms)
499
- √ reading multi-dimensional ARRAY (5 ms)
500
- √ reading ARRAY OF ARRAY (5 ms)
501
- reading dereferenced POINTER values
502
- √ reading POINTER (value) (5 ms)
503
- reading raw data
504
- √ reading a raw value (3 ms)
505
- √ reading a raw value using symbol (2 ms)
506
- √ reading a raw value using path (2 ms)
507
- √ reading multiple raw values (multi/sum command) (4 ms)
508
- reading (misc)
509
- √ reading a value using symbol (3 ms)
510
- writing values
511
- writing standard values
512
- √ writing BOOL (22 ms)
513
- √ writing BYTE (10 ms)
514
- √ writing WORD (8 ms)
515
- √ writing DWORD (10 ms)
516
- √ writing SINT (18 ms)
517
- √ writing USINT (6 ms)
518
- √ writing INT (16 ms)
519
- √ writing UINT (8 ms)
520
- √ writing DINT (13 ms)
521
- √ writing UDINT (7 ms)
522
- √ writing REAL (30 ms)
523
- √ writing STRING (14 ms)
524
- √ writing DATE (6 ms)
525
- √ writing DT (15 ms)
526
- √ writing TOD (15 ms)
527
- √ writing TIME (8 ms)
528
- √ writing LREAL (28 ms)
529
- writing standard array values
530
- √ writing ARRAY OF BOOL (14 ms)
531
- √ writing ARRAY OF BYTE (7 ms)
532
- √ writing ARRAY OF WORD (7 ms)
533
- √ writing ARRAY OF DWORD (9 ms)
534
- √ writing ARRAY OF SINT (13 ms)
535
- √ writing ARRAY OF USINT (7 ms)
536
- √ writing ARRAY OF INT (15 ms)
537
- √ writing ARRAY OF UINT (7 ms)
538
- √ writing ARRAY OF DINT (13 ms)
539
- √ writing ARRAY OF UDINT (9 ms)
540
- √ writing ARRAY OF REAL (25 ms)
541
- √ writing ARRAY OF STRING (17 ms)
542
- √ writing ARRAY OF DATE (7 ms)
543
- √ writing ARRAY OF DT (18 ms)
544
- √ writing ARRAY OF TOD (18 ms)
545
- √ writing ARRAY OF TIME (10 ms)
546
- √ writing ARRAY OF LREAL (35 ms)
547
- writing complex values
548
- √ writing STRUCT (19 ms)
549
- √ writing ALIAS (10 ms)
550
- √ writing ENUM (25 ms)
551
- √ writing POINTER (address) (13 ms)
552
- √ writing SUBRANGE (12 ms)
553
- √ writing FUNCTION_BLOCK (39 ms)
554
- writing complex array values
555
- √ writing ARRAY OF STRUCT (24 ms)
556
- √ writing ARRAY OF ALIAS (11 ms)
557
- √ writing ARRAY OF ENUM (28 ms)
558
- √ writing ARRAY OF POINTER (address) (14 ms)
559
- √ writing ARRAY OF SUBRANGE (11 ms)
560
- √ writing ARRAY OF FUNCTION_BLOCK (48 ms)
561
- writing special types / cases
562
- √ writing ARRAY with negative index (18 ms)
563
- √ writing multi-dimensional ARRAY (13 ms)
564
- √ writing ARRAY OF ARRAY (12 ms)
565
- √ writing an empty FUNCTION_BLOCK (7 ms)
566
- writing dereferenced POINTER and REFERENCE values
567
- √ writing POINTER (value) (15 ms)
568
- writing raw data
569
- √ writing a raw value (7 ms)
570
- √ writing a raw value using symbol (4 ms)
571
- √ writing a raw value using path (10 ms)
572
- √ writing multiple raw values (multi/sum command) (11 ms)
573
- writing (misc)
574
- √ writing a value using symbol (5 ms)
575
- variable handles
576
- √ creating and deleting a varible handle (12 ms)
577
- √ reading value using a variable handle (6 ms)
578
- √ writing value using a variable handle (19 ms)
579
- √ creating and deleting multiple varible handles (multi/sum command) (5 ms)
580
- subscriptions (ADS notifications)
581
- √ subscribing and unsubscribing successfully (2010 ms)
582
- √ subscribing to a changing value (10 ms) with default cycle time (3018 ms)
583
- √ subscribing to a changing value (10 ms) with 10 ms cycle time (30 ms)
584
- √ subscribing to a constant value with maximum delay of 2000 ms (2010 ms)
585
- √ subscribing to a raw ADS address (220 ms)
586
- √ subscribing using subscribeValue() (2010 ms)
587
- √ subscribing to a raw ADS address using subscribeRaw() (218 ms)
588
- miscellaneous
589
- √ sending read write ADS command (7 ms)
590
- √ sending multiple read write ADS commands (multi/sum command) (10 ms)
591
- issue specific tests
592
- issue 103 (https://github.com/jisotalo/ads-client/issues/103)
593
- √ calling unsubscribeAll() multiple times (should not crash to unhandled exception) (28 ms)
594
- disconnecting
595
- √ disconnecting client (6 ms)
596
- controlling TwinCAT system service
597
- √ connecting (2 ms)
598
- √ setting TwinCAT system to config (5248 ms)
599
- √ setting TwinCAT system to run (6303 ms)
600
- √ disconnecting (1 ms)
601
- handling unknown/stale ADS notifications
602
- √ connecting (23 ms)
603
- √ creating an unknown notification handle by forced disconnecting (1033 ms)
604
- √ deleting an unknown notification handle automatically (1021 ms)
605
- √ disconnecting (1 ms)
606
-
607
- Test Suites: 1 passed, 1 total
608
- Tests: 164 passed, 164 total
609
- Snapshots: 0 total
610
- Time: 27.056 s
611
- Ran all test suites matching /TC2\\ads-client.test.js/i.
612
- </pre>
613
- </details>
614
-
615
1480
  # License
616
1481
 
617
1482
  Licensed under [MIT License](http://www.opensource.org/licenses/MIT).