ads-client 1.14.3 → 2.0.0-beta.2
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 +34 -0
- package/LICENSE.txt +1 -1
- package/README.md +326 -1756
- package/dist/ads-client.d.ts +1562 -0
- package/dist/ads-client.js +5660 -0
- package/dist/ads-client.js.map +1 -0
- package/dist/ads-commons.d.ts +810 -0
- package/dist/ads-commons.js +1247 -0
- package/dist/ads-commons.js.map +1 -0
- package/dist/client-error.d.ts +6 -0
- package/dist/client-error.js +30 -0
- package/dist/client-error.js.map +1 -0
- package/dist/types/ads-client-types.d.ts +626 -0
- package/dist/types/ads-client-types.js +5 -0
- package/dist/types/ads-client-types.js.map +1 -0
- package/dist/types/ads-protocol-types.d.ts +460 -0
- package/dist/types/ads-protocol-types.js +35 -0
- package/dist/types/ads-protocol-types.js.map +1 -0
- package/package.json +23 -14
- package/src/ads-client-ads.js +0 -1163
- package/src/ads-client.js +0 -6884
package/src/ads-client-ads.js
DELETED
|
@@ -1,1163 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
ads-client-ads.js
|
|
3
|
-
|
|
4
|
-
Copyright (c) 2020 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
|
-
* AMS/TCP header length
|
|
28
|
-
*/
|
|
29
|
-
const AMS_TCP_HEADER_LENGTH = 6
|
|
30
|
-
exports.AMS_TCP_HEADER_LENGTH = AMS_TCP_HEADER_LENGTH
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* AMS header length
|
|
34
|
-
*/
|
|
35
|
-
const AMS_HEADER_LENGTH = 32
|
|
36
|
-
exports.AMS_HEADER_LENGTH = AMS_HEADER_LENGTH
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* AmsNetId length
|
|
40
|
-
*/
|
|
41
|
-
const AMS_NET_ID_LENGTH = 6
|
|
42
|
-
exports.AMS_NET_ID_LENGTH = AMS_NET_ID_LENGTH
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* ADS index offset length
|
|
46
|
-
*/
|
|
47
|
-
const ADS_INDEX_OFFSET_LENGTH = 4
|
|
48
|
-
exports.ADS_INDEX_OFFSET_LENGTH = ADS_INDEX_OFFSET_LENGTH
|
|
49
|
-
|
|
50
|
-
/**
|
|
51
|
-
* ADS index group length
|
|
52
|
-
*/
|
|
53
|
-
const ADS_INDEX_GROUP_LENGTH = 4
|
|
54
|
-
exports.ADS_INDEX_GROUP_LENGTH = ADS_INDEX_GROUP_LENGTH
|
|
55
|
-
|
|
56
|
-
/**
|
|
57
|
-
* ADS invoke ID maximum value (32bit unsigned integer)
|
|
58
|
-
*/
|
|
59
|
-
const ADS_INVOKE_ID_MAX_VALUE = 4294967295
|
|
60
|
-
exports.ADS_INVOKE_ID_MAX_VALUE = ADS_INVOKE_ID_MAX_VALUE
|
|
61
|
-
|
|
62
|
-
/**
|
|
63
|
-
* AMS header flag (AMS command)
|
|
64
|
-
*/
|
|
65
|
-
const AMS_HEADER_FLAG = {
|
|
66
|
-
AMS_TCP_PORT_AMS_CMD: 0, //0x0000 - Used for ADS commands
|
|
67
|
-
AMS_TCP_PORT_CLOSE: 1, //0x0001
|
|
68
|
-
AMS_TCP_PORT_CONNECT: 4096, // 0x1000
|
|
69
|
-
AMS_TCP_PORT_ROUTER_NOTE: 4097, // 0x1001
|
|
70
|
-
GET_LOCAL_NETID: 4098, // 0x1002
|
|
71
|
-
|
|
72
|
-
toString: function (value) {
|
|
73
|
-
return ((ret = Object.keys(this).find(key => this[key] == value)) != null ? ret : 'UNKNOWN')
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
exports.AMS_HEADER_FLAG = AMS_HEADER_FLAG
|
|
77
|
-
|
|
78
|
-
/**
|
|
79
|
-
* Reserved/known ADS ports
|
|
80
|
-
*
|
|
81
|
-
* Source: TwinCAT.Ads.dll By Beckhoff
|
|
82
|
-
*/
|
|
83
|
-
const ADS_RESERVED_PORTS = {
|
|
84
|
-
None: 0,
|
|
85
|
-
//AMS Router (Port 1)
|
|
86
|
-
Router: 1,
|
|
87
|
-
//AMS Debugger (Port 2)
|
|
88
|
-
Debugger: 2,
|
|
89
|
-
//The TCom Server. Dpc or passive level.
|
|
90
|
-
R0_TComServer: 10, // 0x0000000A
|
|
91
|
-
//TCom Server Task. RT context.
|
|
92
|
-
R0_TComServerTask: 11, // 0x0000000B
|
|
93
|
-
//TCom Serve Task. Passive level.
|
|
94
|
-
R0_TComServer_PL: 12, // 0x0000000C
|
|
95
|
-
//TwinCAT Debugger
|
|
96
|
-
R0_TcDebugger: 20, // 0x00000014
|
|
97
|
-
//TwinCAT Debugger Task
|
|
98
|
-
R0_TcDebuggerTask: 21, // 0x00000015
|
|
99
|
-
//The License Server (Port 30)
|
|
100
|
-
R0_LicenseServer: 30, // 0x0000001E
|
|
101
|
-
//Logger (Port 100)
|
|
102
|
-
Logger: 100, // 0x00000064
|
|
103
|
-
//Event Logger (Port 110)
|
|
104
|
-
EventLog: 110, // 0x0000006E
|
|
105
|
-
//application for coupler (EK), gateway (EL), etc.
|
|
106
|
-
DeviceApplication: 120, // 0x00000078
|
|
107
|
-
//Event Logger UM
|
|
108
|
-
EventLog_UM: 130, // 0x00000082
|
|
109
|
-
//Event Logger RT
|
|
110
|
-
EventLog_RT: 131, // 0x00000083
|
|
111
|
-
//Event Logger Publisher
|
|
112
|
-
EventLogPublisher: 132, // 0x00000084
|
|
113
|
-
//R0 Realtime (Port 200)
|
|
114
|
-
R0_Realtime: 200, // 0x000000C8
|
|
115
|
-
//R0 Trace (Port 290)
|
|
116
|
-
R0_Trace: 290, // 0x00000122
|
|
117
|
-
//R0 IO (Port 300)
|
|
118
|
-
R0_IO: 300, // 0x0000012C
|
|
119
|
-
//NC (R0) (Port 500)
|
|
120
|
-
R0_NC: 500, // 0x000001F4
|
|
121
|
-
//R0 Satzausführung (Port 501)
|
|
122
|
-
R0_NCSAF: 501, // 0x000001F5
|
|
123
|
-
//R0 Satzvorbereitung (Port 511)
|
|
124
|
-
R0_NCSVB: 511, // 0x000001FF
|
|
125
|
-
//Preconfigured Nc2-Nc3-Instance
|
|
126
|
-
R0_NCINSTANCE: 520, // 0x00000208
|
|
127
|
-
//R0 ISG (Port 550)
|
|
128
|
-
R0_ISG: 550, // 0x00000226
|
|
129
|
-
//R0 CNC (Port 600)
|
|
130
|
-
R0_CNC: 600, // 0x00000258
|
|
131
|
-
//R0 Line (Port 700)
|
|
132
|
-
R0_LINE: 700, // 0x000002BC
|
|
133
|
-
//R0 PLC (Port 800)
|
|
134
|
-
R0_PLC: 800, // 0x00000320
|
|
135
|
-
//Tc2 PLC RuntimeSystem 1 (Port 801)
|
|
136
|
-
Tc2_Plc1: 801, // 0x00000321
|
|
137
|
-
//Tc2 PLC RuntimeSystem 2 (Port 811)
|
|
138
|
-
Tc2_Plc2: 811, // 0x0000032B
|
|
139
|
-
//Tc2 PLC RuntimeSystem 3 (Port 821)
|
|
140
|
-
Tc2_Plc3: 821, // 0x00000335
|
|
141
|
-
//Tc2 PLC RuntimeSystem 4 (Port 831)
|
|
142
|
-
Tc2_Plc4: 831, // 0x0000033F
|
|
143
|
-
//R0 RTS (Port 850)
|
|
144
|
-
R0_RTS: 850, // 0x00000352
|
|
145
|
-
//Tc3 PLC RuntimeSystem 1 (Port 851)
|
|
146
|
-
Tc3_Plc1: 851,
|
|
147
|
-
//Tc3 PLC RuntimeSystem 2 (Port 852)
|
|
148
|
-
Tc3_Plc2: 852,
|
|
149
|
-
//Tc3 PLC RuntimeSystem 3 (Port 853)
|
|
150
|
-
Tc3_Plc3: 853,
|
|
151
|
-
//Tc3 PLC RuntimeSystem 4 (Port 854)
|
|
152
|
-
Tc3_Plc4: 854,
|
|
153
|
-
//Tc3 PLC RuntimeSystem 5 (Port 855)
|
|
154
|
-
Tc3_Plc5: 855,
|
|
155
|
-
//Camshaft Controller (R0) (Port 900)
|
|
156
|
-
CamshaftController: 900, // 0x00000384
|
|
157
|
-
//R0 CAM Tool (Port 950)
|
|
158
|
-
R0_CAMTOOL: 950, // 0x000003B6
|
|
159
|
-
//R0 User (Port 2000)
|
|
160
|
-
R0_USER: 2000, // 0x000007D0
|
|
161
|
-
//(Port 10000)
|
|
162
|
-
R3_CTRLPROG: 10000, // 0x00002710
|
|
163
|
-
//System Service (AMSPORT_R3_SYSSERV, 10000)
|
|
164
|
-
SystemService: 10000, // 0x00002710
|
|
165
|
-
//(Port 10001)
|
|
166
|
-
R3_SYSCTRL: 10001, // 0x00002711
|
|
167
|
-
//Port 10100
|
|
168
|
-
R3_SYSSAMPLER: 10100, // 0x00002774
|
|
169
|
-
//Port 10200
|
|
170
|
-
R3_TCPRAWCONN: 10200, // 0x000027D8
|
|
171
|
-
//Port 10201
|
|
172
|
-
R3_TCPIPSERVER: 10201, // 0x000027D9
|
|
173
|
-
//Port 10300
|
|
174
|
-
R3_SYSMANAGER: 10300, // 0x0000283C
|
|
175
|
-
//Port 10400
|
|
176
|
-
R3_SMSSERVER: 10400, // 0x000028A0
|
|
177
|
-
//Port 10500
|
|
178
|
-
R3_MODBUSSERVER: 10500, // 0x00002904
|
|
179
|
-
//Port 10502
|
|
180
|
-
R3_AMSLOGGER: 10502, // 0x00002906
|
|
181
|
-
//Port 10600
|
|
182
|
-
R3_XMLDATASERVER: 10600, // 0x00002968
|
|
183
|
-
//Port 10700
|
|
184
|
-
R3_AUTOCONFIG: 10700, // 0x000029CC
|
|
185
|
-
//Port 10800
|
|
186
|
-
R3_PLCCONTROL: 10800, // 0x00002A30
|
|
187
|
-
//Port 10900
|
|
188
|
-
R3_FTPCLIENT: 10900, // 0x00002A94
|
|
189
|
-
//Port 11000
|
|
190
|
-
R3_NCCTRL: 11000, // 0x00002AF8
|
|
191
|
-
//Port 11500
|
|
192
|
-
R3_NCINTERPRETER: 11500, // 0x00002CEC
|
|
193
|
-
//Port 11600
|
|
194
|
-
R3_GSTINTERPRETER: 11600, // 0x00002D50
|
|
195
|
-
//Port 12000
|
|
196
|
-
R3_STRECKECTRL: 12000, // 0x00002EE0
|
|
197
|
-
//Port 13000
|
|
198
|
-
R3_CAMCTRL: 13000, // 0x000032C8
|
|
199
|
-
//Port 14000
|
|
200
|
-
R3_SCOPE: 14000, // 0x000036B0
|
|
201
|
-
//Port 14100
|
|
202
|
-
R3_CONDITIONMON: 14100, // 0x00003714
|
|
203
|
-
//Port 15000
|
|
204
|
-
R3_SINECH1: 15000, // 0x00003A98
|
|
205
|
-
//Port 16000
|
|
206
|
-
R3_CONTROLNET: 16000, // 0x00003E80
|
|
207
|
-
//Port 17000
|
|
208
|
-
R3_OPCSERVER: 17000, // 0x00004268
|
|
209
|
-
//Port 17500
|
|
210
|
-
R3_OPCCLIENT: 17500, // 0x0000445C
|
|
211
|
-
//Port 18000
|
|
212
|
-
R3_MAILSERVER: 18000, // 0x00004650
|
|
213
|
-
//Port 19000
|
|
214
|
-
R3_EL60XX: 19000, // 0x00004A38
|
|
215
|
-
//Port 19100
|
|
216
|
-
R3_MANAGEMENT: 19100, // 0x00004A9C
|
|
217
|
-
//Port 19200
|
|
218
|
-
R3_MIELEHOME: 19200, // 0x00004B00
|
|
219
|
-
//Port 19300
|
|
220
|
-
R3_CPLINK3: 19300, // 0x00004B64
|
|
221
|
-
//Port 19500
|
|
222
|
-
R3_VNSERVICE: 19500, // 0x00004C2C
|
|
223
|
-
//Multiuser (Port 19600)
|
|
224
|
-
R3_MULTIUSER: 19600, // 0x00004C90
|
|
225
|
-
//Default (AMS router assigns)
|
|
226
|
-
USEDEFAULT: 65535, // 0x0000FFFF
|
|
227
|
-
}
|
|
228
|
-
exports.ADS_RESERVED_PORTS = ADS_RESERVED_PORTS
|
|
229
|
-
|
|
230
|
-
/**
|
|
231
|
-
* ADS command
|
|
232
|
-
*
|
|
233
|
-
* Source: TwinCAT.Ads.dll By Beckhoff
|
|
234
|
-
*/
|
|
235
|
-
const ADS_COMMAND = {
|
|
236
|
-
//Invalid
|
|
237
|
-
Invalid: 0,
|
|
238
|
-
//None / Uninitialized
|
|
239
|
-
None: 0,
|
|
240
|
-
//ReadDeviceInfo command
|
|
241
|
-
ReadDeviceInfo: 1,
|
|
242
|
-
//Read Command
|
|
243
|
-
Read: 2,
|
|
244
|
-
//Write Command
|
|
245
|
-
Write: 3,
|
|
246
|
-
//ReadState Command
|
|
247
|
-
ReadState: 4,
|
|
248
|
-
//WriteControl Command
|
|
249
|
-
WriteControl: 5,
|
|
250
|
-
//AddNotification Command
|
|
251
|
-
AddNotification: 6,
|
|
252
|
-
//DeleteNotification Command
|
|
253
|
-
DeleteNotification: 7,
|
|
254
|
-
//Notification event.
|
|
255
|
-
Notification: 8,
|
|
256
|
-
//ReadWrite Command
|
|
257
|
-
ReadWrite: 9,
|
|
258
|
-
|
|
259
|
-
toString: function (value) {
|
|
260
|
-
return (Object.keys(this).find(key => this[key] == value)) || 'UNKNOWN';
|
|
261
|
-
}
|
|
262
|
-
}
|
|
263
|
-
exports.ADS_COMMAND = ADS_COMMAND
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
/**
|
|
268
|
-
* ADS state flags
|
|
269
|
-
*
|
|
270
|
-
* Source: TwinCAT.Ads.dll By Beckhoff
|
|
271
|
-
*/
|
|
272
|
-
const ADS_STATE_FLAGS = {
|
|
273
|
-
//The response (AMSCMDSF_RESPONSE)
|
|
274
|
-
Response: 1,
|
|
275
|
-
//(AMSCMDSF_NORETURN)
|
|
276
|
-
NoReturn: 2,
|
|
277
|
-
//AdsCommand
|
|
278
|
-
AdsCommand: 4,
|
|
279
|
-
//Internal generated cmds (AMSCMDSF_SYSCMD)
|
|
280
|
-
SysCommand: 8,
|
|
281
|
-
//High Priority (R0 to R0 checked at task begin, AMSCMDSF_HIGHPRIO)
|
|
282
|
-
HighPriority: 16, // 0x0010
|
|
283
|
-
//(cbData um 8 Byte vergrößert, AMSCMDSF_TIMESTAMPADDED)
|
|
284
|
-
TimeStampAdded: 32, // 0x0020
|
|
285
|
-
//(UDP instead of TCP, AMSCMDSF_UDP)
|
|
286
|
-
Udp: 64, // 0x0040
|
|
287
|
-
//(command during init phase of TwinCAT, AMSCMDSF_INITCMD)
|
|
288
|
-
InitCmd: 128, // 0x0080
|
|
289
|
-
//(AMSCMDSF_BROADCAST)
|
|
290
|
-
Broadcast: 32768, // 0x8000
|
|
291
|
-
//Mask Ads Request
|
|
292
|
-
//MaskAdsRequest: 0x0004, // 0x0004
|
|
293
|
-
//Mask Ads Response
|
|
294
|
-
//MaskAdsResponse: 0x0005, // 0x0005
|
|
295
|
-
|
|
296
|
-
toString: function (value) {
|
|
297
|
-
let flags = []
|
|
298
|
-
|
|
299
|
-
for (let key of Object.keys(this)) {
|
|
300
|
-
if (typeof this[key] !== 'number')
|
|
301
|
-
continue
|
|
302
|
-
|
|
303
|
-
if((value & this[key]) == this[key])
|
|
304
|
-
flags.push(key)
|
|
305
|
-
}
|
|
306
|
-
|
|
307
|
-
//Specials: For helping debugging
|
|
308
|
-
if (!flags.includes('Udp'))
|
|
309
|
-
flags.push('Tcp')
|
|
310
|
-
|
|
311
|
-
if (!flags.includes('Response'))
|
|
312
|
-
flags.push('Request')
|
|
313
|
-
|
|
314
|
-
return flags.join(', ')
|
|
315
|
-
}
|
|
316
|
-
}
|
|
317
|
-
exports.ADS_STATE_FLAGS = ADS_STATE_FLAGS
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
/**
|
|
321
|
-
* ADS error code
|
|
322
|
-
*
|
|
323
|
-
* Source: Beckhoff InfoSys
|
|
324
|
-
*/
|
|
325
|
-
const ADS_ERROR = {
|
|
326
|
-
0: 'No error',
|
|
327
|
-
1: 'Internal error',
|
|
328
|
-
2: 'No Rtime',
|
|
329
|
-
3: 'Allocation locked memory error',
|
|
330
|
-
4: 'Insert mailbox error',
|
|
331
|
-
5: 'Wrong receive HMSG',
|
|
332
|
-
6: 'Target port not found',
|
|
333
|
-
7: 'Target machine not found',
|
|
334
|
-
8: 'Unknown command ID',
|
|
335
|
-
9: 'Bad task ID',
|
|
336
|
-
10: 'No IO',
|
|
337
|
-
11: 'Unknown ADS command',
|
|
338
|
-
12: 'Win 32 error',
|
|
339
|
-
13: 'Port not connected',
|
|
340
|
-
14: 'Invalid ADS length',
|
|
341
|
-
15: 'Invalid AMS Net ID',
|
|
342
|
-
16: 'Low Installation level',
|
|
343
|
-
17: 'No debug available',
|
|
344
|
-
18: 'Port disabled',
|
|
345
|
-
19: 'Port already connected',
|
|
346
|
-
20: 'ADS Sync Win32 error',
|
|
347
|
-
21: 'ADS Sync Timeout',
|
|
348
|
-
22: 'ADS Sync AMS error',
|
|
349
|
-
23: 'ADS Sync no index map',
|
|
350
|
-
24: 'Invalid ADS port',
|
|
351
|
-
25: 'No memory',
|
|
352
|
-
26: 'TCP send error',
|
|
353
|
-
27: 'Host unreachable',
|
|
354
|
-
28: 'Invalid AMS fragment',
|
|
355
|
-
29: 'TLS send error – secure ADS connection failed.',
|
|
356
|
-
30: 'Access denied – secure ADS access denied.',
|
|
357
|
-
1280: 'No locked memory can be allocated',
|
|
358
|
-
1281: 'The size of the router memory could not be changed',
|
|
359
|
-
1282: 'The mailbox has reached the maximum number of possible messages. The current sent message was rejected',
|
|
360
|
-
1283: 'The mailbox has reached the maximum number of possible messages.',
|
|
361
|
-
1284: 'Unknown port type',
|
|
362
|
-
1285: 'Router is not initialized',
|
|
363
|
-
1286: 'The desired port number is already assigned',
|
|
364
|
-
1287: 'Port not registered',
|
|
365
|
-
1288: 'The maximum number of Ports reached',
|
|
366
|
-
1289: 'Invalid port',
|
|
367
|
-
1290: 'TwinCAT Router not active',
|
|
368
|
-
1291: 'The mailbox has reached the maximum number for fragmented messages.',
|
|
369
|
-
1292: 'A fragment timeout has occurred.',
|
|
370
|
-
1293: 'The port is removed.',
|
|
371
|
-
1792: 'General device error',
|
|
372
|
-
1793: 'Service is not supported by server',
|
|
373
|
-
1794: 'Invalid index group',
|
|
374
|
-
1795: 'Invalid index offset',
|
|
375
|
-
1796: 'Reading/writing not permitted',
|
|
376
|
-
1797: 'Parameter size not correct',
|
|
377
|
-
1798: 'Invalid parameter value(s)',
|
|
378
|
-
1799: 'Device is not in a ready state',
|
|
379
|
-
1800: 'Device is busy',
|
|
380
|
-
1801: 'Invalid context (must be in Windows)',
|
|
381
|
-
1802: 'Out of memory',
|
|
382
|
-
1803: 'Invalid parameter value(s)',
|
|
383
|
-
1804: 'Not found (files, ...)',
|
|
384
|
-
1805: 'Syntax error in command or file',
|
|
385
|
-
1806: 'Objects do not match',
|
|
386
|
-
1807: 'Object already exists',
|
|
387
|
-
1808: 'Symbol not found',
|
|
388
|
-
1809: 'Symbol version invalid',
|
|
389
|
-
1810: 'Server is in invalid state',
|
|
390
|
-
1811: 'AdsTransMode not supported',
|
|
391
|
-
1812: 'Notification handle is invalid',
|
|
392
|
-
1813: 'Notification client not registered',
|
|
393
|
-
1814: 'No more notification handles',
|
|
394
|
-
1815: 'Size for watch too big',
|
|
395
|
-
1816: 'Device not initialized',
|
|
396
|
-
1817: 'Device has a timeout',
|
|
397
|
-
1818: 'Query interface failed',
|
|
398
|
-
1819: 'Wrong interface required',
|
|
399
|
-
1820: 'Class ID is invalid',
|
|
400
|
-
1821: 'Object ID is invalid',
|
|
401
|
-
1822: 'Request is pending',
|
|
402
|
-
1823: 'Request is aborted',
|
|
403
|
-
1824: 'Signal warning',
|
|
404
|
-
1825: 'Invalid array index',
|
|
405
|
-
1826: 'Symbol not active',
|
|
406
|
-
1827: 'Access denied',
|
|
407
|
-
1828: 'Missing license',
|
|
408
|
-
1829: 'License expired',
|
|
409
|
-
1830: 'License exceeded',
|
|
410
|
-
1831: 'License invalid',
|
|
411
|
-
1832: 'License invalid system id',
|
|
412
|
-
1833: 'License not time limited',
|
|
413
|
-
1834: 'License issue time in the future',
|
|
414
|
-
1835: 'License time period to long',
|
|
415
|
-
1836: 'Exception occured during system start',
|
|
416
|
-
1837: 'License file read twice',
|
|
417
|
-
1838: 'Invalid signature',
|
|
418
|
-
1839: 'Public key certificate',
|
|
419
|
-
1856: 'Error class <client error>',
|
|
420
|
-
1857: 'Invalid parameter at service',
|
|
421
|
-
1858: 'Polling list is empty',
|
|
422
|
-
1859: 'Var connection already in use',
|
|
423
|
-
1860: 'Invoke ID in use',
|
|
424
|
-
1861: 'Timeout elapsed',
|
|
425
|
-
1862: 'Error in win32 subsystem',
|
|
426
|
-
1863: 'Invalid client timeout value',
|
|
427
|
-
1864: 'Ads-port not opened',
|
|
428
|
-
1865: 'No AMS address.',
|
|
429
|
-
1872: 'Internal error in ads sync',
|
|
430
|
-
1873: 'Hash table overflow',
|
|
431
|
-
1874: 'Key not found in hash',
|
|
432
|
-
1875: 'No more symbols in cache',
|
|
433
|
-
1876: 'Invalid response received',
|
|
434
|
-
1877: 'Sync port is locked',
|
|
435
|
-
4096: 'Internal fatal error in the TwinCAT real-time system',
|
|
436
|
-
4097: 'Timer value not vaild',
|
|
437
|
-
4098: 'Task pointer has the invalid value ZERO',
|
|
438
|
-
4099: 'Task stack pointer has the invalid value ZERO',
|
|
439
|
-
4100: 'The demand task priority is already assigned',
|
|
440
|
-
4101: 'No more free TCB (Task Control Block) available. Maximum number of TCBs is 64',
|
|
441
|
-
4102: 'No more free semaphores available. Maximum number of semaphores is 64',
|
|
442
|
-
4103: 'No more free queue available. Maximum number of queue is 64',
|
|
443
|
-
4109: 'An external synchronization interrupt is already applied',
|
|
444
|
-
4110: 'No external synchronization interrupt applied',
|
|
445
|
-
4111: 'The apply of the external synchronization interrupt failed',
|
|
446
|
-
4112: 'Call of a service function in the wrong context',
|
|
447
|
-
4119: 'Intel VT-x extension is not supported',
|
|
448
|
-
4120: 'Intel VT-x extension is not enabled in system BIOS',
|
|
449
|
-
4121: 'Missing function in Intel VT-x extension',
|
|
450
|
-
4122: 'Enabling Intel VT-x fails',
|
|
451
|
-
}
|
|
452
|
-
exports.ADS_ERROR = ADS_ERROR
|
|
453
|
-
|
|
454
|
-
/**
|
|
455
|
-
* ADS notification transmission mode
|
|
456
|
-
*
|
|
457
|
-
* Source: TwinCAT.Ads.dll By Beckhoff
|
|
458
|
-
*/
|
|
459
|
-
const ADS_TRANS_MODE = {
|
|
460
|
-
None: 0,
|
|
461
|
-
ClientCycle: 1,
|
|
462
|
-
ClientOnChange: 2,
|
|
463
|
-
Cyclic: 3,
|
|
464
|
-
OnChange: 4,
|
|
465
|
-
CyclicInContext: 5,
|
|
466
|
-
OnChangeInContext: 6,
|
|
467
|
-
}
|
|
468
|
-
exports.ADS_TRANS_MODE = ADS_TRANS_MODE
|
|
469
|
-
|
|
470
|
-
/**
|
|
471
|
-
* ADS state
|
|
472
|
-
*
|
|
473
|
-
* Source: TwinCAT.Ads.dll By Beckhoff
|
|
474
|
-
*/
|
|
475
|
-
const ADS_STATE = {
|
|
476
|
-
Invalid: 0,
|
|
477
|
-
Idle: 1,
|
|
478
|
-
Reset: 2,
|
|
479
|
-
Initialize: 3,
|
|
480
|
-
Start: 4,
|
|
481
|
-
Run: 5,
|
|
482
|
-
Stop: 6,
|
|
483
|
-
SaveConfig: 7,
|
|
484
|
-
LoadConfig: 8,
|
|
485
|
-
PowerFailure: 9,
|
|
486
|
-
PowerGood: 10,
|
|
487
|
-
Error: 11,
|
|
488
|
-
Shutdown: 12,
|
|
489
|
-
Susped: 13,
|
|
490
|
-
Resume: 14,
|
|
491
|
-
Config: 15,
|
|
492
|
-
Reconfig: 16,
|
|
493
|
-
Stopping: 17,
|
|
494
|
-
Incompatible: 18,
|
|
495
|
-
Exception: 19,
|
|
496
|
-
|
|
497
|
-
toString: function (value) {
|
|
498
|
-
return (Object.keys(this).find(key => this[key] == value)) || 'UNKNOWN';
|
|
499
|
-
}
|
|
500
|
-
}
|
|
501
|
-
exports.ADS_STATE = ADS_STATE
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
/**
|
|
505
|
-
* Reserved ADS index groups
|
|
506
|
-
*
|
|
507
|
-
* Source: TwinCAT.Ads.dll By Beckhoff
|
|
508
|
-
*/
|
|
509
|
-
const ADS_RESERVED_INDEX_GROUPS = {
|
|
510
|
-
//PlcRWIB (0x4000, 16384)
|
|
511
|
-
PlcRWIB: 16384, // 0x00004000
|
|
512
|
-
//PlcRWOB (0x4010, 16400)
|
|
513
|
-
PlcRWOB: 16400, // 0x00004010
|
|
514
|
-
//PlcRWMB (0x4020, 16416)
|
|
515
|
-
PlcRWMB: 16416, // 0x00004020
|
|
516
|
-
//PlcRWRB (0x4030, 16432)
|
|
517
|
-
PlcRWRB: 16432, // 0x00004030
|
|
518
|
-
//PlcRWDB (0x4040,16448)
|
|
519
|
-
PlcRWDB: 16448, // 0x00004040
|
|
520
|
-
//SymbolTable (0xF000, 61440)
|
|
521
|
-
SymbolTable: 61440, // 0x0000F000
|
|
522
|
-
//SymbolName (0xF001, 61441)
|
|
523
|
-
SymbolName: 61441, // 0x0000F001
|
|
524
|
-
//SymbolValue (0xF002, 61442)
|
|
525
|
-
SymbolValue: 61442, // 0x0000F002
|
|
526
|
-
//SymbolHandleByName (0xF003, 61443)
|
|
527
|
-
SymbolHandleByName: 61443, // 0x0000F003
|
|
528
|
-
//SymbolValueByName (0xF004, 61444)
|
|
529
|
-
SymbolValueByName: 61444, // 0x0000F004
|
|
530
|
-
//SymbolValueByHandle (0xF005, 61445)
|
|
531
|
-
SymbolValueByHandle: 61445, // 0x0000F005
|
|
532
|
-
//SymbolReleaseHandle (0xF006, 61446)
|
|
533
|
-
SymbolReleaseHandle: 61446, // 0x0000F006
|
|
534
|
-
//SymbolInfoByName (0xF007, 61447)
|
|
535
|
-
SymbolInfoByName: 61447, // 0x0000F007
|
|
536
|
-
//SymbolVersion (0xF008, 61448)
|
|
537
|
-
SymbolVersion: 61448, // 0x0000F008
|
|
538
|
-
//SymbolInfoByNameEx (0xF009, 61449)
|
|
539
|
-
SymbolInfoByNameEx: 61449, // 0x0000F009
|
|
540
|
-
//SymbolDownload (F00A, 61450)
|
|
541
|
-
SymbolDownload: 61450, // 0x0000F00A
|
|
542
|
-
//SymbolUpload (F00B, 61451)
|
|
543
|
-
SymbolUpload: 61451, // 0x0000F00B
|
|
544
|
-
//SymbolUploadInfo (0xF00C, 61452)
|
|
545
|
-
SymbolUploadInfo: 61452, // 0x0000F00C
|
|
546
|
-
//SymbolDownload2
|
|
547
|
-
SymbolDownload2: 0xF00D, //Added, not from .dll
|
|
548
|
-
//SymbolDataTypeUpload
|
|
549
|
-
SymbolDataTypeUpload: 0xF00E, //Added, not from .dll
|
|
550
|
-
//SymbolUploadInfo2
|
|
551
|
-
SymbolUploadInfo2: 0xF00F, //Added, not from .dll - 24 bytes of info, uploadinfo3 would contain 64 bytes
|
|
552
|
-
//Notification of named handle (0xF010, 61456)
|
|
553
|
-
SymbolNote: 61456, // 0x0000F010
|
|
554
|
-
//DataDataTypeInfoByNameEx
|
|
555
|
-
DataDataTypeInfoByNameEx: 0xF011, //Added, not from .dll
|
|
556
|
-
//read/write input byte(s) (0xF020, 61472)
|
|
557
|
-
IOImageRWIB: 61472, // 0x0000F020
|
|
558
|
-
//read/write input bit (0xF021, 61473)
|
|
559
|
-
IOImageRWIX: 61473, // 0x0000F021
|
|
560
|
-
//read/write output byte(s) (0xF030, 61488)
|
|
561
|
-
IOImageRWOB: 61488, // 0x0000F030
|
|
562
|
-
//read/write output bit (0xF031, 61489)
|
|
563
|
-
IOImageRWOX: 61489, // 0x0000F031
|
|
564
|
-
//write inputs to null (0xF040, 61504)
|
|
565
|
-
IOImageClearI: 61504, // 0x0000F040
|
|
566
|
-
//write outputs to null (0xF050, 61520)
|
|
567
|
-
IOImageClearO: 61520, // 0x0000F050
|
|
568
|
-
//
|
|
569
|
-
//ADS Sum Read Command (ADSIGRP_SUMUP_READ, 0xF080, 61568)
|
|
570
|
-
//
|
|
571
|
-
SumCommandRead: 61568, // 0x0000F080
|
|
572
|
-
//
|
|
573
|
-
//ADS Sum Write Command (ADSIGRP_SUMUP_WRITE, 0xF081, 61569)
|
|
574
|
-
//
|
|
575
|
-
SumCommandWrite: 61569, // 0x0000F081
|
|
576
|
-
//
|
|
577
|
-
//ADS sum Read/Write command (ADSIGRP_SUMUP_READWRITE, 0xF082, 61570)
|
|
578
|
-
//
|
|
579
|
-
SumCommandReadWrite: 61570, // 0x0000F082
|
|
580
|
-
//
|
|
581
|
-
//ADS sum ReadEx command (ADSIGRP_SUMUP_READEX, 0xF083, 61571)
|
|
582
|
-
//AdsRW IOffs list size
|
|
583
|
-
//W: {list of IGrp, IOffs, Length}
|
|
584
|
-
//R: {list of results, Length} followed by {list of data (expepted lengths)}
|
|
585
|
-
//
|
|
586
|
-
SumCommandReadEx: 61571, // 0x0000F083
|
|
587
|
-
//
|
|
588
|
-
//ADS sum ReadEx2 command (ADSIGRP_SUMUP_READEX2, 0xF084, 61572)
|
|
589
|
-
//AdsRW IOffs list size
|
|
590
|
-
//W: {list of IGrp, IOffs, Length}
|
|
591
|
-
//R: {list of results, Length} followed by {list of data (returned lengths)}
|
|
592
|
-
//
|
|
593
|
-
SumCommandReadEx2: 61572, // 0x0000F084
|
|
594
|
-
//
|
|
595
|
-
//ADS sum AddDevNote command (ADSIGRP_SUMUP_ADDDEVNOTE, 0xF085, 61573)
|
|
596
|
-
//AdsRW IOffs list size
|
|
597
|
-
//W: {list of IGrp, IOffs, Attrib}
|
|
598
|
-
//R: {list of results, handles}
|
|
599
|
-
//
|
|
600
|
-
SumCommandAddDevNote: 61573, // 0x0000F085
|
|
601
|
-
//
|
|
602
|
-
//ADS sum DelDevNot command (ADSIGRP_SUMUP_DELDEVNOTE, 0xF086, 61574)
|
|
603
|
-
//AdsRW IOffs list size
|
|
604
|
-
//W: {list of handles}
|
|
605
|
-
//R: {list of results}
|
|
606
|
-
//
|
|
607
|
-
SumCommandDelDevNote: 61574, // 0x0000F086
|
|
608
|
-
//DeviceData (0xF100,61696)
|
|
609
|
-
DeviceData: 61696, // 0x0000F100
|
|
610
|
-
|
|
611
|
-
toString: function (value) {
|
|
612
|
-
return (Object.keys(this).find(key => this[key] == value)) || 'UNKNOWN'
|
|
613
|
-
}
|
|
614
|
-
}
|
|
615
|
-
exports.ADS_RESERVED_INDEX_GROUPS = ADS_RESERVED_INDEX_GROUPS
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
/**
|
|
622
|
-
* ADS symbol flags
|
|
623
|
-
*
|
|
624
|
-
* Source: TwinCAT.Ads.dll By Beckhoff
|
|
625
|
-
*/
|
|
626
|
-
const ADS_SYMBOL_FLAGS = {
|
|
627
|
-
//None
|
|
628
|
-
None: 0,
|
|
629
|
-
//ADSSYMBOLFLAG_PERSISTENT
|
|
630
|
-
Persistent: 1,
|
|
631
|
-
//ADSSYMBOLFLAG_BITVALUE
|
|
632
|
-
BitValue: 2,
|
|
633
|
-
//ADSSYMBOLFLAG_REFERENCETO
|
|
634
|
-
ReferenceTo: 4,
|
|
635
|
-
//ADSSYMBOLFLAG_TYPEGUID
|
|
636
|
-
TypeGuid: 8,
|
|
637
|
-
//ADSSYMBOLFLAG_TCCOMIFACEPTR
|
|
638
|
-
TComInterfacePtr: 16, // 0x0010
|
|
639
|
-
//ADSSYMBOLFLAG_READONLY
|
|
640
|
-
ReadOnly: 32, // 0x0020
|
|
641
|
-
//ADSSYMBOLFLAG_ITFMETHODACCESS
|
|
642
|
-
ItfMethodAccess: 64, // 0x0040
|
|
643
|
-
//ADSSYMBOLFLAG_METHODDEREF
|
|
644
|
-
MethodDeref: 128, // 0x0080
|
|
645
|
-
//ADSSYMBOLFLAG_CONTEXTMASK (4 Bit)
|
|
646
|
-
ContextMask: 3840, // 0x0F00
|
|
647
|
-
//ADSSYMBOLFLAG_ATTRIBUTES
|
|
648
|
-
Attributes: 4096, // 0x1000
|
|
649
|
-
//
|
|
650
|
-
// Symbol is static (ADSSYMBOLFLAG_STATIC,0x2000)
|
|
651
|
-
//
|
|
652
|
-
Static: 8192, // 0x2000
|
|
653
|
-
//
|
|
654
|
-
// Persistent data will not restored after reset (cold, ADSSYMBOLFLAG_INITONRESET 0x4000)
|
|
655
|
-
//
|
|
656
|
-
InitOnReset: 16384, // 0x4000
|
|
657
|
-
//
|
|
658
|
-
// Extended Flags in symbol (ADSSYMBOLFLAG_EXTENDEDFLAGS,0x8000)
|
|
659
|
-
//
|
|
660
|
-
ExtendedFlags: 32768, // 0x8000
|
|
661
|
-
|
|
662
|
-
toStringArray: function (flags) {
|
|
663
|
-
let flagsStr = []
|
|
664
|
-
|
|
665
|
-
Object.keys(ADS_SYMBOL_FLAGS).forEach((item) => {
|
|
666
|
-
//Check if flag is available
|
|
667
|
-
if ((flags & ADS_SYMBOL_FLAGS[item]) === ADS_SYMBOL_FLAGS[item]) {
|
|
668
|
-
if (flags === 0 || ADS_SYMBOL_FLAGS[item] !== 0) flagsStr.push(item)
|
|
669
|
-
}
|
|
670
|
-
})
|
|
671
|
-
|
|
672
|
-
return flagsStr
|
|
673
|
-
}
|
|
674
|
-
}
|
|
675
|
-
exports.ADS_SYMBOL_FLAGS = ADS_SYMBOL_FLAGS
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
/**
|
|
680
|
-
* ADS data type flags
|
|
681
|
-
*
|
|
682
|
-
* Source: TwinCAT.Ads.dll By Beckhoff
|
|
683
|
-
*/
|
|
684
|
-
const ADS_DATA_TYPE_FLAGS = {
|
|
685
|
-
//ADSDATATYPEFLAG_DATATYPE
|
|
686
|
-
DataType: 1,
|
|
687
|
-
//ADSDATATYPEFLAG_DATAITEM
|
|
688
|
-
DataItem: 2,
|
|
689
|
-
//ADSDATATYPEFLAG_REFERENCETO
|
|
690
|
-
ReferenceTo: 4,
|
|
691
|
-
//ADSDATATYPEFLAG_METHODDEREF
|
|
692
|
-
MethodDeref: 8,
|
|
693
|
-
//ADSDATATYPEFLAG_OVERSAMPLE
|
|
694
|
-
Oversample: 16, // 0x00000010
|
|
695
|
-
//ADSDATATYPEFLAG_BITVALUES
|
|
696
|
-
BitValues: 32, // 0x00000020
|
|
697
|
-
//ADSDATATYPEFLAG_PROPITEM
|
|
698
|
-
PropItem: 64, // 0x00000040
|
|
699
|
-
//ADSDATATYPEFLAG_TYPEGUID
|
|
700
|
-
TypeGuid: 128, // 0x00000080
|
|
701
|
-
//ADSDATATYPEFLAG_PERSISTENT
|
|
702
|
-
Persistent: 256, // 0x00000100
|
|
703
|
-
//ADSDATATYPEFLAG_COPYMASK
|
|
704
|
-
CopyMask: 512, // 0x00000200
|
|
705
|
-
//ADSDATATYPEFLAG_TCCOMIFACEPTR
|
|
706
|
-
TComInterfacePtr: 1024, // 0x00000400
|
|
707
|
-
//ADSDATATYPEFLAG_METHODINFOS
|
|
708
|
-
MethodInfos: 2048, // 0x00000800
|
|
709
|
-
//ADSDATATYPEFLAG_ATTRIBUTES
|
|
710
|
-
Attributes: 4096, // 0x00001000
|
|
711
|
-
//ADSDATATYPEFLAG_ENUMINFOS
|
|
712
|
-
EnumInfos: 8192, // 0x00002000
|
|
713
|
-
//
|
|
714
|
-
// this flag is set if the datatype is aligned (ADSDATATYPEFLAG_ALIGNED)
|
|
715
|
-
//
|
|
716
|
-
Aligned: 65536, // 0x00010000
|
|
717
|
-
//
|
|
718
|
-
// data item is static - do not use offs (ADSDATATYPEFLAG_STATIC)
|
|
719
|
-
//
|
|
720
|
-
Static: 131072, // 0x00020000
|
|
721
|
-
//
|
|
722
|
-
// means "ContainSpLevelss" for DATATYPES and "HasSpLevels" for DATAITEMS (ADSDATATYPEFLAG_SPLEVELS)
|
|
723
|
-
//
|
|
724
|
-
SpLevels: 262144, // 0x00040000
|
|
725
|
-
//
|
|
726
|
-
// do not restore persistent data (ADSDATATYPEFLAG_IGNOREPERSIST)
|
|
727
|
-
//
|
|
728
|
-
IgnorePersist: 524288, // 0x00080000
|
|
729
|
-
//Any size array (ADSDATATYPEFLAG_ANYSIZEARRAY)
|
|
730
|
-
// <remarks>
|
|
731
|
-
// If the index is exeeded, a value access to this array will return <see cref="F:TwinCAT.Ads.AdsErrorCode.DeviceInvalidArrayIndex" />
|
|
732
|
-
// </remarks>
|
|
733
|
-
AnySizeArray: 1048576, // 0x00100000
|
|
734
|
-
//
|
|
735
|
-
// data type used for persistent variables -> should be saved with persistent data (ADSDATATYPEFLAG_PERSIST_DT,0x00200000)
|
|
736
|
-
//
|
|
737
|
-
PersistantDatatype: 2097152, // 0x00200000
|
|
738
|
-
//
|
|
739
|
-
// Persistent data will not restored after reset (cold) (ADSDATATYPEFLAG_INITONRESET,0x00400000)
|
|
740
|
-
//
|
|
741
|
-
InitOnResult: 4194304, // 0x00400000
|
|
742
|
-
//None / No Flag set
|
|
743
|
-
None: 0,
|
|
744
|
-
|
|
745
|
-
toStringArray: function (flags) {
|
|
746
|
-
let flagsStr = []
|
|
747
|
-
|
|
748
|
-
Object.keys(ADS_DATA_TYPE_FLAGS).forEach((item) => {
|
|
749
|
-
//Check if flag is available
|
|
750
|
-
if ((flags & ADS_DATA_TYPE_FLAGS[item]) === ADS_DATA_TYPE_FLAGS[item]) {
|
|
751
|
-
if (flags === 0 || ADS_DATA_TYPE_FLAGS[item] !== 0) flagsStr.push(item)
|
|
752
|
-
}
|
|
753
|
-
})
|
|
754
|
-
|
|
755
|
-
return flagsStr
|
|
756
|
-
}
|
|
757
|
-
}
|
|
758
|
-
exports.ADS_DATA_TYPE_FLAGS = ADS_DATA_TYPE_FLAGS
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
/**
|
|
762
|
-
* ADS data types
|
|
763
|
-
*
|
|
764
|
-
* Source: TwinCAT.Ads.dll By Beckhoff
|
|
765
|
-
*/
|
|
766
|
-
const ADS_DATA_TYPES = {
|
|
767
|
-
/// <summary>Empty Type</summary>
|
|
768
|
-
ADST_VOID: 0,
|
|
769
|
-
/// <summary>Integer 16 Bit</summary>
|
|
770
|
-
ADST_INT16: 2,
|
|
771
|
-
/// <summary>Integer 32 Bit</summary>
|
|
772
|
-
ADST_INT32: 3,
|
|
773
|
-
/// <summary>Real (32 Bit)</summary>
|
|
774
|
-
ADST_REAL32: 4,
|
|
775
|
-
/// <summary>Real 64 Bit</summary>
|
|
776
|
-
ADST_REAL64: 5,
|
|
777
|
-
/// <summary>Integer 8 Bit</summary>
|
|
778
|
-
ADST_INT8: 16, // 0x00000010
|
|
779
|
-
/// <summary>Unsigned integer 8 Bit</summary>
|
|
780
|
-
ADST_UINT8: 17, // 0x00000011
|
|
781
|
-
/// <summary>Unsigned integer 16 Bit</summary>
|
|
782
|
-
ADST_UINT16: 18, // 0x00000012
|
|
783
|
-
/// <summary>Unsigned Integer 32 Bit</summary>
|
|
784
|
-
ADST_UINT32: 19, // 0x00000013
|
|
785
|
-
/// <summary>LONG Integer 64 Bit</summary>
|
|
786
|
-
ADST_INT64: 20, // 0x00000014
|
|
787
|
-
/// <summary>Unsigned Long integer 64 Bit</summary>
|
|
788
|
-
ADST_UINT64: 21, // 0x00000015
|
|
789
|
-
/// <summary>STRING</summary>
|
|
790
|
-
ADST_STRING: 30, // 0x0000001E
|
|
791
|
-
/// <summary>WSTRING</summary>
|
|
792
|
-
ADST_WSTRING: 31, // 0x0000001F
|
|
793
|
-
/// <summary>ADS REAL80</summary>
|
|
794
|
-
ADST_REAL80: 32, // 0x00000020
|
|
795
|
-
/// <summary>ADS BIT</summary>
|
|
796
|
-
ADST_BIT: 33, // 0x00000021
|
|
797
|
-
/// <summary>Internal Only</summary>
|
|
798
|
-
ADST_MAXTYPES: 34, // 0x00000022
|
|
799
|
-
/// <summary>Blob</summary>
|
|
800
|
-
ADST_BIGTYPE: 65, // 0x00000041
|
|
801
|
-
|
|
802
|
-
toString: function (value) {
|
|
803
|
-
return (Object.keys(this).find(key => this[key] == value)) || 'UNKNOWN'
|
|
804
|
-
}
|
|
805
|
-
}
|
|
806
|
-
exports.ADS_DATA_TYPES = ADS_DATA_TYPES
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
/**
|
|
811
|
-
* ADS RCP method parameter flags
|
|
812
|
-
*
|
|
813
|
-
* Source: TwinCAT.Ads.dll By Beckhoff
|
|
814
|
-
*/
|
|
815
|
-
const RCP_METHOD_PARAM_FLAGS = {
|
|
816
|
-
/// <summary>Input Parameter (ADSMETHODPARAFLAG_IN)</summary>
|
|
817
|
-
In: 1,
|
|
818
|
-
/// <summary>Output Parameter (ADSMETHODPARAFLAG_OUT)</summary>
|
|
819
|
-
Out: 2,
|
|
820
|
-
/// <summary>
|
|
821
|
-
/// By reference Parameter (ADSMETHODPARAFLAG_BYREFERENCE)
|
|
822
|
-
/// </summary>
|
|
823
|
-
ByReference: 4,
|
|
824
|
-
/// <summary>Mask for In parameters.</summary>
|
|
825
|
-
MaskIn: 5,
|
|
826
|
-
/// <summary>Mask for Out parameters.</summary>
|
|
827
|
-
MaskOut: 6,
|
|
828
|
-
|
|
829
|
-
toStringArray: function (flags) {
|
|
830
|
-
let flagsStr = []
|
|
831
|
-
|
|
832
|
-
Object.keys(RCP_METHOD_PARAM_FLAGS).forEach((item) => {
|
|
833
|
-
//Check if flag is available
|
|
834
|
-
if ((flags & RCP_METHOD_PARAM_FLAGS[item]) === RCP_METHOD_PARAM_FLAGS[item]) {
|
|
835
|
-
if (flags === 0 || RCP_METHOD_PARAM_FLAGS[item] !== 0) flagsStr.push(item)
|
|
836
|
-
}
|
|
837
|
-
})
|
|
838
|
-
|
|
839
|
-
return flagsStr
|
|
840
|
-
}
|
|
841
|
-
}
|
|
842
|
-
exports.RCP_METHOD_PARAM_FLAGS = RCP_METHOD_PARAM_FLAGS
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
/**
|
|
847
|
-
* AMS router state
|
|
848
|
-
*/
|
|
849
|
-
const AMS_ROUTER_STATE = {
|
|
850
|
-
STOP: 0,
|
|
851
|
-
START: 1,
|
|
852
|
-
REMOVED: 2,
|
|
853
|
-
|
|
854
|
-
toString: function (value) {
|
|
855
|
-
return (Object.keys(this).find(key => this[key] == value)) || 'UNKNOWN'
|
|
856
|
-
}
|
|
857
|
-
}
|
|
858
|
-
exports.AMS_ROUTER_STATE = AMS_ROUTER_STATE
|
|
859
|
-
|
|
860
|
-
/**
|
|
861
|
-
* Base data types
|
|
862
|
-
*
|
|
863
|
-
* Object that handles PLC base data types
|
|
864
|
-
*/
|
|
865
|
-
const BASE_DATA_TYPES = {
|
|
866
|
-
|
|
867
|
-
/**
|
|
868
|
-
* Returns true if given data type is found and known
|
|
869
|
-
*
|
|
870
|
-
* @param {string} name Data type name
|
|
871
|
-
*/
|
|
872
|
-
isKnownType: function (name) {
|
|
873
|
-
return this.find(name.trim()) != null
|
|
874
|
-
},
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
/**
|
|
879
|
-
* Finds the given data type from array
|
|
880
|
-
*
|
|
881
|
-
* @param {string} name Data type name
|
|
882
|
-
*/
|
|
883
|
-
find: function (name) {
|
|
884
|
-
let regExpRes = null
|
|
885
|
-
|
|
886
|
-
//First, try to find easy way
|
|
887
|
-
let type = this.types.find(type => type.name.includes(name.toUpperCase()))
|
|
888
|
-
|
|
889
|
-
if (!type) {
|
|
890
|
-
//Not found, try to find the correct type with regular expressions
|
|
891
|
-
//We can find also STRING(xx), WSTRING(xx) and DWORD(100..2000) for example
|
|
892
|
-
type = this.types.find(type => {
|
|
893
|
-
const re = new RegExp('^(' + type.name.join('|') + ')([\\[\\(](.*)[\\)\\]])*$', 'i')
|
|
894
|
-
|
|
895
|
-
//Using match instead of test so we get capture groups too
|
|
896
|
-
regExpRes = name.trim().match(re)
|
|
897
|
-
|
|
898
|
-
return (regExpRes != null)
|
|
899
|
-
})
|
|
900
|
-
}
|
|
901
|
-
|
|
902
|
-
if (type == null)
|
|
903
|
-
return null
|
|
904
|
-
|
|
905
|
-
//We are here -> type is found
|
|
906
|
-
//If string/wstring, regExpRes[3] is the string length -> use it
|
|
907
|
-
if (type.adsDataType === ADS_DATA_TYPES.ADST_STRING) {
|
|
908
|
-
type.size = (regExpRes[3] != null ? (parseInt(regExpRes[3]) + 1) : type.size)
|
|
909
|
-
} else if (type.adsDataType === ADS_DATA_TYPES.ADST_WSTRING) {
|
|
910
|
-
type.size = (regExpRes[3] != null ? (parseInt(regExpRes[3]) * 2 + 2) : type.size)
|
|
911
|
-
}
|
|
912
|
-
|
|
913
|
-
return type
|
|
914
|
-
},
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
/**
|
|
919
|
-
* Writes given value to given or new buffer
|
|
920
|
-
*
|
|
921
|
-
* @param {object} settings Reference to AdsClient settings
|
|
922
|
-
* @param {string} name Data type name
|
|
923
|
-
* @param {any} value Value to write
|
|
924
|
-
* @param {Buffer} [buffer] Optional - Buffer to write to. If not given, new Buffer is allocated
|
|
925
|
-
*/
|
|
926
|
-
toBuffer: function (settings, name, value, buffer = null) {
|
|
927
|
-
const type = this.find(name)
|
|
928
|
-
|
|
929
|
-
if (type == null) {
|
|
930
|
-
throw new Error(`Error: Base type ${name} not found from BaseDataTypes - If this should be found, report an issue`)
|
|
931
|
-
}
|
|
932
|
-
|
|
933
|
-
//If buffer not given, allocate new
|
|
934
|
-
if (buffer == null) {
|
|
935
|
-
const type = this.find(name)
|
|
936
|
-
buffer = Buffer.allocUnsafe(type.size)
|
|
937
|
-
}
|
|
938
|
-
|
|
939
|
-
type.toBuffer(value, buffer, settings)
|
|
940
|
-
return buffer
|
|
941
|
-
},
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
/**
|
|
946
|
-
* Reads given data type from given buffer
|
|
947
|
-
*
|
|
948
|
-
* @param {object} settings Reference to AdsClient settings
|
|
949
|
-
* @param {string} name Data type name
|
|
950
|
-
* @param {Buffer} buffer Buffer to read from
|
|
951
|
-
*/
|
|
952
|
-
fromBuffer: function (settings, name, buffer) {
|
|
953
|
-
const type = this.find(name)
|
|
954
|
-
|
|
955
|
-
if (type == null) {
|
|
956
|
-
throw new Error(`Error: Base type ${name} not found from BaseDataTypes - If this should be found, report an issue`)
|
|
957
|
-
}
|
|
958
|
-
return type.fromBuffer(buffer, settings)
|
|
959
|
-
},
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
/**
|
|
964
|
-
* All base data types and properties
|
|
965
|
-
*/
|
|
966
|
-
types: [
|
|
967
|
-
{
|
|
968
|
-
name: ['STRING'],
|
|
969
|
-
adsDataType: ADS_DATA_TYPES.ADST_STRING,
|
|
970
|
-
size: 81, //Just default size
|
|
971
|
-
},
|
|
972
|
-
{
|
|
973
|
-
name: ['WSTRING'],
|
|
974
|
-
adsDataType: ADS_DATA_TYPES.ADST_WSTRING,
|
|
975
|
-
size: 162, //Just default size
|
|
976
|
-
},
|
|
977
|
-
{
|
|
978
|
-
name: ['BOOL', 'BIT', 'BIT8'],
|
|
979
|
-
adsDataType: ADS_DATA_TYPES.ADST_BIT,
|
|
980
|
-
size: 1,
|
|
981
|
-
toBuffer: (value, buffer) => buffer.writeUInt8(value === true || value === 1 ? 1 : 0),
|
|
982
|
-
fromBuffer: buffer => buffer.readUInt8(0) === 1
|
|
983
|
-
},
|
|
984
|
-
{
|
|
985
|
-
name: ['BYTE', 'USINT', 'BITARR8', 'UINT8'],
|
|
986
|
-
adsDataType: ADS_DATA_TYPES.ADST_UINT8,
|
|
987
|
-
size: 1,
|
|
988
|
-
toBuffer: (value, buffer) => buffer.writeUInt8(value),
|
|
989
|
-
fromBuffer: buffer => buffer.readUInt8(0)
|
|
990
|
-
},
|
|
991
|
-
{
|
|
992
|
-
name: ['SINT', 'INT8'],
|
|
993
|
-
adsDataType: ADS_DATA_TYPES.ADST_INT8,
|
|
994
|
-
size: 1,
|
|
995
|
-
toBuffer: (value, buffer) => buffer.writeInt8(value),
|
|
996
|
-
fromBuffer: buffer => buffer.readInt8(0)
|
|
997
|
-
},
|
|
998
|
-
{
|
|
999
|
-
name: ['UINT', 'WORD', 'BITARR16', 'UINT16'],
|
|
1000
|
-
adsDataType: ADS_DATA_TYPES.ADST_UINT16,
|
|
1001
|
-
size: 2,
|
|
1002
|
-
toBuffer: (value, buffer) => buffer.writeUInt16LE(value),
|
|
1003
|
-
fromBuffer: buffer => buffer.readUInt16LE(0)
|
|
1004
|
-
},
|
|
1005
|
-
{
|
|
1006
|
-
name: ['INT', 'INT16'],
|
|
1007
|
-
adsDataType: ADS_DATA_TYPES.ADST_INT16,
|
|
1008
|
-
size: 2,
|
|
1009
|
-
toBuffer: (value, buffer) => buffer.writeInt16LE(value),
|
|
1010
|
-
fromBuffer: buffer => buffer.readInt16LE(0)
|
|
1011
|
-
},
|
|
1012
|
-
{
|
|
1013
|
-
name: ['DINT', 'INT32'],
|
|
1014
|
-
adsDataType: ADS_DATA_TYPES.ADST_INT32,
|
|
1015
|
-
size: 4,
|
|
1016
|
-
toBuffer: (value, buffer) => buffer.writeInt32LE(value),
|
|
1017
|
-
fromBuffer: buffer => buffer.readInt32LE(0)
|
|
1018
|
-
},
|
|
1019
|
-
{
|
|
1020
|
-
name: ['UDINT', 'DWORD', 'TIME', 'TIME_OF_DAY', 'TOD', 'BITARR32', 'UINT32'],
|
|
1021
|
-
adsDataType: ADS_DATA_TYPES.ADST_UINT32,
|
|
1022
|
-
size: 4,
|
|
1023
|
-
toBuffer: (value, buffer) => buffer.writeUInt32LE(value),
|
|
1024
|
-
fromBuffer: buffer => buffer.readUInt32LE(0)
|
|
1025
|
-
},
|
|
1026
|
-
{
|
|
1027
|
-
name: ['DATE_AND_TIME', 'DT', 'DATE'],
|
|
1028
|
-
adsDataType: ADS_DATA_TYPES.ADST_UINT32,
|
|
1029
|
-
size: 4,
|
|
1030
|
-
toBuffer: (value, buffer, settings) => {
|
|
1031
|
-
if (settings.convertDatesToJavascript === true && value.getTime)
|
|
1032
|
-
buffer.writeUInt32LE(value.getTime() / 1000)
|
|
1033
|
-
else
|
|
1034
|
-
buffer.writeUInt32LE(value)
|
|
1035
|
-
},
|
|
1036
|
-
fromBuffer: (buffer, settings) => {
|
|
1037
|
-
if (settings.convertDatesToJavascript === true)
|
|
1038
|
-
return new Date(buffer.readUInt32LE(0) * 1000)
|
|
1039
|
-
else
|
|
1040
|
-
return buffer.readUInt32LE(0)
|
|
1041
|
-
}
|
|
1042
|
-
},
|
|
1043
|
-
{
|
|
1044
|
-
name: ['REAL', 'FLOAT'],
|
|
1045
|
-
adsDataType: ADS_DATA_TYPES.ADST_REAL32,
|
|
1046
|
-
size: 4,
|
|
1047
|
-
toBuffer: (value, buffer) => buffer.writeFloatLE(value),
|
|
1048
|
-
fromBuffer: buffer => buffer.readFloatLE(0)
|
|
1049
|
-
},
|
|
1050
|
-
{
|
|
1051
|
-
name: ['LREAL', 'DOUBLE'],
|
|
1052
|
-
adsDataType: ADS_DATA_TYPES.ADST_REAL64,
|
|
1053
|
-
size: 8,
|
|
1054
|
-
toBuffer: (value, buffer) => buffer.writeDoubleLE(value),
|
|
1055
|
-
fromBuffer: buffer => buffer.readDoubleLE(0)
|
|
1056
|
-
},
|
|
1057
|
-
{
|
|
1058
|
-
name: ['LWORD', 'ULINT', 'LTIME', 'UINT64'],
|
|
1059
|
-
adsDataType: ADS_DATA_TYPES.ADST_UINT64,
|
|
1060
|
-
size: 8,
|
|
1061
|
-
toBuffer: (value, buffer, settings) => {
|
|
1062
|
-
//64 bit integers are missing from older Node.js Buffer, so use buffer instead if so
|
|
1063
|
-
if (buffer.writeBigUInt64LE && !settings.disableBigInt)
|
|
1064
|
-
buffer.writeBigUInt64LE(value)
|
|
1065
|
-
else
|
|
1066
|
-
value.copy(buffer)
|
|
1067
|
-
},
|
|
1068
|
-
fromBuffer: (buffer, settings) => {
|
|
1069
|
-
if (buffer.readBigInt64LE && !settings.disableBigInt)
|
|
1070
|
-
return buffer.readBigUInt64LE(0)
|
|
1071
|
-
else
|
|
1072
|
-
return buffer
|
|
1073
|
-
}
|
|
1074
|
-
},
|
|
1075
|
-
{
|
|
1076
|
-
name: ['LINT', 'INT64'],
|
|
1077
|
-
adsDataType: ADS_DATA_TYPES.ADST_INT64,
|
|
1078
|
-
size: 8,
|
|
1079
|
-
toBuffer: (value, buffer, settings) => {
|
|
1080
|
-
//64 bit integers are missing from older Node.js Buffer, so use buffer instead if so
|
|
1081
|
-
if (buffer.writeBigInt64LE && !settings.disableBigInt)
|
|
1082
|
-
buffer.writeBigInt64LE(value)
|
|
1083
|
-
else
|
|
1084
|
-
value.copy(buffer)
|
|
1085
|
-
},
|
|
1086
|
-
fromBuffer: (buffer, settings) => {
|
|
1087
|
-
if (buffer.readBigInt64LE && !settings.disableBigInt)
|
|
1088
|
-
return buffer.readBigInt64LE(0)
|
|
1089
|
-
else
|
|
1090
|
-
return buffer
|
|
1091
|
-
}
|
|
1092
|
-
},
|
|
1093
|
-
],
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
/**
|
|
1099
|
-
* Returns true if given data type is found and known
|
|
1100
|
-
*
|
|
1101
|
-
* @param {string} name Data type name
|
|
1102
|
-
*/
|
|
1103
|
-
isPseudoType: function (name) {
|
|
1104
|
-
return (this.findPseudoType(name) !== undefined)
|
|
1105
|
-
},
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
/**
|
|
1110
|
-
* Finds the given pseudo data type from array using regular expressions
|
|
1111
|
-
*
|
|
1112
|
-
* @param {string} name Pseudo data type name
|
|
1113
|
-
*/
|
|
1114
|
-
findPseudoType: function (name) {
|
|
1115
|
-
|
|
1116
|
-
return this.pseudoTypes.find(type => {
|
|
1117
|
-
const regexName = type.name.map(t => `^${t}`)
|
|
1118
|
-
|
|
1119
|
-
const re = new RegExp(regexName.join('|'), 'i')
|
|
1120
|
-
|
|
1121
|
-
return re.test(name.trim())
|
|
1122
|
-
})
|
|
1123
|
-
},
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
/**
|
|
1127
|
-
* Finds the given pseudo data type from array using regular expressions
|
|
1128
|
-
*
|
|
1129
|
-
* @param {string} name Pseudo data type name
|
|
1130
|
-
*/
|
|
1131
|
-
getTypeByPseudoType: function (name, byteSize) {
|
|
1132
|
-
return this.findPseudoType(name).actualTypesBySize[byteSize]
|
|
1133
|
-
},
|
|
1134
|
-
|
|
1135
|
-
/**
|
|
1136
|
-
* All pseudo data types and their actual types depending on size
|
|
1137
|
-
* Example: XINT is 4 bytes @ 32 bit platform -> DINT
|
|
1138
|
-
*/
|
|
1139
|
-
pseudoTypes: [
|
|
1140
|
-
{
|
|
1141
|
-
name: ['XINT', '__XINT'],
|
|
1142
|
-
actualTypesBySize: {
|
|
1143
|
-
4: 'DINT',
|
|
1144
|
-
8: 'LINT'
|
|
1145
|
-
}
|
|
1146
|
-
},
|
|
1147
|
-
{
|
|
1148
|
-
name: ['UXINT', '__UXINT', 'POINTER TO', 'REFERENCE TO', 'PVOID'],
|
|
1149
|
-
actualTypesBySize: {
|
|
1150
|
-
4: 'UDINT',
|
|
1151
|
-
8: 'ULINT'
|
|
1152
|
-
}
|
|
1153
|
-
},
|
|
1154
|
-
{
|
|
1155
|
-
name: ['XWORD', '__XWORD'],
|
|
1156
|
-
actualTypesBySize: {
|
|
1157
|
-
4: 'DWORD',
|
|
1158
|
-
8: 'LWORD'
|
|
1159
|
-
}
|
|
1160
|
-
},
|
|
1161
|
-
]
|
|
1162
|
-
}
|
|
1163
|
-
exports.BASE_DATA_TYPES = BASE_DATA_TYPES
|