ads-client 1.14.2 → 2.0.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +46 -0
- package/LICENSE.txt +1 -1
- package/README.md +303 -1742
- package/dist/ads-client.d.ts +1562 -0
- package/dist/ads-client.js +5660 -0
- package/dist/ads-client.js.map +1 -0
- package/dist/ads-commons.d.ts +810 -0
- package/dist/ads-commons.js +1247 -0
- package/dist/ads-commons.js.map +1 -0
- package/dist/client-error.d.ts +6 -0
- package/dist/client-error.js +30 -0
- package/dist/client-error.js.map +1 -0
- package/dist/types/ads-client-types.d.ts +626 -0
- package/dist/types/ads-client-types.js +5 -0
- package/dist/types/ads-client-types.js.map +1 -0
- package/dist/types/ads-protocol-types.d.ts +460 -0
- package/dist/types/ads-protocol-types.js +35 -0
- package/dist/types/ads-protocol-types.js.map +1 -0
- package/package.json +20 -11
- package/src/ads-client-ads.js +0 -1163
- package/src/ads-client.js +0 -6884
|
@@ -0,0 +1,1562 @@
|
|
|
1
|
+
import EventEmitter from "events";
|
|
2
|
+
import type { ActiveSubscription, AdsClientConnection, AdsClientSettings, AdsCommandToSend, AdsDataTypeContainer, AdsSymbolContainer, AdsUploadInfo, ConnectionMetaData, SubscriptionSettings, ReadValueResult, WriteValueResult, VariableHandle, RpcMethodCallResult, CreateVariableHandleMultiResult, ReadRawMultiResult, ReadRawMultiCommand, WriteRawMultiResult, DeleteVariableHandleMultiResult, ReadWriteRawMultiResult, ReadWriteRawMultiCommand, WriteRawMultiCommand, ClientEvents, SubscriptionCallback, DebugLevel } from "./types/ads-client-types";
|
|
3
|
+
import { AdsDataType, AdsDeviceInfo, AdsResponse, AdsState, AdsSymbol, AmsAddress, AmsTcpPacket } from "./types/ads-protocol-types";
|
|
4
|
+
import * as ADS from './ads-commons';
|
|
5
|
+
export * as ADS from './ads-commons';
|
|
6
|
+
export type * from "./types/ads-client-types";
|
|
7
|
+
export type * from './types/ads-protocol-types';
|
|
8
|
+
export type * from './client-error';
|
|
9
|
+
/**
|
|
10
|
+
* A class for handling TwinCAT ADS protocol communication.
|
|
11
|
+
*
|
|
12
|
+
* Settings are provided in constructor - see {@link Client.constructor} and {@link AdsClientSettings}.
|
|
13
|
+
*
|
|
14
|
+
* A client instance should be created for each target, however, a single client
|
|
15
|
+
* can also be used to communicate with multiple endpoints.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
*
|
|
19
|
+
* ```js
|
|
20
|
+
* const client = new Client({
|
|
21
|
+
* targetAmsNetId: "192.168.4.1.1.1",
|
|
22
|
+
* targetAdsPort: 851
|
|
23
|
+
* });
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
export declare class Client extends EventEmitter<ClientEvents> {
|
|
27
|
+
/**
|
|
28
|
+
* Debug instance for debug level 1.
|
|
29
|
+
*/
|
|
30
|
+
private debug;
|
|
31
|
+
/**
|
|
32
|
+
* Debug instance for debug level 2.
|
|
33
|
+
*/
|
|
34
|
+
private debugD;
|
|
35
|
+
/**
|
|
36
|
+
* Debug instance for debug level 3.
|
|
37
|
+
*/
|
|
38
|
+
private debugIO;
|
|
39
|
+
/**
|
|
40
|
+
* Active debug level.
|
|
41
|
+
*/
|
|
42
|
+
private debugLevel_;
|
|
43
|
+
/**
|
|
44
|
+
* Default metadata (when no active connection).
|
|
45
|
+
*/
|
|
46
|
+
private defaultMetaData;
|
|
47
|
+
/**
|
|
48
|
+
* Callback used for AMS/TCP commands, such as port registering.
|
|
49
|
+
*
|
|
50
|
+
* When a response is received, `amsTcpCallback` is called with the response packet.
|
|
51
|
+
*/
|
|
52
|
+
private amsTcpCallback?;
|
|
53
|
+
/**
|
|
54
|
+
* Buffer for received data.
|
|
55
|
+
*
|
|
56
|
+
* All received data from TCP socket is copied here for further processing.
|
|
57
|
+
*/
|
|
58
|
+
private receiveBuffer;
|
|
59
|
+
/**
|
|
60
|
+
* Used TCP socket instance.
|
|
61
|
+
*/
|
|
62
|
+
private socket?;
|
|
63
|
+
/**
|
|
64
|
+
* Handler for socket error event.
|
|
65
|
+
*
|
|
66
|
+
* Called when the socket emits error event (`socket.on("error")`).
|
|
67
|
+
*/
|
|
68
|
+
private socketErrorHandler?;
|
|
69
|
+
/**
|
|
70
|
+
* Handler for socket close event.
|
|
71
|
+
*
|
|
72
|
+
* Called when the socket emits error event (`socket.on("close")`).
|
|
73
|
+
*/
|
|
74
|
+
private socketConnectionLostHandler?;
|
|
75
|
+
/**
|
|
76
|
+
* Timer handle and ID of the timer used for automatic reconnecting.
|
|
77
|
+
*/
|
|
78
|
+
private reconnectionTimer;
|
|
79
|
+
/**
|
|
80
|
+
* Timer handle and ID of the timer used for reading TwinCAT system state.
|
|
81
|
+
*/
|
|
82
|
+
private tcSystemStatePollerTimer;
|
|
83
|
+
/**
|
|
84
|
+
* Timer handle of the timer used for detecting ADS port registeration timeout.
|
|
85
|
+
*/
|
|
86
|
+
private portRegisterTimeoutTimer?;
|
|
87
|
+
/**
|
|
88
|
+
* Container for all active subscriptions.
|
|
89
|
+
*/
|
|
90
|
+
private activeSubscriptions;
|
|
91
|
+
/**
|
|
92
|
+
* Container for previous subscriptions that were active
|
|
93
|
+
* before reconnecting or when PLC runtime symbol version changed.
|
|
94
|
+
*/
|
|
95
|
+
private previousSubscriptions?;
|
|
96
|
+
/**
|
|
97
|
+
* Active ADS requests that are waiting for responses.
|
|
98
|
+
*/
|
|
99
|
+
private activeAdsRequests;
|
|
100
|
+
/**
|
|
101
|
+
* Next invoke ID to be used for ADS requests.
|
|
102
|
+
*/
|
|
103
|
+
private nextInvokeId;
|
|
104
|
+
/**
|
|
105
|
+
* Timestamp (epoch) when the conection to the remote was lost for the first time.
|
|
106
|
+
*
|
|
107
|
+
* Used for detecting if the connection has been lost for long enough
|
|
108
|
+
* for starting the reconnection.
|
|
109
|
+
*/
|
|
110
|
+
private connectionDownSince?;
|
|
111
|
+
/**
|
|
112
|
+
* Active debug level (read-only).
|
|
113
|
+
*
|
|
114
|
+
* Use {@link Client.setDebugLevel} for setting debug level.
|
|
115
|
+
*
|
|
116
|
+
* Debug levels:
|
|
117
|
+
* - 0: no debugging (default)
|
|
118
|
+
* - 1: basic debugging (`$env:DEBUG='ads-client'`)
|
|
119
|
+
* - 2: detailed debugging (`$env:DEBUG='ads-client,ads-client:details'`)
|
|
120
|
+
* - 3: detailed debugging with raw I/O data (`$env:DEBUG='ads-client,ads-client:details,ads-client:raw-data'`)
|
|
121
|
+
*
|
|
122
|
+
* Debug data is available in the console (See [Debug](https://www.npmjs.com/package/debug) library for mode).
|
|
123
|
+
*/
|
|
124
|
+
get debugLevel(): Readonly<DebugLevel>;
|
|
125
|
+
/**
|
|
126
|
+
* Active client settings.
|
|
127
|
+
*
|
|
128
|
+
* You can change some settings directly from this object on the fly, mainly
|
|
129
|
+
* some non-communication related ones.
|
|
130
|
+
*
|
|
131
|
+
* If the client is not yet connected, it's OK to change all settings from here.
|
|
132
|
+
*
|
|
133
|
+
* However, the most correct way is to use the {@link Client.constructor}.
|
|
134
|
+
*
|
|
135
|
+
* @example
|
|
136
|
+
*
|
|
137
|
+
* ```js
|
|
138
|
+
* client.settings.convertDatesToJavascript = false; //OK
|
|
139
|
+
* client.settings.targetAdsPort = 852; //Not OK if already connected (some things might break)
|
|
140
|
+
* ```
|
|
141
|
+
*/
|
|
142
|
+
settings: Required<AdsClientSettings>;
|
|
143
|
+
/**
|
|
144
|
+
* Active connection information.
|
|
145
|
+
*
|
|
146
|
+
* See {@link AdsClientConnection}
|
|
147
|
+
*/
|
|
148
|
+
connection: AdsClientConnection;
|
|
149
|
+
/**
|
|
150
|
+
* Active connection metadata.
|
|
151
|
+
*
|
|
152
|
+
* Metadata includes target device information, symbols, data types and so on.
|
|
153
|
+
*
|
|
154
|
+
* Some properties might not be available in all connection setups and setting combinations.
|
|
155
|
+
*/
|
|
156
|
+
metaData: ConnectionMetaData;
|
|
157
|
+
/**
|
|
158
|
+
* Creates a new ADS client instance.
|
|
159
|
+
*
|
|
160
|
+
* Settings are provided in `settings` parameter - see {@link AdsClientSettings}.
|
|
161
|
+
*
|
|
162
|
+
* @example
|
|
163
|
+
*
|
|
164
|
+
* ```js
|
|
165
|
+
* const client = new Client({
|
|
166
|
+
* targetAmsNetId: "192.168.4.1.1.1",
|
|
167
|
+
* targetAdsPort: 851
|
|
168
|
+
* });
|
|
169
|
+
* ```
|
|
170
|
+
*/
|
|
171
|
+
constructor(settings: AdsClientSettings);
|
|
172
|
+
/**
|
|
173
|
+
* Clears given timer if it's available and increases the ID.
|
|
174
|
+
*
|
|
175
|
+
* @param timerObject Timer object
|
|
176
|
+
*/
|
|
177
|
+
private clearTimer;
|
|
178
|
+
/**
|
|
179
|
+
* Returns target AMS address as a string in a format `amsNetId:port`.
|
|
180
|
+
*
|
|
181
|
+
* @param targetOpts Optional target settings that override values in `settings`
|
|
182
|
+
*/
|
|
183
|
+
private targetToString;
|
|
184
|
+
/**
|
|
185
|
+
* Writes given data buffer to the socket.
|
|
186
|
+
*
|
|
187
|
+
* @param data Data to write
|
|
188
|
+
*/
|
|
189
|
+
private socketWrite;
|
|
190
|
+
/**
|
|
191
|
+
* Connects to the target.
|
|
192
|
+
*
|
|
193
|
+
* @param isReconnecting If `true`, reconnecting is in progress
|
|
194
|
+
*/
|
|
195
|
+
private connectToTarget;
|
|
196
|
+
/**
|
|
197
|
+
* Unregisters ADS port from the router (if required and disconnects from the target.
|
|
198
|
+
*
|
|
199
|
+
* @param forceDisconnect If `true`, the connection is dropped immediately (default: `false`)
|
|
200
|
+
* @param isReconnecting If `true`, reconnecting is in progress (default: `false`)
|
|
201
|
+
*/
|
|
202
|
+
private disconnectFromTarget;
|
|
203
|
+
/**
|
|
204
|
+
* Backups subscriptions, disconnects from the target, connects again to the target
|
|
205
|
+
* and restores the subscriptions.
|
|
206
|
+
*
|
|
207
|
+
* @param forceDisconnect If `true`, the connection is dropped immediately (default: `false`)
|
|
208
|
+
* @param isReconnecting If `true`, reconnecting is in progress (default: `false`)
|
|
209
|
+
*
|
|
210
|
+
* @throws Throws an error if connecting fails
|
|
211
|
+
*/
|
|
212
|
+
private reconnectToTarget;
|
|
213
|
+
/**
|
|
214
|
+
* Registers a free ADS port from the AMS router.
|
|
215
|
+
*
|
|
216
|
+
* If the `settings.localAmsNetId` and `settings.localAdsPort` are set, does nothing.
|
|
217
|
+
*/
|
|
218
|
+
private registerAdsPort;
|
|
219
|
+
/**
|
|
220
|
+
* Unregisters a previously registered ADS port from the AMS router.
|
|
221
|
+
*
|
|
222
|
+
* The remote seems to drop TCP connection after unregistering,
|
|
223
|
+
* so basically calling this always disconnects too.
|
|
224
|
+
*/
|
|
225
|
+
private unregisterAdsPort;
|
|
226
|
+
/**
|
|
227
|
+
* Configures the connection to handle a TwinCAT PLC connection, which is the default
|
|
228
|
+
* assumption when using ads-client.
|
|
229
|
+
*
|
|
230
|
+
* This is not called if the `settings.rawClient` is `true`.
|
|
231
|
+
*/
|
|
232
|
+
private setupPlcConnection;
|
|
233
|
+
/**
|
|
234
|
+
* Starts a poller that will read TwinCAT system state every `settings.connectionCheckInterval` milliseconds.
|
|
235
|
+
*
|
|
236
|
+
* This is used to detect connection operation and if the target TwinCAT system state has changed.
|
|
237
|
+
*
|
|
238
|
+
* This is not called if the `settings.rawClient` is `true`.
|
|
239
|
+
*/
|
|
240
|
+
private startTcSystemStatePoller;
|
|
241
|
+
/**
|
|
242
|
+
* Reads active TwinCAT system state and detects if it has changed or if the connection is down.
|
|
243
|
+
*
|
|
244
|
+
* This is called from timer started by `startTcSystemStatePoller()`.
|
|
245
|
+
*
|
|
246
|
+
* Afterwards starts the poller timer again.
|
|
247
|
+
*/
|
|
248
|
+
private checkTcSystemState;
|
|
249
|
+
/**
|
|
250
|
+
* A subscription callback that is called when the target PLC runtime state has changed.
|
|
251
|
+
*
|
|
252
|
+
* This is not called if the `settings.rawClient` is `true`.
|
|
253
|
+
*
|
|
254
|
+
* @param data Received data
|
|
255
|
+
* @param subscription The subscription object (unused here)
|
|
256
|
+
*/
|
|
257
|
+
private onPlcRuntimeStateChanged;
|
|
258
|
+
/**
|
|
259
|
+
* A subscription callback that is called when the target PLC runtime symbol version has changed.
|
|
260
|
+
*
|
|
261
|
+
* @param data Received data
|
|
262
|
+
* @param subscription The subscription object (unused here)
|
|
263
|
+
*/
|
|
264
|
+
private onPlcSymbolVersionChanged;
|
|
265
|
+
/**
|
|
266
|
+
* Event listener callback for TCP socket error event.
|
|
267
|
+
*
|
|
268
|
+
* See also {@link Client.socketErrorHandler} which is `onSocketError.bind(this)`
|
|
269
|
+
*/
|
|
270
|
+
private onSocketError;
|
|
271
|
+
/**
|
|
272
|
+
* Handles a lost connection, called when connection to the remote is lost.
|
|
273
|
+
*
|
|
274
|
+
* The connection might be lost for example due to a closed socket, socket error,
|
|
275
|
+
* TwinCAT system state change or local router state change.
|
|
276
|
+
*
|
|
277
|
+
* @param socketFailure If `true`, the connection was lost due to a TCP socket problem (default: `false`)
|
|
278
|
+
*/
|
|
279
|
+
private onConnectionLost;
|
|
280
|
+
/**
|
|
281
|
+
* Creates an AMS/TCP request from given packet object.
|
|
282
|
+
*
|
|
283
|
+
* @param packet Object containing the full AMS/TCP packet
|
|
284
|
+
*/
|
|
285
|
+
private createAmsTcpRequest;
|
|
286
|
+
/**
|
|
287
|
+
* Creates an AMS header from given packet object.
|
|
288
|
+
*
|
|
289
|
+
* @param packet Object containing the full AMS/TCP packet
|
|
290
|
+
*/
|
|
291
|
+
private createAmsHeader;
|
|
292
|
+
/**
|
|
293
|
+
* Creates an AMS/TCP header from given packet and AMS header
|
|
294
|
+
*
|
|
295
|
+
* @param packet Object containing the full AMS/TCP packet
|
|
296
|
+
* @param amsHeader Buffer containing the previously created AMS header
|
|
297
|
+
*/
|
|
298
|
+
private createAmsTcpHeader;
|
|
299
|
+
/**
|
|
300
|
+
* Checks received data buffer for full AMS packets.
|
|
301
|
+
*
|
|
302
|
+
* If a full packet is found, it is passed forward.
|
|
303
|
+
*
|
|
304
|
+
* Calls itself recursively if multiple packets available.
|
|
305
|
+
* If so, calls also `setImmediate()` to prevent blocking the event loop.
|
|
306
|
+
*/
|
|
307
|
+
private handleReceivedData;
|
|
308
|
+
/**
|
|
309
|
+
* Parses an AMS/TCP packet from given buffer and then handles it.
|
|
310
|
+
*
|
|
311
|
+
* @param data Buffer that contains data for a single full AMS/TCP packet
|
|
312
|
+
*/
|
|
313
|
+
private parseAmsTcpPacket;
|
|
314
|
+
/**
|
|
315
|
+
* Parses an AMS/TCP header from given buffer.
|
|
316
|
+
*
|
|
317
|
+
* Returns the rest of the payload as data,
|
|
318
|
+
*
|
|
319
|
+
* @param data Buffer that contains data for a single full AMS/TCP packet
|
|
320
|
+
*/
|
|
321
|
+
private parseAmsTcpHeader;
|
|
322
|
+
/**
|
|
323
|
+
* Parses an AMS header from given buffer.
|
|
324
|
+
*
|
|
325
|
+
* Returns the rest of the payload as data.
|
|
326
|
+
*
|
|
327
|
+
* @param data Buffer that contains data for a single AMS packet (without AMS/TCP header)
|
|
328
|
+
*/
|
|
329
|
+
private parseAmsHeader;
|
|
330
|
+
/**
|
|
331
|
+
* Parses ADS data from given buffer.
|
|
332
|
+
*
|
|
333
|
+
* Uses `packet.ams` to determine the ADS command.
|
|
334
|
+
*
|
|
335
|
+
* @param data Buffer that contains data for a single ADS packet (without AMS/TCP header and AMS header)
|
|
336
|
+
*/
|
|
337
|
+
private parseAdsResponse;
|
|
338
|
+
/**
|
|
339
|
+
* Handles the parsed AMS/TCP packet and actions/callbacks related to it.
|
|
340
|
+
*
|
|
341
|
+
* @param packet Fully parsed AMS/TCP packet, includes AMS/TCP header and if available, also AMS header and ADS data
|
|
342
|
+
*/
|
|
343
|
+
private onAmsTcpPacketReceived;
|
|
344
|
+
/**
|
|
345
|
+
* Handles received ADS command.
|
|
346
|
+
*
|
|
347
|
+
* @param packet Fully parsed AMS/TCP packet, includes AMS/TCP header, AMS header and ADS data
|
|
348
|
+
*/
|
|
349
|
+
private onAdsCommandReceived;
|
|
350
|
+
/**
|
|
351
|
+
* Called when local AMS router state has changed (router notification is received).
|
|
352
|
+
*
|
|
353
|
+
* Router state changes multiple times for example when local TwinCAT system
|
|
354
|
+
* is changed from `Config` -> `Run` and vice-versa. If connected to a local system, router state changes might also cause
|
|
355
|
+
* client the reconnect automatically.
|
|
356
|
+
*
|
|
357
|
+
* Router state is received from the router with AMS command `AMS_TCP_PORT_ROUTER_NOTE` (see {@link ADS.AMS_HEADER_FLAG.AMS_TCP_PORT_ROUTER_NOTE})
|
|
358
|
+
*
|
|
359
|
+
* @param state New router state
|
|
360
|
+
*/
|
|
361
|
+
private onRouterStateChanged;
|
|
362
|
+
/**
|
|
363
|
+
* Parses received ADS notification data (stamps) from given data.
|
|
364
|
+
*
|
|
365
|
+
* @param data Raw data to convert
|
|
366
|
+
*/
|
|
367
|
+
private parseAdsNotification;
|
|
368
|
+
/**
|
|
369
|
+
* Adds a new subscription to the target (an ADS device notification).
|
|
370
|
+
*
|
|
371
|
+
* Sends a `AddNotification` ADS command.
|
|
372
|
+
*
|
|
373
|
+
* @param settings Subscription settings / subscription to add
|
|
374
|
+
* @param internal If `true`, this is an internal subscription of the client
|
|
375
|
+
* @param targetOpts Optional target settings that override values in `settings` (**NOTE:** If used, no caching is available -> possible performance impact)
|
|
376
|
+
*/
|
|
377
|
+
private addSubscription;
|
|
378
|
+
/**
|
|
379
|
+
* Unsubscribes from all active subscriptions.
|
|
380
|
+
*
|
|
381
|
+
* @param internals If `true`, also internal subscriptions are unsubscribed
|
|
382
|
+
*/
|
|
383
|
+
private removeSubscriptions;
|
|
384
|
+
/**
|
|
385
|
+
* Backups active subscriptions for restoring them later (after reconnecting).
|
|
386
|
+
*
|
|
387
|
+
* Returns number of subscriptions that were saved for restoring.
|
|
388
|
+
*
|
|
389
|
+
* @param unsubscribe If `true`, {@link Client.unsubscribeAll()} is also called after saving
|
|
390
|
+
*/
|
|
391
|
+
private backupSubscriptions;
|
|
392
|
+
/**
|
|
393
|
+
* Restores all previously backed up subscriptions.
|
|
394
|
+
*
|
|
395
|
+
* Returns array of subscription targets that failed to be subscribed
|
|
396
|
+
* (empty array if all were restored successfully).
|
|
397
|
+
*/
|
|
398
|
+
private restoreSubscriptions;
|
|
399
|
+
/**
|
|
400
|
+
* Parses symbol from raw ADS response payload.
|
|
401
|
+
*
|
|
402
|
+
* @param data Data containing ADS symbol (without first 4 bytes of ADS payload containing entry length)
|
|
403
|
+
*/
|
|
404
|
+
private parseAdsResponseSymbol;
|
|
405
|
+
/**
|
|
406
|
+
* Parses data type declaration from raw ADS response payload.
|
|
407
|
+
*
|
|
408
|
+
* @param data Data containing data type declaration (without first 4 bytes of ADS payload containing entry length)
|
|
409
|
+
*/
|
|
410
|
+
private parseAdsResponseDataType;
|
|
411
|
+
/**
|
|
412
|
+
* Gets data type declaration for requested data type.
|
|
413
|
+
*
|
|
414
|
+
* **NOTE:** Only returns the requested data type and its direct children. Not the children of children.
|
|
415
|
+
*
|
|
416
|
+
* To get the full datatype with all items, use {@link Client.buildDataType()}.
|
|
417
|
+
*
|
|
418
|
+
* Returns previously cached value if available, otherwise reads it from the target
|
|
419
|
+
* and caches it.
|
|
420
|
+
*
|
|
421
|
+
* If caching is disabled using `settings.disableCaching`, data is always read from the target.
|
|
422
|
+
*
|
|
423
|
+
* If `targetOpts` is used to override target, caching is always disabled.
|
|
424
|
+
*
|
|
425
|
+
* @param name Data type name in the PLC (such as `ST_Struct`)
|
|
426
|
+
* @param targetOpts Optional target settings that override values in `settings` (**NOTE:** If used, no caching is available -> possible performance impact)
|
|
427
|
+
*/
|
|
428
|
+
private getDataTypeDeclaration;
|
|
429
|
+
/**
|
|
430
|
+
* Builds full data type declaration for requested data type with all children (and their children and so on).
|
|
431
|
+
*
|
|
432
|
+
* If available, previously cached data is used for building the full data type. Otherwise data is read from the target
|
|
433
|
+
* and cached.
|
|
434
|
+
*
|
|
435
|
+
* If caching is disabled using `settings.disableCaching`, data is always read from the target.
|
|
436
|
+
*
|
|
437
|
+
* If `targetOpts` is used to override target, caching is always disabled.
|
|
438
|
+
*
|
|
439
|
+
* @param name Data type name in the PLC (such as `ST_Struct`)
|
|
440
|
+
* @param targetOpts Optional target settings that override values in `settings` (**NOTE:** If used, no caching is available -> possible performance impact)
|
|
441
|
+
* @param isRootType If `true`, this is the root type / first call / not recursive call (default: `true`)
|
|
442
|
+
* @param knownSize Data type size (if known) - used with pseudo data types and TwinCAT 2 primite types
|
|
443
|
+
*/
|
|
444
|
+
private buildDataType;
|
|
445
|
+
/**
|
|
446
|
+
* Converts raw data to Javascript object (primitive PLC types only)
|
|
447
|
+
*
|
|
448
|
+
* @param buffer The raw data to convert
|
|
449
|
+
* @param dataType Target data type
|
|
450
|
+
*/
|
|
451
|
+
private convertBufferToPrimitiveType;
|
|
452
|
+
/**
|
|
453
|
+
* Converts raw data to Javascript object.
|
|
454
|
+
*
|
|
455
|
+
* This is usually called recursively.
|
|
456
|
+
*
|
|
457
|
+
* @param data The raw data to convert
|
|
458
|
+
* @param dataType Target data type
|
|
459
|
+
* @param isArrayItem If `true`, this is an array item (default: `false`)
|
|
460
|
+
*/
|
|
461
|
+
private convertBufferToObject;
|
|
462
|
+
/**
|
|
463
|
+
* Converts a Javascript object to raw data.
|
|
464
|
+
*
|
|
465
|
+
* @param value Javascript object to convert
|
|
466
|
+
* @param dataType Target data type
|
|
467
|
+
* @param objectPath Object path that is passed forward when calling recursively. This is used for error reporting if a property is missing
|
|
468
|
+
* @param isArrayItem If `true`, this is an array item (default: `false`)
|
|
469
|
+
*/
|
|
470
|
+
private convertObjectToBuffer;
|
|
471
|
+
/**
|
|
472
|
+
* Converts a Javascript object (that is PLC primitive type) to raw data
|
|
473
|
+
*
|
|
474
|
+
* @param value Javascript object to convert
|
|
475
|
+
* @param dataType Data type
|
|
476
|
+
* @param buffer Reference to Buffer object where to write the raw value
|
|
477
|
+
*/
|
|
478
|
+
private convertPrimitiveTypeToBuffer;
|
|
479
|
+
/**
|
|
480
|
+
* Merges objects recursively.
|
|
481
|
+
*
|
|
482
|
+
* Used for example in {@link Client.writeValue()} when `autoFill` setting is used
|
|
483
|
+
* to merge active values (missing properties) to user-provided properties.
|
|
484
|
+
*
|
|
485
|
+
* This is based on https://stackoverflow.com/a/34749873/8140625
|
|
486
|
+
* and https://stackoverflow.com/a/49727784/8140625 with some changes.
|
|
487
|
+
*
|
|
488
|
+
* @param caseSensitive If `true`, the property keys are handled as case-sensitive (as they normally are). In TwinCAT everything is case-insensitive --> `false`.
|
|
489
|
+
* @param target Target object where to merge source objects (this is the value provide by user)
|
|
490
|
+
* @param sources One or more source object, which keys are merged to target if target is missing them
|
|
491
|
+
*/
|
|
492
|
+
private deepMergeObjects;
|
|
493
|
+
/**
|
|
494
|
+
* Connects to the target that is configured in {@link Client.settings} (set in {@link Client.constructor}).
|
|
495
|
+
*
|
|
496
|
+
* If success, returns the connection information (see {@link AdsClientConnection})
|
|
497
|
+
*
|
|
498
|
+
* @throws Throws an error if connecting fails
|
|
499
|
+
*
|
|
500
|
+
* @example
|
|
501
|
+
* ```js
|
|
502
|
+
* try {
|
|
503
|
+
* const res = await client.connect();
|
|
504
|
+
*
|
|
505
|
+
* console.log(`Connected to the ${res.targetAmsNetId}`);
|
|
506
|
+
* console.log(`Router assigned us AmsNetId ${res.localAmsNetId} and port ${res.localAdsPort}`);
|
|
507
|
+
* } catch (err) {
|
|
508
|
+
* console.log("Connecting failed:", err);
|
|
509
|
+
* }
|
|
510
|
+
* ```
|
|
511
|
+
*/
|
|
512
|
+
connect(): Promise<Required<AdsClientConnection>>;
|
|
513
|
+
/**
|
|
514
|
+
* Disconnects from the target and closes active connection.
|
|
515
|
+
*
|
|
516
|
+
* Subscriptions are deleted in a handled manner and ADS port is unregisterd.
|
|
517
|
+
*
|
|
518
|
+
* **WARNING:** If `force` is used, active subscriptions are not deleted!
|
|
519
|
+
* This affects PLCs performance in the long run.
|
|
520
|
+
*
|
|
521
|
+
* @param force If `true`, the connection is dropped immediately (uncontrolled) - use only in special "emergency" cases (default: `false`)
|
|
522
|
+
*
|
|
523
|
+
* @throws Throws an error if disconnecting fails. However the connection stil ended.
|
|
524
|
+
*
|
|
525
|
+
* @example
|
|
526
|
+
* ```js
|
|
527
|
+
* try {
|
|
528
|
+
* const res = await client.disconnect();
|
|
529
|
+
* console.log("Disconnected");
|
|
530
|
+
* } catch (err) {
|
|
531
|
+
* console.log("Disconnected with error:", err);
|
|
532
|
+
* }
|
|
533
|
+
* ```
|
|
534
|
+
*/
|
|
535
|
+
disconnect(force?: boolean): Promise<void>;
|
|
536
|
+
/**
|
|
537
|
+
* Reconnects to the target (disconnects and then connects again).
|
|
538
|
+
*
|
|
539
|
+
* Active subscriptions are saved and restored automatically after reconnecting.
|
|
540
|
+
*
|
|
541
|
+
* **WARNING:** If `forceDisconnect` is used, active subscriptions are not deleted!
|
|
542
|
+
* This affects PLCs performance in the long run.
|
|
543
|
+
*
|
|
544
|
+
* @param forceDisconnect If `true`, the connection is dropped immediately (uncontrolled - as `force` in {@link Client.disconnect()}) - use only in special "emergency" cases (default: `false`)
|
|
545
|
+
*
|
|
546
|
+
* @throws Throws an error if connecting fails
|
|
547
|
+
*/
|
|
548
|
+
reconnect(forceDisconnect?: boolean): Promise<Required<AdsClientConnection>>;
|
|
549
|
+
/**
|
|
550
|
+
* Sets active debug level.
|
|
551
|
+
*
|
|
552
|
+
* Debug levels:
|
|
553
|
+
* - 0: no debugging (default)
|
|
554
|
+
* - 1: basic debugging (`$env:DEBUG='ads-client'`)
|
|
555
|
+
* - 2: detailed debugging (`$env:DEBUG='ads-client,ads-client:details'`)
|
|
556
|
+
* - 3: detailed debugging with raw I/O data (`$env:DEBUG='ads-client,ads-client:details,ads-client:raw-data'`)
|
|
557
|
+
*
|
|
558
|
+
* Debug data is available in the console (See [Debug](https://www.npmjs.com/package/debug) library for mode).
|
|
559
|
+
*/
|
|
560
|
+
setDebugLevel(level: DebugLevel): void;
|
|
561
|
+
/**
|
|
562
|
+
* Sends a raw ADS command to the target.
|
|
563
|
+
*
|
|
564
|
+
* This can be useful in some special cases or custom system. See {@link ADS.ADS_COMMAND} for common commands.
|
|
565
|
+
*
|
|
566
|
+
* **NOTE:** Client already includes all the most common commands:
|
|
567
|
+
* - {@link Client.readRaw}() - `Read` command
|
|
568
|
+
* - {@link Client.writeRaw}() - `Write` command
|
|
569
|
+
* - {@link Client.readDeviceInfo}() - `ReadDeviceInfo` command
|
|
570
|
+
* - {@link Client.readState}() - `ReadState` command
|
|
571
|
+
* - {@link Client.writeControl}() - `WriteControl` command
|
|
572
|
+
* - {@link Client.subscribe}() - `AddNotification` command
|
|
573
|
+
* - {@link Client.unsubscribe}() - `DeleteNotification` command
|
|
574
|
+
* - {@link Client.readWriteRaw}() - `ReadWrite` command
|
|
575
|
+
*
|
|
576
|
+
* @template T ADS response type. If omitted, generic {@link AdsResponse} type is used
|
|
577
|
+
*
|
|
578
|
+
* @throws Throws an error if sending the command fails or if target responds with an error
|
|
579
|
+
*
|
|
580
|
+
* @example
|
|
581
|
+
* ```js
|
|
582
|
+
* TODO - DOCUMENTATION ONGOING
|
|
583
|
+
* ```
|
|
584
|
+
*/
|
|
585
|
+
sendAdsCommand<T = AdsResponse>(command: AdsCommandToSend): Promise<AmsTcpPacket<T>>;
|
|
586
|
+
/**
|
|
587
|
+
* Sends an ADS `WriteControl` command to the target.
|
|
588
|
+
*
|
|
589
|
+
* More info: [Beckhoff documentation](https://infosys.beckhoff.com/content/1033/tc3_ads_intro/115879947.html?id=4720330147059483431)
|
|
590
|
+
*
|
|
591
|
+
* @param adsState Requested ADS state - see {@link ADS.ADS_STATE}. Can be a number or a valid string, such as `Config`
|
|
592
|
+
* @param deviceState Requested device state (default: `0`)
|
|
593
|
+
* @param data Additional data to send (if any)
|
|
594
|
+
* @param targetOpts Optional target settings that override values in `settings`
|
|
595
|
+
*
|
|
596
|
+
* @throws Throws an error if sending the command fails or if the target responds with an error.
|
|
597
|
+
*
|
|
598
|
+
* @example
|
|
599
|
+
* ```js
|
|
600
|
+
* try {
|
|
601
|
+
* //Set target (PLC) to run
|
|
602
|
+
* await client.writeControl("Run");
|
|
603
|
+
* } catch (err) {
|
|
604
|
+
* console.log("Error:", err);
|
|
605
|
+
* }
|
|
606
|
+
* ```
|
|
607
|
+
*/
|
|
608
|
+
writeControl(adsState: keyof typeof ADS.ADS_STATE | number, deviceState?: number, data?: Buffer, targetOpts?: Partial<AmsAddress>): Promise<void>;
|
|
609
|
+
/**
|
|
610
|
+
* Starts the target PLC runtime. Same as pressing the green play button in TwinCAT XAE.
|
|
611
|
+
*
|
|
612
|
+
* **NOTE:** This requires that the target is a PLC runtime or has equivalent ADS protocol support.
|
|
613
|
+
*
|
|
614
|
+
* @param targetOpts Optional target settings that override values in `settings`
|
|
615
|
+
*
|
|
616
|
+
* @throws Throws an error if sending the command fails or if target responds with an error
|
|
617
|
+
*
|
|
618
|
+
* @example
|
|
619
|
+
* ```js
|
|
620
|
+
* try {
|
|
621
|
+
* await client.startPlc();
|
|
622
|
+
* } catch (err) {
|
|
623
|
+
* console.log("Error:", err);
|
|
624
|
+
* }
|
|
625
|
+
* ```
|
|
626
|
+
*/
|
|
627
|
+
startPlc(targetOpts?: Partial<AmsAddress>): Promise<void>;
|
|
628
|
+
/**
|
|
629
|
+
* Resets the target PLC runtime. Same as reset cold in TwinCAT XAE.
|
|
630
|
+
*
|
|
631
|
+
* @param targetOpts Optional target settings that override values in `settings`
|
|
632
|
+
*
|
|
633
|
+
* @throws Throws an error if sending the command fails or if the target responds with an error.
|
|
634
|
+
*
|
|
635
|
+
* @example
|
|
636
|
+
* ```js
|
|
637
|
+
* try {
|
|
638
|
+
* await client.resetPlc();
|
|
639
|
+
* } catch (err) {
|
|
640
|
+
* console.log("Error:", err);
|
|
641
|
+
* }
|
|
642
|
+
* ```
|
|
643
|
+
*/
|
|
644
|
+
resetPlc(targetOpts?: Partial<AmsAddress>): Promise<void>;
|
|
645
|
+
/**
|
|
646
|
+
* Stops the target PLC runtime. Same as pressing the red stop button in TwinCAT XAE.
|
|
647
|
+
*
|
|
648
|
+
* @param targetOpts Optional target settings that override values in `settings`
|
|
649
|
+
*
|
|
650
|
+
* @throws Throws an error if sending the command fails or if the target responds with an error.
|
|
651
|
+
*
|
|
652
|
+
* @example
|
|
653
|
+
* ```js
|
|
654
|
+
* try {
|
|
655
|
+
* await client.stopPlc();
|
|
656
|
+
* } catch (err) {
|
|
657
|
+
* console.log("Error:", err);
|
|
658
|
+
* }
|
|
659
|
+
* ```
|
|
660
|
+
*/
|
|
661
|
+
stopPlc(targetOpts?: Partial<AmsAddress>): Promise<void>;
|
|
662
|
+
/**
|
|
663
|
+
* Restarts the PLC runtime. Same as calling first {@link resetPlc}() and then {@link startPlc}()`
|
|
664
|
+
*
|
|
665
|
+
* **NOTE:** This requires that the target is a PLC runtime or has equivalent ADS protocol support.
|
|
666
|
+
*
|
|
667
|
+
* @example
|
|
668
|
+
* ```js
|
|
669
|
+
* try {
|
|
670
|
+
* await client.restartPlc();
|
|
671
|
+
* } catch (err) {
|
|
672
|
+
* console.log("Error:", err);
|
|
673
|
+
* }
|
|
674
|
+
* ```
|
|
675
|
+
*
|
|
676
|
+
* @param targetOpts Optional target settings that override values in `settings`
|
|
677
|
+
*
|
|
678
|
+
* @throws Throws an error if sending the command fails or if the target responds with an error.
|
|
679
|
+
*
|
|
680
|
+
*/
|
|
681
|
+
restartPlc(targetOpts?: Partial<AmsAddress>): Promise<void>;
|
|
682
|
+
/**
|
|
683
|
+
* Sets the target TwinCAT system to run mode. Same as **Restart TwinCAT system** in TwinCAT XAE.
|
|
684
|
+
*
|
|
685
|
+
* **NOTE:** As default, also reconnects the client afterwards to restore subscriptions.
|
|
686
|
+
*
|
|
687
|
+
* @example
|
|
688
|
+
* ```js
|
|
689
|
+
* try {
|
|
690
|
+
* //Reconnect the client
|
|
691
|
+
* await client.setTcSystemToRun();
|
|
692
|
+
*
|
|
693
|
+
* //Don't reconnect the client
|
|
694
|
+
* await client.setTcSystemToRun(false);
|
|
695
|
+
* } catch (err) {
|
|
696
|
+
* console.log("Error:", err);
|
|
697
|
+
* }
|
|
698
|
+
* ```
|
|
699
|
+
*
|
|
700
|
+
* @param reconnect If `true`, connection is reconnected afterwards to restore subscriptions etc. (default: `true`)
|
|
701
|
+
* @param targetOpts Optional target settings that override values in `settings`
|
|
702
|
+
*
|
|
703
|
+
* @throws Throws an error if sending the command fails or if the target responds with an error.
|
|
704
|
+
*
|
|
705
|
+
*/
|
|
706
|
+
setTcSystemToRun(reconnect?: boolean, targetOpts?: Partial<AmsAddress>): Promise<void>;
|
|
707
|
+
/**
|
|
708
|
+
* Sets the target TwinCAT system to config mode. Same as **Restart TwinCAT (Config mode)** in TwinCAT XAE.
|
|
709
|
+
*
|
|
710
|
+
* **NOTE:** If the target is a PLC runtime, the connection might be lost.
|
|
711
|
+
*
|
|
712
|
+
* @example
|
|
713
|
+
* ```js
|
|
714
|
+
* try {
|
|
715
|
+
* await client.setTcSystemToConfig();
|
|
716
|
+
* } catch (err) {
|
|
717
|
+
* console.log("Error:", err);
|
|
718
|
+
* }
|
|
719
|
+
* ```
|
|
720
|
+
*
|
|
721
|
+
* @param targetOpts Optional target settings that override values in `settings`
|
|
722
|
+
*
|
|
723
|
+
* @throws Throws an error if sending the command fails or if the target responds with an error.
|
|
724
|
+
*
|
|
725
|
+
*/
|
|
726
|
+
setTcSystemToConfig(targetOpts?: Partial<AmsAddress>): Promise<void>;
|
|
727
|
+
/**
|
|
728
|
+
* Restarts the target TwinCAT system.
|
|
729
|
+
*
|
|
730
|
+
* Just a wrapper for {@link setTcSystemToRun}() - the operation is the same.
|
|
731
|
+
*
|
|
732
|
+
* **NOTE:** As default, also reconnects the client afterwards to restore subscriptions.
|
|
733
|
+
*
|
|
734
|
+
* @example
|
|
735
|
+
* ```js
|
|
736
|
+
* try {
|
|
737
|
+
* //Reconnect the client
|
|
738
|
+
* await client.restartTcSystem();
|
|
739
|
+
*
|
|
740
|
+
* //Don't reconnect the client
|
|
741
|
+
* await client.restartTcSystem(false);
|
|
742
|
+
* } catch (err) {
|
|
743
|
+
* console.log("Error:", err);
|
|
744
|
+
* }
|
|
745
|
+
* ```
|
|
746
|
+
*
|
|
747
|
+
* @param reconnect If `true`, connection is reconnected afterwards to restore subscriptions etc. (default: `true`)
|
|
748
|
+
* @param targetOpts Optional target settings that override values in `settings`
|
|
749
|
+
*
|
|
750
|
+
* @throws Throws an error if sending the command fails or if the target responds with an error.
|
|
751
|
+
*
|
|
752
|
+
*/
|
|
753
|
+
restartTcSystem(reconnect?: boolean, targetOpts?: Partial<AmsAddress>): Promise<void>;
|
|
754
|
+
/**
|
|
755
|
+
* Returns symbol for given variable path, such as `GVL_Test.ExampleStruct`.
|
|
756
|
+
*
|
|
757
|
+
* Returns previously cached value if available, otherwise reads it from the target
|
|
758
|
+
* and caches it.
|
|
759
|
+
*
|
|
760
|
+
* If caching is disabled using `settings.disableCaching`, data is always read from the target.
|
|
761
|
+
*
|
|
762
|
+
* If `targetOpts` is used to override target, caching is always disabled.
|
|
763
|
+
*
|
|
764
|
+
* **NOTE:** This requires that the target is a PLC runtime or has equivalent ADS protocol support.
|
|
765
|
+
*
|
|
766
|
+
* @example
|
|
767
|
+
* ```js
|
|
768
|
+
* try {
|
|
769
|
+
* const symbol = await client.getSymbol('GVL_Test.ExampleStruct');
|
|
770
|
+
* } catch (err) {
|
|
771
|
+
* console.log("Error:", err);
|
|
772
|
+
* }
|
|
773
|
+
* ```
|
|
774
|
+
*
|
|
775
|
+
* @param path Symbol variable path at the target (such as `GVL_Test.ExampleStruct`)
|
|
776
|
+
* @param targetOpts Optional target settings that override values in `settings`. If used, caching is disabled -> possible performance impact.
|
|
777
|
+
*
|
|
778
|
+
* @throws Throws an error if sending the command fails or if the target responds with an error.
|
|
779
|
+
*/
|
|
780
|
+
getSymbol(path: string, targetOpts?: Partial<AmsAddress>): Promise<AdsSymbol>;
|
|
781
|
+
/**
|
|
782
|
+
* Returns full data type declaration for requested data type (such as `ST_Struct`) with all children (and their children and so on).
|
|
783
|
+
*
|
|
784
|
+
* If available, previously cached data is used for building the full data type. Otherwise data is read from the target
|
|
785
|
+
* and cached.
|
|
786
|
+
*
|
|
787
|
+
* If caching is disabled using `settings.disableCaching`, data is always read from the target.
|
|
788
|
+
*
|
|
789
|
+
* If `targetOpts` is used to override target, caching is always disabled.
|
|
790
|
+
*
|
|
791
|
+
* **NOTE:** This requires that the target is a PLC runtime or has equivalent ADS protocol support.
|
|
792
|
+
*
|
|
793
|
+
* @example
|
|
794
|
+
* ```js
|
|
795
|
+
* try {
|
|
796
|
+
* const dataType = await client.getDataType('ST_Struct');
|
|
797
|
+
* } catch (err) {
|
|
798
|
+
* console.log("Error:", err);
|
|
799
|
+
* }
|
|
800
|
+
* ```
|
|
801
|
+
*
|
|
802
|
+
* @param name Data type name at the target (such as `ST_Struct`)
|
|
803
|
+
* @param targetOpts Optional target settings that override values in `settings`. If used, caching is disabled -> possible performance impact.
|
|
804
|
+
*
|
|
805
|
+
* @throws Throws an error if sending the command fails or if the target responds with an error.
|
|
806
|
+
*/
|
|
807
|
+
getDataType(name: string, targetOpts?: Partial<AmsAddress>): Promise<AdsDataType>;
|
|
808
|
+
/**
|
|
809
|
+
* Reads target ADS state - see {@link ADS.ADS_STATE}).
|
|
810
|
+
*
|
|
811
|
+
* This is the ADS protocol `ReadState` command.
|
|
812
|
+
*
|
|
813
|
+
* See also {@link readPlcRuntimeState}() and {@link readTcSystemState}().
|
|
814
|
+
*
|
|
815
|
+
* @example
|
|
816
|
+
* ```js
|
|
817
|
+
* try {
|
|
818
|
+
* const state = await client.readState();
|
|
819
|
+
* } catch (err) {
|
|
820
|
+
* console.log("Error:", err);
|
|
821
|
+
* }
|
|
822
|
+
* ```
|
|
823
|
+
*
|
|
824
|
+
* @param targetOpts Optional target settings that override values in `settings`
|
|
825
|
+
*
|
|
826
|
+
* @throws Throws an error if sending the command fails or if the target responds with an error.
|
|
827
|
+
*/
|
|
828
|
+
readState(targetOpts?: Partial<AmsAddress>): Promise<AdsState>;
|
|
829
|
+
/**
|
|
830
|
+
* Reads target PLC runtime state (usually `Run`, `Stop` etc. - see {@link ADS.ADS_STATE})
|
|
831
|
+
*
|
|
832
|
+
* If `targetOpts` is not used to override target, the state is also
|
|
833
|
+
* saved to the `metaData.plcRuntimeState`.
|
|
834
|
+
*
|
|
835
|
+
* This is the same as {@link readState}(), except that the result is saved to
|
|
836
|
+
* the `metaData.plcRuntimeState`.
|
|
837
|
+
*
|
|
838
|
+
* **NOTE:** This requires that the target is a PLC runtime or has equivalent ADS protocol support.
|
|
839
|
+
*
|
|
840
|
+
* @example
|
|
841
|
+
* ```js
|
|
842
|
+
* try {
|
|
843
|
+
* const plcState = await client.readPlcRuntimeState();
|
|
844
|
+
* } catch (err) {
|
|
845
|
+
* console.log("Error:", err);
|
|
846
|
+
* }
|
|
847
|
+
* ```
|
|
848
|
+
*
|
|
849
|
+
* @param targetOpts Optional target settings that override values in `settings`
|
|
850
|
+
*
|
|
851
|
+
* @throws Throws an error if sending the command fails or if the target responds with an error.
|
|
852
|
+
*/
|
|
853
|
+
readPlcRuntimeState(targetOpts?: Partial<AmsAddress>): Promise<AdsState>;
|
|
854
|
+
/**
|
|
855
|
+
* Reads target TwinCAT system state from ADS port 10000 (usually `Run` or `Config`).
|
|
856
|
+
*
|
|
857
|
+
* If `targetOpts` is not used to override target, the state is also
|
|
858
|
+
* saved to the `metaData.tcSystemState`.
|
|
859
|
+
*
|
|
860
|
+
* This is the same as {@link readState}(), except that the result is saved to
|
|
861
|
+
* the `metaData.tcSystemState`.
|
|
862
|
+
*
|
|
863
|
+
* @example
|
|
864
|
+
* ```js
|
|
865
|
+
* try {
|
|
866
|
+
* const tcSystemState = await client.readTcSystemState();
|
|
867
|
+
* } catch (err) {
|
|
868
|
+
* console.log("Error:", err);
|
|
869
|
+
* }
|
|
870
|
+
* ```
|
|
871
|
+
*
|
|
872
|
+
* @param targetOpts Optional target settings that override values in `settings`
|
|
873
|
+
*
|
|
874
|
+
* @throws Throws an error if sending the command fails or if the target responds with an error.
|
|
875
|
+
*/
|
|
876
|
+
readTcSystemState(targetOpts?: Partial<AmsAddress>): Promise<AdsState>;
|
|
877
|
+
/**
|
|
878
|
+
* Reads target PLC runtime symbol version.
|
|
879
|
+
*
|
|
880
|
+
* Symbol version usually changes when the PLC software is updated with download.
|
|
881
|
+
*
|
|
882
|
+
* **NOTE:** This requires that the target is a PLC runtime or has equivalent ADS protocol support.
|
|
883
|
+
*
|
|
884
|
+
* Note that if `settings.rawClient` is not used, the symbol version should
|
|
885
|
+
* already be up-to-date in `metaData.plcSymbolVersion`, as the client
|
|
886
|
+
* subscribes to its changes during connecting.
|
|
887
|
+
*
|
|
888
|
+
* If `targetOpts` is not used to override target, the state is also
|
|
889
|
+
* saved to the `metaData.plcSymbolVersion`.
|
|
890
|
+
*
|
|
891
|
+
* @example
|
|
892
|
+
* ```js
|
|
893
|
+
* try {
|
|
894
|
+
* const symbolVersion = await client.readPlcSymbolVersion();
|
|
895
|
+
* } catch (err) {
|
|
896
|
+
* console.log("Error:", err);
|
|
897
|
+
* }
|
|
898
|
+
* ```
|
|
899
|
+
*
|
|
900
|
+
* @param targetOpts Optional target settings that override values in `settings`
|
|
901
|
+
*
|
|
902
|
+
* @throws Throws an error if sending the command fails or if the target responds with an error.
|
|
903
|
+
*/
|
|
904
|
+
readPlcSymbolVersion(targetOpts?: Partial<AmsAddress>): Promise<number>;
|
|
905
|
+
/**
|
|
906
|
+
* Subscribes to symbol value change notifications (ADS notifications) by variable path,
|
|
907
|
+
* such as `GVL_Test.ExampleStruct`.
|
|
908
|
+
*
|
|
909
|
+
* Provided callback is called with the latest value of the symbol when the value changes or when
|
|
910
|
+
* enough time has passed (depending on settings).
|
|
911
|
+
*
|
|
912
|
+
* **NOTE**: Consider using `subscribe()` instead, this is just a wrapper for it.
|
|
913
|
+
*
|
|
914
|
+
* **NOTE:** This requires that the target is a PLC runtime or has equivalent ADS protocol support.
|
|
915
|
+
*
|
|
916
|
+
* @example
|
|
917
|
+
* ```js
|
|
918
|
+
* //Checks if value has changed every 100ms
|
|
919
|
+
* //Callback is called only when the value has changed
|
|
920
|
+
* await client.subscribeSymbol(
|
|
921
|
+
* 'GVL_Test.ExampleStruct.',
|
|
922
|
+
* (data, subscription) => {
|
|
923
|
+
* console.log(`Value of ${subscription.symbol.name} has changed: ${data.value}`);
|
|
924
|
+
* },
|
|
925
|
+
* 100
|
|
926
|
+
* );
|
|
927
|
+
* ```
|
|
928
|
+
*
|
|
929
|
+
* @param path Variable path in the PLC (such as `GVL_Test.ExampleStruct`)
|
|
930
|
+
* @param callback Callback function to call when a new value is received (`(data, subscription) => {}`)
|
|
931
|
+
* @param cycleTime Cycle time for subscription (default: `200 ms`)
|
|
932
|
+
*
|
|
933
|
+
* - If `sendOnChange` is `true` (default), PLC checks if value has changed with `cycleTime` interval.
|
|
934
|
+
* If the value has changed, the PLC sends the value and the callback is called.
|
|
935
|
+
* - If `sendOnChange` is `false`, PLC constantly sends the value with `cycleTime` interval
|
|
936
|
+
* and the callback is called.
|
|
937
|
+
*
|
|
938
|
+
* @param sendOnChange Send a new value only when the value has changed (default: `true`)
|
|
939
|
+
*
|
|
940
|
+
* - If `true` (default), the PLC checks the value for changes every `cycleTime` milliseconds. If the value has changed, PLC sends the new value and the callback is called.
|
|
941
|
+
* - If `false`, the PLC sends the value cyclically every `cycleTime` milliseconds (and the callback is called)
|
|
942
|
+
*
|
|
943
|
+
* NOTE: When subscribing, the value is always sent once.
|
|
944
|
+
*
|
|
945
|
+
* @param maxDelay How long the PLC waits before sending the value at maximum? (default: `0` ms --> maximum delay is off)
|
|
946
|
+
*
|
|
947
|
+
* If the value is not changing, the first notification with the active value after subscribing is sent after `maxDelay`.
|
|
948
|
+
*
|
|
949
|
+
* If the value is changing, the PLC sends one or more notifications every `maxDelay`.
|
|
950
|
+
*
|
|
951
|
+
* So if `cycleTime` is 100 ms, `maxDelay` is 1000 ms and value changes every 100 ms, the PLC sends 10 notifications every 1000 ms.
|
|
952
|
+
* This can be useful for throttling.
|
|
953
|
+
*
|
|
954
|
+
* @param targetOpts Optional target settings that override values in `settings`. If used, caching
|
|
955
|
+
* is disabled -> possible performance impact.
|
|
956
|
+
*
|
|
957
|
+
* @throws Throws an error if sending the command fails or if the target responds with an error.
|
|
958
|
+
*
|
|
959
|
+
* @template T In Typescript, the data type of the value, for example `subscribeSymbol<number>(...)` or `subscribeSymbol<ST_TypedStruct>(...)`. (default: `any`)
|
|
960
|
+
*
|
|
961
|
+
*/
|
|
962
|
+
subscribeSymbol<T = any>(path: string, callback: SubscriptionCallback<T>, cycleTime?: number, sendOnChange?: boolean, maxDelay?: number, targetOpts?: Partial<AmsAddress>): Promise<ActiveSubscription<T>>;
|
|
963
|
+
/**
|
|
964
|
+
* Subscribes to raw value change notifications (ADS notifications) by raw ADS address (index group, index offset and data length).
|
|
965
|
+
*
|
|
966
|
+
* Provided callback is called with the latest value when the value changes or when
|
|
967
|
+
* enough time has passed (depending on settings).
|
|
968
|
+
*
|
|
969
|
+
* **NOTE**: Consider using `subscribe()` instead, this is just a wrapper for it.
|
|
970
|
+
*
|
|
971
|
+
* **NOTE:** This requires that the target is a PLC runtime or has equivalent ADS protocol support.
|
|
972
|
+
*
|
|
973
|
+
* @example
|
|
974
|
+
* ```js
|
|
975
|
+
* //Checks if value has changed every 100ms
|
|
976
|
+
* //Callback is called only when the value has changed
|
|
977
|
+
* await client.subscribeRaw(16448, 414816, 2, (data, subscription) => {
|
|
978
|
+
* console.log(`Value has changed: ${data.value.toString('hex')}`);
|
|
979
|
+
* }, 100);
|
|
980
|
+
* ```
|
|
981
|
+
*
|
|
982
|
+
* @param indexGroup Index group (address) of the data to subscribe to
|
|
983
|
+
* @param indexOffset Index offset (address) of the data to subscribe to
|
|
984
|
+
* @param size Data length (bytes)
|
|
985
|
+
* @param callback Callback function to call when a new value is received (`(data, subscription) => {}`)
|
|
986
|
+
* @param cycleTime Cycle time for subscription (default: `200 ms`)
|
|
987
|
+
*
|
|
988
|
+
* - If `sendOnChange` is `true` (default), PLC checks if value has changed with `cycleTime` interval.
|
|
989
|
+
* If the value has changed, the PLC sends the value and the callback is called.
|
|
990
|
+
* - If `sendOnChange` is `false`, PLC constantly sends the value with `cycleTime` interval
|
|
991
|
+
* and the callback is called.
|
|
992
|
+
*
|
|
993
|
+
* @param sendOnChange Send a new value only when the value has changed (default: `true`)
|
|
994
|
+
*
|
|
995
|
+
* - If `true` (default), the PLC checks the value for changes every `cycleTime` milliseconds. If the value has changed, PLC sends the new value and the callback is called.
|
|
996
|
+
* - If `false`, the PLC sends the value cyclically every `cycleTime` milliseconds (and the callback is called)
|
|
997
|
+
*
|
|
998
|
+
* NOTE: When subscribing, the value is always sent once.
|
|
999
|
+
*
|
|
1000
|
+
* @param maxDelay How long the PLC waits before sending the value at maximum? (default: `0` ms --> maximum delay is off)
|
|
1001
|
+
*
|
|
1002
|
+
* If the value is not changing, the first notification with the active value after subscribing is sent after `maxDelay`.
|
|
1003
|
+
*
|
|
1004
|
+
* If the value is changing, the PLC sends one or more notifications every `maxDelay`.
|
|
1005
|
+
*
|
|
1006
|
+
* So if `cycleTime` is 100 ms, `maxDelay` is 1000 ms and value changes every 100 ms, the PLC sends 10 notifications every 1000 ms.
|
|
1007
|
+
* This can be useful for throttling.
|
|
1008
|
+
*
|
|
1009
|
+
* @param targetOpts Optional target settings that override values in `settings`. If used, caching
|
|
1010
|
+
* is disabled -> possible performance impact.
|
|
1011
|
+
*
|
|
1012
|
+
* @throws Throws an error if sending the command fails or if the target responds with an error.
|
|
1013
|
+
*/
|
|
1014
|
+
subscribeRaw(indexGroup: number, indexOffset: number, size: number, callback: SubscriptionCallback<Buffer>, cycleTime?: number, sendOnChange?: boolean, maxDelay?: number, targetOpts?: Partial<AmsAddress>): Promise<ActiveSubscription<Buffer>>;
|
|
1015
|
+
/**
|
|
1016
|
+
* Subscribes to value change notifications (ADS notifications) by variable path
|
|
1017
|
+
* (such as `GVL_Test.ExampleStruct`) or raw ADS address (index group, index offset and data length).
|
|
1018
|
+
*
|
|
1019
|
+
* Provided callback is called with the latest value when the value changes or when
|
|
1020
|
+
* enough time has passed (depending on settings).
|
|
1021
|
+
*
|
|
1022
|
+
* **NOTE:** This requires that the target is a PLC runtime or has equivalent ADS protocol support.
|
|
1023
|
+
*
|
|
1024
|
+
* @example
|
|
1025
|
+
* ```js
|
|
1026
|
+
* //Checks if value has changed every 100ms
|
|
1027
|
+
* //Callback is called only when the value has changed
|
|
1028
|
+
* await client.subscribe({
|
|
1029
|
+
* target: 'GVL_Test.ExampleStruct',
|
|
1030
|
+
* callback: (data, subscription) => {
|
|
1031
|
+
* console.log(`Value of ${subscription.symbol.name} has changed: ${data.value}`);
|
|
1032
|
+
* },
|
|
1033
|
+
* cycleTime: 100
|
|
1034
|
+
* });
|
|
1035
|
+
* ```
|
|
1036
|
+
*
|
|
1037
|
+
* @example
|
|
1038
|
+
* ```js
|
|
1039
|
+
* //Checks if value has changed every 100ms
|
|
1040
|
+
* //Callback is called only when the value has changed
|
|
1041
|
+
* await client.subscribe({
|
|
1042
|
+
* target: {
|
|
1043
|
+
* indexGroup: 16448,
|
|
1044
|
+
* indexOffset: 414816,
|
|
1045
|
+
* size: 2
|
|
1046
|
+
* },
|
|
1047
|
+
* callback: (data, subscription) => {
|
|
1048
|
+
* console.log(`Value has changed: ${data.value}`);
|
|
1049
|
+
* },
|
|
1050
|
+
* cycleTime: 100
|
|
1051
|
+
* });
|
|
1052
|
+
* ```
|
|
1053
|
+
*
|
|
1054
|
+
* @param options Subscription options
|
|
1055
|
+
* @param targetOpts Optional target settings that override values in `settings`. If used, caching
|
|
1056
|
+
* is disabled -> possible performance impact.
|
|
1057
|
+
*
|
|
1058
|
+
* @throws Throws an error if sending the command fails or if the target responds with an error.
|
|
1059
|
+
*
|
|
1060
|
+
* @template T In Typescript, the data type of the value, for example `subscribe<number>(...)` or `subscribe<ST_TypedStruct>(...)`. If the target is a raw address, use `subscribe<Buffer>`. (default: `any`)
|
|
1061
|
+
*/
|
|
1062
|
+
subscribe<T = any>(options: SubscriptionSettings<T>, targetOpts?: Partial<AmsAddress>): Promise<ActiveSubscription<T>>;
|
|
1063
|
+
/**
|
|
1064
|
+
* Unsubscribes the subscription (deletes ADS notification).
|
|
1065
|
+
*
|
|
1066
|
+
* PLC stops checking the value for changes (if configured so) and no longer sends new values.
|
|
1067
|
+
*
|
|
1068
|
+
* @example
|
|
1069
|
+
* ```js
|
|
1070
|
+
* const sub = await client.subscribe(...);
|
|
1071
|
+
*
|
|
1072
|
+
* //later
|
|
1073
|
+
* try {
|
|
1074
|
+
* await client.unsubscribe(sub);
|
|
1075
|
+
* } catch (err) {
|
|
1076
|
+
* console.log("Error:", err);
|
|
1077
|
+
* }
|
|
1078
|
+
* ```
|
|
1079
|
+
*
|
|
1080
|
+
* @param subscription Subscription to unsubscribe (created previously by subscribing for example using `subscribe()`)
|
|
1081
|
+
*
|
|
1082
|
+
* @throws Throws an error if sending the command fails or if the target responds with an error.
|
|
1083
|
+
*/
|
|
1084
|
+
unsubscribe(subscription: ActiveSubscription): Promise<void>;
|
|
1085
|
+
/**
|
|
1086
|
+
* Unsubscribes all active subscription (deletes all ADS notifications).
|
|
1087
|
+
*
|
|
1088
|
+
* PLC stops checking the values for changes (if configured so) and no longer sends new values.
|
|
1089
|
+
*
|
|
1090
|
+
* @example
|
|
1091
|
+
* ```js
|
|
1092
|
+
* const sub = await client.subscribe(...);
|
|
1093
|
+
* const sub2 = await client.subscribe(...);
|
|
1094
|
+
*
|
|
1095
|
+
* //later
|
|
1096
|
+
* try {
|
|
1097
|
+
* await client.unsubscribeAll();
|
|
1098
|
+
* } catch (err) {
|
|
1099
|
+
* console.log("Error:", err);
|
|
1100
|
+
* }
|
|
1101
|
+
* ```
|
|
1102
|
+
*
|
|
1103
|
+
* @throws Throws an error if sending the command fails or if the target responds with an error.
|
|
1104
|
+
*/
|
|
1105
|
+
unsubscribeAll(): Promise<void>;
|
|
1106
|
+
/**
|
|
1107
|
+
* Reads target device information.
|
|
1108
|
+
*
|
|
1109
|
+
* This is the ADS protocol `ReadDeviceInfo` command.
|
|
1110
|
+
*
|
|
1111
|
+
* If `targetOpts` is not used to override target, the state is also
|
|
1112
|
+
* saved to the `metaData.deviceInfo`.
|
|
1113
|
+
*
|
|
1114
|
+
* @example
|
|
1115
|
+
* ```js
|
|
1116
|
+
* try {
|
|
1117
|
+
* const deviceInfo = await client.readDeviceInfo();
|
|
1118
|
+
* } catch (err) {
|
|
1119
|
+
* console.log("Error:", err);
|
|
1120
|
+
* }
|
|
1121
|
+
* ```
|
|
1122
|
+
*
|
|
1123
|
+
* @param targetOpts Optional target settings that override values in `settings`
|
|
1124
|
+
*
|
|
1125
|
+
* @throws Throws an error if sending the command fails or if the target responds with an error.
|
|
1126
|
+
*/
|
|
1127
|
+
readDeviceInfo(targetOpts?: Partial<AmsAddress>): Promise<AdsDeviceInfo>;
|
|
1128
|
+
/**
|
|
1129
|
+
* Reads target PLC runtime upload information.
|
|
1130
|
+
*
|
|
1131
|
+
* Upload information includes information about target PLC runtime data types and symbols (count and total data length).
|
|
1132
|
+
*
|
|
1133
|
+
* **NOTE:** This requires that the target is a PLC runtime or has equivalent ADS protocol support.
|
|
1134
|
+
*
|
|
1135
|
+
* If `targetOpts` is not used to override target, the upload info is also
|
|
1136
|
+
* saved to the `metaData.plcUploadInfo`.
|
|
1137
|
+
*
|
|
1138
|
+
* @example
|
|
1139
|
+
* ```js
|
|
1140
|
+
* try {
|
|
1141
|
+
* const uploadInfo = await client.readPlcUploadInfo();
|
|
1142
|
+
* } catch (err) {
|
|
1143
|
+
* console.log("Error:", err);
|
|
1144
|
+
* }
|
|
1145
|
+
* ```
|
|
1146
|
+
*
|
|
1147
|
+
* @param targetOpts Optional target settings that override values in `settings`
|
|
1148
|
+
*
|
|
1149
|
+
* @throws Throws an error if sending the command fails or if the target responds with an error.
|
|
1150
|
+
*/
|
|
1151
|
+
readPlcUploadInfo(targetOpts?: Partial<AmsAddress>): Promise<AdsUploadInfo>;
|
|
1152
|
+
/**
|
|
1153
|
+
* Returns all symbols from the target PLC runtime.
|
|
1154
|
+
*
|
|
1155
|
+
* **NOTE:** This requires that the target is a PLC runtime or has equivalent ADS protocol support.
|
|
1156
|
+
*
|
|
1157
|
+
* **WARNING:** The returned object might be VERY large!
|
|
1158
|
+
*
|
|
1159
|
+
* If `targetOpts` is not used to override target, the upload info is also
|
|
1160
|
+
* saved to the `metaData.symbols`.
|
|
1161
|
+
*
|
|
1162
|
+
* @example
|
|
1163
|
+
* ```js
|
|
1164
|
+
* try {
|
|
1165
|
+
* const symbols = await client.getSymbols();
|
|
1166
|
+
* } catch (err) {
|
|
1167
|
+
* console.log("Error:", err);
|
|
1168
|
+
* }
|
|
1169
|
+
* ```
|
|
1170
|
+
*
|
|
1171
|
+
* @throws Throws an error if sending the command fails or if the target responds with an error.
|
|
1172
|
+
*
|
|
1173
|
+
* @param targetOpts Optional target settings that override values in `settings`
|
|
1174
|
+
*/
|
|
1175
|
+
getSymbols(targetOpts?: Partial<AmsAddress>): Promise<AdsSymbolContainer>;
|
|
1176
|
+
/**
|
|
1177
|
+
* Caches all symbols from the target PLC runtime.
|
|
1178
|
+
*
|
|
1179
|
+
* Can be used to pre-cache all symbols to speed up communication.
|
|
1180
|
+
* Caching is only available for the original target configured in the settings.
|
|
1181
|
+
*
|
|
1182
|
+
* If caching is disabled using `settings.disableCaching` nothing is done.
|
|
1183
|
+
*
|
|
1184
|
+
* Calling `getSymbols()` without `targetOpts` has the same effect.
|
|
1185
|
+
*
|
|
1186
|
+
* **NOTE:** This requires that the target is a PLC runtime or has equivalent ADS protocol support.
|
|
1187
|
+
*
|
|
1188
|
+
* @example
|
|
1189
|
+
* ```js
|
|
1190
|
+
* try {
|
|
1191
|
+
* await client.cacheSymbols();
|
|
1192
|
+
* //client.metaData.plcSymbols now has all PLC runtime symbols
|
|
1193
|
+
* } catch (err) {
|
|
1194
|
+
* console.log("Error:", err);
|
|
1195
|
+
* }
|
|
1196
|
+
* ```
|
|
1197
|
+
*
|
|
1198
|
+
* @throws Throws an error if sending the command fails or if the target responds with an error.
|
|
1199
|
+
*/
|
|
1200
|
+
cacheSymbols(): Promise<void>;
|
|
1201
|
+
/**
|
|
1202
|
+
* Returns all target PLC runtime data types.
|
|
1203
|
+
*
|
|
1204
|
+
* If `targetOpts` is not used to override target and `settings.disableCaching` is not set,
|
|
1205
|
+
* the results are cached.
|
|
1206
|
+
*
|
|
1207
|
+
* **WARNING: The returned object might be VERY large!**
|
|
1208
|
+
*
|
|
1209
|
+
* As default, the results do not have subitems constructred, unlike when calling `getDataType()`.
|
|
1210
|
+
* To get all data types with full constructions (children and their children and so on), set parameter
|
|
1211
|
+
* `fullTypes` to `true`. **WARNING: This heavily increases the result size and CPU usage.**
|
|
1212
|
+
*
|
|
1213
|
+
* @example
|
|
1214
|
+
* ```js
|
|
1215
|
+
* try {
|
|
1216
|
+
* const dataTypes = await client.getDataTypes();
|
|
1217
|
+
* //with built data types
|
|
1218
|
+
* const fullDataTypes = await client.getDataTypes(true);
|
|
1219
|
+
* } catch (err) {
|
|
1220
|
+
* console.log("Error:", err);
|
|
1221
|
+
* }
|
|
1222
|
+
* ```
|
|
1223
|
+
*
|
|
1224
|
+
* @param buildFullTypes If `true`, all data types are built to include all subitems (and their subitems and so on)
|
|
1225
|
+
* @param targetOpts Optional target settings that override values in `settings`
|
|
1226
|
+
*
|
|
1227
|
+
* @throws Throws an error if sending the command fails or if the target responds with an error.
|
|
1228
|
+
*/
|
|
1229
|
+
getDataTypes(buildFullTypes?: boolean, targetOpts?: Partial<AmsAddress>): Promise<AdsDataTypeContainer>;
|
|
1230
|
+
/**
|
|
1231
|
+
* Caches all data types from the target PLC runtime.
|
|
1232
|
+
*
|
|
1233
|
+
* Can be used to pre-cache all data types to speed up communication.
|
|
1234
|
+
* Caching is only available for the original target configured in the settings.
|
|
1235
|
+
*
|
|
1236
|
+
* If caching is disabled using `settings.disableCaching` nothing is done.
|
|
1237
|
+
*
|
|
1238
|
+
* Calling `getDataTypes()` without `targetOpts` has the same effect.
|
|
1239
|
+
*
|
|
1240
|
+
* **NOTE:** This requires that the target is a PLC runtime or has equivalent ADS protocol support.
|
|
1241
|
+
*
|
|
1242
|
+
* @example
|
|
1243
|
+
* ```js
|
|
1244
|
+
* try {
|
|
1245
|
+
* await client.cacheDataTypes();
|
|
1246
|
+
* //client.metaData.plcDataTypes now has all PLC runtime data types
|
|
1247
|
+
* } catch (err) {
|
|
1248
|
+
* console.log("Error:", err);
|
|
1249
|
+
* }
|
|
1250
|
+
* ```
|
|
1251
|
+
*
|
|
1252
|
+
* @throws Throws an error if sending the command fails or if the target responds with an error.
|
|
1253
|
+
*/
|
|
1254
|
+
cacheDataTypes(): Promise<void>;
|
|
1255
|
+
/**
|
|
1256
|
+
* **TODO - DOCUMENTATION ONGOING**
|
|
1257
|
+
*
|
|
1258
|
+
* Reads raw byte data from the target system by provided index group, index offset and data length (bytes)
|
|
1259
|
+
*
|
|
1260
|
+
* This is the `ADS read` command in ADS protocol.
|
|
1261
|
+
*
|
|
1262
|
+
* @param indexGroup Index group (address) of the data to read
|
|
1263
|
+
* @param indexOffset Index offset (address) of the data to read
|
|
1264
|
+
* @param size Data length to read (bytes)
|
|
1265
|
+
* @param targetOpts Optional target settings that override values in `settings`
|
|
1266
|
+
*/
|
|
1267
|
+
readRaw(indexGroup: number, indexOffset: number, size: number, targetOpts?: Partial<AmsAddress>): Promise<Buffer>;
|
|
1268
|
+
/**
|
|
1269
|
+
* **TODO - DOCUMENTATION ONGOING**
|
|
1270
|
+
*
|
|
1271
|
+
* Writes raw byte data to the target system by provided index group and index offset.
|
|
1272
|
+
*
|
|
1273
|
+
* This is the `ADS write` command in ADS protocol.
|
|
1274
|
+
*
|
|
1275
|
+
* @param indexGroup Index group (address) of the data to write to
|
|
1276
|
+
* @param indexOffset Index offset (address) of the data to write to
|
|
1277
|
+
* @param value Data to write
|
|
1278
|
+
* @param targetOpts Optional target settings that override values in `settings`
|
|
1279
|
+
*/
|
|
1280
|
+
writeRaw(indexGroup: number, indexOffset: number, value: Buffer, targetOpts?: Partial<AmsAddress>): Promise<void>;
|
|
1281
|
+
/**
|
|
1282
|
+
* **TODO - DOCUMENTATION ONGOING**
|
|
1283
|
+
*
|
|
1284
|
+
* Sends multiple readRaw() commands in one ADS packet
|
|
1285
|
+
*
|
|
1286
|
+
* Reads raw byte data from the target system by provided index group, index offset and data length (bytes)
|
|
1287
|
+
*
|
|
1288
|
+
* Uses ADS sum command under the hood (better performance)
|
|
1289
|
+
*
|
|
1290
|
+
* @param commands Array of read commands
|
|
1291
|
+
* @param targetOpts Optional target settings that override values in `settings`
|
|
1292
|
+
*/
|
|
1293
|
+
readRawMulti(commands: ReadRawMultiCommand[], targetOpts?: Partial<AmsAddress>): Promise<ReadRawMultiResult[]>;
|
|
1294
|
+
/**
|
|
1295
|
+
* **TODO - DOCUMENTATION ONGOING**
|
|
1296
|
+
*
|
|
1297
|
+
* Sends multiple writeRaw() commands in one ADS packet
|
|
1298
|
+
*
|
|
1299
|
+
* Writes raw byte data to the target system by provided index group and index offset.
|
|
1300
|
+
*
|
|
1301
|
+
* Uses ADS sum command under the hood (better performance)
|
|
1302
|
+
*
|
|
1303
|
+
* @param commands Array of write commands
|
|
1304
|
+
* @param targetOpts Optional target settings that override values in `settings`
|
|
1305
|
+
*/
|
|
1306
|
+
writeRawMulti(commands: WriteRawMultiCommand[], targetOpts?: Partial<AmsAddress>): Promise<WriteRawMultiResult[]>;
|
|
1307
|
+
/**
|
|
1308
|
+
* **TODO - DOCUMENTATION ONGOING**
|
|
1309
|
+
*
|
|
1310
|
+
* Reads raw byte data from the target system by symbol path.
|
|
1311
|
+
*
|
|
1312
|
+
* Supports also reading POINTER and REFERENCE values by using deference operator in path (`^`)
|
|
1313
|
+
*
|
|
1314
|
+
* This uses the ADS command `READ_SYMVAL_BYNAME` under the hood
|
|
1315
|
+
*
|
|
1316
|
+
* @param path Variable path in the PLC to read (such as `GVL_Test.ExampleStruct`)
|
|
1317
|
+
* @param targetOpts Optional target settings that override values in `settings`
|
|
1318
|
+
*/
|
|
1319
|
+
readRawByPath(path: string, targetOpts?: Partial<AmsAddress>): Promise<Buffer>;
|
|
1320
|
+
/**
|
|
1321
|
+
* **TODO - DOCUMENTATION ONGOING**
|
|
1322
|
+
*
|
|
1323
|
+
* Writes raw byte data to the target system by symbol path.
|
|
1324
|
+
*
|
|
1325
|
+
* Supports also reading POINTER and REFERENCE values by using deference operator in path (`^`)
|
|
1326
|
+
*
|
|
1327
|
+
* Unlike `readRawByPath()`, this uses variable handles under the hood, the as there is no direct ADS command available for this.
|
|
1328
|
+
*
|
|
1329
|
+
* @param path Variable path in the PLC to read (such as `GVL_Test.ExampleStruct`)
|
|
1330
|
+
* @param value Data to write
|
|
1331
|
+
* @param targetOpts Optional target settings that override values in `settings`
|
|
1332
|
+
*/
|
|
1333
|
+
writeRawByPath(path: string, value: Buffer, targetOpts?: Partial<AmsAddress>): Promise<void>;
|
|
1334
|
+
/**
|
|
1335
|
+
* **TODO - DOCUMENTATION ONGOING**
|
|
1336
|
+
*
|
|
1337
|
+
* Writes raw data to the target and reads the result as raw data
|
|
1338
|
+
*
|
|
1339
|
+
* Uses `ADS ReadWrite` command
|
|
1340
|
+
*
|
|
1341
|
+
* @param indexGroup Address index group
|
|
1342
|
+
* @param indexOffset Address index offset
|
|
1343
|
+
* @param size How many bytes to read
|
|
1344
|
+
* @param writeData Data to write
|
|
1345
|
+
* @param targetOpts Optional target settings that override values in `settings`
|
|
1346
|
+
*/
|
|
1347
|
+
readWriteRaw(indexGroup: number, indexOffset: number, size: number, writeData: Buffer, targetOpts?: Partial<AmsAddress>): Promise<Buffer>;
|
|
1348
|
+
/**
|
|
1349
|
+
* **TODO - DOCUMENTATION ONGOING**
|
|
1350
|
+
*
|
|
1351
|
+
* Sends multiple readWriteRaw() commands in one ADS packet
|
|
1352
|
+
*
|
|
1353
|
+
* Uses ADS sum command under the hood (better performance)
|
|
1354
|
+
*
|
|
1355
|
+
* @param commands Array of read write commands
|
|
1356
|
+
* @param targetOpts Optional target settings that override values in `settings`
|
|
1357
|
+
*/
|
|
1358
|
+
readWriteRawMulti(commands: ReadWriteRawMultiCommand[], targetOpts?: Partial<AmsAddress>): Promise<ReadWriteRawMultiResult[]>;
|
|
1359
|
+
/**
|
|
1360
|
+
* **TODO - DOCUMENTATION ONGOING**
|
|
1361
|
+
*
|
|
1362
|
+
* Reads a value by a variable path (such as `GVL_Test.ExampleStruct`) and converts the value to a Javascript object.
|
|
1363
|
+
*
|
|
1364
|
+
* Returns the converted value, the raw value, the data type and the symbol.
|
|
1365
|
+
*
|
|
1366
|
+
* @param path Variable path in the PLC to read (such as `GVL_Test.ExampleStruct`)
|
|
1367
|
+
* @param targetOpts Optional target settings that override values in `settings`
|
|
1368
|
+
*
|
|
1369
|
+
* @template T In Typescript, the data type of the value, for example `readValue<number>(...)` or `readValue<ST_TypedStruct>(...)` (default: `any`)
|
|
1370
|
+
*/
|
|
1371
|
+
readValue<T = any>(path: string, targetOpts?: Partial<AmsAddress>): Promise<ReadValueResult<T>>;
|
|
1372
|
+
/**
|
|
1373
|
+
* **TODO - DOCUMENTATION ONGOING**
|
|
1374
|
+
*
|
|
1375
|
+
* Reads a value by a symbol and converts the value to a Javascript object.
|
|
1376
|
+
*
|
|
1377
|
+
* Returns the converted value, the raw value, the data type and the symbol.
|
|
1378
|
+
*
|
|
1379
|
+
* @param symbol Symbol (acquired using `getSymbol()`)
|
|
1380
|
+
* @param targetOpts Optional target settings that override values in `settings`
|
|
1381
|
+
*
|
|
1382
|
+
* @template T In Typescript, the data type of the value, for example `readValueBySymbol<number>(...)` or `readValueBySymbol<ST_TypedStruct>(...)` (default: `any`)
|
|
1383
|
+
*/
|
|
1384
|
+
readValueBySymbol<T = any>(symbol: AdsSymbol, targetOpts?: Partial<AmsAddress>): Promise<ReadValueResult<T>>;
|
|
1385
|
+
/**
|
|
1386
|
+
* **TODO - DOCUMENTATION ONGOING**
|
|
1387
|
+
*
|
|
1388
|
+
* Writes a value by a variable path (such as `GVL_Test.ExampleStruct`). Converts the value from a Javascript object to a raw value.
|
|
1389
|
+
*
|
|
1390
|
+
* Returns the converted value, the raw value, the data type and the symbol.
|
|
1391
|
+
*
|
|
1392
|
+
* **NOTE:** Do not use `autoFill` for `UNION` types, it works without errors but the result isn't probably the desired one
|
|
1393
|
+
*
|
|
1394
|
+
* @param path Variable path in the PLC to read (such as `GVL_Test.ExampleStruct`)
|
|
1395
|
+
* @param value Value to write
|
|
1396
|
+
* @param targetOpts Optional target settings that override values in `settings`
|
|
1397
|
+
* @param autoFill If true and data type is a container (`STRUCT`, `FUNCTION_BLOCK` etc.), missing properties are automatically **set to default values** (usually `0` or `''`)
|
|
1398
|
+
*
|
|
1399
|
+
* @template T In Typescript, the data type of the value, for example `writeValue<number>(...)` or `writeValue<ST_TypedStruct>(...)`
|
|
1400
|
+
*/
|
|
1401
|
+
writeValue<T = any>(path: string, value: T, autoFill?: boolean, targetOpts?: Partial<AmsAddress>): Promise<WriteValueResult<T>>;
|
|
1402
|
+
/**
|
|
1403
|
+
* **TODO - DOCUMENTATION ONGOING**
|
|
1404
|
+
*
|
|
1405
|
+
* Writes a value by symbol. Converts the value from a Javascript object to a raw value.
|
|
1406
|
+
*
|
|
1407
|
+
* Returns the converted value, the raw value, the data type and the symbol.
|
|
1408
|
+
*
|
|
1409
|
+
* **NOTE:** Do not use `autoFill` for `UNION` types, it works without errors but the result isn't probably the desired one
|
|
1410
|
+
*
|
|
1411
|
+
* @param symbol Symbol (acquired using `getSymbol()`)
|
|
1412
|
+
* @param value Value to write
|
|
1413
|
+
* @param targetOpts Optional target settings that override values in `settings`
|
|
1414
|
+
* @param autoFill If true and data type is a container (`STRUCT`, `FUNCTION_BLOCK` etc.), missing properties are automatically **set to default values** (usually `0` or `''`)
|
|
1415
|
+
*
|
|
1416
|
+
* @template T In Typescript, the data type of the value, for example `writeValue<number>(...)` or `writeValue<ST_TypedStruct>(...)`
|
|
1417
|
+
*/
|
|
1418
|
+
writeValueBySymbol<T = any>(symbol: AdsSymbol, value: T, autoFill?: boolean, targetOpts?: Partial<AmsAddress>): Promise<WriteValueResult<T>>;
|
|
1419
|
+
/**
|
|
1420
|
+
* **TODO - DOCUMENTATION ONGOING**
|
|
1421
|
+
*
|
|
1422
|
+
* Returns a default (empty) Javascript object representing provided PLC data type.
|
|
1423
|
+
*
|
|
1424
|
+
* @param dataType Data type name in the PLC as string (such as `ST_Struct`) or `AdsDataType` object
|
|
1425
|
+
* @param targetOpts Optional target settings that override values in `settings`
|
|
1426
|
+
*
|
|
1427
|
+
* @template T Typescript data type of the PLC data, for example `readValue<number>(...)` or `readValue<ST_TypedStruct>(...)`
|
|
1428
|
+
*/
|
|
1429
|
+
getDefaultPlcObject<T = any>(dataType: string | AdsDataType, targetOpts?: Partial<AmsAddress>): Promise<T>;
|
|
1430
|
+
/**
|
|
1431
|
+
* **TODO - DOCUMENTATION ONGOING**
|
|
1432
|
+
*
|
|
1433
|
+
* Converts a raw byte value to a Javascript object.
|
|
1434
|
+
*
|
|
1435
|
+
* @param data Raw PLC data as Buffer (read for example with `readRaw()`)
|
|
1436
|
+
* @param dataType Data type name in the PLC as string (such as `ST_Struct`) or `AdsDataType` object
|
|
1437
|
+
* @param targetOpts Optional target settings that override values in `settings`
|
|
1438
|
+
*
|
|
1439
|
+
* @template T Typescript data type of the PLC data, for example `convertFromRaw<number>(...)` or `convertFromRaw<ST_TypedStruct>(...)`
|
|
1440
|
+
*/
|
|
1441
|
+
convertFromRaw<T = any>(data: Buffer, dataType: string | AdsDataType, targetOpts?: Partial<AmsAddress>): Promise<T>;
|
|
1442
|
+
/**
|
|
1443
|
+
* **TODO - DOCUMENTATION ONGOING**
|
|
1444
|
+
*
|
|
1445
|
+
* Converts a Javascript object to raw byte data.
|
|
1446
|
+
*
|
|
1447
|
+
* **NOTE:** Do not use `autoFill` for `UNION` types, it works without errors but the result isn't probably the desired one
|
|
1448
|
+
*
|
|
1449
|
+
* @param value Javascript object that represents the `dataType` in target system
|
|
1450
|
+
* @param dataType Data type name in the PLC as string (such as `ST_Struct`) or `AdsDataType` object
|
|
1451
|
+
* @param autoFill If true and data type is a container (`STRUCT`, `FUNCTION_BLOCK` etc.), missing properties are automatically **set to default values** (usually `0` or `''`)
|
|
1452
|
+
* @param targetOpts Optional target settings that override values in `settings`
|
|
1453
|
+
*
|
|
1454
|
+
* @template T Typescript data type of the PLC data, for example `convertFromRaw<number>(...)` or `convertFromRaw<ST_TypedStruct>(...)`
|
|
1455
|
+
*/
|
|
1456
|
+
convertToRaw(value: any, dataType: string | AdsDataType, autoFill?: boolean, targetOpts?: Partial<AmsAddress>): Promise<Buffer>;
|
|
1457
|
+
/**
|
|
1458
|
+
* **TODO - DOCUMENTATION ONGOING**
|
|
1459
|
+
*
|
|
1460
|
+
* Creates a variable handle for a PLC symbol by given variable path
|
|
1461
|
+
*
|
|
1462
|
+
* Variable value can be accessed by using the handle with `readRawByHandle()` and `writeRawByHandle()`
|
|
1463
|
+
*
|
|
1464
|
+
* @param path Full variable path in the PLC (such as `GVL_Test.ExampleStruct`)
|
|
1465
|
+
* @param targetOpts Optional target settings that override values in `settings` (**NOTE:** If used, no caching is available -> possible performance impact)
|
|
1466
|
+
*/
|
|
1467
|
+
createVariableHandle(path: string, targetOpts?: Partial<AmsAddress>): Promise<VariableHandle>;
|
|
1468
|
+
/**
|
|
1469
|
+
* **TODO - DOCUMENTATION ONGOING**
|
|
1470
|
+
*
|
|
1471
|
+
* Sends multiple createVariableHandle() commands in one ADS packet
|
|
1472
|
+
*
|
|
1473
|
+
* Creates a variable handle for a PLC symbol by given variable path
|
|
1474
|
+
*
|
|
1475
|
+
* Variable value can be accessed by using the handle with `readRawByHandle()` and `writeRawByHandle()`
|
|
1476
|
+
*
|
|
1477
|
+
* Uses ADS sum command under the hood (better perfomance)
|
|
1478
|
+
*
|
|
1479
|
+
* @param paths Array of full variable paths in the PLC (such as `GVL_Test.ExampleStruct`)
|
|
1480
|
+
* @param targetOpts Optional target settings that override values in `settings`
|
|
1481
|
+
*/
|
|
1482
|
+
createVariableHandleMulti(paths: string[], targetOpts?: Partial<AmsAddress>): Promise<CreateVariableHandleMultiResult[]>;
|
|
1483
|
+
/**
|
|
1484
|
+
* **TODO - DOCUMENTATION ONGOING**
|
|
1485
|
+
*
|
|
1486
|
+
* Deletes a variable handle that was previously created using `createVariableHandle()`
|
|
1487
|
+
*
|
|
1488
|
+
* @param handle Variable handle to delete
|
|
1489
|
+
* @param targetOpts Optional target settings that override values in `settings` (**NOTE:** If used, no caching is available -> possible performance impact)
|
|
1490
|
+
*/
|
|
1491
|
+
deleteVariableHandle(handle: VariableHandle | number, targetOpts?: Partial<AmsAddress>): Promise<void>;
|
|
1492
|
+
/**
|
|
1493
|
+
* **TODO - DOCUMENTATION ONGOING**
|
|
1494
|
+
*
|
|
1495
|
+
* Sends multiple deleteVariableHandle() commands in one ADS packet
|
|
1496
|
+
*
|
|
1497
|
+
* Deletes a variable handle that was previously created using `createVariableHandle()`
|
|
1498
|
+
*
|
|
1499
|
+
* Uses ADS sum command under the hood (better performance)
|
|
1500
|
+
*
|
|
1501
|
+
* @param handles Array of variable handles to delete
|
|
1502
|
+
* @param targetOpts Optional target settings that override values in `settings`
|
|
1503
|
+
*/
|
|
1504
|
+
deleteVariableHandleMulti(handles: (VariableHandle | number)[], targetOpts?: Partial<AmsAddress>): Promise<DeleteVariableHandleMultiResult[]>;
|
|
1505
|
+
/**
|
|
1506
|
+
* **TODO - DOCUMENTATION ONGOING**
|
|
1507
|
+
*
|
|
1508
|
+
* Reads raw byte data from the target system by previously created variable handle
|
|
1509
|
+
*
|
|
1510
|
+
* @param handle Variable handle
|
|
1511
|
+
* @param size Optional data length to read (bytes) - as default, size in handle is used if available. Uses 0xFFFFFFFF as fallback.
|
|
1512
|
+
* @param targetOpts Optional target settings that override values in `settings` (**NOTE:** If used, no caching is available -> possible performance impact)
|
|
1513
|
+
*/
|
|
1514
|
+
readRawByHandle(handle: VariableHandle | number, size?: number, targetOpts?: Partial<AmsAddress>): Promise<Buffer>;
|
|
1515
|
+
/**
|
|
1516
|
+
* **TODO - DOCUMENTATION ONGOING**
|
|
1517
|
+
*
|
|
1518
|
+
* Writes raw byte data to the target system by previously created variable handle
|
|
1519
|
+
*
|
|
1520
|
+
* @param handle Variable handle
|
|
1521
|
+
* @param value Data to write
|
|
1522
|
+
* @param targetOpts Optional target settings that override values in `settings` (**NOTE:** If used, no caching is available -> possible performance impact)
|
|
1523
|
+
*/
|
|
1524
|
+
writeRawByHandle(handle: VariableHandle | number, value: Buffer, targetOpts?: Partial<AmsAddress>): Promise<void>;
|
|
1525
|
+
/**
|
|
1526
|
+
* **TODO - DOCUMENTATION ONGOING**
|
|
1527
|
+
*
|
|
1528
|
+
* Reads raw data by symbol
|
|
1529
|
+
*
|
|
1530
|
+
* @param symbol Symbol (acquired using `getSymbol()`)
|
|
1531
|
+
* @param targetOpts Optional target settings that override values in `settings` (**NOTE:** If used, no caching is available -> possible performance impact)
|
|
1532
|
+
*/
|
|
1533
|
+
readRawBySymbol(symbol: AdsSymbol, targetOpts?: Partial<AmsAddress>): Promise<Buffer>;
|
|
1534
|
+
/**
|
|
1535
|
+
* **TODO - DOCUMENTATION ONGOING**
|
|
1536
|
+
*
|
|
1537
|
+
* Writes raw data by symbol
|
|
1538
|
+
*
|
|
1539
|
+
* @param symbol Symbol (acquired using `getSymbol()`)
|
|
1540
|
+
* @param value Data to write
|
|
1541
|
+
* @param targetOpts Optional target settings that override values in `settings`
|
|
1542
|
+
*/
|
|
1543
|
+
writeRawBySymbol(symbol: AdsSymbol, value: Buffer, targetOpts?: Partial<AmsAddress>): Promise<void>;
|
|
1544
|
+
/**
|
|
1545
|
+
* **TODO - DOCUMENTATION ONGOING**
|
|
1546
|
+
*
|
|
1547
|
+
* Invokes/calls a function block RPC method from PLC
|
|
1548
|
+
*
|
|
1549
|
+
* Returns method return value and/or outputs (if any)
|
|
1550
|
+
*
|
|
1551
|
+
* For RPC support, the method needs to have `{attribute 'TcRpcEnable'}` attribute above the `METHOD` definition
|
|
1552
|
+
*
|
|
1553
|
+
* @param path Full function block instance path in the PLC (such as `GVL_Test.ExampleBlock`)
|
|
1554
|
+
* @param method Function block method name to call
|
|
1555
|
+
* @param parameters Function block method parameters (inputs) (if any)
|
|
1556
|
+
* @param targetOpts Optional target settings that override values in `settings`
|
|
1557
|
+
*
|
|
1558
|
+
* @template T Typescript data type of the method return value, for example `invokeRpcMethod<number>(...)` or `invokeRpcMethod<ST_TypedStruct>(...)`
|
|
1559
|
+
* @template U Typescript data type of the method outputs object, for example `invokeRpcMethod<number, ST_TypedStruct>(...)`
|
|
1560
|
+
*/
|
|
1561
|
+
invokeRpcMethod<T = any, U = Record<string, any>>(path: string, method: string, parameters?: Record<string, any>, targetOpts?: Partial<AmsAddress>): Promise<RpcMethodCallResult<T, U>>;
|
|
1562
|
+
}
|