ads-client 1.14.3 → 2.0.0-beta.1

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.
@@ -0,0 +1,460 @@
1
+ import { ADS } from "../ads-client";
2
+ import { PlcPrimitiveType } from "./ads-client-types";
3
+ /**
4
+ * AMS address
5
+ *
6
+ * Combination of AmsNetId and ADS port
7
+ */
8
+ export interface AmsAddress {
9
+ /** AmsNetId, such as `192.168.1.2.1.1`*/
10
+ amsNetId: string;
11
+ /** ADS port, such as `851` */
12
+ adsPort: number;
13
+ }
14
+ /**
15
+ * AMS packet for communication
16
+ */
17
+ export interface AmsTcpPacket<T = AdsData> {
18
+ /** AMS TCP header */
19
+ amsTcp: AmsTcpHeader;
20
+ /** AMS header */
21
+ ams: AmsHeader;
22
+ /** ADS data */
23
+ ads: T;
24
+ }
25
+ /**
26
+ * AMS TCP header
27
+ */
28
+ export interface AmsTcpHeader {
29
+ /** AMS command as number */
30
+ command: number;
31
+ /** AMS command as string */
32
+ commandStr: keyof typeof ADS.AMS_HEADER_FLAG | string;
33
+ /** AMS data length (bytes) */
34
+ length?: number;
35
+ /** AMS data (if any)) */
36
+ data?: Buffer | AmsRouterStateData | AmsPortRegisteredData;
37
+ }
38
+ /**
39
+ * AMS header
40
+ */
41
+ export interface AmsHeader {
42
+ /** Target AmsNetId and port (receiver) */
43
+ targetAmsAddress: AmsAddress;
44
+ /** Source AmsNetId and port (sender) */
45
+ sourceAmsAddress: AmsAddress;
46
+ /** ADS command as number */
47
+ adsCommand: number;
48
+ /** ADS command as enumerated string */
49
+ adsCommandStr: keyof typeof ADS.ADS_COMMAND | string;
50
+ /** ADS state flags as number (bits) */
51
+ stateFlags: number;
52
+ /** ADS state flags as comma separated string */
53
+ stateFlagsStr: string;
54
+ /** ADS data length */
55
+ dataLength: number;
56
+ /** ADS error code */
57
+ errorCode: number;
58
+ /** Command invoke ID */
59
+ invokeId: number;
60
+ /** True if error */
61
+ error?: boolean;
62
+ /** Error message as string */
63
+ errorStr?: string;
64
+ }
65
+ /**
66
+ * ADS data
67
+ */
68
+ export type AdsData = AdsResponse | AdsRequest;
69
+ /**
70
+ * AmsTcpHeader data that is received when AMS router state changes
71
+ */
72
+ export interface AmsRouterStateData {
73
+ /** New router state as number */
74
+ routerState: number;
75
+ }
76
+ /**
77
+ * AmsTcpHeader data that is received when AMS port is registered from the router
78
+ */
79
+ export type AmsPortRegisteredData = AmsAddress;
80
+ /**
81
+ * AMS router state
82
+ */
83
+ export interface AmsRouterState {
84
+ /** Router state */
85
+ state: number;
86
+ /** Router state as string */
87
+ stateStr: string;
88
+ }
89
+ /**
90
+ * ADS response
91
+ */
92
+ export type AdsResponse = EmptyAdsResponse | UnknownAdsResponse | AdsReadResponse | AdsReadWriteResponse | AdsWriteResponse | AdsReadDeviceInfoResponse | AdsNotificationResponse | AdsAddNotificationResponse | AdsDeleteNotificationResponse | AdsWriteControlResponse;
93
+ /**
94
+ * ADS request
95
+ */
96
+ export interface AdsRequest {
97
+ /** Payload of the ADS request (if any) */
98
+ payload?: Buffer;
99
+ }
100
+ /**
101
+ * ADS error
102
+ */
103
+ export interface AdsError {
104
+ /** ADS error code (0 = no error, -1 = other than ADS error) */
105
+ errorCode: number;
106
+ /** ADS error string */
107
+ errorStr?: string;
108
+ }
109
+ /**
110
+ * Base ADS reponse (that is received in all responses)
111
+ */
112
+ export interface BaseAdsResponse {
113
+ /** True if response has error (ADS or our own customer error) */
114
+ error: boolean;
115
+ /** ADS error code (0 = no error, -1 = other than ADS error) */
116
+ errorCode: number;
117
+ /** ADS error string */
118
+ errorStr?: string;
119
+ }
120
+ /**
121
+ * Empty ADS response (no payload)
122
+ */
123
+ export type EmptyAdsResponse = {
124
+ [K in any]: never;
125
+ };
126
+ /**
127
+ * ADS response for `Read` command
128
+ */
129
+ export interface AdsReadResponse extends BaseAdsResponse {
130
+ /** Data length */
131
+ length: number;
132
+ /** Response data */
133
+ payload: Buffer;
134
+ }
135
+ /**
136
+ * ADS response for `ReadWrite` command
137
+ */
138
+ export interface AdsReadWriteResponse extends BaseAdsResponse {
139
+ /** Data length */
140
+ length: number;
141
+ /** Response data */
142
+ payload: Buffer;
143
+ }
144
+ /**
145
+ * ADS response for `Write` command
146
+ */
147
+ export interface AdsWriteResponse extends BaseAdsResponse {
148
+ }
149
+ /**
150
+ * ADS response for `ReadDeviceInfo` command
151
+ */
152
+ export interface AdsReadDeviceInfoResponse extends BaseAdsResponse {
153
+ /** Device info */
154
+ payload: AdsDeviceInfo;
155
+ }
156
+ /**
157
+ * ADS response for `ReadState` command
158
+ */
159
+ export interface AdsReadStateResponse extends BaseAdsResponse {
160
+ /** ADS state */
161
+ payload: AdsState;
162
+ }
163
+ /**
164
+ * ADS response for `AddNotification` command
165
+ */
166
+ export interface AdsAddNotificationResponse extends BaseAdsResponse {
167
+ /** Device notification handle */
168
+ payload: AdsAddNotificationResponseData;
169
+ }
170
+ /**
171
+ * ADS response for `DeleteNotification` command
172
+ */
173
+ export interface AdsDeleteNotificationResponse extends BaseAdsResponse {
174
+ }
175
+ /**
176
+ * ADS response for `WriteControl` command
177
+ */
178
+ export interface AdsWriteControlResponse extends BaseAdsResponse {
179
+ }
180
+ /**
181
+ * ADS response for `Notification` command
182
+ */
183
+ export interface AdsNotificationResponse extends BaseAdsResponse {
184
+ /** Notification data */
185
+ payload: AdsNotification;
186
+ }
187
+ /**
188
+ * ADS response for unknown command
189
+ */
190
+ export interface UnknownAdsResponse extends BaseAdsResponse {
191
+ }
192
+ /**
193
+ * ADS device info
194
+ */
195
+ export interface AdsDeviceInfo {
196
+ /** Major version number */
197
+ majorVersion: number;
198
+ /** Minor version number */
199
+ minorVersion: number;
200
+ /** Build version */
201
+ versionBuild: number;
202
+ /** Device name */
203
+ deviceName: string;
204
+ }
205
+ /**
206
+ * ADS state
207
+ */
208
+ export interface AdsState {
209
+ /** ADS state */
210
+ adsState: number;
211
+ /** ADS state as string (if any) */
212
+ adsStateStr?: string;
213
+ /** Device state */
214
+ deviceState: number;
215
+ }
216
+ /**
217
+ * ADS `AddNotification` reponse payload
218
+ */
219
+ export interface AdsAddNotificationResponseData {
220
+ /** Notification handle */
221
+ notificationHandle: number;
222
+ }
223
+ /**
224
+ * ADS notification with number of stamps
225
+ */
226
+ export interface AdsNotification {
227
+ /** Total data length (bytes) */
228
+ length: number;
229
+ /** How many stamps does this packet have */
230
+ stampCount: number;
231
+ /** Stamps */
232
+ stamps: AdsNotificationStamp[];
233
+ }
234
+ /**
235
+ * Single ADS notification stamp with multiple samples
236
+ */
237
+ export interface AdsNotificationStamp {
238
+ /** Timestamp of the included data*/
239
+ timestamp: Date;
240
+ /** How many samples */
241
+ count: number;
242
+ /** Samples (payload) */
243
+ samples: AdsNotificationSample[];
244
+ }
245
+ /**
246
+ * Single ADS notification sample
247
+ */
248
+ export interface AdsNotificationSample {
249
+ /** Notification handle this data belongs to */
250
+ notificationHandle: number;
251
+ /** Data (payload) length */
252
+ length: number;
253
+ /** Data (raw) */
254
+ payload: Buffer;
255
+ }
256
+ /**
257
+ * ADS raw address
258
+ */
259
+ export interface AdsRawAddress {
260
+ /** Address indexGroup */
261
+ indexGroup: number;
262
+ /** Address indexOffset */
263
+ indexOffset: number;
264
+ /** Size as bytes (if any) */
265
+ size?: number;
266
+ }
267
+ /**
268
+ * ADS symbol object
269
+ */
270
+ export interface AdsSymbol {
271
+ /** Symbol address indexGroup */
272
+ indexGroup: number;
273
+ /** Symbol address indexOffset */
274
+ indexOffset: number;
275
+ /** Symbol size (bytes) */
276
+ size: number;
277
+ /** ADS data type as number (see ADS.ADS_DATA_TYPES) */
278
+ adsDataType: number;
279
+ /** ADS data type as string (see ADS.ADS_DATA_TYPES) */
280
+ adsDataTypeStr: string;
281
+ /** Symbol flags as bit-notation (see ADS.ADS_SYMBOL_FLAGS) */
282
+ flags: number;
283
+ /** Symbol flags as string array (see ADS.ADS_SYMBOL_FLAGS) */
284
+ flagsStr: string[];
285
+ /** If symbol is an array, its array dimension */
286
+ arrayDimension: number;
287
+ /** Symbol name (variable path) */
288
+ name: string;
289
+ /** Symbol data type */
290
+ type: string;
291
+ /** Symbol comment (variable comment in the PLC code) */
292
+ comment: string;
293
+ /** If symbol is an array, information of each array dimension */
294
+ arrayInfo: Array<AdsArrayInfoEntry>;
295
+ /** GUID of the symbol */
296
+ typeGuid: string;
297
+ /** Symbol attributes, such as pragmas */
298
+ attributes: Array<AdsAttributeEntry>;
299
+ extendedFlags: number;
300
+ /** Rest bytes in the end of data that have no meaning yet */
301
+ reserved: Buffer;
302
+ }
303
+ /**
304
+ * Array information entry for symbol or data type
305
+ */
306
+ export interface AdsArrayInfoEntry {
307
+ /** Array start/first index */
308
+ startIndex: number;
309
+ /** Array length */
310
+ length: number;
311
+ }
312
+ /**
313
+ * Attribute entry for symbol, data type, RPC method etc.
314
+ */
315
+ export interface AdsAttributeEntry {
316
+ /** Attribute name */
317
+ name: string;
318
+ /** Attribute value */
319
+ value: string;
320
+ }
321
+ /**
322
+ * ADS data type object
323
+ */
324
+ export interface AdsDataType {
325
+ /** Structure version */
326
+ version: number;
327
+ /** Hash value of data type (for comparison) */
328
+ hashValue: number;
329
+ /** Type hash value */
330
+ typeHashValue: number;
331
+ /** Data type size (bytes or bits if `BitValues` flag) */
332
+ size: number;
333
+ /** Offset of the entry in parent data type (bytes or bits if `BitValues` flag) */
334
+ offset: number;
335
+ /** ADS data type as number (see `ADS.ADS_DATA_TYPES`) */
336
+ adsDataType: number;
337
+ /** ADS data type as string (see `ADS.ADS_DATA_TYPES`) */
338
+ adsDataTypeStr: keyof typeof ADS.ADS_DATA_TYPES | string;
339
+ /** Data type flags as bit-notation (see `ADS.ADS_DATA_TYPE_FLAGS`) */
340
+ flags: number;
341
+ /** Data type flags as string array (see `ADS.ADS_DATA_TYPE_FLAGS`) */
342
+ flagsStr: (keyof typeof ADS.ADS_DATA_TYPE_FLAGS | string)[];
343
+ /** Array dimension (if array) */
344
+ arrayDimension: number;
345
+ /**
346
+ * Name of this entry
347
+ *
348
+ * **IMPORTANT NOTE**:
349
+ * - If entry is a subitem (e.g. struct member, `item: WORD`), this is the variable name (`item`)
350
+ * - If entry is not a subitem / it's the topmost type, this is the data type name (`WORD`)
351
+ *
352
+ * See also `type`
353
+ */
354
+ name: string;
355
+ /**
356
+ * Type of this entry
357
+ *
358
+ * **IMPORTANT NOTE**:
359
+ * - If entry is a subitem (e.g. struct member, `item: WORD`), this is the variable type (`WORD`)
360
+ * - If entry is not a subitem / it's the topmost type, this is empty string (``)
361
+ *
362
+ * See also `name`
363
+ */
364
+ type: string;
365
+ /** Data type comment (comment in the PLC code) */
366
+ comment: string;
367
+ /** If data type is an array, information of each array dimension */
368
+ arrayInfos: AdsArrayInfoEntry[];
369
+ /** Subitems (children data types) of this data type (e.g. struct members)*/
370
+ subItems: AdsDataType[];
371
+ /** Data type unique identifier (GUID) */
372
+ typeGuid: string;
373
+ /** RPC methods */
374
+ rpcMethods: AdsRpcMethodEntry[];
375
+ /** Attributes */
376
+ attributes: AdsAttributeEntry[];
377
+ /** Enumeration info */
378
+ enumInfos: AdsEnumInfoEntry[];
379
+ /** Data type extended flags */
380
+ extendedFlags: number;
381
+ /** Reserved data */
382
+ reserved: Buffer;
383
+ }
384
+ /**
385
+ * RPC method entry for a data type
386
+ */
387
+ export interface AdsRpcMethodEntry {
388
+ /** Structure version */
389
+ version: number;
390
+ /** vTable index for this method */
391
+ vTableIndex: number;
392
+ /** Size of the return type (bytes) */
393
+ returnTypeSize: number;
394
+ /** Size of the biggest element for alignment (bytes) */
395
+ returnAlignSize: number;
396
+ /** Reserved */
397
+ reserved: number;
398
+ /** Unique identifier (GUID) of the return type */
399
+ returnTypeGuid: string;
400
+ /** Return value ADS data type as number (see `ADS.ADS_DATA_TYPES`) */
401
+ returnAdsDataType: number;
402
+ /** Return value ADS data type as string (see `ADS.ADS_DATA_TYPES`) */
403
+ returnAdsDataTypeStr: keyof typeof ADS.ADS_DATA_TYPES | string;
404
+ /** PRC method flags as bit-notation (see `ADS.ADS_RCP_METHOD_FLAGS`) */
405
+ flags: number;
406
+ /** RPC method flags as string array (see `ADS.ADS_RCP_METHOD_FLAGS`) */
407
+ flagsStr: (keyof typeof ADS.ADS_RCP_METHOD_FLAGS | string)[];
408
+ /** RPC method name*/
409
+ name: string;
410
+ /** RPC method return data type */
411
+ retunDataType: string;
412
+ /** RPC method comment (comment in the PLC code) */
413
+ comment: string;
414
+ /** Parameters (inputs and outputs) */
415
+ parameters: AdsRpcMethodParameterEntry[];
416
+ /** Method attributes */
417
+ attributes: AdsAttributeEntry[];
418
+ }
419
+ /**
420
+ * RPC method parameter entry for a RPC method
421
+ */
422
+ export interface AdsRpcMethodParameterEntry {
423
+ /** Size (bytes) */
424
+ size: number;
425
+ /** Size for alignment (bytes) */
426
+ alignSize: number;
427
+ /** ADS data type as number (see `ADS.ADS_DATA_TYPES`) */
428
+ adsDataType: number;
429
+ /** ADS data type as string (see `ADS.ADS_DATA_TYPES`) */
430
+ adsDataTypeStr: string;
431
+ /** RPC method parameter flags as bit-notation (see `ADS.RCP_METHOD_PARAM_FLAGS`) */
432
+ flags: number;
433
+ /** RPC method parameter flags as string array (see `ADS.RCP_METHOD_PARAM_FLAGS`) */
434
+ flagsStr: (keyof typeof ADS.ADS_RCP_METHOD_PARAM_FLAGS | string)[];
435
+ /** Reserved */
436
+ reserved: number;
437
+ /** GUID of data type */
438
+ typeGuid: string;
439
+ /** Index-1 of corresponding parameter with length info (not relevant) */
440
+ lengthIsParameterIndex: number;
441
+ /** Parameter name*/
442
+ name: string;
443
+ /** Parameter data type */
444
+ type: string;
445
+ /** Parameter comment (comment in the PLC code) */
446
+ comment: string;
447
+ /** Attributes */
448
+ attributes: AdsAttributeEntry[];
449
+ /** Reserved data in the end of entry (if any) */
450
+ reserved2: Buffer;
451
+ }
452
+ /**
453
+ * ADS enumeration entry
454
+ */
455
+ export interface AdsEnumInfoEntry {
456
+ /** Enumeration name*/
457
+ name: string;
458
+ /** Enumeration value */
459
+ value: PlcPrimitiveType;
460
+ }
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ /*
4
+ Copyright (c) Jussi Isotalo <j.isotalo91@gmail.com>
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ of this software and associated documentation files (the "Software"), to deal
8
+ in the Software without restriction, including without limitation the rights
9
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ copies of the Software, and to permit persons to whom the Software is
11
+ furnished to do so, subject to the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be included in all
14
+ copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ SOFTWARE.
23
+ */ ;
24
+ ;
25
+ ;
26
+ ;
27
+ ;
28
+ ;
29
+ ;
30
+ ;
31
+ ;
32
+ ;
33
+ ;
34
+ ;
35
+ //# sourceMappingURL=ads-protocol-types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ads-protocol-types.js","sourceRoot":"","sources":["../../src/types/ads-protocol-types.ts"],"names":[],"mappings":";;AAAA;;;;;;;;;;;;;;;;;;;;EAoBE,CAAA,CAAC;AAuHF,CAAC;AAwCD,CAAC;AAUD,CAAC;AAMD,CAAC;AAQD,CAAC;AAQD,CAAC;AAQD,CAAC;AAKwE,CAAC;AAKP,CAAC;AAQpE,CAAC;AAK6D,CAAC"}
package/package.json CHANGED
@@ -1,12 +1,15 @@
1
1
  {
2
2
  "name": "ads-client",
3
- "version": "1.14.3",
4
- "description": "Beckhoff TwinCAT ADS client library for Node.js (unofficial). Connects to Beckhoff TwinCAT automation systems using ADS protocol.",
5
- "main": "./src/ads-client.js",
3
+ "version": "2.0.0-beta.1",
4
+ "description": "Beckhoff TwinCAT ADS client library for Node.js (unofficial). Connect to a Beckhoff TwinCAT automation system using the ADS protocol from a Node.js app.",
5
+ "main": "./dist/ads-client.js",
6
6
  "scripts": {
7
7
  "test": "jest --runInBand",
8
- "test-um": "set ADS_CLIENT_TEST_AMS=192.168.4.1.1.1 && jest --runInBand",
9
- "generate-docs": "jsdoc ./src/ads-client.js ./README.md -c ./jsdoc-conf.json -d ./docs/ -t ./node_modules/docdash/"
8
+ "test-dev": "jest --runInBand --bail=true --verbose=false --summaryThreshold=1",
9
+ "test-watch": "npm run test -- --watch --config test/jest.config.js",
10
+ "build": "tsc",
11
+ "watch": "tsc -w",
12
+ "create-docs": "npx typedoc"
10
13
  },
11
14
  "keywords": [
12
15
  "ADS",
@@ -34,18 +37,23 @@
34
37
  "url": "https://github.com/jisotalo/ads-client.git"
35
38
  },
36
39
  "dependencies": {
37
- "debug": "^4.3.3",
40
+ "debug": "^4.3.5",
38
41
  "iconv-lite": "^0.6.3",
39
- "long": "^5.2.0"
42
+ "long": "^5.2.3"
40
43
  },
41
44
  "devDependencies": {
42
- "docdash": "^1.2.0",
43
- "jest": "^28.1.3",
44
- "jsdoc": "^3.6.7"
45
+ "@tsconfig/node16": "^16.1.3",
46
+ "@types/debug": "^4.1.12",
47
+ "@types/jest": "^29.5.12",
48
+ "@types/node": "^20.14.12",
49
+ "jest": "^29.7.0",
50
+ "typedoc": "^0.26.5",
51
+ "typescript": "^5.5.4"
45
52
  },
46
53
  "files": [
47
- "src/",
54
+ "dist/",
48
55
  "CHANGELOG.md",
49
56
  "README.md"
50
- ]
57
+ ],
58
+ "types": "./dist/ads-client.d.ts"
51
59
  }