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

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,29 +1,39 @@
1
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
2
  import * as ADS from './ads-commons';
5
- export * 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";
6
5
  export type * from "./types/ads-client-types";
7
6
  export type * from './types/ads-protocol-types';
8
7
  export type * from './client-error';
8
+ /**
9
+ * Common ADS constants and helper functions
10
+ *
11
+ * @category Client
12
+ */
13
+ export * as ADS from './ads-commons';
9
14
  /**
10
15
  * A class for handling TwinCAT ADS protocol communication.
11
16
  *
12
17
  * Settings are provided in constructor - see {@link Client.constructor} and {@link AdsClientSettings}.
13
18
  *
14
- * A client instance should be created for each target, however, a single client
15
- * can also be used to communicate with multiple endpoints.
19
+ * A client instance should be created for each target.
20
+ * However, a single client instance can also be used to communicate with
21
+ * multiple endpoints using the `targetOpts` parameter available in all methods.
16
22
  *
17
- * @example
23
+ * Client also emits different events, such as `client.on('connect', ...)`.
24
+ * See {@link AdsClientEvents} for all available events.
18
25
  *
26
+ * @example
19
27
  * ```js
20
28
  * const client = new Client({
21
29
  * targetAmsNetId: "192.168.4.1.1.1",
22
30
  * targetAdsPort: 851
23
31
  * });
24
32
  * ```
33
+ *
34
+ * @category Client
25
35
  */
26
- export declare class Client extends EventEmitter<ClientEvents> {
36
+ export declare class Client extends EventEmitter<AdsClientEvents> {
27
37
  /**
28
38
  * Debug instance for debug level 1.
29
39
  */
@@ -169,6 +179,12 @@ export declare class Client extends EventEmitter<ClientEvents> {
169
179
  * ```
170
180
  */
171
181
  constructor(settings: AdsClientSettings);
182
+ /**
183
+ * Emits a warning, which results in a `warning` event, and a console message if `hideConsoleWarnings` is not set.
184
+ *
185
+ * @param message Warning message
186
+ */
187
+ private warn;
172
188
  /**
173
189
  * Clears given timer if it's available and increases the ID.
174
190
  *
@@ -573,14 +589,44 @@ export declare class Client extends EventEmitter<ClientEvents> {
573
589
  * - {@link Client.unsubscribe}() - `DeleteNotification` command
574
590
  * - {@link Client.readWriteRaw}() - `ReadWrite` command
575
591
  *
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
592
  * @example
581
593
  * ```js
582
- * TODO - DOCUMENTATION ONGOING
594
+ * try {
595
+ * //Creating readRaw(16448, 414816, 2) command manually and sending it using sendAdsCommand()
596
+ *
597
+ * const data = Buffer.alloc(12);
598
+ * let pos = 0;
599
+ *
600
+ * //0..3 IndexGroup
601
+ * data.writeUInt32LE(16448, pos);
602
+ * pos += 4;
603
+ *
604
+ * //4..7 IndexOffset
605
+ * data.writeUInt32LE(414816, pos);
606
+ * pos += 4;
607
+ *
608
+ * //8..11 Read data length
609
+ * data.writeUInt32LE(2, pos);
610
+ * pos += 4;
611
+ *
612
+ * const res = await this.sendAdsCommand<AdsReadResponse>({
613
+ * adsCommand: ADS.ADS_COMMAND.Read,
614
+ * targetAmsNetId: targetOpts.amsNetId,
615
+ * targetAdsPort: targetOpts.adsPort,
616
+ * payload: data
617
+ * });
618
+ *
619
+ * console.log(res.ads.payload); //<Buffer ff 7f>
620
+ *
621
+ * } catch (err) {
622
+ * console.log("Error:", err);
623
+ * }
583
624
  * ```
625
+ *
626
+ * @template T In Typescript, the type of the ADS response. If omitted, generic {@link AdsResponse} type is used.
627
+ *
628
+ * @throws Throws an error if sending the command fails or if target responds with an error
629
+ *
584
630
  */
585
631
  sendAdsCommand<T = AdsResponse>(command: AdsCommandToSend): Promise<AmsTcpPacket<T>>;
586
632
  /**
@@ -752,7 +798,7 @@ export declare class Client extends EventEmitter<ClientEvents> {
752
798
  */
753
799
  restartTcSystem(reconnect?: boolean, targetOpts?: Partial<AmsAddress>): Promise<void>;
754
800
  /**
755
- * Returns symbol for given variable path, such as `GVL_Test.ExampleStruct`.
801
+ * Returns a symbol object for given variable path, such as `GVL_Test.ExampleStruct`.
756
802
  *
757
803
  * Returns previously cached value if available, otherwise reads it from the target
758
804
  * and caches it.
@@ -766,7 +812,7 @@ export declare class Client extends EventEmitter<ClientEvents> {
766
812
  * @example
767
813
  * ```js
768
814
  * try {
769
- * const symbol = await client.getSymbol('GVL_Test.ExampleStruct');
815
+ * const symbol = await client.getSymbol('GVL_Read.StandardTypes.INT_');
770
816
  * } catch (err) {
771
817
  * console.log("Error:", err);
772
818
  * }
@@ -918,7 +964,7 @@ export declare class Client extends EventEmitter<ClientEvents> {
918
964
  * //Checks if value has changed every 100ms
919
965
  * //Callback is called only when the value has changed
920
966
  * await client.subscribeValue(
921
- * 'GVL_Test.ExampleStruct.',
967
+ * 'GVL_Subscription.NumericValue_10ms',
922
968
  * (data, subscription) => {
923
969
  * console.log(`Value of ${subscription.symbol.name} has changed: ${data.value}`);
924
970
  * },
@@ -961,7 +1007,7 @@ export declare class Client extends EventEmitter<ClientEvents> {
961
1007
  */
962
1008
  subscribeValue<T = any>(path: string, callback: SubscriptionCallback<T>, cycleTime?: number, sendOnChange?: boolean, maxDelay?: number, targetOpts?: Partial<AmsAddress>): Promise<ActiveSubscription<T>>;
963
1009
  /**
964
- * Subscribes to raw value change notifications (ADS notifications) by raw ADS address (index group, index offset and data length).
1010
+ * Subscribes to raw value change notifications (ADS notifications) by a raw ADS address (index group, index offset and data length).
965
1011
  *
966
1012
  * Provided callback is called with the latest value when the value changes or when
967
1013
  * enough time has passed (depending on settings).
@@ -1026,7 +1072,7 @@ export declare class Client extends EventEmitter<ClientEvents> {
1026
1072
  * //Checks if value has changed every 100ms
1027
1073
  * //Callback is called only when the value has changed
1028
1074
  * await client.subscribe({
1029
- * target: 'GVL_Test.ExampleStruct',
1075
+ * target: 'GVL_Subscription.NumericValue_10ms',
1030
1076
  * callback: (data, subscription) => {
1031
1077
  * console.log(`Value of ${subscription.symbol.name} has changed: ${data.value}`);
1032
1078
  * },
@@ -1082,6 +1128,17 @@ export declare class Client extends EventEmitter<ClientEvents> {
1082
1128
  * @throws Throws an error if sending the command fails or if the target responds with an error.
1083
1129
  */
1084
1130
  unsubscribe(subscription: ActiveSubscription): Promise<void>;
1131
+ /**
1132
+ * Sends a delete ADS notification command to the target system.
1133
+ *
1134
+ * Doesn't delete subscriptions, just sends the ADS command.
1135
+ *
1136
+ * @param notificationHandle Notification handle to delete (number)
1137
+ * @param targetAmsAddress Target system address
1138
+ *
1139
+ * @throws NOTE: Throws error if failed
1140
+ */
1141
+ private deleteNotificationHandle;
1085
1142
  /**
1086
1143
  * Unsubscribes all active subscription (deletes all ADS notifications).
1087
1144
  *
@@ -1253,310 +1310,757 @@ export declare class Client extends EventEmitter<ClientEvents> {
1253
1310
  */
1254
1311
  cacheDataTypes(): Promise<void>;
1255
1312
  /**
1256
- * **TODO - DOCUMENTATION ONGOING**
1313
+ * Reads raw data from the target system by a raw ADS address (index group, index offset and data length).
1314
+ *
1315
+ * This is the ADS protocol `Read` command.
1316
+ *
1317
+ * @example
1318
+ * ```js
1319
+ * try {
1320
+ * const data = await client.readRaw(16448, 414816, 2);
1321
+ * console.log(data); //<Buffer ff 7f>
1257
1322
  *
1258
- * Reads raw byte data from the target system by provided index group, index offset and data length (bytes)
1323
+ * const converted = await client.convertFromRaw(data, 'INT');
1324
+ * console.log(converted); //32767
1259
1325
  *
1260
- * This is the `ADS read` command in ADS protocol.
1326
+ * } catch (err) {
1327
+ * console.log("Error:", err);
1328
+ * }
1329
+ * ```
1261
1330
  *
1262
1331
  * @param indexGroup Index group (address) of the data to read
1263
1332
  * @param indexOffset Index offset (address) of the data to read
1264
1333
  * @param size Data length to read (bytes)
1265
1334
  * @param targetOpts Optional target settings that override values in `settings`
1335
+ *
1336
+ * @throws Throws an error if sending the command fails or if the target responds with an error.
1266
1337
  */
1267
1338
  readRaw(indexGroup: number, indexOffset: number, size: number, targetOpts?: Partial<AmsAddress>): Promise<Buffer>;
1268
1339
  /**
1269
- * **TODO - DOCUMENTATION ONGOING**
1340
+ * Writes raw data to the target system by a raw ADS address (index group, index offset and data length).
1341
+ *
1342
+ * This is the ADS protocol `Write` command.
1270
1343
  *
1271
- * Writes raw byte data to the target system by provided index group and index offset.
1344
+ * @example
1345
+ * ```js
1346
+ * try {
1347
+ * const data = await client.convertToRaw(32767, 'INT');
1348
+ * console.log(data); //<Buffer ff 7f>
1272
1349
  *
1273
- * This is the `ADS write` command in ADS protocol.
1350
+ * await client.writeRaw(16448, 414816, data);
1351
+ * } catch (err) {
1352
+ * console.log("Error:", err);
1353
+ * }
1354
+ * ```
1274
1355
  *
1275
1356
  * @param indexGroup Index group (address) of the data to write to
1276
1357
  * @param indexOffset Index offset (address) of the data to write to
1277
1358
  * @param value Data to write
1278
1359
  * @param targetOpts Optional target settings that override values in `settings`
1360
+ *
1361
+ * @throws Throws an error if sending the command fails or if the target responds with an error.
1279
1362
  */
1280
1363
  writeRaw(indexGroup: number, indexOffset: number, value: Buffer, targetOpts?: Partial<AmsAddress>): Promise<void>;
1281
1364
  /**
1282
- * **TODO - DOCUMENTATION ONGOING**
1365
+ * Sends multiple `readRaw()` commands in one ADS packet.
1366
+ *
1367
+ * Reads raw data from the target system by a raw ADS addresses (index group, index offset and data length).
1368
+ * Results are returned for each command separately - see {@link ReadRawMultiResult} for details.
1283
1369
  *
1284
- * Sends multiple readRaw() commands in one ADS packet
1370
+ * Uses ADS sum command under the hood (better and faster performance).
1371
+ * See [Beckhoff Information System](https://infosys.beckhoff.com/english.php?content=../content/1033/tc3_adsdll2/9007199379576075.html&id=9180083787138954512) for more info.
1285
1372
  *
1286
- * Reads raw byte data from the target system by provided index group, index offset and data length (bytes)
1373
+ * @example
1374
+ * ```js
1375
+ * try {
1376
+ * const results = await client.readRawMulti([
1377
+ * {
1378
+ * indexGroup: 16448,
1379
+ * indexOffset: 414816,
1380
+ * size: 2
1381
+ * },
1382
+ * {
1383
+ * indexGroup: 16448,
1384
+ * indexOffset: 414900,
1385
+ * size: 128
1386
+ * }
1387
+ * ]);
1388
+ *
1389
+ * if(results[0].success) {
1390
+ * console.log(`First result: ${results[0].value}`); //First result: <Buffer ff 7f>
1391
+ * } else {
1392
+ * console.log(`First read command failed: ${results[0].errorStr}`);
1393
+ * }
1287
1394
  *
1288
- * Uses ADS sum command under the hood (better performance)
1395
+ * } catch (err) {
1396
+ * console.log("Error:", err);
1397
+ * }
1398
+ * ```
1289
1399
  *
1290
1400
  * @param commands Array of read commands
1291
1401
  * @param targetOpts Optional target settings that override values in `settings`
1402
+ *
1403
+ * @throws Throws an error if sending the command fails or if the target responds with an error.
1292
1404
  */
1293
1405
  readRawMulti(commands: ReadRawMultiCommand[], targetOpts?: Partial<AmsAddress>): Promise<ReadRawMultiResult[]>;
1294
1406
  /**
1295
- * **TODO - DOCUMENTATION ONGOING**
1407
+ * Sends multiple `writeRaw()` commands in one ADS packet.
1408
+ *
1409
+ * Writes raw data to the target system by a raw ADS addresses (index group and index offset).
1410
+ * Results are returned for each command separately - see {@link WriteRawMultiResult} for details.
1296
1411
  *
1297
- * Sends multiple writeRaw() commands in one ADS packet
1412
+ * Uses ADS sum command under the hood (better and faster performance).
1413
+ * See [Beckhoff Information System](https://infosys.beckhoff.com/english.php?content=../content/1033/tc3_adsdll2/9007199379576075.html&id=9180083787138954512) for more info.
1298
1414
  *
1299
- * Writes raw byte data to the target system by provided index group and index offset.
1415
+ * @example
1416
+ * ```js
1417
+ * try {
1418
+ * const data1 = await client.convertToRaw(32767, 'INT');
1419
+ * console.log(data1); //<Buffer ff 7f>
1420
+ *
1421
+ * const data2 = Buffer.alloc(128); //example
1422
+ *
1423
+ * const results = await client.writeRawMulti([
1424
+ * {
1425
+ * indexGroup: 16448,
1426
+ * indexOffset: 414816,
1427
+ * value: data1
1428
+ * },
1429
+ * {
1430
+ * indexGroup: 16448,
1431
+ * indexOffset: 414900,
1432
+ * value: data2
1433
+ * }
1434
+ * ]);
1435
+ *
1436
+ * if(results[0].success) {
1437
+ * console.log(`First write command successful`);
1438
+ * } else {
1439
+ * console.log(`First write command failed: ${results[0].errorStr}`);
1440
+ * }
1300
1441
  *
1301
- * Uses ADS sum command under the hood (better performance)
1442
+ * } catch (err) {
1443
+ * console.log("Error:", err);
1444
+ * }
1445
+ * ```
1302
1446
  *
1303
1447
  * @param commands Array of write commands
1304
1448
  * @param targetOpts Optional target settings that override values in `settings`
1449
+ *
1450
+ * @throws Throws an error if sending the command fails or if the target responds with an error.
1305
1451
  */
1306
1452
  writeRawMulti(commands: WriteRawMultiCommand[], targetOpts?: Partial<AmsAddress>): Promise<WriteRawMultiResult[]>;
1307
1453
  /**
1308
- * **TODO - DOCUMENTATION ONGOING**
1454
+ * Reads raw data from the target system by variable path (such as `GVL_Test.ExampleStruct`).
1309
1455
  *
1310
- * Reads raw byte data from the target system by symbol path.
1456
+ * Supports also reading `POINTER` and `REFERENCE` values (see example).
1311
1457
  *
1312
- * Supports also reading POINTER and REFERENCE values by using deference operator in path (`^`)
1458
+ * This uses the ADS `READ_SYMVAL_BYNAME` under the hood, so only one
1459
+ * round-trip is needed.
1313
1460
  *
1314
- * This uses the ADS command `READ_SYMVAL_BYNAME` under the hood
1461
+ * @example
1462
+ * ```js
1463
+ * try {
1464
+ * const data = await client.readRawByPath('GVL_Read.StandardTypes.INT_');
1465
+ * console.log(data); //<Buffer ff 7f>
1466
+ *
1467
+ * const converted = await client.convertFromRaw(data, 'INT');
1468
+ * console.log(converted); //32767
1469
+ *
1470
+ * //Reading a POINTER value (Note the dereference operator ^)
1471
+ * const ptrValue = await client.readRawByPath('GVL_Read.ComplexTypes.POINTER_^');
1472
+ *
1473
+ * //Reading a REFERENCE value
1474
+ * const refValue = await client.readRawByPath('GVL_Read.ComplexTypes.REFERENCE_');
1475
+ *
1476
+ * } catch (err) {
1477
+ * console.log("Error:", err);
1478
+ * }
1479
+ * ```
1315
1480
  *
1316
1481
  * @param path Variable path in the PLC to read (such as `GVL_Test.ExampleStruct`)
1317
1482
  * @param targetOpts Optional target settings that override values in `settings`
1483
+ *
1484
+ * @throws Throws an error if sending the command fails or if the target responds with an error.
1318
1485
  */
1319
1486
  readRawByPath(path: string, targetOpts?: Partial<AmsAddress>): Promise<Buffer>;
1320
1487
  /**
1321
- * **TODO - DOCUMENTATION ONGOING**
1488
+ * Writes raw data to the target system by variable path (such as `GVL_Test.ExampleStruct`).
1322
1489
  *
1323
- * Writes raw byte data to the target system by symbol path.
1490
+ * Supports also writing `POINTER` and `REFERENCE` values (see example).
1324
1491
  *
1325
- * Supports also reading POINTER and REFERENCE values by using deference operator in path (`^`)
1492
+ * NOTE: Unlike with {@link readRawByPath}(), this command uses multiple ADS requests for the operation.
1326
1493
  *
1327
- * Unlike `readRawByPath()`, this uses variable handles under the hood, the as there is no direct ADS command available for this.
1494
+ * @example
1495
+ * ```js
1496
+ * try {
1497
+ * const data = await client.convertToRaw(32767, 'INT');
1498
+ * console.log(data); //<Buffer ff 7f>
1328
1499
  *
1329
- * @param path Variable path in the PLC to read (such as `GVL_Test.ExampleStruct`)
1500
+ * await client.writeRawByPath('GVL_Write.StandardTypes.INT_', data);
1501
+ *
1502
+ * //Writing a POINTER value (Note the dereference operator ^)
1503
+ * const ptrValue = ...
1504
+ * await client.writeRawByPath('GVL_Read.ComplexTypes.POINTER_^', ptrValue);
1505
+ *
1506
+ * //Writing a REFERENCE value
1507
+ * const refValue = ...
1508
+ * await client.readRawByPath('GVL_Read.ComplexTypes.REFERENCE_');
1509
+ *
1510
+ * } catch (err) {
1511
+ * console.log("Error:", err);
1512
+ * }
1513
+ * ```
1514
+ *
1515
+ * @param path Variable path in the PLC to write (such as `GVL_Test.ExampleStruct`)
1330
1516
  * @param value Data to write
1331
1517
  * @param targetOpts Optional target settings that override values in `settings`
1518
+ *
1519
+ * @throws Throws an error if sending the command fails or if the target responds with an error.
1332
1520
  */
1333
1521
  writeRawByPath(path: string, value: Buffer, targetOpts?: Partial<AmsAddress>): Promise<void>;
1334
1522
  /**
1335
- * **TODO - DOCUMENTATION ONGOING**
1523
+ * Writes raw data to the target system by a raw ADS address (index group, index offset)
1524
+ * and reads the result as raw data.
1525
+ *
1526
+ * This is the ADS protocol `ReadWrite` command.
1336
1527
  *
1337
- * Writes raw data to the target and reads the result as raw data
1528
+ * @example
1529
+ * ```js
1530
+ * const { ADS } = require('../dist/ads-client');
1338
1531
  *
1339
- * Uses `ADS ReadWrite` command
1532
+ * try {
1533
+ * //Reading raw value by symbol path (= same as readRawByPath())
1534
+ * const path = ADS.encodeStringToPlcStringBuffer('GVL_Read.StandardTypes.INT_');
1535
+ * const data = await client.readWriteRaw(ADS.ADS_RESERVED_INDEX_GROUPS.SymbolValueByName, 0, 0xFFFFFFFF, path);
1536
+ * console.log(data); //<Buffer ff 7f>
1537
+ *
1538
+ * } catch (err) {
1539
+ * console.log("Error:", err);
1540
+ * }
1541
+ * ```
1340
1542
  *
1341
1543
  * @param indexGroup Address index group
1342
1544
  * @param indexOffset Address index offset
1343
- * @param size How many bytes to read
1344
- * @param writeData Data to write
1545
+ * @param size Data length to read (bytes)
1546
+ * @param value Value to write
1345
1547
  * @param targetOpts Optional target settings that override values in `settings`
1548
+ *
1549
+ * @throws Throws an error if sending the command fails or if the target responds with an error.
1346
1550
  */
1347
- readWriteRaw(indexGroup: number, indexOffset: number, size: number, writeData: Buffer, targetOpts?: Partial<AmsAddress>): Promise<Buffer>;
1551
+ readWriteRaw(indexGroup: number, indexOffset: number, size: number, value: Buffer, targetOpts?: Partial<AmsAddress>): Promise<Buffer>;
1348
1552
  /**
1349
- * **TODO - DOCUMENTATION ONGOING**
1553
+ * Sends multiple `readWriteRaw()` commands in one ADS packet.
1350
1554
  *
1351
- * Sends multiple readWriteRaw() commands in one ADS packet
1555
+ * Writes raw data to the target system by a raw ADS address (index group, index offset)
1556
+ * and reads the result as raw data.
1352
1557
  *
1353
- * Uses ADS sum command under the hood (better performance)
1558
+ * Uses ADS sum command under the hood (better and faster performance).
1559
+ * See [Beckhoff Information System](https://infosys.beckhoff.com/english.php?content=../content/1033/tc3_adsdll2/9007199379576075.html&id=9180083787138954512) for more info.
1354
1560
  *
1355
- * @param commands Array of read write commands
1561
+ * @example
1562
+ * ```js
1563
+ * try {
1564
+ * //Reading raw values by symbol paths (= same as readRawByPath())
1565
+ * const path = ADS.encodeStringToPlcStringBuffer('GVL_Read.StandardTypes.INT_');
1566
+ * const path2 = ADS.encodeStringToPlcStringBuffer('GVL_Read.StandardTypes.REAL_');
1567
+ *
1568
+ * const results = await client.readWriteRawMulti([
1569
+ * {
1570
+ * indexGroup: ADS.ADS_RESERVED_INDEX_GROUPS.SymbolValueByName,
1571
+ * indexOffset: 0,
1572
+ * size: 0xFFFF,
1573
+ * value: path
1574
+ * },
1575
+ * {
1576
+ * indexGroup: ADS.ADS_RESERVED_INDEX_GROUPS.SymbolValueByName,
1577
+ * indexOffset: 0,
1578
+ * size: 0xFFFF,
1579
+ * value: path2
1580
+ * }
1581
+ * ]);
1582
+ *
1583
+ * if(results[0].success) {
1584
+ * console.log(`First result: ${results[0].value}`); //First result: <Buffer ff 7f>
1585
+ * } else {
1586
+ * console.log(`First read/write command failed: ${results[0].errorStr}`);
1587
+ * }
1588
+ *
1589
+ * } catch (err) {
1590
+ * console.log("Error:", err);
1591
+ * }
1592
+ *
1593
+ * ```
1594
+ *
1595
+ * @param commands Array of read/write commands
1356
1596
  * @param targetOpts Optional target settings that override values in `settings`
1597
+ *
1598
+ * @throws Throws an error if sending the command fails or if the target responds with an error.
1357
1599
  */
1358
1600
  readWriteRawMulti(commands: ReadWriteRawMultiCommand[], targetOpts?: Partial<AmsAddress>): Promise<ReadWriteRawMultiResult[]>;
1359
1601
  /**
1360
- * **TODO - DOCUMENTATION ONGOING**
1602
+ * Reads variable's value from the target system by a variable path (such as `GVL_Test.ExampleStruct`)
1603
+ * and returns the value as a Javascript object.
1604
+ *
1605
+ * Returns variable's
1606
+ * - converted value
1607
+ * - raw value
1608
+ * - data type
1609
+ * - symbol
1361
1610
  *
1362
- * Reads a value by a variable path (such as `GVL_Test.ExampleStruct`) and converts the value to a Javascript object.
1611
+ * **NOTE:** This requires that the target is a PLC runtime or has equivalent ADS protocol support.
1363
1612
  *
1364
- * Returns the converted value, the raw value, the data type and the symbol.
1613
+ * @example
1614
+ * ```js
1615
+ * try {
1616
+ * const res = await client.readValue('GVL_Read.StandardTypes.INT_');
1617
+ * console.log(res.value);
1618
+ * } catch (err) {
1619
+ * console.log("Error:", err);
1620
+ * }
1621
+ * ```
1365
1622
  *
1366
- * @param path Variable path in the PLC to read (such as `GVL_Test.ExampleStruct`)
1623
+ * @param path Variable path in the PLC (such as `GVL_Test.ExampleStruct`)
1367
1624
  * @param targetOpts Optional target settings that override values in `settings`
1368
1625
  *
1369
1626
  * @template T In Typescript, the data type of the value, for example `readValue<number>(...)` or `readValue<ST_TypedStruct>(...)` (default: `any`)
1627
+ * @throws Throws an error if sending the command fails or if the target responds with an error.
1370
1628
  */
1371
1629
  readValue<T = any>(path: string, targetOpts?: Partial<AmsAddress>): Promise<ReadValueResult<T>>;
1372
1630
  /**
1373
- * **TODO - DOCUMENTATION ONGOING**
1631
+ * Reads variable's value from the target system by a symbol object (acquired using `getSymbol()`)
1632
+ * and returns the value as a Javascript object.
1374
1633
  *
1375
- * Reads a value by a symbol and converts the value to a Javascript object.
1634
+ * Returns variable's
1635
+ * - converted value
1636
+ * - raw value
1637
+ * - data type
1638
+ * - symbol
1376
1639
  *
1377
- * Returns the converted value, the raw value, the data type and the symbol.
1640
+ * **NOTE:** This requires that the target is a PLC runtime or has equivalent ADS protocol support.
1641
+ *
1642
+ * @example
1643
+ * ```js
1644
+ * try {
1645
+ * const symbol = await client.getSymbol('GVL_Read.StandardTypes.INT_');
1646
+ *
1647
+ * const res = await client.readValueBySymbol(symbol);
1648
+ * console.log(res.value);
1649
+ * } catch (err) {
1650
+ * console.log("Error:", err);
1651
+ * }
1652
+ * ```
1378
1653
  *
1379
- * @param symbol Symbol (acquired using `getSymbol()`)
1654
+ * @param symbol Symbol object
1380
1655
  * @param targetOpts Optional target settings that override values in `settings`
1381
1656
  *
1382
1657
  * @template T In Typescript, the data type of the value, for example `readValueBySymbol<number>(...)` or `readValueBySymbol<ST_TypedStruct>(...)` (default: `any`)
1658
+ * @throws Throws an error if sending the command fails or if the target responds with an error.
1383
1659
  */
1384
1660
  readValueBySymbol<T = any>(symbol: AdsSymbol, targetOpts?: Partial<AmsAddress>): Promise<ReadValueResult<T>>;
1385
1661
  /**
1386
- * **TODO - DOCUMENTATION ONGOING**
1662
+ * Writes variable's value to the target system by a variable path (such as `GVL_Test.ExampleStruct`).
1663
+ * Converts the value from a Javascript object to a raw value.
1387
1664
  *
1388
- * Writes a value by a variable path (such as `GVL_Test.ExampleStruct`). Converts the value from a Javascript object to a raw value.
1665
+ * Returns variable's
1666
+ * - converted value
1667
+ * - raw value
1668
+ * - data type
1669
+ * - symbol
1389
1670
  *
1390
- * Returns the converted value, the raw value, the data type and the symbol.
1671
+ * **NOTE:** Do not use `autoFill` for `UNION` types, it doesn't work correctly.
1391
1672
  *
1392
- * **NOTE:** Do not use `autoFill` for `UNION` types, it works without errors but the result isn't probably the desired one
1673
+ * **NOTE:** This requires that the target is a PLC runtime or has equivalent ADS protocol support.
1393
1674
  *
1394
- * @param path Variable path in the PLC to read (such as `GVL_Test.ExampleStruct`)
1675
+ * @example
1676
+ * ```js
1677
+ * try {
1678
+ * const value = {
1679
+ * example: true
1680
+ * };
1681
+ *
1682
+ * const res = await client.writeValue('GVL_Read.StandardTypes.INT_', value);
1683
+ * } catch (err) {
1684
+ * console.log("Error:", err);
1685
+ * }
1686
+ * ```
1687
+ *
1688
+ * @param path Variable path in the PLC (such as `GVL_Test.ExampleStruct`)
1395
1689
  * @param value Value to write
1396
1690
  * @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 `''`)
1691
+ * @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).
1398
1692
  *
1399
1693
  * @template T In Typescript, the data type of the value, for example `writeValue<number>(...)` or `writeValue<ST_TypedStruct>(...)`
1694
+ * @throws Throws an error if sending the command fails or if the target responds with an error.
1400
1695
  */
1401
1696
  writeValue<T = any>(path: string, value: T, autoFill?: boolean, targetOpts?: Partial<AmsAddress>): Promise<WriteValueResult<T>>;
1402
1697
  /**
1403
- * **TODO - DOCUMENTATION ONGOING**
1698
+ * Writes variable's value to the target system by a symbol object (acquired using `getSymbol()`).
1699
+ * Converts the value from a Javascript object to a raw value.
1700
+ *
1701
+ * Returns variable's
1702
+ * - converted value
1703
+ * - raw value
1704
+ * - data type
1705
+ * - symbol
1404
1706
  *
1405
- * Writes a value by symbol. Converts the value from a Javascript object to a raw value.
1707
+ * **NOTE:** Do not use `autoFill` for `UNION` types, it doesn't work correctly.
1406
1708
  *
1407
- * Returns the converted value, the raw value, the data type and the symbol.
1709
+ * **NOTE:** This requires that the target is a PLC runtime or has equivalent ADS protocol support.
1710
+ *
1711
+ * @example
1712
+ * ```js
1713
+ * try {
1714
+ * const symbol = await client.getSymbol('GVL_Read.StandardTypes.INT_');
1408
1715
  *
1409
- * **NOTE:** Do not use `autoFill` for `UNION` types, it works without errors but the result isn't probably the desired one
1716
+ * const res = await client.writeValueBySymbol(symbol, 32767);
1717
+ * } catch (err) {
1718
+ * console.log("Error:", err);
1719
+ * }
1720
+ * ```
1410
1721
  *
1411
- * @param symbol Symbol (acquired using `getSymbol()`)
1722
+ * @param symbol Symbol object
1412
1723
  * @param value Value to write
1413
1724
  * @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 `''`)
1725
+ * @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).
1415
1726
  *
1416
1727
  * @template T In Typescript, the data type of the value, for example `writeValue<number>(...)` or `writeValue<ST_TypedStruct>(...)`
1728
+ * @throws Throws an error if sending the command fails or if the target responds with an error.
1417
1729
  */
1418
1730
  writeValueBySymbol<T = any>(symbol: AdsSymbol, value: T, autoFill?: boolean, targetOpts?: Partial<AmsAddress>): Promise<WriteValueResult<T>>;
1419
1731
  /**
1420
- * **TODO - DOCUMENTATION ONGOING**
1421
- *
1422
1732
  * Returns a default (empty) Javascript object representing provided PLC data type.
1423
1733
  *
1424
- * @param dataType Data type name in the PLC as string (such as `ST_Struct`) or `AdsDataType` object
1734
+ * @example
1735
+ * ```js
1736
+ * try {
1737
+ * const res = await client.getDefaultPlcObject('INT');
1738
+ * console.log(res); //0
1739
+
1740
+ * const res2 = await client.getDefaultPlcObject('Tc2_Standard.TON');
1741
+ * console.log(res2); //{ IN: false, PT: 0, Q: false, ET: 0, M: false, StartTime: 0 }
1742
+ *
1743
+ * } catch (err) {
1744
+ * console.log("Error:", err);
1745
+ * }
1746
+ * ```
1747
+ *
1748
+ * @param dataType Data type name in the PLC as string (such as `ST_Struct`) or data type object (acquired using {@link getDataType}())
1425
1749
  * @param targetOpts Optional target settings that override values in `settings`
1426
1750
  *
1427
- * @template T Typescript data type of the PLC data, for example `readValue<number>(...)` or `readValue<ST_TypedStruct>(...)`
1751
+ * @template T Typescript data type of the PLC data, for example `getDefaultPlcObject<number>(...)` or `getDefaultPlcObject<ST_TypedStruct>(...)`
1752
+ * @throws Throws an error if sending the command fails or if the target responds with an error.
1428
1753
  */
1429
1754
  getDefaultPlcObject<T = any>(dataType: string | AdsDataType, targetOpts?: Partial<AmsAddress>): Promise<T>;
1430
1755
  /**
1431
- * **TODO - DOCUMENTATION ONGOING**
1756
+ * Converts raw data to a Javascript object by using the provided data type.
1757
+ *
1758
+ * @example
1759
+ * ```js
1760
+ * try {
1761
+ * const data = await client.readRaw(16448, 414816, 2);
1762
+ * console.log(data); //<Buffer ff 7f>
1432
1763
  *
1433
- * Converts a raw byte value to a Javascript object.
1764
+ * const converted = await client.convertFromRaw(data, 'INT');
1765
+ * console.log(converted); //32767
1434
1766
  *
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
1767
+ * } catch (err) {
1768
+ * console.log("Error:", err);
1769
+ * }
1770
+ * ```
1771
+ *
1772
+ * @param data Raw data (acquired for example using {@link readRaw}())
1773
+ * @param dataType Data type name in the PLC as string (such as `ST_Struct`) or data type object (acquired using {@link getDataType}())
1437
1774
  * @param targetOpts Optional target settings that override values in `settings`
1438
1775
  *
1439
1776
  * @template T Typescript data type of the PLC data, for example `convertFromRaw<number>(...)` or `convertFromRaw<ST_TypedStruct>(...)`
1777
+ * @throws Throws an error if sending the command fails or if the target responds with an error.
1440
1778
  */
1441
1779
  convertFromRaw<T = any>(data: Buffer, dataType: string | AdsDataType, targetOpts?: Partial<AmsAddress>): Promise<T>;
1442
1780
  /**
1443
- * **TODO - DOCUMENTATION ONGOING**
1781
+ * Converts a Javascript object to raw data by using the provided data type.
1444
1782
  *
1445
- * Converts a Javascript object to raw byte data.
1783
+ * **NOTE:** Do not use `autoFill` for `UNION` types, it doesn't work correctly.
1784
+
1785
+ * @example
1786
+ * ```js
1787
+ * try {
1788
+ * const data = await client.convertToRaw(32767, 'INT');
1789
+ * console.log(data); //<Buffer ff 7f>
1446
1790
  *
1447
- * **NOTE:** Do not use `autoFill` for `UNION` types, it works without errors but the result isn't probably the desired one
1791
+ * } catch (err) {
1792
+ * console.log("Error:", err);
1793
+ * }
1794
+ * ```
1448
1795
  *
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 `''`)
1796
+ * @param value Value to convert
1797
+ * @param dataType Data type name in the PLC as string (such as `ST_Struct`) or data type object (acquired using {@link getDataType}())
1798
+ * @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).
1452
1799
  * @param targetOpts Optional target settings that override values in `settings`
1453
1800
  *
1454
- * @template T Typescript data type of the PLC data, for example `convertFromRaw<number>(...)` or `convertFromRaw<ST_TypedStruct>(...)`
1801
+ * @throws Throws an error if sending the command fails or if the target responds with an error.
1455
1802
  */
1456
1803
  convertToRaw(value: any, dataType: string | AdsDataType, autoFill?: boolean, targetOpts?: Partial<AmsAddress>): Promise<Buffer>;
1457
1804
  /**
1458
- * **TODO - DOCUMENTATION ONGOING**
1805
+ * Creates a handle to a variable at the target system by variable path (such as `GVL_Test.ExampleStruct`).
1459
1806
  *
1460
- * Creates a variable handle for a PLC symbol by given variable path
1807
+ * The handle can be then used for reading and writing the value.
1461
1808
  *
1462
- * Variable value can be accessed by using the handle with `readRawByHandle()` and `writeRawByHandle()`
1809
+ * Reading and writing dereferenced `POINTER` and `REFERENCE` values is also possible.
1810
+ * See {@link readRawByHandle}() and {@link writeRawByHandle}().
1463
1811
  *
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)
1812
+ * NOTE: The handle should be deleted after it's no longer needed,
1813
+ * as there is a limited amount of handles available. See {@link deleteVariableHandle}().
1814
+ *
1815
+ * @example
1816
+ * ```js
1817
+ * try {
1818
+ * //POINTER value (Note the dereference operator ^)
1819
+ * const handle1 = await client.createVariableHandle('GVL_Read.ComplexTypes.POINTER_^');
1820
+ * const value = await client.readRawByHandle(handle1);
1821
+ * await client.deleteVariableHandle(handle1);
1822
+ *
1823
+ * const handle2 = await client.createVariableHandle('GVL_Read.StandardTypes.INT_');
1824
+ * const value2 = await client.readRawByHandle(handle2);
1825
+ * await client.deleteVariableHandle(handle2);
1826
+ *
1827
+ * //Now you use convertFromRaw() to get actual values
1828
+ *
1829
+ * } catch (err) {
1830
+ * console.log("Error:", err);
1831
+ * }
1832
+ * ```
1833
+ *
1834
+ * @param path Variable path in the PLC to read (such as `GVL_Test.ExampleStruct`)
1835
+ * @param targetOpts Optional target settings that override values in `settings`
1836
+ *
1837
+ * @throws Throws an error if sending the command fails or if the target responds with an error.
1466
1838
  */
1467
1839
  createVariableHandle(path: string, targetOpts?: Partial<AmsAddress>): Promise<VariableHandle>;
1468
1840
  /**
1469
- * **TODO - DOCUMENTATION ONGOING**
1841
+ * Sends multiple {@link createVariableHandle}() commands in one ADS packet.
1842
+ *
1843
+ * Creates a handle to a variable at the target system by variable path (such as `GVL_Test.ExampleStruct`).
1844
+ *
1845
+ * The handle can be then used for reading and writing the value.
1846
+ *
1847
+ * Reading and writing dereferenced `POINTER` and `REFERENCE` values is also possible.
1848
+ * See {@link readRawByHandle}() and {@link writeRawByHandle}().
1470
1849
  *
1471
- * Sends multiple createVariableHandle() commands in one ADS packet
1850
+ * NOTE: The handle should be deleted after it's no longer needed,
1851
+ * as there is a limited amount of handles available. See {@link deleteVariableHandle}().
1472
1852
  *
1473
- * Creates a variable handle for a PLC symbol by given variable path
1853
+ * Uses ADS sum command under the hood (better and faster performance).
1854
+ * See [Beckhoff Information System](https://infosys.beckhoff.com/english.php?content=../content/1033/tc3_adsdll2/9007199379576075.html&id=9180083787138954512) for more info.
1474
1855
  *
1475
- * Variable value can be accessed by using the handle with `readRawByHandle()` and `writeRawByHandle()`
1856
+ * @example
1857
+ * ```js
1858
+ * try {
1859
+ * const results = await client.createVariableHandleMulti([
1860
+ * 'GVL_Read.StandardTypes.INT_',
1861
+ * 'GVL_Read.StandardTypes.REAL_'
1862
+ * ]);
1476
1863
  *
1477
- * Uses ADS sum command under the hood (better perfomance)
1864
+ * if(results[0].success) {
1865
+ * console.log(`First handle: ${results[0].handle}`);
1866
+ * } else {
1867
+ * console.log(`Creating first handle failed: ${results[0].errorStr}`);
1868
+ * }
1478
1869
  *
1479
- * @param paths Array of full variable paths in the PLC (such as `GVL_Test.ExampleStruct`)
1870
+ * } catch (err) {
1871
+ * console.log("Error:", err);
1872
+ * }
1873
+ * ```
1874
+ *
1875
+ * @param paths Array of variable paths in the PLC to read (such as `GVL_Test.ExampleStruct`)
1480
1876
  * @param targetOpts Optional target settings that override values in `settings`
1877
+ *
1878
+ * @throws Throws an error if sending the command fails or if the target responds with an error.
1481
1879
  */
1482
1880
  createVariableHandleMulti(paths: string[], targetOpts?: Partial<AmsAddress>): Promise<CreateVariableHandleMultiResult[]>;
1483
1881
  /**
1484
- * **TODO - DOCUMENTATION ONGOING**
1882
+ * Deletes a variable handle that was previously created
1883
+ * using {@link createVariableHandle}().
1884
+ *
1885
+ * @example
1886
+ * ```js
1887
+ * try {
1888
+ * const handle = createVariableHandle(...);
1485
1889
  *
1486
- * Deletes a variable handle that was previously created using `createVariableHandle()`
1890
+ * //After use, deleting the handle
1891
+ * await client.deleteVariableHandle(handle);
1892
+ *
1893
+ * } catch (err) {
1894
+ * console.log("Error:", err);
1895
+ * }
1896
+ * ```
1487
1897
  *
1488
1898
  * @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)
1899
+ * @param targetOpts Optional target settings that override values in `settings`
1900
+ *
1901
+ * @throws Throws an error if sending the command fails or if the target responds with an error.
1490
1902
  */
1491
1903
  deleteVariableHandle(handle: VariableHandle | number, targetOpts?: Partial<AmsAddress>): Promise<void>;
1492
1904
  /**
1493
- * **TODO - DOCUMENTATION ONGOING**
1905
+ * Sends multiple {@link deleteVariableHandle}() commands in one ADS packet.
1906
+ *
1907
+ * Deletes a variable handle that was previously created
1908
+ * using {@link createVariableHandle}().
1494
1909
  *
1495
- * Sends multiple deleteVariableHandle() commands in one ADS packet
1910
+ * Uses ADS sum command under the hood (better and faster performance).
1911
+ * See [Beckhoff Information System](https://infosys.beckhoff.com/english.php?content=../content/1033/tc3_adsdll2/9007199379576075.html&id=9180083787138954512) for more info.
1496
1912
  *
1497
- * Deletes a variable handle that was previously created using `createVariableHandle()`
1913
+ * @example
1914
+ * ```js
1915
+ * try {
1916
+ * const handle1 = createVariableHandle(...);
1917
+ * const handle2 = createVariableHandle(...);
1918
+ *
1919
+ * //After use, deleting the handles
1920
+ * const results = await client.deleteVariableHandleMulti([handle1, handle2]);
1921
+ *
1922
+ * if(results[0].success) {
1923
+ * console.log(`First deleted`);
1924
+ * } else {
1925
+ * console.log(`Deleting first handle failed: ${results[0].errorStr}`);
1926
+ * }
1498
1927
  *
1499
- * Uses ADS sum command under the hood (better performance)
1928
+ * } catch (err) {
1929
+ * console.log("Error:", err);
1930
+ * }
1931
+ * ```
1500
1932
  *
1501
1933
  * @param handles Array of variable handles to delete
1502
1934
  * @param targetOpts Optional target settings that override values in `settings`
1935
+ *
1936
+ * @throws Throws an error if sending the command fails or if the target responds with an error.
1503
1937
  */
1504
1938
  deleteVariableHandleMulti(handles: (VariableHandle | number)[], targetOpts?: Partial<AmsAddress>): Promise<DeleteVariableHandleMultiResult[]>;
1505
1939
  /**
1506
- * **TODO - DOCUMENTATION ONGOING**
1940
+ * Reads raw data from the target system by a previously created variable handle (acquired using {@link createVariableHandle}())
1507
1941
  *
1508
- * Reads raw byte data from the target system by previously created variable handle
1942
+ * @example
1943
+ * ```js
1944
+ * try {
1945
+ * const handle = await client.createVariableHandle('GVL_Read.StandardTypes.INT_'');
1946
+ * const value = await client.readRawByHandle(handle);
1947
+ * await client.deleteVariableHandle(handle);
1509
1948
  *
1949
+ * } catch (err) {
1950
+ * console.log("Error:", err);
1951
+ * }
1952
+ * ```
1510
1953
  * @param handle Variable handle
1511
1954
  * @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)
1955
+ * @param targetOpts Optional target settings that override values in `settings`
1956
+ *
1957
+ * @throws Throws an error if sending the command fails or if the target responds with an error.
1513
1958
  */
1514
1959
  readRawByHandle(handle: VariableHandle | number, size?: number, targetOpts?: Partial<AmsAddress>): Promise<Buffer>;
1515
1960
  /**
1516
- * **TODO - DOCUMENTATION ONGOING**
1961
+ * Writes raw data to the target system by a previously created variable handle (acquired using {@link createVariableHandle}())
1962
+ *
1963
+ * @example
1964
+ * ```js
1965
+ * try {
1966
+ * const value = await client.convertToRaw(32767, 'INT');
1967
+ * console.log(value); //<Buffer ff 7f>
1517
1968
  *
1518
- * Writes raw byte data to the target system by previously created variable handle
1969
+ * const handle = await client.createVariableHandle('GVL_Read.StandardTypes.INT_');
1970
+ * await client.writeRawByHandle(handle, value);
1971
+ * await client.deleteVariableHandle(handle);
1972
+ *
1973
+ * } catch (err) {
1974
+ * console.log("Error:", err);
1975
+ * }
1976
+ * ```
1519
1977
  *
1520
1978
  * @param handle Variable handle
1521
1979
  * @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)
1980
+ * @param targetOpts Optional target settings that override values in `settings`
1981
+ *
1982
+ * @throws Throws an error if sending the command fails or if the target responds with an error.
1523
1983
  */
1524
1984
  writeRawByHandle(handle: VariableHandle | number, value: Buffer, targetOpts?: Partial<AmsAddress>): Promise<void>;
1525
1985
  /**
1526
- * **TODO - DOCUMENTATION ONGOING**
1986
+ * Reads raw data from the target system by a symbol object (acquired using `getSymbol()`)
1527
1987
  *
1528
- * Reads raw data by symbol
1988
+ * @example
1989
+ * ```js
1990
+ * try {
1991
+ * const symbol = await client.getSymbol('GVL_Read.StandardTypes.INT_');
1992
+ * const value = await client.readRawBySymbol(symbol);
1529
1993
  *
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)
1994
+ * } catch (err) {
1995
+ * console.log("Error:", err);
1996
+ * }
1997
+ * ```
1998
+ *
1999
+ * @param symbol Symbol
2000
+ * @param targetOpts Optional target settings that override values in `settings`
2001
+ *
2002
+ * @throws Throws an error if sending the command fails or if the target responds with an error.
1532
2003
  */
1533
2004
  readRawBySymbol(symbol: AdsSymbol, targetOpts?: Partial<AmsAddress>): Promise<Buffer>;
1534
2005
  /**
1535
- * **TODO - DOCUMENTATION ONGOING**
2006
+ * Writes raw data to the target system by a symbol object (acquired using `getSymbol()`)
1536
2007
  *
1537
- * Writes raw data by symbol
2008
+ * @example
2009
+ * ```js
2010
+ * try {
2011
+ * const value = await client.convertToRaw(32767, 'INT');
2012
+ * console.log(value); //<Buffer ff 7f>
1538
2013
  *
1539
- * @param symbol Symbol (acquired using `getSymbol()`)
2014
+ * const symbol = await client.getSymbol('GVL_Read.StandardTypes.INT_');
2015
+ * await client.writeRawBySymbol(symbol, value);
2016
+ *
2017
+ * } catch (err) {
2018
+ * console.log("Error:", err);
2019
+ * }
2020
+ * ```
2021
+ *
2022
+ * @param symbol Symbol
1540
2023
  * @param value Data to write
1541
2024
  * @param targetOpts Optional target settings that override values in `settings`
2025
+ *
2026
+ * @throws Throws an error if sending the command fails or if the target responds with an error.
1542
2027
  */
1543
2028
  writeRawBySymbol(symbol: AdsSymbol, value: Buffer, targetOpts?: Partial<AmsAddress>): Promise<void>;
1544
2029
  /**
1545
- * **TODO - DOCUMENTATION ONGOING**
2030
+ * Invokes a function block RPC method on the target system.
1546
2031
  *
1547
- * Invokes/calls a function block RPC method from PLC
2032
+ * Returns the return value of the method and outputs (if any).
1548
2033
  *
1549
- * Returns method return value and/or outputs (if any)
2034
+ * NOTE: In the PLC, `{attribute 'TcRpcEnable'}` is required above the `METHOD` definition.
1550
2035
  *
1551
- * For RPC support, the method needs to have `{attribute 'TcRpcEnable'}` attribute above the `METHOD` definition
2036
+ * @example
2037
+ * ```js
2038
+ * try {
2039
+ * const res = await client.invokeRpcMethod('GVL_RPC.RpcBlock', 'Calculator', {
2040
+ * Value1: 1,
2041
+ * Value2: 123
2042
+ * });
2043
+ *
2044
+ * console.log(res);
2045
+ * //{
2046
+ * // returnValue: true,
2047
+ * // outputs: { Sum: 124, Product: 123, Division: 0.008130080997943878 }
2048
+ * //}
1552
2049
  *
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)
2050
+ * } catch (err) {
2051
+ * console.log("Error:", err);
2052
+ * }
2053
+ * ```
2054
+ *
2055
+ * @param path Variable path in the PLC of the function block instance (such as `GVL_Test.ExampleBlock`)
2056
+ * @param method Function block method name
2057
+ * @param parameters Method parameters (inputs) (if any)
1556
2058
  * @param targetOpts Optional target settings that override values in `settings`
1557
2059
  *
1558
2060
  * @template T Typescript data type of the method return value, for example `invokeRpcMethod<number>(...)` or `invokeRpcMethod<ST_TypedStruct>(...)`
1559
2061
  * @template U Typescript data type of the method outputs object, for example `invokeRpcMethod<number, ST_TypedStruct>(...)`
2062
+ *
2063
+ * @throws Throws an error if sending the command fails or if the target responds with an error.
1560
2064
  */
1561
2065
  invokeRpcMethod<T = any, U = Record<string, any>>(path: string, method: string, parameters?: Record<string, any>, targetOpts?: Partial<AmsAddress>): Promise<RpcMethodCallResult<T, U>>;
1562
2066
  }