motion-master-client 0.0.77 → 0.0.85
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/README.md +227 -138
- package/package.json +1 -1
- package/src/cli.d.ts +1 -1
- package/src/cli.js +160 -160
- package/src/index.d.ts +30 -28
- package/src/index.js +33 -31
- package/src/index.js.map +1 -1
- package/src/lib/cia402.d.ts +184 -182
- package/src/lib/cia402.js +393 -391
- package/src/lib/cia402.js.map +1 -1
- package/src/lib/config-file.d.ts +13 -13
- package/src/lib/config-file.js +49 -49
- package/src/lib/data-monitoring.d.ts +12 -12
- package/src/lib/data-monitoring.js +33 -33
- package/src/lib/device-log-line.d.ts +5 -5
- package/src/lib/device-log-line.js +2 -2
- package/src/lib/device-parameter.d.ts +56 -56
- package/src/lib/device-parameter.js +38 -38
- package/src/lib/device.d.ts +46 -9
- package/src/lib/device.js +166 -2
- package/src/lib/device.js.map +1 -1
- package/src/lib/encoder-register.d.ts +16 -16
- package/src/lib/encoder-register.js +116 -116
- package/src/lib/hardware-description.d.ts +46 -46
- package/src/lib/hardware-description.js +109 -109
- package/src/lib/integro-encoder-calibration.d.ts +31 -0
- package/src/lib/integro-encoder-calibration.js +196 -0
- package/src/lib/integro-encoder-calibration.js.map +1 -0
- package/src/lib/logger.d.ts +1 -1
- package/src/lib/logger.js +7 -7
- package/src/lib/monitoring-config.d.ts +31 -31
- package/src/lib/monitoring-config.js +2 -2
- package/src/lib/monitoring-entry.d.ts +9 -9
- package/src/lib/monitoring-entry.js +2 -2
- package/src/lib/motion-master-client.d.ts +77 -77
- package/src/lib/motion-master-client.js +196 -196
- package/src/lib/motion-master-pub-sub-client.d.ts +17 -17
- package/src/lib/motion-master-pub-sub-client.js +72 -72
- package/src/lib/motion-master-pub-sub-client.js.map +1 -1
- package/src/lib/motion-master-pub-sub-socket.d.ts +42 -42
- package/src/lib/motion-master-pub-sub-socket.js +2 -2
- package/src/lib/motion-master-pub-sub-web-socket.d.ts +18 -18
- package/src/lib/motion-master-pub-sub-web-socket.js +65 -65
- package/src/lib/motion-master-pub-sub-worker-socket.d.ts +18 -18
- package/src/lib/motion-master-pub-sub-worker-socket.js +47 -47
- package/src/lib/motion-master-req-res-client.d.ts +1104 -1062
- package/src/lib/motion-master-req-res-client.js +2137 -1997
- package/src/lib/motion-master-req-res-client.js.map +1 -1
- package/src/lib/motion-master-req-res-socket.d.ts +60 -60
- package/src/lib/motion-master-req-res-socket.js +2 -2
- package/src/lib/motion-master-req-res-web-socket.d.ts +28 -28
- package/src/lib/motion-master-req-res-web-socket.js +97 -97
- package/src/lib/motion-master-req-res-worker-socket.d.ts +24 -24
- package/src/lib/motion-master-req-res-worker-socket.js +71 -71
- package/src/lib/motion-master.proto.d.ts +5183 -5183
- package/src/lib/motion-master.proto.js +53218 -53218
- package/src/lib/operators.d.ts +20 -20
- package/src/lib/operators.js +82 -83
- package/src/lib/operators.js.map +1 -1
- package/src/lib/options.d.ts +10 -10
- package/src/lib/options.js +13 -13
- package/src/lib/os-command.d.ts +387 -173
- package/src/lib/os-command.js +555 -269
- package/src/lib/os-command.js.map +1 -1
- package/src/lib/parameter.d.ts +156 -138
- package/src/lib/parameter.js +377 -152
- package/src/lib/parameter.js.map +1 -1
- package/src/lib/product-id-range.d.ts +7 -7
- package/src/lib/product-id-range.js +11 -11
- package/src/lib/request-status-resolver.d.ts +4 -4
- package/src/lib/request-status-resolver.js +344 -344
- package/src/lib/somanet-product.d.ts +37 -0
- package/src/lib/somanet-product.js +126 -0
- package/src/lib/somanet-product.js.map +1 -0
- package/src/lib/system-log-line.d.ts +9 -9
- package/src/lib/system-log-line.js +2 -2
- package/src/lib/types.d.ts +141 -141
- package/src/lib/types.js +28 -28
- package/src/lib/urls.d.ts +3 -3
- package/src/lib/urls.js +9 -9
- package/src/lib/util.d.ts +21 -45
- package/src/lib/util.js +113 -379
- package/src/lib/util.js.map +1 -1
- package/src/lib/web-socket-connection-close-codes.d.ts +8 -8
- package/src/lib/web-socket-connection-close-codes.js +88 -88
package/README.md
CHANGED
|
@@ -1,138 +1,227 @@
|
|
|
1
|
-
# Motion Master Client
|
|
2
|
-
|
|
3
|
-
Motion Master Client is a library and CLI program written in [TypeScript](https://www.typescriptlang.org). It is used for communicating with Motion Master process over [WebSocket](https://developer.mozilla.org/en-US/docs/Web/API/WebSocket) connections by exchanging [Protocol Buffers](https://developers.google.com/protocol-buffers) serialized messages.
|
|
4
|
-
|
|
5
|
-
##
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
```
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
```
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
```
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
1
|
+
# Motion Master Client
|
|
2
|
+
|
|
3
|
+
Motion Master Client is a library and CLI program written in [TypeScript](https://www.typescriptlang.org). It is used for communicating with Motion Master process over [WebSocket](https://developer.mozilla.org/en-US/docs/Web/API/WebSocket) connections by exchanging [Protocol Buffers](https://developers.google.com/protocol-buffers) serialized messages.
|
|
4
|
+
|
|
5
|
+
## Usage
|
|
6
|
+
|
|
7
|
+
The Motion Master Client library can be equally used on a server with Node.js or in browsers.
|
|
8
|
+
|
|
9
|
+
### Server usage
|
|
10
|
+
|
|
11
|
+
Initialize a project:
|
|
12
|
+
|
|
13
|
+
```sh
|
|
14
|
+
mkdir hello-somanet
|
|
15
|
+
cd hello-somanet
|
|
16
|
+
npm init --yes
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
Install the required dependencies:
|
|
20
|
+
|
|
21
|
+
```sh
|
|
22
|
+
npm install --save motion-master-client rxjs ws
|
|
23
|
+
npm install --save-dev ts-node typescript
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
Create a TypeScript configuration:
|
|
27
|
+
|
|
28
|
+
```sh
|
|
29
|
+
npx tsc --init
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
Create a main program file:
|
|
33
|
+
|
|
34
|
+
```sh
|
|
35
|
+
touch main.ts
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
Add the following content to the _main.ts_ file:
|
|
39
|
+
|
|
40
|
+
```ts
|
|
41
|
+
import { createMotionMasterClient } from 'motion-master-client';
|
|
42
|
+
import { lastValueFrom } from 'rxjs';
|
|
43
|
+
|
|
44
|
+
// Ensure that Node.js has the global WebSocket object available.
|
|
45
|
+
Object.assign(globalThis, { WebSocket: require('ws') });
|
|
46
|
+
|
|
47
|
+
const client = createMotionMasterClient('192.168.200.253');
|
|
48
|
+
|
|
49
|
+
client.whenReady().then(async () => {
|
|
50
|
+
const devices = await lastValueFrom(client.request.getDevices());
|
|
51
|
+
const message = JSON.stringify(devices, null, 2);
|
|
52
|
+
console.log(message);
|
|
53
|
+
client.closeSockets();
|
|
54
|
+
});
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
Run the program:
|
|
58
|
+
|
|
59
|
+
```sh
|
|
60
|
+
npx ts-node main.ts
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
The program will:
|
|
64
|
+
|
|
65
|
+
1. Create an instance of the client and connect to a Motion Master process running at 192.168.200.253.
|
|
66
|
+
2. The client needs some time to connect, so it must be ready before making requests. Most of the requests are implemented and documented in the [MotionMasterReqResClient](https://synapticon.github.io/oblac/motion-master-client/classes/MotionMasterReqResClient.html) class.
|
|
67
|
+
3. The client requests a list of devices, which are then printed to the console.
|
|
68
|
+
4. The client closes opened sockets.
|
|
69
|
+
|
|
70
|
+
Here's another example that demonstrates how to get and set device parameter values:
|
|
71
|
+
|
|
72
|
+
```ts
|
|
73
|
+
import { createMotionMasterClient } from 'motion-master-client';
|
|
74
|
+
|
|
75
|
+
// Ensure that Node.js has the global WebSocket object available.
|
|
76
|
+
Object.assign(globalThis, { WebSocket: require('ws') });
|
|
77
|
+
|
|
78
|
+
const client = createMotionMasterClient('192.168.200.253');
|
|
79
|
+
|
|
80
|
+
client.whenReady().then(async () => {
|
|
81
|
+
// Device is referenced by a position (0).
|
|
82
|
+
const motorRatedCurrent = await client.request.upload(0, 0x6075, 0);
|
|
83
|
+
console.log(`Motor rated current: ${motorRatedCurrent}`);
|
|
84
|
+
|
|
85
|
+
// The device parameter is referenced by an ID, which consists of
|
|
86
|
+
// the index (0x6076), subindex (0x00), and the device serial number (8504-03-0002369-2329).
|
|
87
|
+
const motorRatedTorque = await client.request.upload('0x6076:00.8504-03-0002369-2329');
|
|
88
|
+
console.log(`Motor rated current: ${motorRatedTorque}`);
|
|
89
|
+
|
|
90
|
+
// Update the Max current parameter value to 2000.
|
|
91
|
+
await client.request.download(0, 0x6073, 0, 2000);
|
|
92
|
+
|
|
93
|
+
client.closeSockets();
|
|
94
|
+
});
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
## Understanding requests
|
|
98
|
+
|
|
99
|
+
When the client is instantiated, it connects to the Motion Master process using the WebSocket protocol. As it is a bi-directional, full-duplex communication protocol, there needs to be a mechanism that couples requests with responses. This is solved by having a message ID that is a mandatory attribute of each request; responses produced by that request will include the same message ID.
|
|
100
|
+
|
|
101
|
+
For some requests, such as firmware installation, Motion Master will send progress messages until the firmware installation is complete. Therefore, when making a request with the client library, functions will return an Observable of request statuses. This means that you can subscribe to an Observable and receive status messages over time. These observables are asynchronous, meaning your program can continue to do other things while the request executes. For the purpose of utilizing Observables and implementing reactive programming, the client library uses [RxJs](https://rxjs.dev/).
|
|
102
|
+
|
|
103
|
+
To demonstrate the use of reactive programming, let's create a program that monitors the drive and core temperatures:
|
|
104
|
+
|
|
105
|
+
```ts
|
|
106
|
+
import { createMotionMasterClient } from 'motion-master-client';
|
|
107
|
+
import { map, mergeMap } from 'rxjs';
|
|
108
|
+
|
|
109
|
+
// Ensure that Node.js has the global WebSocket object available.
|
|
110
|
+
Object.assign(globalThis, { WebSocket: require('ws') });
|
|
111
|
+
|
|
112
|
+
const client = createMotionMasterClient('192.168.200.253');
|
|
113
|
+
|
|
114
|
+
const subscription = client.onceReady$
|
|
115
|
+
.pipe(
|
|
116
|
+
mergeMap(() =>
|
|
117
|
+
client.startMonitoring(
|
|
118
|
+
[
|
|
119
|
+
[0, 0x2030, 1], // Core temperature
|
|
120
|
+
[0, 0x2031, 1], // Drive temperature
|
|
121
|
+
],
|
|
122
|
+
1000000, // microseconds
|
|
123
|
+
{ topic: 'temperatures-monitoring', distinct: true }
|
|
124
|
+
)
|
|
125
|
+
),
|
|
126
|
+
map((values) => `core=${values[0]} drive=${values[1]}`)
|
|
127
|
+
)
|
|
128
|
+
.subscribe(console.log);
|
|
129
|
+
|
|
130
|
+
process.on('SIGINT', function () {
|
|
131
|
+
console.log('\nGracefully shutting down from SIGINT (Ctrl-C).\nStopping monitoring and closing sockets.');
|
|
132
|
+
subscription?.unsubscribe();
|
|
133
|
+
client.closeSockets();
|
|
134
|
+
process.exit(0);
|
|
135
|
+
});
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
## Class Diagrams
|
|
139
|
+
|
|
140
|
+
```mermaid
|
|
141
|
+
---
|
|
142
|
+
title: Client & socket classes
|
|
143
|
+
---
|
|
144
|
+
classDiagram
|
|
145
|
+
class MotionMasterClient {
|
|
146
|
+
+MotionMasterReqResClient request
|
|
147
|
+
+MotionMasterPubSubClient monitor
|
|
148
|
+
+startMonitoring()
|
|
149
|
+
+stopMonitoring()
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
class MotionMasterReqResClient {
|
|
153
|
+
+MotionMasterReqResSocket socket
|
|
154
|
+
note "Has all the request methods\ncorresponding to the proto file."
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
class MotionMasterReqResSocket
|
|
158
|
+
<<interface>> MotionMasterReqResSocket
|
|
159
|
+
MotionMasterReqResSocket: +BehaviorSubject~boolean~ opened\$
|
|
160
|
+
MotionMasterReqResSocket: +BehaviorSubject~boolean~ alive\$
|
|
161
|
+
MotionMasterReqResSocket: +Observable~MotionMasterMessage~ message\$
|
|
162
|
+
MotionMasterReqResSocket: +open(string url, number pingSystemInterval?, number systemAliveTimeout?)
|
|
163
|
+
MotionMasterReqResSocket: +close()
|
|
164
|
+
MotionMasterReqResSocket: +send(MotionMasterMessage message)
|
|
165
|
+
|
|
166
|
+
class MotionMasterReqResWebSocket {
|
|
167
|
+
note "Keeps the connection alive by\nsending the ping system messages\nin regular intervals."
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
class MotionMasterReqResWorkerSocket {
|
|
171
|
+
+Worker worker
|
|
172
|
+
note "Passes messages between\nthe UI and worker thread."
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
class MotionMasterPubSubClient {
|
|
176
|
+
+MotionMasterPubSubSocket socket
|
|
177
|
+
+Subject<[string, MotionMasterMessage[]]> data\$
|
|
178
|
+
+Observable~MotionMasterMessage~ notification\$
|
|
179
|
+
+Observable~MotionMasterMessage~ systemEvent\$
|
|
180
|
+
+Observable~MotionMasterMessage~ deviceEvent\$
|
|
181
|
+
+subscribe(MonitoringConfig config)
|
|
182
|
+
+unsubscribe(string messageId)
|
|
183
|
+
+unsubscribeAll()
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
class MotionMasterPubSubSocket
|
|
187
|
+
<<interface>> MotionMasterPubSubSocket
|
|
188
|
+
MotionMasterPubSubSocket: +BehaviorSubject~boolean~ opened\$
|
|
189
|
+
MotionMasterPubSubSocket: +Observable<[string, MotionMasterMessage]> data\$
|
|
190
|
+
MotionMasterPubSubSocket: +open(string url)
|
|
191
|
+
MotionMasterPubSubSocket: +close()
|
|
192
|
+
|
|
193
|
+
class MotionMasterPubSubWebSocket {
|
|
194
|
+
note "Deserializes incoming data into\na tuple of topic and message."
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
class MotionMasterPubSubWorkerSocket {
|
|
198
|
+
+Worker worker
|
|
199
|
+
note "Passes messages between\nthe UI and worker thread."
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
MotionMasterClient *-- MotionMasterReqResClient
|
|
203
|
+
MotionMasterClient *-- MotionMasterPubSubClient
|
|
204
|
+
|
|
205
|
+
MotionMasterReqResClient *-- MotionMasterReqResSocket
|
|
206
|
+
MotionMasterReqResWebSocket <|-- MotionMasterReqResSocket
|
|
207
|
+
MotionMasterReqResWorkerSocket <|-- MotionMasterReqResSocket
|
|
208
|
+
|
|
209
|
+
MotionMasterPubSubClient *-- MotionMasterPubSubSocket
|
|
210
|
+
MotionMasterPubSubWebSocket <|-- MotionMasterPubSubSocket
|
|
211
|
+
MotionMasterPubSubWorkerSocket <|-- MotionMasterPubSubSocket
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
## Build & Publish
|
|
215
|
+
|
|
216
|
+
To update the `motion-master-client` version, first modify the version in `libs/motion-master-client/package.json`. Then, from the repository root, build the library by executing the following command:
|
|
217
|
+
|
|
218
|
+
```sh
|
|
219
|
+
npm run build motion-master-client
|
|
220
|
+
```
|
|
221
|
+
|
|
222
|
+
After building the library, proceed to publish it by following these steps:
|
|
223
|
+
|
|
224
|
+
```sh
|
|
225
|
+
cd dist/libs/motion-master-client
|
|
226
|
+
npm publish
|
|
227
|
+
```
|
package/package.json
CHANGED
package/src/cli.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export {};
|
|
1
|
+
export {};
|