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

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,7 +1,7 @@
1
1
  import EventEmitter from "events";
2
2
  import * as ADS from './ads-commons';
3
- import type { ActiveSubscription, AdsClientConnection, AdsClientSettings, AdsCommandToSend, AdsDataTypeContainer, AdsSymbolContainer, AdsUploadInfo, ConnectionMetaData, SubscriptionSettings, ReadValueResult, WriteValueResult, VariableHandle, RpcMethodCallResult, CreateVariableHandleMultiResult, ReadRawMultiResult, ReadRawMultiCommand, WriteRawMultiResult, DeleteVariableHandleMultiResult, ReadWriteRawMultiResult, ReadWriteRawMultiCommand, WriteRawMultiCommand, SubscriptionCallback, DebugLevel, AdsClientEvents } from "./types/ads-client-types";
4
- import { AdsDataType, AdsDeviceInfo, AdsResponse, AdsState, AdsSymbol, AmsAddress, AmsTcpPacket } from "./types/ads-protocol-types";
3
+ import type { ActiveSubscription, AdsClientConnection, AdsClientSettings, AdsCommandToSend, AdsDataTypeContainer, AdsSymbolContainer, ConnectionMetaData, SubscriptionSettings, ReadValueResult, WriteValueResult, VariableHandle, RpcMethodCallResult, CreateVariableHandleMultiResult, ReadRawMultiResult, ReadRawMultiCommand, WriteRawMultiResult, DeleteVariableHandleMultiResult, ReadWriteRawMultiResult, ReadWriteRawMultiCommand, WriteRawMultiCommand, SubscriptionCallback, DebugLevel, AdsClientEvents, SendAdsCommandWithFallbackResult } from "./types/ads-client-types";
4
+ import { AdsDataType, AdsDeviceInfo, AdsResponse, AdsState, AdsSymbol, AmsAddress, AmsTcpPacket, AdsUploadInfo } from "./types/ads-protocol-types";
5
5
  export type * from "./types/ads-client-types";
6
6
  export type * from './types/ads-protocol-types';
7
7
  export type * from './client-error';
@@ -271,6 +271,14 @@ export declare class Client extends EventEmitter<AdsClientEvents> {
271
271
  * @param subscription The subscription object (unused here)
272
272
  */
273
273
  private onPlcRuntimeStateChanged;
274
+ /**
275
+ * Checks if PLC runtime state has changed, and if so, emits an event.
276
+ *
277
+ * Call from `onPlcRuntimeStateChanged()` and `readPlcRuntimeState()`.
278
+ *
279
+ * @param state Active PLC runtime state
280
+ */
281
+ private handlePlcRuntimeStateChange;
274
282
  /**
275
283
  * A subscription callback that is called when the target PLC runtime symbol version has changed.
276
284
  *
@@ -623,12 +631,69 @@ export declare class Client extends EventEmitter<AdsClientEvents> {
623
631
  * }
624
632
  * ```
625
633
  *
634
+ * @param command The ADS command to send
635
+ *
626
636
  * @template T In Typescript, the type of the ADS response. If omitted, generic {@link AdsResponse} type is used.
627
637
  *
628
638
  * @throws Throws an error if sending the command fails or if target responds with an error
629
639
  *
630
640
  */
631
641
  sendAdsCommand<T = AdsResponse>(command: AdsCommandToSend): Promise<AmsTcpPacket<T>>;
642
+ /**
643
+ * Sends a raw ADS command to the target with fallback. A wrapper for {@link Client.sendAdsCommand}().
644
+ *
645
+ * Calls `sendAdsCommand(command)` and if it fails with
646
+ * ADS error 1793 or 1808 then calls the `sendAdsCommand(fallback)`.
647
+ *
648
+ * See {@link Client.readPlcUploadInfo}() for use case.
649
+ *
650
+ * The ideas is copied from TwinCAT.Ads.dll (`TwinCAT.Ads.AdsClientExtensions.ReadWithFallbackAsync()`).
651
+ *
652
+ * @example
653
+ * ```js
654
+ * try {
655
+ * const data = Buffer.alloc(12);
656
+ * //...code omitted...
657
+ *
658
+ * const command = {
659
+ * adsCommand: ADS.ADS_COMMAND.Read,
660
+ * targetAmsNetId: targetOpts.amsNetId,
661
+ * targetAdsPort: targetOpts.adsPort,
662
+ * payload: data
663
+ * };
664
+ *
665
+ * const fbData = Buffer.alloc(12);
666
+ * //...code omitted...
667
+ *
668
+ * const fallback = {
669
+ * adsCommand: ADS.ADS_COMMAND.Read,
670
+ * targetAmsNetId: targetOpts.amsNetId,
671
+ * targetAdsPort: targetOpts.adsPort,
672
+ * payload: fbData
673
+ * };
674
+ *
675
+ * const { response: res, fallbackUsed } = await this.sendAdsCommandWithFallback<AdsReadResponse>(command, fallback);
676
+ *
677
+ * //If we are here, one of those commands was succcesful
678
+ * if(fallbackUsed) {
679
+ * console.log("Fallback was used. Result:", res.ads.payload);
680
+ * } else {
681
+ * console.log("Fallback was not used. Result:", res.ads.payload);
682
+ * }
683
+ *
684
+ * } catch (err) {
685
+ * console.log("Error:", err);
686
+ * }
687
+ * ```
688
+ *
689
+ * @param command The main ADS command to send
690
+ * @param fallback The fallback ADS command to send
691
+ *
692
+ * @template T In Typescript, the type of the ADS response. If omitted, generic {@link AdsResponse} type is used.
693
+ *
694
+ * @throws Throws an error if sending the command fails or if target responds with an error
695
+ */
696
+ sendAdsCommandWithFallback<T = AdsResponse>(command: AdsCommandToSend, fallback: AdsCommandToSend): Promise<SendAdsCommandWithFallbackResult<T>>;
632
697
  /**
633
698
  * Sends an ADS `WriteControl` command to the target.
634
699
  *
@@ -1501,11 +1566,11 @@ export declare class Client extends EventEmitter<AdsClientEvents> {
1501
1566
  *
1502
1567
  * //Writing a POINTER value (Note the dereference operator ^)
1503
1568
  * const ptrValue = ...
1504
- * await client.writeRawByPath('GVL_Read.ComplexTypes.POINTER_^', ptrValue);
1569
+ * await client.writeRawByPath('GVL_Write.ComplexTypes.POINTER_^', ptrValue);
1505
1570
  *
1506
1571
  * //Writing a REFERENCE value
1507
1572
  * const refValue = ...
1508
- * await client.readRawByPath('GVL_Read.ComplexTypes.REFERENCE_');
1573
+ * await client.writeRawByPath('GVL_Write.ComplexTypes.REFERENCE_');
1509
1574
  *
1510
1575
  * } catch (err) {
1511
1576
  * console.log("Error:", err);
@@ -1675,11 +1740,9 @@ export declare class Client extends EventEmitter<AdsClientEvents> {
1675
1740
  * @example
1676
1741
  * ```js
1677
1742
  * try {
1678
- * const value = {
1679
- * example: true
1680
- * };
1743
+ * const res = await client.writeValue('GVL_Write.StandardTypes.INT_', 32767);
1744
+ * console.log('Value written:', res.value);
1681
1745
  *
1682
- * const res = await client.writeValue('GVL_Read.StandardTypes.INT_', value);
1683
1746
  * } catch (err) {
1684
1747
  * console.log("Error:", err);
1685
1748
  * }