abb-rws-client 0.7.2 → 1.0.0

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.
Files changed (70) hide show
  1. package/CHANGELOG.md +137 -0
  2. package/README.md +17 -8
  3. package/dist/HalJsonParser.d.ts +55 -0
  4. package/dist/HalJsonParser.d.ts.map +1 -0
  5. package/dist/HalJsonParser.js +155 -0
  6. package/dist/HalJsonParser.js.map +1 -0
  7. package/dist/HttpSession.d.ts.map +1 -1
  8. package/dist/HttpSession.js +13 -2
  9. package/dist/HttpSession.js.map +1 -1
  10. package/dist/IRWSAdapter.d.ts +7 -1
  11. package/dist/IRWSAdapter.d.ts.map +1 -1
  12. package/dist/MdnsDiscovery.d.ts +57 -0
  13. package/dist/MdnsDiscovery.d.ts.map +1 -0
  14. package/dist/MdnsDiscovery.js +313 -0
  15. package/dist/MdnsDiscovery.js.map +1 -0
  16. package/dist/MultiRobotManager.d.ts +5 -2
  17. package/dist/MultiRobotManager.d.ts.map +1 -1
  18. package/dist/MultiRobotManager.js +8 -3
  19. package/dist/MultiRobotManager.js.map +1 -1
  20. package/dist/RWS1Adapter.d.ts +60 -2
  21. package/dist/RWS1Adapter.d.ts.map +1 -1
  22. package/dist/RWS1Adapter.js +152 -4
  23. package/dist/RWS1Adapter.js.map +1 -1
  24. package/dist/ResourceMapper.d.ts +4 -0
  25. package/dist/ResourceMapper.d.ts.map +1 -1
  26. package/dist/ResourceMapper.js +9 -1
  27. package/dist/ResourceMapper.js.map +1 -1
  28. package/dist/RobotManager.d.ts +72 -12
  29. package/dist/RobotManager.d.ts.map +1 -1
  30. package/dist/RobotManager.js +255 -50
  31. package/dist/RobotManager.js.map +1 -1
  32. package/dist/RwsClient2.d.ts +150 -10
  33. package/dist/RwsClient2.d.ts.map +1 -1
  34. package/dist/RwsClient2.js +599 -236
  35. package/dist/RwsClient2.js.map +1 -1
  36. package/dist/WsSubscriber.d.ts +31 -5
  37. package/dist/WsSubscriber.d.ts.map +1 -1
  38. package/dist/WsSubscriber.js +104 -50
  39. package/dist/WsSubscriber.js.map +1 -1
  40. package/dist/detect.d.ts +12 -3
  41. package/dist/detect.d.ts.map +1 -1
  42. package/dist/detect.js +69 -25
  43. package/dist/detect.js.map +1 -1
  44. package/dist/index.d.ts +3 -1
  45. package/dist/index.d.ts.map +1 -1
  46. package/dist/index.js +2 -0
  47. package/dist/index.js.map +1 -1
  48. package/dist/types.js +3 -3
  49. package/dist/types.js.map +1 -1
  50. package/examples/05-remote-control-rmmp.mjs +10 -12
  51. package/examples/06-pull-module-source.mjs +13 -20
  52. package/package.json +62 -60
  53. package/src/HalJsonParser.ts +137 -0
  54. package/src/HttpSession.ts +460 -0
  55. package/src/IRWSAdapter.ts +422 -0
  56. package/src/Logger.ts +54 -0
  57. package/src/MdnsDiscovery.ts +336 -0
  58. package/src/MultiRobotManager.ts +159 -0
  59. package/src/RWS1Adapter.ts +1018 -0
  60. package/src/RWS2Adapter.ts +19 -0
  61. package/src/ResourceMapper.ts +517 -0
  62. package/src/ResponseParser.ts +710 -0
  63. package/src/RobotManager.ts +1705 -0
  64. package/src/RwsClient.ts +1150 -0
  65. package/src/RwsClient2.ts +2214 -0
  66. package/src/WsSubscriber.ts +350 -0
  67. package/src/XhtmlParser.ts +53 -0
  68. package/src/detect.ts +261 -0
  69. package/src/index.ts +83 -0
  70. package/src/types.ts +336 -0
package/src/index.ts ADDED
@@ -0,0 +1,83 @@
1
+ /**
2
+ * abb-rws-client — public API
3
+ *
4
+ * Typed HTTP/WebSocket client for ABB robot controllers, covering BOTH RWS protocols:
5
+ * - RWS 1.0 — IRC5 / RobotWare 6.x → use `RwsClient` (HTTP Digest, JSON via ?json=1)
6
+ * - RWS 2.0 — OmniCore / RobotWare 7.x → use `RwsClient2` (HTTP Basic, XHTML;v=2.0)
7
+ *
8
+ * Don't know which protocol the controller speaks? Use `createClient(host)` —
9
+ * it probes the WWW-Authenticate header and returns the right one.
10
+ *
11
+ * For polymorphic code that wants a single type across both protocols, use
12
+ * the `IRWSAdapter` interface and the `RWS1Adapter` / `RWS2Adapter` wrappers
13
+ * — or the `createAdapter(host)` helper.
14
+ *
15
+ * Higher-level helpers:
16
+ * - `RobotManager` — connection lifecycle, polling, WS subscriptions, port discovery
17
+ * - `MultiRobotManager` — multi-controller orchestration
18
+ * - `XhtmlParser` — RWS 2.0 response parser (exported for advanced users)
19
+ * - `setLogger(impl)` — install your own logging backend
20
+ */
21
+
22
+ // Protocol clients
23
+ export { RwsClient } from './RwsClient.js';
24
+ export { RwsClient2 } from './RwsClient2.js';
25
+
26
+ // Unified-interface adapters
27
+ export { RWS1Adapter } from './RWS1Adapter.js';
28
+ export { RWS2Adapter } from './RWS2Adapter.js';
29
+ export type { IRWSAdapter } from './IRWSAdapter.js';
30
+
31
+ // High-level managers
32
+ export { RobotManager } from './RobotManager.js';
33
+ export type { RobotState, ChangeHandler, ProbeResult, DiscoveredController, ErrorListener, RobotManagerOptions } from './RobotManager.js';
34
+ export { MultiRobotManager } from './MultiRobotManager.js';
35
+ export type { RobotConfig } from './MultiRobotManager.js';
36
+
37
+ // mDNS/Bonjour discovery (also reachable as RobotManager.discoverControllersMdns)
38
+ export { discoverControllersMdns } from './MdnsDiscovery.js';
39
+ export type { MdnsController, MdnsDiscoveryOptions } from './MdnsDiscovery.js';
40
+
41
+ // Auto-detection helpers
42
+ export { createClient, createAdapter, probeHost, probeProtocol } from './detect.js';
43
+ export type { AnyClient, Protocol, ConnectOptions, ProbeResult as DetectProbeResult } from './detect.js';
44
+
45
+ // Helpers
46
+ export { XhtmlParser } from './XhtmlParser.js';
47
+ export { setLogger } from './Logger.js';
48
+ export type { Logger } from './Logger.js';
49
+
50
+ // Errors
51
+ export { RwsError } from './types.js';
52
+
53
+ // Type exports (preserved from v0.6.0 + new additions)
54
+ export type {
55
+ RwsClientOptions,
56
+ RwsErrorCode,
57
+ ControllerState,
58
+ OperationMode,
59
+ ExecutionState,
60
+ ExecutionInfo,
61
+ ExecutionCycle,
62
+ JointTarget,
63
+ RobTarget,
64
+ CartesianFull,
65
+ Signal,
66
+ RapidTask,
67
+ IoNetwork,
68
+ IoDevice,
69
+ SystemInfo,
70
+ ControllerIdentity,
71
+ ControllerClock,
72
+ ElogMessage,
73
+ FileEntry,
74
+ MastershipDomain,
75
+ CollisionDetectionState,
76
+ RapidSymbolProperties,
77
+ RapidSymbolInfo,
78
+ RapidSymbolSearchParams,
79
+ UiInstruction,
80
+ RestartMode,
81
+ SubscriptionResource,
82
+ SubscriptionEvent,
83
+ } from './types.js';
package/src/types.ts ADDED
@@ -0,0 +1,336 @@
1
+ // abb-rws-client — shared type definitions
2
+ // Used by BOTH protocol clients: RwsClient (RWS 1.0 / IRC5 / RW6) and
3
+ // RwsClient2 (RWS 2.0 / OmniCore / RW7). See src/index.ts for the public surface.
4
+
5
+ export type ControllerState =
6
+ | 'init'
7
+ | 'motoroff'
8
+ | 'motoron'
9
+ | 'guardstop'
10
+ | 'emergencystop'
11
+ | 'emergencystopreset'
12
+ | 'sysfail';
13
+
14
+ export type OperationMode = 'AUTO' | 'MANR' | 'MANF';
15
+ export type ExecutionState = 'running' | 'stopped';
16
+
17
+ /** Full execution state including current cycle mode. */
18
+ export interface ExecutionInfo {
19
+ state: ExecutionState;
20
+ /** Current cycle mode: 'once' | 'forever' | 'asis' | 'oncedone' */
21
+ cycle: string;
22
+ }
23
+
24
+ export interface JointTarget {
25
+ rax_1: number;
26
+ rax_2: number;
27
+ rax_3: number;
28
+ rax_4: number;
29
+ rax_5: number;
30
+ rax_6: number;
31
+ }
32
+
33
+ export interface RobTarget {
34
+ x: number;
35
+ y: number;
36
+ z: number;
37
+ q1: number;
38
+ q2: number;
39
+ q3: number;
40
+ q4: number;
41
+ }
42
+
43
+ export interface Signal {
44
+ name: string;
45
+ value: string;
46
+ type: 'DI' | 'DO' | 'AI' | 'AO' | 'GI' | 'GO';
47
+ lvalue: string;
48
+ }
49
+
50
+ export interface RapidTask {
51
+ name: string;
52
+ type: string;
53
+ taskstate: string;
54
+ excstate: ExecutionState;
55
+ active: boolean;
56
+ motiontask: boolean;
57
+ }
58
+
59
+ /** Extended RobTarget that includes robot configuration flags returned by /cartesian */
60
+ export interface CartesianFull extends RobTarget {
61
+ /** Shoulder configuration: 0 = front, -1 = back */
62
+ j1: number;
63
+ /** Elbow configuration: -1 = down, 1 = up */
64
+ j4: number;
65
+ /** Wrist configuration: -1 = flip, 1 = no flip */
66
+ j6: number;
67
+ /** External axis configuration */
68
+ jx: number;
69
+ }
70
+
71
+ export interface IoNetwork {
72
+ name: string;
73
+ /** Physical state: 'running' | 'stopped' */
74
+ pstate: string;
75
+ /** Logical state: 'started' | 'stopped' */
76
+ lstate: string;
77
+ }
78
+
79
+ export interface IoDevice {
80
+ name: string;
81
+ network: string;
82
+ lstate: string;
83
+ pstate: string;
84
+ address: string;
85
+ }
86
+
87
+ export interface SystemInfo {
88
+ /** Controller/system name */
89
+ name: string;
90
+ /** RobotWare version string, e.g. '6.13.0164' */
91
+ rwVersion: string;
92
+ /** System GUID */
93
+ sysid: string;
94
+ /** Timestamp when RobotWare started */
95
+ startTime: string;
96
+ /** Licensed RobotWare options */
97
+ options: string[];
98
+ }
99
+
100
+ export interface ControllerIdentity {
101
+ /** Controller name */
102
+ name: string;
103
+ /** Controller ID */
104
+ id: string;
105
+ /** 'Real Controller' | 'Virtual Controller' */
106
+ type: string;
107
+ /** MAC address */
108
+ mac: string;
109
+ }
110
+
111
+ export interface ElogMessage {
112
+ /** Sequence number */
113
+ seqnum: number;
114
+ /** Event code, e.g. 10126 */
115
+ code: number;
116
+ /** 1 = info, 2 = warning, 3 = error */
117
+ msgtype: number;
118
+ /** Timestamp string from controller */
119
+ timestamp: string;
120
+ /** Source name (subsystem that generated the event) */
121
+ srcName: string;
122
+ title: string;
123
+ desc: string;
124
+ causes: string;
125
+ consequences: string;
126
+ actions: string;
127
+ }
128
+
129
+ /** Controller clock date/time. */
130
+ export interface ControllerClock {
131
+ /** Format: 'YYYY-MM-DD T HH:MM:SS' */
132
+ datetime: string;
133
+ }
134
+
135
+ /** Active RAPID UI instruction (e.g. TPReadNum, TPReadFK waiting for input). */
136
+ export interface UiInstruction {
137
+ /** Instruction name, e.g. 'TPReadNum', 'TPReadFK' */
138
+ instr: string;
139
+ /** Event type: 'SEND' | 'POST' | 'ABORT' */
140
+ event: string;
141
+ /** Stack URL — used as {stackurl} when setting a parameter value */
142
+ stack: string;
143
+ /** Execution level: 'NORMAL' | 'TRAP' | ... */
144
+ execlv: string;
145
+ /** Message text displayed on FlexPendant */
146
+ msg: string;
147
+ }
148
+
149
+ /** A RAPID symbol found by search (abbreviated properties). */
150
+ export interface RapidSymbolInfo {
151
+ /** Full symbol path, e.g. 'RAPID/T_ROB1/user/reg1' */
152
+ symburl: string;
153
+ name: string;
154
+ /** Symbol type: 'var' | 'per' | 'con' | 'fun' | 'prc' | etc. */
155
+ symtyp: string;
156
+ /** Data type name, e.g. 'num', 'string', 'bool', 'robtarget' */
157
+ dattyp: string;
158
+ /** Number of array dimensions (0 = scalar) */
159
+ ndim: number;
160
+ local: boolean;
161
+ ro: boolean;
162
+ taskvar: boolean;
163
+ }
164
+
165
+ /** Parameters for RAPID symbol search. */
166
+ export interface RapidSymbolSearchParams {
167
+ /** Task name; required */
168
+ task: string;
169
+ /** Search scope: 'block' | 'scope' | 'stack' */
170
+ view?: 'block' | 'scope' | 'stack';
171
+ /** Variable filter: 'rw' | 'ro' | 'loop' | 'any' */
172
+ vartyp?: string;
173
+ /** Symbol type filter: 'var' | 'per' | 'con' | 'fun' | 'prc' | 'mod' | 'tsk' | 'any' */
174
+ symtyp?: string;
175
+ /** Data type filter, e.g. 'num', 'bool', 'robtarget' */
176
+ dattyp?: string;
177
+ /** Regex pattern for symbol name matching */
178
+ regexp?: string;
179
+ /** Whether to search recursively; default true */
180
+ recursive?: boolean;
181
+ /** URL of module/routine to search within */
182
+ blockurl?: string;
183
+ }
184
+
185
+ /** Controller restart mode. */
186
+ export type RestartMode = 'restart' | 'istart' | 'pstart' | 'bstart';
187
+
188
+ export interface FileEntry {
189
+ name: string;
190
+ type: 'file' | 'dir';
191
+ /** File size in bytes (files only) */
192
+ size?: number;
193
+ /** Creation timestamp from controller */
194
+ created?: string;
195
+ /** Last-modified timestamp from controller */
196
+ modified?: string;
197
+ /** Whether the file is read-only (files only) */
198
+ readonly?: boolean;
199
+ }
200
+
201
+ export type MastershipDomain = 'cfg' | 'motion' | 'rapid';
202
+
203
+ /**
204
+ * Collision detection state returned by GET /rw/panel/coldetstate.
205
+ * INIT = no collision detected (normal operation).
206
+ * TRIGGERED = collision detected, not yet acknowledged.
207
+ * CONFIRMED = collision confirmed.
208
+ * TRIGGERED_ACK = collision acknowledged.
209
+ */
210
+ export type CollisionDetectionState = 'INIT' | 'TRIGGERED' | 'CONFIRMED' | 'TRIGGERED_ACK';
211
+
212
+ /** Execution cycle mode returned/set by /rw/rapid/execution */
213
+ export type ExecutionCycle = 'once' | 'forever' | 'asis';
214
+
215
+ /**
216
+ * RAPID symbol properties returned by GET /rw/rapid/symbol/properties/RAPID/{task}/{module}/{symbol}.
217
+ * symtyp: 'var' | 'per' | 'con' | 'par' | 'fun' | 'prc' | 'mod' | 'tsk' | 'any' | 'udef' | 'atm' | 'rec' | 'ali' | 'rcp'
218
+ */
219
+ export interface RapidSymbolProperties {
220
+ /** Full symbol URL path */
221
+ symburl: string;
222
+ /** Symbol type: var/per/con/par/fun/prc/mod/tsk/any/udef/atm/rec/ali/rcp */
223
+ symtyp: string;
224
+ /** Whether the symbol has a name */
225
+ named: boolean;
226
+ /** Data type name, e.g. 'num', 'string', 'bool', 'robtarget' */
227
+ dattyp: string;
228
+ /** Number of array dimensions (0 = scalar) */
229
+ ndim: number;
230
+ /** Dimension sizes as a string, e.g. '[3]' for 3-element array */
231
+ dim: string;
232
+ /** Whether the symbol is heap-allocated */
233
+ heap: boolean;
234
+ /** Whether the symbol definition is complete (linked) */
235
+ linked: boolean;
236
+ /** Whether the symbol is module-local (not global) */
237
+ local: boolean;
238
+ /** Whether the persistent is read-only */
239
+ ro: boolean;
240
+ /** Whether the symbol is task-global (taskvar) */
241
+ taskvar: boolean;
242
+ /** Storage type: 'local' | 'task' | 'global' */
243
+ storage: string;
244
+ /** URL reference to the type symbol */
245
+ typurl: string;
246
+ }
247
+
248
+ export interface RwsClientOptions {
249
+ /** IP address or hostname, e.g. '192.168.125.1' or '127.0.0.1' for RobotStudio */
250
+ host: string;
251
+ /** HTTP port; default 80 */
252
+ port?: number;
253
+ /** Default 'Admin' */
254
+ username?: string;
255
+ /** Default 'robotics' */
256
+ password?: string;
257
+ /** Minimum ms between requests; default 55ms (enforces <20 req/sec RWS rate limit) */
258
+ requestIntervalMs?: number;
259
+ /** Request timeout in ms; default 5000 */
260
+ timeout?: number;
261
+ /** Saved -http-session- cookie value to reuse an existing controller session slot */
262
+ sessionCookie?: string;
263
+ }
264
+
265
+ export type SubscriptionResource =
266
+ | 'execution'
267
+ | 'controllerstate'
268
+ | 'operationmode'
269
+ | 'speedratio'
270
+ | 'coldetstate'
271
+ | 'uiinstr'
272
+ | { type: 'signal'; name: string }
273
+ | { type: 'persvar'; name: string }
274
+ | { type: 'taskchange'; task: string }
275
+ | { type: 'execycle' }
276
+ | { type: 'elog'; domain: number };
277
+
278
+ export interface SubscriptionEvent {
279
+ resource: string;
280
+ value: string;
281
+ timestamp: Date;
282
+ }
283
+
284
+ export type RwsErrorCode =
285
+ | 'SESSION_EXPIRED'
286
+ | 'AUTH_FAILED'
287
+ | 'MOTORS_OFF'
288
+ | 'MODULE_NOT_FOUND'
289
+ | 'RATE_LIMITED'
290
+ | 'CONTROLLER_BUSY'
291
+ | 'NETWORK_ERROR'
292
+ | 'PARSE_ERROR'
293
+ | 'PROTOCOL_DETECT_FAILED'
294
+ | 'UNKNOWN';
295
+
296
+ /**
297
+ * Typed error thrown by all abb-rws-client public methods.
298
+ * Always check `code` for programmatic error handling.
299
+ */
300
+ export class RwsError extends Error {
301
+ readonly code: RwsErrorCode;
302
+ readonly httpStatus?: number;
303
+ readonly rwsDetail?: string;
304
+
305
+ constructor(message: string, code: RwsErrorCode, httpStatus?: number, rwsDetail?: string) {
306
+ super(message);
307
+ this.name = 'RwsError';
308
+ this.code = code;
309
+ this.httpStatus = httpStatus;
310
+ this.rwsDetail = rwsDetail;
311
+ // Restore prototype chain so instanceof checks work correctly when targeting ES2022
312
+ Object.setPrototypeOf(this, new.target.prototype);
313
+ }
314
+ }
315
+
316
+ // ─── Internal types (not re-exported from index.ts) ─────────────────────────
317
+
318
+ /** @internal Parsed fields from a WWW-Authenticate: Digest ... header (RFC 2617) */
319
+ export interface DigestChallenge {
320
+ realm: string;
321
+ nonce: string;
322
+ opaque?: string;
323
+ /** 'auth' | 'auth-int' — if absent, use RFC 2069 compat mode */
324
+ qop?: string;
325
+ /** Hash algorithm — typically 'MD5' (default) */
326
+ algorithm?: string;
327
+ stale?: boolean;
328
+ domain?: string;
329
+ }
330
+
331
+ /** @internal Return type for all HttpSession HTTP methods */
332
+ export interface HttpResponse {
333
+ status: number;
334
+ body: string;
335
+ headers: Headers;
336
+ }