ads-client 2.0.0-beta.2 → 2.0.0-beta.3

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.
@@ -1,75 +1,182 @@
1
1
  import ClientError from "../client-error";
2
2
  import { AdsDataType, AdsDeviceInfo, AdsRawAddress, AdsResponse, AdsState, AdsSymbol, AmsAddress, AmsRouterState, AmsTcpPacket, BaseAdsResponse } from "./ads-protocol-types";
3
+ /**
4
+ * Possible debug levels
5
+ *
6
+ * @category Types
7
+ */
3
8
  export type DebugLevel = 0 | 1 | 2 | 3;
4
9
  /**
5
10
  * Events for the client, for example `client.on('connect', ...)`
11
+ *
12
+ * @category Types
6
13
  */
7
- export interface ClientEvents {
14
+ export interface AdsClientEvents {
8
15
  /**
9
- * Emitted when client has connected to the target
16
+ * Emitted when the client has connected to the target.
10
17
  *
18
+ * **Parameters:**
11
19
  * - `connection`: Active connection information
20
+ *
21
+ * @example
22
+ * ```js
23
+ * client.on('connect', (connection) => {
24
+ * console.log('Connected:', connection);
25
+ * });
26
+ * ```
12
27
  */
13
28
  'connect': [connection: AdsClientConnection];
14
29
  /**
15
- * Emitted when client has disconnected from the target
30
+ * Emitted when the client has disconnected from the target.
16
31
  *
32
+ * **Parameters:**
17
33
  * - `isReconnecting`: True if disconnect happened during reconnecting
34
+ *
35
+ * @example
36
+ * ```js
37
+ * client.on('disconnect', (isReconnecting) => {
38
+ * console.log('Disconnected - is reconnecting:', isReconnecting);
39
+ * });
40
+ * ```
18
41
  */
19
42
  'disconnect': [isReconnecting: boolean];
20
43
  /**
21
- * Emitted when client has reconnected to the target after a disconnection
44
+ * Emitted when the client has reconnected to the target after a disconnection.
22
45
  *
46
+ * **Parameters:**
23
47
  * - `allSubscriptionsRestored`: True if all subscriptions were restored successfully
24
48
  * - `unrestoredSubscriptions`: Array of subscription paths that failed to be restored
49
+ *
50
+ * @example
51
+ * ```js
52
+ * client.on('reconnect', (allSubscriptionsRestored, unrestoredSubscriptions) => {
53
+ * if(allSubscriptionsRestored) {
54
+ * console.log('Reconnected and all subscriptions restored');
55
+ * } else {
56
+ * console.log('Reconnected but following subscriptions were not restored:', unrestoredSubscriptions);
57
+ * }
58
+ * });
59
+ * ```
25
60
  */
26
61
  'reconnect': [allSubscriptionsRestored: boolean, unrestoredSubscriptions: string[]];
27
62
  /**
28
- * Emitted when client has lost the connection to the target
63
+ * Emitted when the client has lost the connection to the target.
29
64
  *
65
+ * **Parameters:**
30
66
  * - `socketFailure`: True if connection was lost due to a socket/tcp problem
67
+ *
68
+ * @example
69
+ * ```js
70
+ * client.on('connectionLost', (socketFailure) => {
71
+ * console.log('Connection to the target was lost. TCP socket failure:', socketFailure);
72
+ * });
73
+ * ```
31
74
  */
32
75
  'connectionLost': [socketFailure: boolean];
33
76
  /**
34
- * Emitted when PLC runtime symbol version has changed
77
+ * Emitted when the target PLC runtime symbol version has changed.
35
78
  *
79
+ * **Parameters:**
36
80
  * - `version`: New PLC runtime symbol version
37
81
  * - `previousVersion`: Previous PLC runtime symbol version (if known)
82
+ *
83
+ * @example
84
+ * ```js
85
+ * client.on('plcSymbolVersionChange', (version, previousVersion) => {
86
+ * console.log(`Target PLC runtime symbol version changed from ${previousVersion} to ${version}`);
87
+ * });
88
+ * ```
38
89
  */
39
90
  'plcSymbolVersionChange': [version: number, previousVersion?: number];
40
91
  /**
41
- * Emitted when PLC runtime state has changed
92
+ * Emitted when the target PLC runtime state has changed
42
93
  *
94
+ * **Parameters:**
43
95
  * - `state`: New PLC runtime state
44
96
  * - `previousState`: Previous PLC runtime state (if known)
97
+ *
98
+ * @example
99
+ * ```js
100
+ * client.on('plcRuntimeStateChange', (state, previousState) => {
101
+ * console.log(`Target PLC state has changed from ${previousState} to ${state}`);
102
+ * });
103
+ * ```
45
104
  */
46
105
  'plcRuntimeStateChange': [state: AdsState, previousState?: AdsState];
47
106
  /**
48
- * Emitted when TwinCAT system state has changed
107
+ * Emitted when the target TwinCAT system state has changed.
49
108
  *
109
+ * **Parameters:**
50
110
  * - `state`: New TwinCAT system state
51
111
  * - `previousState`: Previous TwinCAT system state (if known)
112
+ *
113
+ * @example
114
+ * ```js
115
+ * client.on('tcSystemStateChange', (state, previousState) => {
116
+ * console.log(`Target TwinCAT system state has changed from ${previousState} to ${state}`);
117
+ * });
118
+ * ```
52
119
  */
53
120
  'tcSystemStateChange': [state: AdsState, previousState?: AdsState];
54
121
  /**
55
- * Emitted when AMS router state has changed
122
+ * Emitted when the AMS router state has changed.
56
123
  *
124
+ * **Parameters:**
57
125
  * - `state`: New AMS router state
58
126
  * - `previousState`: Previous AMS router state (if known)
127
+ *
128
+ * @example
129
+ * ```js
130
+ * client.on('routerStateChange', (state, previousState) => {
131
+ * console.log(`TwinCAT AMS router state has changed from ${previousState} to ${state}`);
132
+ * });
133
+ * ```
59
134
  */
60
135
  'routerStateChange': [state: AmsRouterState, previousState?: AmsRouterState];
61
136
  /**
62
- * Emitted when the client has had an error, such as
63
- * - unknown ADS notification received
64
- * - handling ADS notification failed
65
- * - unknown ADS command received
137
+ * Emitted when the client has had an error, such as:
66
138
  *
139
+ * - handling received ADS notification failed
140
+ * - unknown ADS command received
141
+ *
142
+ * **Parameters:**
67
143
  * - `error`: Error that was thrown
144
+ *
145
+ * @example
146
+ * ```js
147
+ * client.on('client-error'', (error) => {
148
+ * console.log('Error occured:', error);
149
+ * });
150
+ * ```
68
151
  */
69
152
  'client-error': [error: ClientError];
153
+ /**
154
+ * Emitted when the client encounters a non-critical abnormal event, such as:
155
+ *
156
+ * - connected to a non-running TwinCAT system
157
+ * - re-connection attempted after connection loss
158
+ * - lost connection re-established
159
+ * - unknown ADS notification received
160
+ *
161
+ * As default, the client writes these warnings to the console unless `settings.hideConsoleWarnings` is set.
162
+ * The setting does not disable the `warning` event.
163
+ *
164
+ * **Parameters:**
165
+ * - `message`: Warning message
166
+ *
167
+ * @example
168
+ * ```js
169
+ * client.on('warning', (message) => {
170
+ * console.log('WARNING:', message);
171
+ * });
172
+ * ```
173
+ */
174
+ 'warning': [message: string];
70
175
  }
71
176
  /**
72
177
  * Client settings
178
+ *
179
+ * @category Types
73
180
  */
74
181
  export interface AdsClientSettings {
75
182
  /**
@@ -226,9 +333,15 @@ export interface AdsClientSettings {
226
333
  /**
227
334
  * **Optional**: If set, no warnings are written to console using `console.log()` (default: `false`)
228
335
  *
229
- * As default, the client writes some warnings to console, such as connection loss and reconnection information.
336
+ * As default, the client writes warnings to the console, such as
337
+ * - connected to a non-running TwinCAT system
338
+ * - re-connection attempted after connection loss
339
+ * - lost connection re-established
340
+ * - unknown ADS notification received
341
+ *
342
+ * The exact same warnings are emitted using the `warning` event. See {@link AdsClientEvents}.
230
343
  *
231
- * If set, the client **never** writes anything to console.
344
+ * If this setting is set, the client never writes anything to the console.
232
345
  */
233
346
  hideConsoleWarnings?: boolean;
234
347
  /**
@@ -275,9 +388,23 @@ export interface AdsClientSettings {
275
388
  * As default, the client caches the results after reading them from the target.
276
389
  */
277
390
  disableCaching?: boolean;
391
+ /**
392
+ * **Optional**: If set, the client automatically deletes ADS notifications for unknown subscriptions (default: `true`).
393
+ *
394
+ * Otherwise, when a notification for an unknown subscription is received, the client will emit a warning.
395
+ *
396
+ * Unknown subscriptions can occur, if a previous subscription wasn't unsubscribed (using the `unsubscribe()` method)
397
+ * and the target keeps sending notifications.
398
+ *
399
+ * As default, the client automatically deletes unknown subscriptions on the PLC to conserve resources.
400
+ * A warning will be emitted when an unknown subscription is deleted.
401
+ */
402
+ deleteUnknownSubscriptions?: boolean;
278
403
  }
279
404
  /**
280
405
  * Internal timer object to keep the timer state saved
406
+ *
407
+ * @category Types
281
408
  */
282
409
  export interface TimerObject {
283
410
  /** Timer ID */
@@ -287,6 +414,8 @@ export interface TimerObject {
287
414
  }
288
415
  /**
289
416
  * Active client connection
417
+ *
418
+ * @category Types
290
419
  */
291
420
  export interface AdsClientConnection {
292
421
  /** Connection status of the client, true if connected */
@@ -306,6 +435,8 @@ export interface AdsClientConnection {
306
435
  * Object containing all active subscriptions for each target address
307
436
  *
308
437
  * Target address (`amsNetId:port`) is used as a key
438
+ *
439
+ * @category Types
309
440
  */
310
441
  export interface ActiveSubscriptionContainer {
311
442
  [K: string]: TargetActiveSubscriptionContainer;
@@ -314,12 +445,16 @@ export interface ActiveSubscriptionContainer {
314
445
  * Object containing all active subscriptions for each notification handle (for one target)
315
446
  *
316
447
  * Notification handle is used as a key
448
+ *
449
+ * @category Types
317
450
  */
318
451
  export interface TargetActiveSubscriptionContainer {
319
452
  [K: number]: ActiveSubscription;
320
453
  }
321
454
  /**
322
455
  * Object containing information for a single active subscription
456
+ *
457
+ * @category Types
323
458
  */
324
459
  export interface ActiveSubscription<T = any> {
325
460
  /** Settings for this subscription */
@@ -343,6 +478,8 @@ export interface ActiveSubscription<T = any> {
343
478
  }
344
479
  /**
345
480
  * Subscription data (value and timestamp)
481
+ *
482
+ * @category Types
346
483
  */
347
484
  export interface SubscriptionData<T = any> {
348
485
  timestamp: Date;
@@ -352,6 +489,8 @@ export interface SubscriptionData<T = any> {
352
489
  * Object containing all active ADS requests that are waiting for responses
353
490
  *
354
491
  * Invoke ID is used as a key
492
+ *
493
+ * @category Types
355
494
  */
356
495
  export interface ActiveAdsRequestContainer {
357
496
  [K: number]: ActiveAdsRequest;
@@ -359,6 +498,8 @@ export interface ActiveAdsRequestContainer {
359
498
  /**
360
499
  * Active ADS command that is waiting for answer
361
500
  * Callback is called when response is received
501
+ *
502
+ * @category Types
362
503
  */
363
504
  export interface ActiveAdsRequest {
364
505
  timeoutTimerHandle?: NodeJS.Timeout;
@@ -366,6 +507,8 @@ export interface ActiveAdsRequest {
366
507
  }
367
508
  /**
368
509
  * Client connection metadata
510
+ *
511
+ * @category Types
369
512
  */
370
513
  export interface ConnectionMetaData {
371
514
  /** Local AMS router state (if available) */
@@ -393,6 +536,8 @@ export interface ConnectionMetaData {
393
536
  * PLC runtime upload info
394
537
  *
395
538
  * Contains information about symbols and data types
539
+ *
540
+ * @category Types
396
541
  */
397
542
  export interface AdsUploadInfo {
398
543
  /** Number of symbols in the target runtime */
@@ -410,18 +555,24 @@ export interface AdsUploadInfo {
410
555
  }
411
556
  /**
412
557
  * Object containing PLC runtime symbol information objects
558
+ *
559
+ * @category Types
413
560
  */
414
561
  export interface AdsSymbolContainer {
415
562
  [K: string]: AdsSymbol;
416
563
  }
417
564
  /**
418
565
  * Object containing PLC runtime data type objects
566
+ *
567
+ * @category Types
419
568
  */
420
569
  export interface AdsDataTypeContainer {
421
570
  [K: string]: AdsDataType;
422
571
  }
423
572
  /**
424
573
  * ADS command
574
+ *
575
+ * @category Types
425
576
  */
426
577
  export interface AdsCommandToSend {
427
578
  /** Ads command (see `ADS.ADS_COMMAND`)*/
@@ -440,10 +591,14 @@ export interface AdsCommandToSend {
440
591
  *
441
592
  * @param data - The data received
442
593
  * @param subscription - The active subscription object
594
+ *
595
+ * @category Types
443
596
  */
444
597
  export type SubscriptionCallback<T = any> = (data: SubscriptionData<T>, subscription: ActiveSubscription<T>) => void;
445
598
  /**
446
599
  * Settings for a subscription
600
+ *
601
+ * @category Types
447
602
  */
448
603
  export interface SubscriptionSettings<T = any> {
449
604
  /**
@@ -486,12 +641,16 @@ export interface SubscriptionSettings<T = any> {
486
641
  }
487
642
  /**
488
643
  * PLC primitive types (not structs, function blocks etc.)
644
+ *
645
+ * @category Types
489
646
  */
490
647
  export type PlcPrimitiveType = string | boolean | number | Buffer | Date | BigInt;
491
648
  /**
492
649
  * Return value of `readValue()` and `readValueBySymbol()`
493
650
  *
494
651
  * @template T - Type of the value
652
+ *
653
+ * @category Types
495
654
  */
496
655
  export interface ReadValueResult<T = any> {
497
656
  /** Value of the symbol as converted Javascript object */
@@ -505,6 +664,8 @@ export interface ReadValueResult<T = any> {
505
664
  }
506
665
  /**
507
666
  * Return value of `writeValue()` and `writeValueBySymbol()`
667
+ *
668
+ * @category Types
508
669
  */
509
670
  export interface WriteValueResult<T = any> {
510
671
  /** Value of the symbol as converted Javascript object */
@@ -518,6 +679,8 @@ export interface WriteValueResult<T = any> {
518
679
  }
519
680
  /**
520
681
  * Return value of `convertObjectToBuffer()`
682
+ *
683
+ * @category Types
521
684
  */
522
685
  export interface ObjectToBufferConversionResult {
523
686
  /** Converted raw value */
@@ -527,6 +690,8 @@ export interface ObjectToBufferConversionResult {
527
690
  }
528
691
  /**
529
692
  * Variable handle object created using `createVariableHandle()` or `createVariableHandleMulti()`
693
+ *
694
+ * @category Types
530
695
  */
531
696
  export interface VariableHandle {
532
697
  /** Handle number */
@@ -543,6 +708,8 @@ export interface VariableHandle {
543
708
  *
544
709
  * @template T The type of method return value
545
710
  * @template U The type of method outputs
711
+ *
712
+ * @category Types
546
713
  */
547
714
  export interface RpcMethodCallResult<T = any, U = Record<string, any>> {
548
715
  /** Method return value (if any - `undefined` if none) */
@@ -552,11 +719,15 @@ export interface RpcMethodCallResult<T = any, U = Record<string, any>> {
552
719
  }
553
720
  /**
554
721
  * Parameter containing all read commands for `readRawMulti()`
722
+ *
723
+ * @category Types
555
724
  */
556
725
  export interface ReadRawMultiCommand extends Required<AdsRawAddress> {
557
726
  }
558
727
  /**
559
728
  * Return value of `readRawMulti()`
729
+ *
730
+ * @category Types
560
731
  */
561
732
  export interface ReadRawMultiResult extends BaseAdsResponse {
562
733
  /** Command */
@@ -568,6 +739,8 @@ export interface ReadRawMultiResult extends BaseAdsResponse {
568
739
  }
569
740
  /**
570
741
  * Parameter containing all write commands for `writeRawMulti()`
742
+ *
743
+ * @category Types
571
744
  */
572
745
  export interface WriteRawMultiCommand extends AdsRawAddress {
573
746
  /** Value to write */
@@ -577,6 +750,8 @@ export interface WriteRawMultiCommand extends AdsRawAddress {
577
750
  }
578
751
  /**
579
752
  * Return value of `writeRawMulti()`
753
+ *
754
+ * @category Types
580
755
  */
581
756
  export interface WriteRawMultiResult extends BaseAdsResponse {
582
757
  /** Command */
@@ -586,6 +761,8 @@ export interface WriteRawMultiResult extends BaseAdsResponse {
586
761
  }
587
762
  /**
588
763
  * Return value of `createVariableHandleMulti()`
764
+ *
765
+ * @category Types
589
766
  */
590
767
  export interface CreateVariableHandleMultiResult extends BaseAdsResponse {
591
768
  /** Full variable path in the PLC (such as `GVL_Test.ExampleStruct`) */
@@ -597,6 +774,8 @@ export interface CreateVariableHandleMultiResult extends BaseAdsResponse {
597
774
  }
598
775
  /**
599
776
  * Return value of `deleteVariableHandleMulti()`
777
+ *
778
+ * @category Types
600
779
  */
601
780
  export interface DeleteVariableHandleMultiResult extends BaseAdsResponse {
602
781
  /** Variable handle */
@@ -606,15 +785,19 @@ export interface DeleteVariableHandleMultiResult extends BaseAdsResponse {
606
785
  }
607
786
  /**
608
787
  * Parameter containing all read/write commands for `readWriteRawMulti()`
788
+ *
789
+ * @category Types
609
790
  */
610
791
  export interface ReadWriteRawMultiCommand extends Required<AdsRawAddress> {
611
- /** Data to write */
612
- writeData: Buffer;
792
+ /** Value to write */
793
+ value: Buffer;
613
794
  /** How many bytes to read */
614
795
  size: number;
615
796
  }
616
797
  /**
617
798
  * Return value of `readWriteRawMulti()`
799
+ *
800
+ * @category Types
618
801
  */
619
802
  export interface ReadWriteRawMultiResult extends BaseAdsResponse {
620
803
  /** Command */
@@ -1 +1 @@
1
- {"version":3,"file":"ads-client-types.js","sourceRoot":"","sources":["../../src/types/ads-client-types.ts"],"names":[],"mappings":";;AAqZC,CAAC;AA0BD,CAAC"}
1
+ {"version":3,"file":"ads-client-types.js","sourceRoot":"","sources":["../../src/types/ads-client-types.ts"],"names":[],"mappings":";;AAoiBC,CAAC;AA4BD,CAAC"}