ads-client 2.0.0-beta.1 → 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.
- package/CHANGELOG.md +14 -0
- package/README.md +283 -255
- package/dist/ads-client.d.ts +360 -67
- package/dist/ads-client.js +434 -115
- package/dist/ads-client.js.map +1 -1
- package/dist/types/ads-client-types.d.ts +200 -17
- package/dist/types/ads-client-types.js.map +1 -1
- package/dist/types/ads-protocol-types.d.ts +75 -1
- package/dist/types/ads-protocol-types.js.map +1 -1
- package/package.json +4 -3
package/dist/ads-client.d.ts
CHANGED
|
@@ -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
|
-
|
|
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
|
|
15
|
-
* can also be used to communicate with
|
|
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
|
-
*
|
|
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<
|
|
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
|
-
*
|
|
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.
|
|
@@ -903,13 +949,13 @@ export declare class Client extends EventEmitter<ClientEvents> {
|
|
|
903
949
|
*/
|
|
904
950
|
readPlcSymbolVersion(targetOpts?: Partial<AmsAddress>): Promise<number>;
|
|
905
951
|
/**
|
|
906
|
-
* Subscribes to
|
|
952
|
+
* Subscribes to value change notifications (ADS notifications) by a variable path,
|
|
907
953
|
* such as `GVL_Test.ExampleStruct`.
|
|
908
954
|
*
|
|
909
955
|
* Provided callback is called with the latest value of the symbol when the value changes or when
|
|
910
956
|
* enough time has passed (depending on settings).
|
|
911
957
|
*
|
|
912
|
-
*
|
|
958
|
+
* Check also `subscribe()` instead, this is just a wrapper for it.
|
|
913
959
|
*
|
|
914
960
|
* **NOTE:** This requires that the target is a PLC runtime or has equivalent ADS protocol support.
|
|
915
961
|
*
|
|
@@ -917,7 +963,7 @@ export declare class Client extends EventEmitter<ClientEvents> {
|
|
|
917
963
|
* ```js
|
|
918
964
|
* //Checks if value has changed every 100ms
|
|
919
965
|
* //Callback is called only when the value has changed
|
|
920
|
-
* await client.
|
|
966
|
+
* await client.subscribeValue(
|
|
921
967
|
* 'GVL_Test.ExampleStruct.',
|
|
922
968
|
* (data, subscription) => {
|
|
923
969
|
* console.log(`Value of ${subscription.symbol.name} has changed: ${data.value}`);
|
|
@@ -956,17 +1002,17 @@ export declare class Client extends EventEmitter<ClientEvents> {
|
|
|
956
1002
|
*
|
|
957
1003
|
* @throws Throws an error if sending the command fails or if the target responds with an error.
|
|
958
1004
|
*
|
|
959
|
-
* @template T In Typescript, the data type of the value, for example `
|
|
1005
|
+
* @template T In Typescript, the data type of the value, for example `subscribeValue<number>(...)` or `subscribeValue<ST_TypedStruct>(...)`. (default: `any`)
|
|
960
1006
|
*
|
|
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).
|
|
968
1014
|
*
|
|
969
|
-
*
|
|
1015
|
+
* Check also `subscribe()` instead, this is just a wrapper for it.
|
|
970
1016
|
*
|
|
971
1017
|
* **NOTE:** This requires that the target is a PLC runtime or has equivalent ADS protocol support.
|
|
972
1018
|
*
|
|
@@ -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,148 +1310,384 @@ export declare class Client extends EventEmitter<ClientEvents> {
|
|
|
1253
1310
|
*/
|
|
1254
1311
|
cacheDataTypes(): Promise<void>;
|
|
1255
1312
|
/**
|
|
1256
|
-
*
|
|
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.
|
|
1257
1316
|
*
|
|
1258
|
-
*
|
|
1317
|
+
* @example
|
|
1318
|
+
* ```js
|
|
1319
|
+
* try {
|
|
1320
|
+
* const data = await client.readRaw(16448, 414816, 2);
|
|
1321
|
+
* console.log(data); //<Buffer ff 7f>
|
|
1259
1322
|
*
|
|
1260
|
-
*
|
|
1323
|
+
* const converted = await client.convertFromRaw(data, 'INT');
|
|
1324
|
+
* console.log(converted); //32767
|
|
1325
|
+
*
|
|
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
|
-
*
|
|
1340
|
+
* Writes raw data to the target system by a raw ADS address (index group, index offset and data length).
|
|
1270
1341
|
*
|
|
1271
|
-
*
|
|
1342
|
+
* This is the ADS protocol `Write` command.
|
|
1343
|
+
*
|
|
1344
|
+
* @example
|
|
1345
|
+
* ```js
|
|
1346
|
+
* try {
|
|
1347
|
+
* const data = await client.convertToRaw(32767, 'INT');
|
|
1348
|
+
* console.log(data); //<Buffer ff 7f>
|
|
1272
1349
|
*
|
|
1273
|
-
*
|
|
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
|
-
*
|
|
1365
|
+
* Sends multiple `readRaw()` commands in one ADS packet.
|
|
1283
1366
|
*
|
|
1284
|
-
*
|
|
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.
|
|
1285
1369
|
*
|
|
1286
|
-
*
|
|
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.
|
|
1287
1372
|
*
|
|
1288
|
-
*
|
|
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
|
+
* }
|
|
1394
|
+
*
|
|
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
|
-
*
|
|
1407
|
+
* Sends multiple `writeRaw()` commands in one ADS packet.
|
|
1296
1408
|
*
|
|
1297
|
-
*
|
|
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.
|
|
1298
1411
|
*
|
|
1299
|
-
*
|
|
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.
|
|
1300
1414
|
*
|
|
1301
|
-
*
|
|
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
|
+
* }
|
|
1441
|
+
*
|
|
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
|
-
*
|
|
1454
|
+
* Reads raw data from the target system by variable path (such as `GVL_Test.ExampleStruct`).
|
|
1455
|
+
*
|
|
1456
|
+
* Supports also reading `POINTER` and `REFERENCE` values (see example).
|
|
1457
|
+
*
|
|
1458
|
+
* This uses the ADS `READ_SYMVAL_BYNAME` under the hood, so only one
|
|
1459
|
+
* round-trip is needed.
|
|
1460
|
+
*
|
|
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
|
|
1309
1469
|
*
|
|
1310
|
-
*
|
|
1470
|
+
* //Reading a POINTER value (Note the dereference operator ^)
|
|
1471
|
+
* const ptrValue = await client.readRawByPath('GVL_Read.ComplexTypes.POINTER_^');
|
|
1311
1472
|
*
|
|
1312
|
-
*
|
|
1473
|
+
* //Reading a REFERENCE value
|
|
1474
|
+
* const refValue = await client.readRawByPath('GVL_Read.ComplexTypes.REFERENCE_');
|
|
1313
1475
|
*
|
|
1314
|
-
*
|
|
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
|
-
*
|
|
1488
|
+
* Writes raw data to the target system by variable path (such as `GVL_Test.ExampleStruct`).
|
|
1322
1489
|
*
|
|
1323
|
-
*
|
|
1490
|
+
* Supports also writing `POINTER` and `REFERENCE` values (see example).
|
|
1324
1491
|
*
|
|
1325
|
-
*
|
|
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.
|
|
1328
1494
|
*
|
|
1329
|
-
* @
|
|
1495
|
+
* @example
|
|
1496
|
+
* ```js
|
|
1497
|
+
* try {
|
|
1498
|
+
* const data = await client.convertToRaw(32767, 'INT');
|
|
1499
|
+
* console.log(data); //<Buffer ff 7f>
|
|
1500
|
+
*
|
|
1501
|
+
* await client.writeRawByPath('GVL_Write.StandardTypes.INT_', data);
|
|
1502
|
+
*
|
|
1503
|
+
* //Writing a POINTER value (Note the dereference operator ^)
|
|
1504
|
+
* const ptrValue = ...
|
|
1505
|
+
* await client.writeRawByPath('GVL_Read.ComplexTypes.POINTER_^', ptrValue);
|
|
1506
|
+
*
|
|
1507
|
+
* //Writing a REFERENCE value
|
|
1508
|
+
* const refValue = ...
|
|
1509
|
+
* await client.readRawByPath('GVL_Read.ComplexTypes.REFERENCE_');
|
|
1510
|
+
*
|
|
1511
|
+
* } catch (err) {
|
|
1512
|
+
* console.log("Error:", err);
|
|
1513
|
+
* }
|
|
1514
|
+
* ```
|
|
1515
|
+
*
|
|
1516
|
+
* @param path Variable path in the PLC to write (such as `GVL_Test.ExampleStruct`)
|
|
1330
1517
|
* @param value Data to write
|
|
1331
1518
|
* @param targetOpts Optional target settings that override values in `settings`
|
|
1519
|
+
*
|
|
1520
|
+
* @throws Throws an error if sending the command fails or if the target responds with an error.
|
|
1332
1521
|
*/
|
|
1333
1522
|
writeRawByPath(path: string, value: Buffer, targetOpts?: Partial<AmsAddress>): Promise<void>;
|
|
1334
1523
|
/**
|
|
1335
|
-
*
|
|
1524
|
+
* Writes raw data to the target system by a raw ADS address (index group, index offset)
|
|
1525
|
+
* and reads the result as raw data.
|
|
1336
1526
|
*
|
|
1337
|
-
*
|
|
1527
|
+
* This is the ADS protocol `ReadWrite` command.
|
|
1338
1528
|
*
|
|
1339
|
-
*
|
|
1529
|
+
* @example
|
|
1530
|
+
* ```js
|
|
1531
|
+
* const { ADS } = require('../dist/ads-client');
|
|
1532
|
+
*
|
|
1533
|
+
* try {
|
|
1534
|
+
* //Reading raw value by symbol path (= same as readRawByPath())
|
|
1535
|
+
* const path = ADS.encodeStringToPlcStringBuffer('GVL_Read.StandardTypes.INT_');
|
|
1536
|
+
* const data = await client.readWriteRaw(ADS.ADS_RESERVED_INDEX_GROUPS.SymbolValueByName, 0, 0xFFFFFFFF, path);
|
|
1537
|
+
* console.log(data); //<Buffer ff 7f>
|
|
1538
|
+
*
|
|
1539
|
+
* } catch (err) {
|
|
1540
|
+
* console.log("Error:", err);
|
|
1541
|
+
* }
|
|
1542
|
+
* ```
|
|
1340
1543
|
*
|
|
1341
1544
|
* @param indexGroup Address index group
|
|
1342
1545
|
* @param indexOffset Address index offset
|
|
1343
|
-
* @param size
|
|
1344
|
-
* @param
|
|
1546
|
+
* @param size Data length to read (bytes)
|
|
1547
|
+
* @param value Value to write
|
|
1345
1548
|
* @param targetOpts Optional target settings that override values in `settings`
|
|
1549
|
+
*
|
|
1550
|
+
* @throws Throws an error if sending the command fails or if the target responds with an error.
|
|
1346
1551
|
*/
|
|
1347
|
-
readWriteRaw(indexGroup: number, indexOffset: number, size: number,
|
|
1552
|
+
readWriteRaw(indexGroup: number, indexOffset: number, size: number, value: Buffer, targetOpts?: Partial<AmsAddress>): Promise<Buffer>;
|
|
1348
1553
|
/**
|
|
1349
|
-
*
|
|
1554
|
+
* Sends multiple `readWriteRaw()` commands in one ADS packet.
|
|
1350
1555
|
*
|
|
1351
|
-
*
|
|
1556
|
+
* Writes raw data to the target system by a raw ADS address (index group, index offset)
|
|
1557
|
+
* and reads the result as raw data.
|
|
1352
1558
|
*
|
|
1353
|
-
* Uses ADS sum command under the hood (better performance)
|
|
1559
|
+
* Uses ADS sum command under the hood (better and faster performance).
|
|
1560
|
+
* See [Beckhoff Information System](https://infosys.beckhoff.com/english.php?content=../content/1033/tc3_adsdll2/9007199379576075.html&id=9180083787138954512) for more info.
|
|
1561
|
+
*
|
|
1562
|
+
* @example
|
|
1563
|
+
* ```js
|
|
1564
|
+
* try {
|
|
1565
|
+
* //Reading raw values by symbol paths (= same as readRawByPath())
|
|
1566
|
+
* const path = ADS.encodeStringToPlcStringBuffer('GVL_Read.StandardTypes.INT_');
|
|
1567
|
+
* const path2 = ADS.encodeStringToPlcStringBuffer('GVL_Read.StandardTypes.REAL_');
|
|
1568
|
+
*
|
|
1569
|
+
* const results = await client.readWriteRawMulti([
|
|
1570
|
+
* {
|
|
1571
|
+
* indexGroup: ADS.ADS_RESERVED_INDEX_GROUPS.SymbolValueByName,
|
|
1572
|
+
* indexOffset: 0,
|
|
1573
|
+
* size: 0xFFFF,
|
|
1574
|
+
* value: path
|
|
1575
|
+
* },
|
|
1576
|
+
* {
|
|
1577
|
+
* indexGroup: ADS.ADS_RESERVED_INDEX_GROUPS.SymbolValueByName,
|
|
1578
|
+
* indexOffset: 0,
|
|
1579
|
+
* size: 0xFFFF,
|
|
1580
|
+
* value: path2
|
|
1581
|
+
* }
|
|
1582
|
+
* ]);
|
|
1583
|
+
*
|
|
1584
|
+
* if(results[0].success) {
|
|
1585
|
+
* console.log(`First result: ${results[0].value}`); //First result: <Buffer ff 7f>
|
|
1586
|
+
* } else {
|
|
1587
|
+
* console.log(`First read/write command failed: ${results[0].errorStr}`);
|
|
1588
|
+
* }
|
|
1589
|
+
*
|
|
1590
|
+
* } catch (err) {
|
|
1591
|
+
* console.log("Error:", err);
|
|
1592
|
+
* }
|
|
1354
1593
|
*
|
|
1355
|
-
*
|
|
1594
|
+
* ```
|
|
1595
|
+
*
|
|
1596
|
+
* @param commands Array of read/write commands
|
|
1356
1597
|
* @param targetOpts Optional target settings that override values in `settings`
|
|
1598
|
+
*
|
|
1599
|
+
* @throws Throws an error if sending the command fails or if the target responds with an error.
|
|
1357
1600
|
*/
|
|
1358
1601
|
readWriteRawMulti(commands: ReadWriteRawMultiCommand[], targetOpts?: Partial<AmsAddress>): Promise<ReadWriteRawMultiResult[]>;
|
|
1359
1602
|
/**
|
|
1360
|
-
*
|
|
1603
|
+
* Reads variable's value from the target system by a variable path (such as `GVL_Test.ExampleStruct`)
|
|
1604
|
+
* and returns the value as a Javascript object.
|
|
1361
1605
|
*
|
|
1362
|
-
*
|
|
1606
|
+
* Returns variable's
|
|
1607
|
+
* - converted value
|
|
1608
|
+
* - raw value
|
|
1609
|
+
* - data type
|
|
1610
|
+
* - symbol
|
|
1363
1611
|
*
|
|
1364
|
-
*
|
|
1612
|
+
* **NOTE:** This requires that the target is a PLC runtime or has equivalent ADS protocol support.
|
|
1365
1613
|
*
|
|
1366
|
-
* @
|
|
1614
|
+
* @example
|
|
1615
|
+
* ```js
|
|
1616
|
+
* try {
|
|
1617
|
+
* const res = await client.readValue('GVL_Test.ExampleStruct');
|
|
1618
|
+
* console.log(res.value);
|
|
1619
|
+
* } catch (err) {
|
|
1620
|
+
* console.log("Error:", err);
|
|
1621
|
+
* }
|
|
1622
|
+
* ```
|
|
1623
|
+
*
|
|
1624
|
+
* @param path Variable path in the PLC (such as `GVL_Test.ExampleStruct`)
|
|
1367
1625
|
* @param targetOpts Optional target settings that override values in `settings`
|
|
1368
1626
|
*
|
|
1369
1627
|
* @template T In Typescript, the data type of the value, for example `readValue<number>(...)` or `readValue<ST_TypedStruct>(...)` (default: `any`)
|
|
1370
1628
|
*/
|
|
1371
1629
|
readValue<T = any>(path: string, targetOpts?: Partial<AmsAddress>): Promise<ReadValueResult<T>>;
|
|
1372
1630
|
/**
|
|
1373
|
-
*
|
|
1631
|
+
* Reads variable's value from the target system by a symbol object
|
|
1632
|
+
* and returns the value as a Javascript object.
|
|
1374
1633
|
*
|
|
1375
|
-
*
|
|
1634
|
+
* Returns variable's
|
|
1635
|
+
* - converted value
|
|
1636
|
+
* - raw value
|
|
1637
|
+
* - data type
|
|
1638
|
+
* - symbol
|
|
1376
1639
|
*
|
|
1377
|
-
*
|
|
1640
|
+
* **NOTE:** This requires that the target is a PLC runtime or has equivalent ADS protocol support.
|
|
1378
1641
|
*
|
|
1379
|
-
* @
|
|
1642
|
+
* @example
|
|
1643
|
+
* ```js
|
|
1644
|
+
* try {
|
|
1645
|
+
* const symbol = await client.getSymbol('GVL_Test.ExampleStruct');
|
|
1646
|
+
*
|
|
1647
|
+
* const res = await client.readValueBySymbol(symbol);
|
|
1648
|
+
* console.log(res.value);
|
|
1649
|
+
* } catch (err) {
|
|
1650
|
+
* console.log("Error:", err);
|
|
1651
|
+
* }
|
|
1652
|
+
* ```
|
|
1653
|
+
*
|
|
1654
|
+
* @param symbol Symbol object (acquired using {@link getSymbol}())
|
|
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`)
|
|
1383
1658
|
*/
|
|
1384
1659
|
readValueBySymbol<T = any>(symbol: AdsSymbol, targetOpts?: Partial<AmsAddress>): Promise<ReadValueResult<T>>;
|
|
1385
1660
|
/**
|
|
1386
|
-
*
|
|
1661
|
+
* Writes variable's value to the target system by a variable path (such as `GVL_Test.ExampleStruct`).
|
|
1662
|
+
* Converts the value from a Javascript object to a raw value.
|
|
1387
1663
|
*
|
|
1388
|
-
*
|
|
1664
|
+
* Returns variable's
|
|
1665
|
+
* - converted value
|
|
1666
|
+
* - raw value
|
|
1667
|
+
* - data type
|
|
1668
|
+
* - symbol
|
|
1389
1669
|
*
|
|
1390
|
-
*
|
|
1670
|
+
* **NOTE:** Do not use `autoFill` for `UNION` types, it doesn't work correctly.
|
|
1391
1671
|
*
|
|
1392
|
-
* **NOTE:**
|
|
1672
|
+
* **NOTE:** This requires that the target is a PLC runtime or has equivalent ADS protocol support.
|
|
1393
1673
|
*
|
|
1394
|
-
* @
|
|
1674
|
+
* @example
|
|
1675
|
+
* ```js
|
|
1676
|
+
* try {
|
|
1677
|
+
* const value = {
|
|
1678
|
+
* example: true
|
|
1679
|
+
* };
|
|
1680
|
+
*
|
|
1681
|
+
* const res = await client.writeValue('GVL_Test.ExampleStruct', value);
|
|
1682
|
+
* } catch (err) {
|
|
1683
|
+
* console.log("Error:", err);
|
|
1684
|
+
* }
|
|
1685
|
+
* ```
|
|
1686
|
+
*
|
|
1687
|
+
* @param path Variable path in the PLC (such as `GVL_Test.ExampleStruct`)
|
|
1395
1688
|
* @param value Value to write
|
|
1396
1689
|
* @param targetOpts Optional target settings that override values in `settings`
|
|
1397
|
-
* @param autoFill If
|
|
1690
|
+
* @param autoFill If set and the data type is a container (`STRUCT`, `FUNCTION_BLOCK` etc.), missing properties are automatically set to default values (usually `0` or `''`).
|
|
1398
1691
|
*
|
|
1399
1692
|
* @template T In Typescript, the data type of the value, for example `writeValue<number>(...)` or `writeValue<ST_TypedStruct>(...)`
|
|
1400
1693
|
*/
|