ads-client 2.0.0-beta.3 → 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.
- package/CHANGELOG.md +35 -0
- package/README.md +1536 -303
- package/dist/ads-client.d.ts +350 -76
- package/dist/ads-client.js +585 -147
- package/dist/ads-client.js.map +1 -1
- package/dist/ads-commons.d.ts +17 -2
- package/dist/ads-commons.js +46 -8
- package/dist/ads-commons.js.map +1 -1
- package/dist/types/ads-client-types.d.ts +22 -22
- package/dist/types/ads-client-types.js.map +1 -1
- package/dist/types/ads-protocol-types.d.ts +37 -0
- package/package.json +3 -4
package/dist/ads-client.d.ts
CHANGED
|
@@ -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,
|
|
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
|
*
|
|
@@ -812,7 +877,7 @@ export declare class Client extends EventEmitter<AdsClientEvents> {
|
|
|
812
877
|
* @example
|
|
813
878
|
* ```js
|
|
814
879
|
* try {
|
|
815
|
-
* const symbol = await client.getSymbol('
|
|
880
|
+
* const symbol = await client.getSymbol('GVL_Read.StandardTypes.INT_');
|
|
816
881
|
* } catch (err) {
|
|
817
882
|
* console.log("Error:", err);
|
|
818
883
|
* }
|
|
@@ -964,7 +1029,7 @@ export declare class Client extends EventEmitter<AdsClientEvents> {
|
|
|
964
1029
|
* //Checks if value has changed every 100ms
|
|
965
1030
|
* //Callback is called only when the value has changed
|
|
966
1031
|
* await client.subscribeValue(
|
|
967
|
-
* '
|
|
1032
|
+
* 'GVL_Subscription.NumericValue_10ms',
|
|
968
1033
|
* (data, subscription) => {
|
|
969
1034
|
* console.log(`Value of ${subscription.symbol.name} has changed: ${data.value}`);
|
|
970
1035
|
* },
|
|
@@ -1072,7 +1137,7 @@ export declare class Client extends EventEmitter<AdsClientEvents> {
|
|
|
1072
1137
|
* //Checks if value has changed every 100ms
|
|
1073
1138
|
* //Callback is called only when the value has changed
|
|
1074
1139
|
* await client.subscribe({
|
|
1075
|
-
* target: '
|
|
1140
|
+
* target: 'GVL_Subscription.NumericValue_10ms',
|
|
1076
1141
|
* callback: (data, subscription) => {
|
|
1077
1142
|
* console.log(`Value of ${subscription.symbol.name} has changed: ${data.value}`);
|
|
1078
1143
|
* },
|
|
@@ -1491,7 +1556,6 @@ export declare class Client extends EventEmitter<AdsClientEvents> {
|
|
|
1491
1556
|
*
|
|
1492
1557
|
* NOTE: Unlike with {@link readRawByPath}(), this command uses multiple ADS requests for the operation.
|
|
1493
1558
|
*
|
|
1494
|
-
*
|
|
1495
1559
|
* @example
|
|
1496
1560
|
* ```js
|
|
1497
1561
|
* try {
|
|
@@ -1502,11 +1566,11 @@ export declare class Client extends EventEmitter<AdsClientEvents> {
|
|
|
1502
1566
|
*
|
|
1503
1567
|
* //Writing a POINTER value (Note the dereference operator ^)
|
|
1504
1568
|
* const ptrValue = ...
|
|
1505
|
-
* await client.writeRawByPath('
|
|
1569
|
+
* await client.writeRawByPath('GVL_Write.ComplexTypes.POINTER_^', ptrValue);
|
|
1506
1570
|
*
|
|
1507
1571
|
* //Writing a REFERENCE value
|
|
1508
1572
|
* const refValue = ...
|
|
1509
|
-
* await client.
|
|
1573
|
+
* await client.writeRawByPath('GVL_Write.ComplexTypes.REFERENCE_');
|
|
1510
1574
|
*
|
|
1511
1575
|
* } catch (err) {
|
|
1512
1576
|
* console.log("Error:", err);
|
|
@@ -1614,7 +1678,7 @@ export declare class Client extends EventEmitter<AdsClientEvents> {
|
|
|
1614
1678
|
* @example
|
|
1615
1679
|
* ```js
|
|
1616
1680
|
* try {
|
|
1617
|
-
* const res = await client.readValue('
|
|
1681
|
+
* const res = await client.readValue('GVL_Read.StandardTypes.INT_');
|
|
1618
1682
|
* console.log(res.value);
|
|
1619
1683
|
* } catch (err) {
|
|
1620
1684
|
* console.log("Error:", err);
|
|
@@ -1625,10 +1689,11 @@ export declare class Client extends EventEmitter<AdsClientEvents> {
|
|
|
1625
1689
|
* @param targetOpts Optional target settings that override values in `settings`
|
|
1626
1690
|
*
|
|
1627
1691
|
* @template T In Typescript, the data type of the value, for example `readValue<number>(...)` or `readValue<ST_TypedStruct>(...)` (default: `any`)
|
|
1692
|
+
* @throws Throws an error if sending the command fails or if the target responds with an error.
|
|
1628
1693
|
*/
|
|
1629
1694
|
readValue<T = any>(path: string, targetOpts?: Partial<AmsAddress>): Promise<ReadValueResult<T>>;
|
|
1630
1695
|
/**
|
|
1631
|
-
* Reads variable's value from the target system by a symbol object
|
|
1696
|
+
* Reads variable's value from the target system by a symbol object (acquired using `getSymbol()`)
|
|
1632
1697
|
* and returns the value as a Javascript object.
|
|
1633
1698
|
*
|
|
1634
1699
|
* Returns variable's
|
|
@@ -1642,7 +1707,7 @@ export declare class Client extends EventEmitter<AdsClientEvents> {
|
|
|
1642
1707
|
* @example
|
|
1643
1708
|
* ```js
|
|
1644
1709
|
* try {
|
|
1645
|
-
* const symbol = await client.getSymbol('
|
|
1710
|
+
* const symbol = await client.getSymbol('GVL_Read.StandardTypes.INT_');
|
|
1646
1711
|
*
|
|
1647
1712
|
* const res = await client.readValueBySymbol(symbol);
|
|
1648
1713
|
* console.log(res.value);
|
|
@@ -1651,10 +1716,11 @@ export declare class Client extends EventEmitter<AdsClientEvents> {
|
|
|
1651
1716
|
* }
|
|
1652
1717
|
* ```
|
|
1653
1718
|
*
|
|
1654
|
-
* @param symbol Symbol object
|
|
1719
|
+
* @param symbol Symbol object
|
|
1655
1720
|
* @param targetOpts Optional target settings that override values in `settings`
|
|
1656
1721
|
*
|
|
1657
1722
|
* @template T In Typescript, the data type of the value, for example `readValueBySymbol<number>(...)` or `readValueBySymbol<ST_TypedStruct>(...)` (default: `any`)
|
|
1723
|
+
* @throws Throws an error if sending the command fails or if the target responds with an error.
|
|
1658
1724
|
*/
|
|
1659
1725
|
readValueBySymbol<T = any>(symbol: AdsSymbol, targetOpts?: Partial<AmsAddress>): Promise<ReadValueResult<T>>;
|
|
1660
1726
|
/**
|
|
@@ -1674,11 +1740,9 @@ export declare class Client extends EventEmitter<AdsClientEvents> {
|
|
|
1674
1740
|
* @example
|
|
1675
1741
|
* ```js
|
|
1676
1742
|
* try {
|
|
1677
|
-
* const
|
|
1678
|
-
*
|
|
1679
|
-
* };
|
|
1743
|
+
* const res = await client.writeValue('GVL_Write.StandardTypes.INT_', 32767);
|
|
1744
|
+
* console.log('Value written:', res.value);
|
|
1680
1745
|
*
|
|
1681
|
-
* const res = await client.writeValue('GVL_Test.ExampleStruct', value);
|
|
1682
1746
|
* } catch (err) {
|
|
1683
1747
|
* console.log("Error:", err);
|
|
1684
1748
|
* }
|
|
@@ -1687,169 +1751,379 @@ export declare class Client extends EventEmitter<AdsClientEvents> {
|
|
|
1687
1751
|
* @param path Variable path in the PLC (such as `GVL_Test.ExampleStruct`)
|
|
1688
1752
|
* @param value Value to write
|
|
1689
1753
|
* @param targetOpts Optional target settings that override values in `settings`
|
|
1690
|
-
* @param autoFill If set and the data type is a container (`STRUCT`, `FUNCTION_BLOCK` etc.), missing properties are automatically set to
|
|
1754
|
+
* @param autoFill If set and the data type is a container (`STRUCT`, `FUNCTION_BLOCK` etc.), missing properties are automatically set to active values read from target (kept as-is).
|
|
1691
1755
|
*
|
|
1692
1756
|
* @template T In Typescript, the data type of the value, for example `writeValue<number>(...)` or `writeValue<ST_TypedStruct>(...)`
|
|
1757
|
+
* @throws Throws an error if sending the command fails or if the target responds with an error.
|
|
1693
1758
|
*/
|
|
1694
1759
|
writeValue<T = any>(path: string, value: T, autoFill?: boolean, targetOpts?: Partial<AmsAddress>): Promise<WriteValueResult<T>>;
|
|
1695
1760
|
/**
|
|
1696
|
-
*
|
|
1761
|
+
* Writes variable's value to the target system by a symbol object (acquired using `getSymbol()`).
|
|
1762
|
+
* Converts the value from a Javascript object to a raw value.
|
|
1697
1763
|
*
|
|
1698
|
-
*
|
|
1764
|
+
* Returns variable's
|
|
1765
|
+
* - converted value
|
|
1766
|
+
* - raw value
|
|
1767
|
+
* - data type
|
|
1768
|
+
* - symbol
|
|
1699
1769
|
*
|
|
1700
|
-
*
|
|
1770
|
+
* **NOTE:** Do not use `autoFill` for `UNION` types, it doesn't work correctly.
|
|
1701
1771
|
*
|
|
1702
|
-
* **NOTE:**
|
|
1772
|
+
* **NOTE:** This requires that the target is a PLC runtime or has equivalent ADS protocol support.
|
|
1703
1773
|
*
|
|
1704
|
-
* @
|
|
1774
|
+
* @example
|
|
1775
|
+
* ```js
|
|
1776
|
+
* try {
|
|
1777
|
+
* const symbol = await client.getSymbol('GVL_Read.StandardTypes.INT_');
|
|
1778
|
+
*
|
|
1779
|
+
* const res = await client.writeValueBySymbol(symbol, 32767);
|
|
1780
|
+
* } catch (err) {
|
|
1781
|
+
* console.log("Error:", err);
|
|
1782
|
+
* }
|
|
1783
|
+
* ```
|
|
1784
|
+
*
|
|
1785
|
+
* @param symbol Symbol object
|
|
1705
1786
|
* @param value Value to write
|
|
1706
1787
|
* @param targetOpts Optional target settings that override values in `settings`
|
|
1707
|
-
* @param autoFill If
|
|
1788
|
+
* @param autoFill If set and the data type is a container (`STRUCT`, `FUNCTION_BLOCK` etc.), missing properties are automatically set to active values read from target (kept as-is).
|
|
1708
1789
|
*
|
|
1709
1790
|
* @template T In Typescript, the data type of the value, for example `writeValue<number>(...)` or `writeValue<ST_TypedStruct>(...)`
|
|
1791
|
+
* @throws Throws an error if sending the command fails or if the target responds with an error.
|
|
1710
1792
|
*/
|
|
1711
1793
|
writeValueBySymbol<T = any>(symbol: AdsSymbol, value: T, autoFill?: boolean, targetOpts?: Partial<AmsAddress>): Promise<WriteValueResult<T>>;
|
|
1712
1794
|
/**
|
|
1713
|
-
* **TODO - DOCUMENTATION ONGOING**
|
|
1714
|
-
*
|
|
1715
1795
|
* Returns a default (empty) Javascript object representing provided PLC data type.
|
|
1716
1796
|
*
|
|
1717
|
-
* @
|
|
1797
|
+
* @example
|
|
1798
|
+
* ```js
|
|
1799
|
+
* try {
|
|
1800
|
+
* const res = await client.getDefaultPlcObject('INT');
|
|
1801
|
+
* console.log(res); //0
|
|
1802
|
+
|
|
1803
|
+
* const res2 = await client.getDefaultPlcObject('Tc2_Standard.TON');
|
|
1804
|
+
* console.log(res2); //{ IN: false, PT: 0, Q: false, ET: 0, M: false, StartTime: 0 }
|
|
1805
|
+
*
|
|
1806
|
+
* } catch (err) {
|
|
1807
|
+
* console.log("Error:", err);
|
|
1808
|
+
* }
|
|
1809
|
+
* ```
|
|
1810
|
+
*
|
|
1811
|
+
* @param dataType Data type name in the PLC as string (such as `ST_Struct`) or data type object (acquired using {@link getDataType}())
|
|
1718
1812
|
* @param targetOpts Optional target settings that override values in `settings`
|
|
1719
1813
|
*
|
|
1720
|
-
* @template T Typescript data type of the PLC data, for example `
|
|
1814
|
+
* @template T Typescript data type of the PLC data, for example `getDefaultPlcObject<number>(...)` or `getDefaultPlcObject<ST_TypedStruct>(...)`
|
|
1815
|
+
* @throws Throws an error if sending the command fails or if the target responds with an error.
|
|
1721
1816
|
*/
|
|
1722
1817
|
getDefaultPlcObject<T = any>(dataType: string | AdsDataType, targetOpts?: Partial<AmsAddress>): Promise<T>;
|
|
1723
1818
|
/**
|
|
1724
|
-
*
|
|
1819
|
+
* Converts raw data to a Javascript object by using the provided data type.
|
|
1820
|
+
*
|
|
1821
|
+
* @example
|
|
1822
|
+
* ```js
|
|
1823
|
+
* try {
|
|
1824
|
+
* const data = await client.readRaw(16448, 414816, 2);
|
|
1825
|
+
* console.log(data); //<Buffer ff 7f>
|
|
1725
1826
|
*
|
|
1726
|
-
*
|
|
1827
|
+
* const converted = await client.convertFromRaw(data, 'INT');
|
|
1828
|
+
* console.log(converted); //32767
|
|
1829
|
+
*
|
|
1830
|
+
* } catch (err) {
|
|
1831
|
+
* console.log("Error:", err);
|
|
1832
|
+
* }
|
|
1833
|
+
* ```
|
|
1727
1834
|
*
|
|
1728
|
-
* @param data Raw
|
|
1729
|
-
* @param dataType Data type name in the PLC as string (such as `ST_Struct`) or
|
|
1835
|
+
* @param data Raw data (acquired for example using {@link readRaw}())
|
|
1836
|
+
* @param dataType Data type name in the PLC as string (such as `ST_Struct`) or data type object (acquired using {@link getDataType}())
|
|
1730
1837
|
* @param targetOpts Optional target settings that override values in `settings`
|
|
1731
1838
|
*
|
|
1732
1839
|
* @template T Typescript data type of the PLC data, for example `convertFromRaw<number>(...)` or `convertFromRaw<ST_TypedStruct>(...)`
|
|
1840
|
+
* @throws Throws an error if sending the command fails or if the target responds with an error.
|
|
1733
1841
|
*/
|
|
1734
1842
|
convertFromRaw<T = any>(data: Buffer, dataType: string | AdsDataType, targetOpts?: Partial<AmsAddress>): Promise<T>;
|
|
1735
1843
|
/**
|
|
1736
|
-
*
|
|
1844
|
+
* Converts a Javascript object to raw data by using the provided data type.
|
|
1737
1845
|
*
|
|
1738
|
-
*
|
|
1846
|
+
* **NOTE:** Do not use `autoFill` for `UNION` types, it doesn't work correctly.
|
|
1847
|
+
|
|
1848
|
+
* @example
|
|
1849
|
+
* ```js
|
|
1850
|
+
* try {
|
|
1851
|
+
* const data = await client.convertToRaw(32767, 'INT');
|
|
1852
|
+
* console.log(data); //<Buffer ff 7f>
|
|
1739
1853
|
*
|
|
1740
|
-
*
|
|
1854
|
+
* } catch (err) {
|
|
1855
|
+
* console.log("Error:", err);
|
|
1856
|
+
* }
|
|
1857
|
+
* ```
|
|
1741
1858
|
*
|
|
1742
|
-
* @param value
|
|
1743
|
-
* @param dataType Data type name in the PLC as string (such as `ST_Struct`) or
|
|
1744
|
-
* @param autoFill If
|
|
1859
|
+
* @param value Value to convert
|
|
1860
|
+
* @param dataType Data type name in the PLC as string (such as `ST_Struct`) or data type object (acquired using {@link getDataType}())
|
|
1861
|
+
* @param autoFill autoFill If set and the data type is a container (`STRUCT`, `FUNCTION_BLOCK` etc.), missing properties are automatically set to default values (`0` or empty string).
|
|
1745
1862
|
* @param targetOpts Optional target settings that override values in `settings`
|
|
1746
1863
|
*
|
|
1747
|
-
* @
|
|
1864
|
+
* @throws Throws an error if sending the command fails or if the target responds with an error.
|
|
1748
1865
|
*/
|
|
1749
1866
|
convertToRaw(value: any, dataType: string | AdsDataType, autoFill?: boolean, targetOpts?: Partial<AmsAddress>): Promise<Buffer>;
|
|
1750
1867
|
/**
|
|
1751
|
-
*
|
|
1868
|
+
* Creates a handle to a variable at the target system by variable path (such as `GVL_Test.ExampleStruct`).
|
|
1752
1869
|
*
|
|
1753
|
-
*
|
|
1870
|
+
* The handle can be then used for reading and writing the value.
|
|
1754
1871
|
*
|
|
1755
|
-
*
|
|
1872
|
+
* Reading and writing dereferenced `POINTER` and `REFERENCE` values is also possible.
|
|
1873
|
+
* See {@link readRawByHandle}() and {@link writeRawByHandle}().
|
|
1756
1874
|
*
|
|
1757
|
-
*
|
|
1758
|
-
*
|
|
1875
|
+
* NOTE: The handle should be deleted after it's no longer needed,
|
|
1876
|
+
* as there is a limited amount of handles available. See {@link deleteVariableHandle}().
|
|
1877
|
+
*
|
|
1878
|
+
* @example
|
|
1879
|
+
* ```js
|
|
1880
|
+
* try {
|
|
1881
|
+
* //POINTER value (Note the dereference operator ^)
|
|
1882
|
+
* const handle1 = await client.createVariableHandle('GVL_Read.ComplexTypes.POINTER_^');
|
|
1883
|
+
* const value = await client.readRawByHandle(handle1);
|
|
1884
|
+
* await client.deleteVariableHandle(handle1);
|
|
1885
|
+
*
|
|
1886
|
+
* const handle2 = await client.createVariableHandle('GVL_Read.StandardTypes.INT_');
|
|
1887
|
+
* const value2 = await client.readRawByHandle(handle2);
|
|
1888
|
+
* await client.deleteVariableHandle(handle2);
|
|
1889
|
+
*
|
|
1890
|
+
* //Now you use convertFromRaw() to get actual values
|
|
1891
|
+
*
|
|
1892
|
+
* } catch (err) {
|
|
1893
|
+
* console.log("Error:", err);
|
|
1894
|
+
* }
|
|
1895
|
+
* ```
|
|
1896
|
+
*
|
|
1897
|
+
* @param path Variable path in the PLC to read (such as `GVL_Test.ExampleStruct`)
|
|
1898
|
+
* @param targetOpts Optional target settings that override values in `settings`
|
|
1899
|
+
*
|
|
1900
|
+
* @throws Throws an error if sending the command fails or if the target responds with an error.
|
|
1759
1901
|
*/
|
|
1760
1902
|
createVariableHandle(path: string, targetOpts?: Partial<AmsAddress>): Promise<VariableHandle>;
|
|
1761
1903
|
/**
|
|
1762
|
-
*
|
|
1904
|
+
* Sends multiple {@link createVariableHandle}() commands in one ADS packet.
|
|
1905
|
+
*
|
|
1906
|
+
* Creates a handle to a variable at the target system by variable path (such as `GVL_Test.ExampleStruct`).
|
|
1763
1907
|
*
|
|
1764
|
-
*
|
|
1908
|
+
* The handle can be then used for reading and writing the value.
|
|
1765
1909
|
*
|
|
1766
|
-
*
|
|
1910
|
+
* Reading and writing dereferenced `POINTER` and `REFERENCE` values is also possible.
|
|
1911
|
+
* See {@link readRawByHandle}() and {@link writeRawByHandle}().
|
|
1767
1912
|
*
|
|
1768
|
-
*
|
|
1913
|
+
* NOTE: The handle should be deleted after it's no longer needed,
|
|
1914
|
+
* as there is a limited amount of handles available. See {@link deleteVariableHandle}().
|
|
1769
1915
|
*
|
|
1770
|
-
* Uses ADS sum command under the hood (better
|
|
1916
|
+
* Uses ADS sum command under the hood (better and faster performance).
|
|
1917
|
+
* See [Beckhoff Information System](https://infosys.beckhoff.com/english.php?content=../content/1033/tc3_adsdll2/9007199379576075.html&id=9180083787138954512) for more info.
|
|
1771
1918
|
*
|
|
1772
|
-
* @
|
|
1919
|
+
* @example
|
|
1920
|
+
* ```js
|
|
1921
|
+
* try {
|
|
1922
|
+
* const results = await client.createVariableHandleMulti([
|
|
1923
|
+
* 'GVL_Read.StandardTypes.INT_',
|
|
1924
|
+
* 'GVL_Read.StandardTypes.REAL_'
|
|
1925
|
+
* ]);
|
|
1926
|
+
*
|
|
1927
|
+
* if(results[0].success) {
|
|
1928
|
+
* console.log(`First handle: ${results[0].handle}`);
|
|
1929
|
+
* } else {
|
|
1930
|
+
* console.log(`Creating first handle failed: ${results[0].errorStr}`);
|
|
1931
|
+
* }
|
|
1932
|
+
*
|
|
1933
|
+
* } catch (err) {
|
|
1934
|
+
* console.log("Error:", err);
|
|
1935
|
+
* }
|
|
1936
|
+
* ```
|
|
1937
|
+
*
|
|
1938
|
+
* @param paths Array of variable paths in the PLC to read (such as `GVL_Test.ExampleStruct`)
|
|
1773
1939
|
* @param targetOpts Optional target settings that override values in `settings`
|
|
1940
|
+
*
|
|
1941
|
+
* @throws Throws an error if sending the command fails or if the target responds with an error.
|
|
1774
1942
|
*/
|
|
1775
1943
|
createVariableHandleMulti(paths: string[], targetOpts?: Partial<AmsAddress>): Promise<CreateVariableHandleMultiResult[]>;
|
|
1776
1944
|
/**
|
|
1777
|
-
*
|
|
1945
|
+
* Deletes a variable handle that was previously created
|
|
1946
|
+
* using {@link createVariableHandle}().
|
|
1778
1947
|
*
|
|
1779
|
-
*
|
|
1948
|
+
* @example
|
|
1949
|
+
* ```js
|
|
1950
|
+
* try {
|
|
1951
|
+
* const handle = createVariableHandle(...);
|
|
1952
|
+
*
|
|
1953
|
+
* //After use, deleting the handle
|
|
1954
|
+
* await client.deleteVariableHandle(handle);
|
|
1955
|
+
*
|
|
1956
|
+
* } catch (err) {
|
|
1957
|
+
* console.log("Error:", err);
|
|
1958
|
+
* }
|
|
1959
|
+
* ```
|
|
1780
1960
|
*
|
|
1781
1961
|
* @param handle Variable handle to delete
|
|
1782
|
-
* @param targetOpts Optional target settings that override values in `settings`
|
|
1962
|
+
* @param targetOpts Optional target settings that override values in `settings`
|
|
1963
|
+
*
|
|
1964
|
+
* @throws Throws an error if sending the command fails or if the target responds with an error.
|
|
1783
1965
|
*/
|
|
1784
1966
|
deleteVariableHandle(handle: VariableHandle | number, targetOpts?: Partial<AmsAddress>): Promise<void>;
|
|
1785
1967
|
/**
|
|
1786
|
-
*
|
|
1968
|
+
* Sends multiple {@link deleteVariableHandle}() commands in one ADS packet.
|
|
1969
|
+
*
|
|
1970
|
+
* Deletes a variable handle that was previously created
|
|
1971
|
+
* using {@link createVariableHandle}().
|
|
1972
|
+
*
|
|
1973
|
+
* Uses ADS sum command under the hood (better and faster performance).
|
|
1974
|
+
* See [Beckhoff Information System](https://infosys.beckhoff.com/english.php?content=../content/1033/tc3_adsdll2/9007199379576075.html&id=9180083787138954512) for more info.
|
|
1975
|
+
*
|
|
1976
|
+
* @example
|
|
1977
|
+
* ```js
|
|
1978
|
+
* try {
|
|
1979
|
+
* const handle1 = createVariableHandle(...);
|
|
1980
|
+
* const handle2 = createVariableHandle(...);
|
|
1787
1981
|
*
|
|
1788
|
-
*
|
|
1982
|
+
* //After use, deleting the handles
|
|
1983
|
+
* const results = await client.deleteVariableHandleMulti([handle1, handle2]);
|
|
1789
1984
|
*
|
|
1790
|
-
*
|
|
1985
|
+
* if(results[0].success) {
|
|
1986
|
+
* console.log(`First deleted`);
|
|
1987
|
+
* } else {
|
|
1988
|
+
* console.log(`Deleting first handle failed: ${results[0].errorStr}`);
|
|
1989
|
+
* }
|
|
1791
1990
|
*
|
|
1792
|
-
*
|
|
1991
|
+
* } catch (err) {
|
|
1992
|
+
* console.log("Error:", err);
|
|
1993
|
+
* }
|
|
1994
|
+
* ```
|
|
1793
1995
|
*
|
|
1794
1996
|
* @param handles Array of variable handles to delete
|
|
1795
1997
|
* @param targetOpts Optional target settings that override values in `settings`
|
|
1998
|
+
*
|
|
1999
|
+
* @throws Throws an error if sending the command fails or if the target responds with an error.
|
|
1796
2000
|
*/
|
|
1797
2001
|
deleteVariableHandleMulti(handles: (VariableHandle | number)[], targetOpts?: Partial<AmsAddress>): Promise<DeleteVariableHandleMultiResult[]>;
|
|
1798
2002
|
/**
|
|
1799
|
-
*
|
|
2003
|
+
* Reads raw data from the target system by a previously created variable handle (acquired using {@link createVariableHandle}())
|
|
1800
2004
|
*
|
|
1801
|
-
*
|
|
2005
|
+
* @example
|
|
2006
|
+
* ```js
|
|
2007
|
+
* try {
|
|
2008
|
+
* const handle = await client.createVariableHandle('GVL_Read.StandardTypes.INT_'');
|
|
2009
|
+
* const value = await client.readRawByHandle(handle);
|
|
2010
|
+
* await client.deleteVariableHandle(handle);
|
|
1802
2011
|
*
|
|
2012
|
+
* } catch (err) {
|
|
2013
|
+
* console.log("Error:", err);
|
|
2014
|
+
* }
|
|
2015
|
+
* ```
|
|
1803
2016
|
* @param handle Variable handle
|
|
1804
2017
|
* @param size Optional data length to read (bytes) - as default, size in handle is used if available. Uses 0xFFFFFFFF as fallback.
|
|
1805
|
-
* @param targetOpts Optional target settings that override values in `settings`
|
|
2018
|
+
* @param targetOpts Optional target settings that override values in `settings`
|
|
2019
|
+
*
|
|
2020
|
+
* @throws Throws an error if sending the command fails or if the target responds with an error.
|
|
1806
2021
|
*/
|
|
1807
2022
|
readRawByHandle(handle: VariableHandle | number, size?: number, targetOpts?: Partial<AmsAddress>): Promise<Buffer>;
|
|
1808
2023
|
/**
|
|
1809
|
-
*
|
|
2024
|
+
* Writes raw data to the target system by a previously created variable handle (acquired using {@link createVariableHandle}())
|
|
1810
2025
|
*
|
|
1811
|
-
*
|
|
2026
|
+
* @example
|
|
2027
|
+
* ```js
|
|
2028
|
+
* try {
|
|
2029
|
+
* const value = await client.convertToRaw(32767, 'INT');
|
|
2030
|
+
* console.log(value); //<Buffer ff 7f>
|
|
2031
|
+
*
|
|
2032
|
+
* const handle = await client.createVariableHandle('GVL_Read.StandardTypes.INT_');
|
|
2033
|
+
* await client.writeRawByHandle(handle, value);
|
|
2034
|
+
* await client.deleteVariableHandle(handle);
|
|
2035
|
+
*
|
|
2036
|
+
* } catch (err) {
|
|
2037
|
+
* console.log("Error:", err);
|
|
2038
|
+
* }
|
|
2039
|
+
* ```
|
|
1812
2040
|
*
|
|
1813
2041
|
* @param handle Variable handle
|
|
1814
2042
|
* @param value Data to write
|
|
1815
|
-
* @param targetOpts Optional target settings that override values in `settings`
|
|
2043
|
+
* @param targetOpts Optional target settings that override values in `settings`
|
|
2044
|
+
*
|
|
2045
|
+
* @throws Throws an error if sending the command fails or if the target responds with an error.
|
|
1816
2046
|
*/
|
|
1817
2047
|
writeRawByHandle(handle: VariableHandle | number, value: Buffer, targetOpts?: Partial<AmsAddress>): Promise<void>;
|
|
1818
2048
|
/**
|
|
1819
|
-
*
|
|
2049
|
+
* Reads raw data from the target system by a symbol object (acquired using `getSymbol()`)
|
|
1820
2050
|
*
|
|
1821
|
-
*
|
|
2051
|
+
* @example
|
|
2052
|
+
* ```js
|
|
2053
|
+
* try {
|
|
2054
|
+
* const symbol = await client.getSymbol('GVL_Read.StandardTypes.INT_');
|
|
2055
|
+
* const value = await client.readRawBySymbol(symbol);
|
|
1822
2056
|
*
|
|
1823
|
-
*
|
|
1824
|
-
*
|
|
2057
|
+
* } catch (err) {
|
|
2058
|
+
* console.log("Error:", err);
|
|
2059
|
+
* }
|
|
2060
|
+
* ```
|
|
2061
|
+
*
|
|
2062
|
+
* @param symbol Symbol
|
|
2063
|
+
* @param targetOpts Optional target settings that override values in `settings`
|
|
2064
|
+
*
|
|
2065
|
+
* @throws Throws an error if sending the command fails or if the target responds with an error.
|
|
1825
2066
|
*/
|
|
1826
2067
|
readRawBySymbol(symbol: AdsSymbol, targetOpts?: Partial<AmsAddress>): Promise<Buffer>;
|
|
1827
2068
|
/**
|
|
1828
|
-
*
|
|
2069
|
+
* Writes raw data to the target system by a symbol object (acquired using `getSymbol()`)
|
|
2070
|
+
*
|
|
2071
|
+
* @example
|
|
2072
|
+
* ```js
|
|
2073
|
+
* try {
|
|
2074
|
+
* const value = await client.convertToRaw(32767, 'INT');
|
|
2075
|
+
* console.log(value); //<Buffer ff 7f>
|
|
1829
2076
|
*
|
|
1830
|
-
*
|
|
2077
|
+
* const symbol = await client.getSymbol('GVL_Read.StandardTypes.INT_');
|
|
2078
|
+
* await client.writeRawBySymbol(symbol, value);
|
|
2079
|
+
*
|
|
2080
|
+
* } catch (err) {
|
|
2081
|
+
* console.log("Error:", err);
|
|
2082
|
+
* }
|
|
2083
|
+
* ```
|
|
1831
2084
|
*
|
|
1832
|
-
* @param symbol Symbol
|
|
2085
|
+
* @param symbol Symbol
|
|
1833
2086
|
* @param value Data to write
|
|
1834
2087
|
* @param targetOpts Optional target settings that override values in `settings`
|
|
2088
|
+
*
|
|
2089
|
+
* @throws Throws an error if sending the command fails or if the target responds with an error.
|
|
1835
2090
|
*/
|
|
1836
2091
|
writeRawBySymbol(symbol: AdsSymbol, value: Buffer, targetOpts?: Partial<AmsAddress>): Promise<void>;
|
|
1837
2092
|
/**
|
|
1838
|
-
*
|
|
2093
|
+
* Invokes a function block RPC method on the target system.
|
|
2094
|
+
*
|
|
2095
|
+
* Returns the return value of the method and outputs (if any).
|
|
2096
|
+
*
|
|
2097
|
+
* NOTE: In the PLC, `{attribute 'TcRpcEnable'}` is required above the `METHOD` definition.
|
|
1839
2098
|
*
|
|
1840
|
-
*
|
|
2099
|
+
* @example
|
|
2100
|
+
* ```js
|
|
2101
|
+
* try {
|
|
2102
|
+
* const res = await client.invokeRpcMethod('GVL_RPC.RpcBlock', 'Calculator', {
|
|
2103
|
+
* Value1: 1,
|
|
2104
|
+
* Value2: 123
|
|
2105
|
+
* });
|
|
1841
2106
|
*
|
|
1842
|
-
*
|
|
2107
|
+
* console.log(res);
|
|
2108
|
+
* //{
|
|
2109
|
+
* // returnValue: true,
|
|
2110
|
+
* // outputs: { Sum: 124, Product: 123, Division: 0.008130080997943878 }
|
|
2111
|
+
* //}
|
|
1843
2112
|
*
|
|
1844
|
-
*
|
|
2113
|
+
* } catch (err) {
|
|
2114
|
+
* console.log("Error:", err);
|
|
2115
|
+
* }
|
|
2116
|
+
* ```
|
|
1845
2117
|
*
|
|
1846
|
-
* @param path
|
|
1847
|
-
* @param method Function block method name
|
|
1848
|
-
* @param parameters
|
|
2118
|
+
* @param path Variable path in the PLC of the function block instance (such as `GVL_Test.ExampleBlock`)
|
|
2119
|
+
* @param method Function block method name
|
|
2120
|
+
* @param parameters Method parameters (inputs) (if any)
|
|
1849
2121
|
* @param targetOpts Optional target settings that override values in `settings`
|
|
1850
2122
|
*
|
|
1851
2123
|
* @template T Typescript data type of the method return value, for example `invokeRpcMethod<number>(...)` or `invokeRpcMethod<ST_TypedStruct>(...)`
|
|
1852
2124
|
* @template U Typescript data type of the method outputs object, for example `invokeRpcMethod<number, ST_TypedStruct>(...)`
|
|
2125
|
+
*
|
|
2126
|
+
* @throws Throws an error if sending the command fails or if the target responds with an error.
|
|
1853
2127
|
*/
|
|
1854
2128
|
invokeRpcMethod<T = any, U = Record<string, any>>(path: string, method: string, parameters?: Record<string, any>, targetOpts?: Partial<AmsAddress>): Promise<RpcMethodCallResult<T, U>>;
|
|
1855
2129
|
}
|