@digipair/skill-mybuddy 0.23.9 → 0.23.11

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/index.esm.js CHANGED
@@ -1,5 +1,6 @@
1
1
  import mybuddy from '@marcbuils/mybuddy';
2
2
 
3
+ const TIMEOUT_READ_COMMANDS = 1000;
3
4
  let MyBuddyService = class MyBuddyService {
4
5
  async connect(params, context) {
5
6
  var _context_privates_MY_BUDDY;
@@ -14,430 +15,532 @@ let MyBuddyService = class MyBuddyService {
14
15
  const { device, angles, speed = 50 } = params;
15
16
  const connection = await this.connect(params, context);
16
17
  const result = connection.write(mybuddy.sendAngles(device, angles, speed));
17
- connection.close();
18
18
  await new Promise((resolve)=>setTimeout(resolve, 50));
19
+ connection.close();
19
20
  return result;
20
21
  }
21
22
  async powerOn(params, _pinsSettingsList, context) {
22
23
  const { device } = params;
23
24
  const connection = await this.connect(params, context);
24
25
  const result = connection.write(mybuddy.powerOn(device));
25
- connection.close();
26
26
  await new Promise((resolve)=>setTimeout(resolve, 50));
27
+ connection.close();
27
28
  return result;
28
29
  }
29
30
  async powerOff(params, _pinsSettingsList, context) {
30
31
  const { device } = params;
31
32
  const connection = await this.connect(params, context);
32
33
  const result = connection.write(mybuddy.powerOff(device));
33
- connection.close();
34
34
  await new Promise((resolve)=>setTimeout(resolve, 50));
35
+ connection.close();
35
36
  return result;
36
37
  }
37
38
  async releaseAllServos(params, _pinsSettingsList, context) {
38
39
  const { device } = params;
39
40
  const connection = await this.connect(params, context);
40
41
  const result = connection.write(mybuddy.releaseAllServos(device));
41
- connection.close();
42
42
  await new Promise((resolve)=>setTimeout(resolve, 50));
43
+ connection.close();
43
44
  return result;
44
45
  }
45
46
  async sendAngle(params, _pinsSettingsList, context) {
46
47
  const { device, id = 1, degree = 0, speed = 60 } = params;
47
48
  const connection = await this.connect(params, context);
48
49
  const result = connection.write(mybuddy.sendAngle(device, id, degree, speed));
49
- connection.close();
50
50
  await new Promise((resolve)=>setTimeout(resolve, 50));
51
+ connection.close();
51
52
  return result;
52
53
  }
53
54
  async sendCoords(params, _pinsSettingsList, context) {
54
55
  const { device, coords, speed, mode } = params;
55
56
  const connection = await this.connect(params, context);
56
57
  const result = connection.write(mybuddy.sendCoords(device, coords, speed, mode));
57
- connection.close();
58
58
  await new Promise((resolve)=>setTimeout(resolve, 50));
59
+ connection.close();
59
60
  return result;
60
61
  }
61
62
  async programPause(params, _pinsSettingsList, context) {
62
63
  const { device } = params;
63
64
  const connection = await this.connect(params, context);
64
65
  const result = connection.write(mybuddy.programPause(device));
65
- connection.close();
66
66
  await new Promise((resolve)=>setTimeout(resolve, 50));
67
+ connection.close();
67
68
  return result;
68
69
  }
69
70
  async programResume(params, _pinsSettingsList, context) {
70
71
  const { device } = params;
71
72
  const connection = await this.connect(params, context);
72
73
  const result = connection.write(mybuddy.programResume(device));
73
- connection.close();
74
74
  await new Promise((resolve)=>setTimeout(resolve, 50));
75
+ connection.close();
75
76
  return result;
76
77
  }
77
78
  async stop(params, _pinsSettingsList, context) {
78
79
  const { device } = params;
79
80
  const connection = await this.connect(params, context);
80
81
  const result = connection.write(mybuddy.stop(device));
81
- connection.close();
82
82
  await new Promise((resolve)=>setTimeout(resolve, 50));
83
+ connection.close();
83
84
  return result;
84
85
  }
85
86
  async jogAngle(params, _pinsSettingsList, context) {
86
87
  const { device, joint_id, direction, speed } = params;
87
88
  const connection = await this.connect(params, context);
88
89
  const result = connection.write(mybuddy.jogAngle(device, joint_id, direction, speed));
89
- connection.close();
90
90
  await new Promise((resolve)=>setTimeout(resolve, 50));
91
+ connection.close();
91
92
  return result;
92
93
  }
93
94
  async jogCoord(params, _pinsSettingsList, context) {
94
95
  const { device, coord_id, direction, speed } = params;
95
96
  const connection = await this.connect(params, context);
96
97
  const result = connection.write(mybuddy.jogCoord(device, coord_id, direction, speed));
97
- connection.close();
98
98
  await new Promise((resolve)=>setTimeout(resolve, 50));
99
+ connection.close();
99
100
  return result;
100
101
  }
101
102
  async jogStop(params, _pinsSettingsList, context) {
102
103
  const { device } = params;
103
104
  const connection = await this.connect(params, context);
104
105
  const result = connection.write(mybuddy.jogStop(device));
105
- connection.close();
106
106
  await new Promise((resolve)=>setTimeout(resolve, 50));
107
+ connection.close();
107
108
  return result;
108
109
  }
109
110
  async setEncoder(params, _pinsSettingsList, context) {
110
111
  const { device, joint_id, encoder } = params;
111
112
  const connection = await this.connect(params, context);
112
113
  const result = connection.write(mybuddy.setEncoder(device, joint_id, encoder));
113
- connection.close();
114
114
  await new Promise((resolve)=>setTimeout(resolve, 50));
115
+ connection.close();
115
116
  return result;
116
117
  }
117
118
  async setEncoders(params, _pinsSettingsList, context) {
118
119
  const { device, encoders, speed } = params;
119
120
  const connection = await this.connect(params, context);
120
121
  const result = connection.write(mybuddy.setEncoders(device, encoders, speed));
121
- connection.close();
122
122
  await new Promise((resolve)=>setTimeout(resolve, 50));
123
+ connection.close();
123
124
  return result;
124
125
  }
125
126
  async setSpeed(params, _pinsSettingsList, context) {
126
127
  const { device, speed } = params;
127
128
  const connection = await this.connect(params, context);
128
129
  const result = connection.write(mybuddy.setSpeed(device, speed));
129
- connection.close();
130
130
  await new Promise((resolve)=>setTimeout(resolve, 50));
131
+ connection.close();
131
132
  return result;
132
133
  }
133
134
  async setServoData(params, _pinsSettingsList, context) {
134
135
  const { device, servo_no, data_id, value } = params;
135
136
  const connection = await this.connect(params, context);
136
137
  const result = connection.write(mybuddy.setServoData(device, servo_no, data_id, value));
137
- connection.close();
138
138
  await new Promise((resolve)=>setTimeout(resolve, 50));
139
+ connection.close();
139
140
  return result;
140
141
  }
141
142
  async setServoCalibration(params, _pinsSettingsList, context) {
142
143
  const { device, servo_no } = params;
143
144
  const connection = await this.connect(params, context);
144
145
  const result = connection.write(mybuddy.setServoCalibration(device, servo_no));
145
- connection.close();
146
146
  await new Promise((resolve)=>setTimeout(resolve, 50));
147
+ connection.close();
147
148
  return result;
148
149
  }
149
150
  async releaseServo(params, _pinsSettingsList, context) {
150
151
  const { device, servo_no } = params;
151
152
  const connection = await this.connect(params, context);
152
153
  const result = connection.write(mybuddy.releaseServo(device, servo_no));
153
- connection.close();
154
154
  await new Promise((resolve)=>setTimeout(resolve, 50));
155
+ connection.close();
155
156
  return result;
156
157
  }
157
158
  async focusServo(params, _pinsSettingsList, context) {
158
159
  const { device, servo_no } = params;
159
160
  const connection = await this.connect(params, context);
160
161
  const result = connection.write(mybuddy.focusServo(device, servo_no));
161
- connection.close();
162
162
  await new Promise((resolve)=>setTimeout(resolve, 50));
163
+ connection.close();
163
164
  return result;
164
165
  }
165
166
  async setPinMode(params, _pinsSettingsList, context) {
166
167
  const { device, pin_no, pin_mode } = params;
167
168
  const connection = await this.connect(params, context);
168
169
  const result = connection.write(mybuddy.setPinMode(device, pin_no, pin_mode));
169
- connection.close();
170
170
  await new Promise((resolve)=>setTimeout(resolve, 50));
171
+ connection.close();
171
172
  return result;
172
173
  }
173
174
  async setDigitalOutput(params, _pinsSettingsList, context) {
174
175
  const { device, pin_no, pin_signal } = params;
175
176
  const connection = await this.connect(params, context);
176
177
  const result = connection.write(mybuddy.setDigitalOutput(device, pin_no, pin_signal));
177
- connection.close();
178
178
  await new Promise((resolve)=>setTimeout(resolve, 50));
179
+ connection.close();
179
180
  return result;
180
181
  }
181
182
  async setGripperState(params, _pinsSettingsList, context) {
182
183
  const { device, flag, speed } = params;
183
184
  const connection = await this.connect(params, context);
184
185
  const result = connection.write(mybuddy.setGripperState(device, flag, speed));
185
- connection.close();
186
186
  await new Promise((resolve)=>setTimeout(resolve, 50));
187
+ connection.close();
187
188
  return result;
188
189
  }
189
190
  async setGripperValue(params, _pinsSettingsList, context) {
190
191
  const { device, value, speed } = params;
191
192
  const connection = await this.connect(params, context);
192
193
  const result = connection.write(mybuddy.setGripperValue(device, value, speed));
193
- connection.close();
194
194
  await new Promise((resolve)=>setTimeout(resolve, 50));
195
+ connection.close();
195
196
  return result;
196
197
  }
197
198
  async setGripperIni(params, _pinsSettingsList, context) {
198
199
  const connection = await this.connect(params, context);
199
200
  const result = connection.write(mybuddy.setGripperIni());
200
- connection.close();
201
201
  await new Promise((resolve)=>setTimeout(resolve, 50));
202
+ connection.close();
202
203
  return result;
203
204
  }
204
205
  async setBasicOutput(params, _pinsSettingsList, context) {
205
206
  const { device, pin_no, pin_signal } = params;
206
207
  const connection = await this.connect(params, context);
207
208
  const result = connection.write(mybuddy.setBasicOutput(device, pin_no, pin_signal));
208
- connection.close();
209
209
  await new Promise((resolve)=>setTimeout(resolve, 50));
210
+ connection.close();
210
211
  return result;
211
212
  }
212
213
  async setColor(params, _pinsSettingsList, context) {
213
214
  const { device, r, g, b } = params;
214
215
  const connection = await this.connect(params, context);
215
216
  const result = connection.write(mybuddy.setColor(device, r, g, b));
216
- connection.close();
217
217
  await new Promise((resolve)=>setTimeout(resolve, 50));
218
+ connection.close();
218
219
  return result;
219
220
  }
220
221
  // Data Retrieval
221
222
  async getAngles(params, _pinsSettingsList, context) {
222
223
  const { device } = params;
223
- let data = null;
224
224
  const connection = await this.connect(params, context);
225
- connection.on('data', (data)=>{
226
- if (data[0] === 0xfe && data[1] === 0xfe && data[2] === device && data[4] === parseInt(mybuddy.COMMAND.GET_ANGLES, 16)) {
227
- data = mybuddy.processReceived(data);
225
+ return new Promise((resolve, reject)=>{
226
+ const timeoutId = setTimeout(()=>{
228
227
  connection.close();
229
- }
228
+ reject('TIMEOUT_READ_COMMANDS');
229
+ }, TIMEOUT_READ_COMMANDS);
230
+ connection.on('data', (data)=>{
231
+ if (data[0] === 0xfe && data[1] === 0xfe && data[2] === device && data[4] === parseInt(mybuddy.COMMAND.GET_ANGLES, 16)) {
232
+ clearTimeout(timeoutId);
233
+ const result = mybuddy.processReceived(data);
234
+ connection.close();
235
+ resolve(result);
236
+ }
237
+ });
238
+ connection.write(mybuddy.getAngles(device));
230
239
  });
231
- connection.write(mybuddy.getAngles(device));
232
- return data;
233
240
  }
234
241
  async isPowerOn(params, _pinsSettingsList, context) {
235
242
  const { device } = params;
236
- let data = null;
237
243
  const connection = await this.connect(params, context);
238
- connection.on('data', (data)=>{
239
- if (data[0] === 0xfe && data[1] === 0xfe && data[2] === device && data[4] === parseInt(mybuddy.COMMAND.IS_POWER_ON, 16)) {
240
- data = mybuddy.processReceived(data);
244
+ return new Promise((resolve, reject)=>{
245
+ const timeoutId = setTimeout(()=>{
241
246
  connection.close();
242
- }
247
+ reject('TIMEOUT_READ_COMMANDS');
248
+ }, TIMEOUT_READ_COMMANDS);
249
+ connection.on('data', (data)=>{
250
+ if (data[0] === 0xfe && data[1] === 0xfe && data[2] === device && data[4] === parseInt(mybuddy.COMMAND.IS_POWER_ON, 16)) {
251
+ clearTimeout(timeoutId);
252
+ const result = mybuddy.processReceived(data);
253
+ connection.close();
254
+ resolve(result);
255
+ }
256
+ });
257
+ connection.write(mybuddy.isPowerOn(device));
243
258
  });
244
- connection.write(mybuddy.isPowerOn(device));
245
- return data;
246
259
  }
247
260
  async isControllerConnect(params, _pinsSettingsList, context) {
248
261
  const { device } = params;
249
- let data = null;
250
262
  const connection = await this.connect(params, context);
251
- connection.on('data', (data)=>{
252
- if (data[0] === 0xfe && data[1] === 0xfe && data[2] === device && data[4] === parseInt(mybuddy.COMMAND.IS_CONTROLLER_CONNECTED, 16)) {
253
- data = mybuddy.processReceived(data);
263
+ return new Promise((resolve, reject)=>{
264
+ const timeoutId = setTimeout(()=>{
254
265
  connection.close();
255
- }
266
+ reject('TIMEOUT_READ_COMMANDS');
267
+ }, TIMEOUT_READ_COMMANDS);
268
+ connection.on('data', (data)=>{
269
+ if (data[0] === 0xfe && data[1] === 0xfe && data[2] === device && data[4] === parseInt(mybuddy.COMMAND.IS_CONTROLLER_CONNECTED, 16)) {
270
+ clearTimeout(timeoutId);
271
+ const result = mybuddy.processReceived(data);
272
+ connection.close();
273
+ resolve(result);
274
+ }
275
+ });
276
+ connection.write(mybuddy.isControllerConnect());
256
277
  });
257
- connection.write(mybuddy.isControllerConnect());
258
- return data;
259
278
  }
260
279
  async getCoords(params, _pinsSettingsList, context) {
261
280
  const { device } = params;
262
- let data = null;
263
281
  const connection = await this.connect(params, context);
264
- connection.on('data', (data)=>{
265
- if (data[0] === 0xfe && data[1] === 0xfe && data[2] === device && data[4] === parseInt(mybuddy.COMMAND.GET_COORDS, 16)) {
266
- data = mybuddy.processReceived(data);
282
+ return new Promise((resolve, reject)=>{
283
+ const timeoutId = setTimeout(()=>{
267
284
  connection.close();
268
- }
285
+ reject('TIMEOUT_READ_COMMANDS');
286
+ }, TIMEOUT_READ_COMMANDS);
287
+ connection.on('data', (data)=>{
288
+ if (data[0] === 0xfe && data[1] === 0xfe && data[2] === device && data[4] === parseInt(mybuddy.COMMAND.GET_COORDS, 16)) {
289
+ clearTimeout(timeoutId);
290
+ const result = mybuddy.processReceived(data);
291
+ connection.close();
292
+ resolve(result);
293
+ }
294
+ });
295
+ connection.write(mybuddy.getCoords(device));
269
296
  });
270
- connection.write(mybuddy.getCoords(device));
271
- return data;
272
297
  }
273
298
  async isInPosition(params, _pinsSettingsList, context) {
274
299
  const { device, data, flag } = params;
275
- let result = null;
276
300
  const connection = await this.connect(params, context);
277
- connection.on('data', (data)=>{
278
- if (data[0] === 0xfe && data[1] === 0xfe && data[2] === device && data[4] === parseInt(mybuddy.COMMAND.IS_IN_POSITION, 16)) {
279
- result = mybuddy.processReceived(data);
301
+ return new Promise((resolve, reject)=>{
302
+ const timeoutId = setTimeout(()=>{
280
303
  connection.close();
281
- }
304
+ reject('TIMEOUT_READ_COMMANDS');
305
+ }, TIMEOUT_READ_COMMANDS);
306
+ connection.on('data', (data)=>{
307
+ if (data[0] === 0xfe && data[1] === 0xfe && data[2] === device && data[4] === parseInt(mybuddy.COMMAND.IS_IN_POSITION, 16)) {
308
+ clearTimeout(timeoutId);
309
+ const result = mybuddy.processReceived(data);
310
+ connection.close();
311
+ resolve(result);
312
+ }
313
+ });
314
+ connection.write(mybuddy.isInPosition(device, data, flag));
282
315
  });
283
- connection.write(mybuddy.isInPosition(device, data, flag));
284
- return result;
285
316
  }
286
317
  async getEncoder(params, _pinsSettingsList, context) {
287
318
  const { device, joint_id } = params;
288
- let data = null;
289
319
  const connection = await this.connect(params, context);
290
- connection.on('data', (data)=>{
291
- if (data[0] === 0xfe && data[1] === 0xfe && data[2] === device && data[4] === parseInt(mybuddy.COMMAND.GET_ENCODER, 16)) {
292
- data = mybuddy.processReceived(data);
320
+ return new Promise((resolve, reject)=>{
321
+ const timeoutId = setTimeout(()=>{
293
322
  connection.close();
294
- }
323
+ reject('TIMEOUT_READ_COMMANDS');
324
+ }, TIMEOUT_READ_COMMANDS);
325
+ connection.on('data', (data)=>{
326
+ if (data[0] === 0xfe && data[1] === 0xfe && data[2] === device && data[4] === parseInt(mybuddy.COMMAND.GET_ENCODER, 16)) {
327
+ clearTimeout(timeoutId);
328
+ const result = mybuddy.processReceived(data);
329
+ connection.close();
330
+ resolve(result);
331
+ }
332
+ });
333
+ connection.write(mybuddy.getEncoder(device, joint_id));
295
334
  });
296
- connection.write(mybuddy.getEncoder(device, joint_id));
297
- return data;
298
335
  }
299
336
  async getEncoders(params, _pinsSettingsList, context) {
300
337
  const { device } = params;
301
- let data = null;
302
338
  const connection = await this.connect(params, context);
303
- connection.on('data', (data)=>{
304
- if (data[0] === 0xfe && data[1] === 0xfe && data[2] === device && data[4] === parseInt(mybuddy.COMMAND.GET_ENCODER, 16)) {
305
- data = mybuddy.processReceived(data);
339
+ return new Promise((resolve, reject)=>{
340
+ const timeoutId = setTimeout(()=>{
306
341
  connection.close();
307
- }
342
+ reject('TIMEOUT_READ_COMMANDS');
343
+ }, TIMEOUT_READ_COMMANDS);
344
+ connection.on('data', (data)=>{
345
+ if (data[0] === 0xfe && data[1] === 0xfe && data[2] === device && data[4] === parseInt(mybuddy.COMMAND.GET_ENCODER, 16)) {
346
+ clearTimeout(timeoutId);
347
+ const result = mybuddy.processReceived(data);
348
+ connection.close();
349
+ resolve(result);
350
+ }
351
+ });
352
+ connection.write(mybuddy.getEncoders(device));
308
353
  });
309
- connection.write(mybuddy.getEncoders(device));
310
- return data;
311
354
  }
312
355
  async getSpeed(params, _pinsSettingsList, context) {
313
356
  const { device } = params;
314
- let data = null;
315
357
  const connection = await this.connect(params, context);
316
- connection.on('data', (data)=>{
317
- if (data[0] === 0xfe && data[1] === 0xfe && data[2] === device && data[4] === parseInt(mybuddy.COMMAND.GET_SPEED, 16)) {
318
- data = mybuddy.processReceived(data);
358
+ return new Promise((resolve, reject)=>{
359
+ const timeoutId = setTimeout(()=>{
319
360
  connection.close();
320
- }
361
+ reject('TIMEOUT_READ_COMMANDS');
362
+ }, TIMEOUT_READ_COMMANDS);
363
+ connection.on('data', (data)=>{
364
+ if (data[0] === 0xfe && data[1] === 0xfe && data[2] === device && data[4] === parseInt(mybuddy.COMMAND.GET_SPEED, 16)) {
365
+ clearTimeout(timeoutId);
366
+ const result = mybuddy.processReceived(data);
367
+ connection.close();
368
+ resolve(result);
369
+ }
370
+ });
371
+ connection.write(mybuddy.getSpeed(device));
321
372
  });
322
- connection.write(mybuddy.getSpeed(device));
323
- return data;
324
373
  }
325
374
  async getJointMin(params, _pinsSettingsList, context) {
326
375
  const { device, joint_id } = params;
327
- let data = null;
328
376
  const connection = await this.connect(params, context);
329
- connection.on('data', (data)=>{
330
- if (data[0] === 0xfe && data[1] === 0xfe && data[2] === device && data[4] === parseInt(mybuddy.COMMAND.GET_JOINT_MIN_ANGLE, 16)) {
331
- data = mybuddy.processReceived(data);
377
+ return new Promise((resolve, reject)=>{
378
+ const timeoutId = setTimeout(()=>{
332
379
  connection.close();
333
- }
380
+ reject('TIMEOUT_READ_COMMANDS');
381
+ }, TIMEOUT_READ_COMMANDS);
382
+ connection.on('data', (data)=>{
383
+ if (data[0] === 0xfe && data[1] === 0xfe && data[2] === device && data[4] === parseInt(mybuddy.COMMAND.GET_JOINT_MIN_ANGLE, 16)) {
384
+ clearTimeout(timeoutId);
385
+ const result = mybuddy.processReceived(data);
386
+ connection.close();
387
+ resolve(result);
388
+ }
389
+ });
390
+ connection.write(mybuddy.getJointMin(device, joint_id));
334
391
  });
335
- connection.write(mybuddy.getJointMin(device, joint_id));
336
- return data;
337
392
  }
338
393
  async getJointMax(params, _pinsSettingsList, context) {
339
394
  const { device, joint_id } = params;
340
- let data = null;
341
395
  const connection = await this.connect(params, context);
342
- connection.on('data', (data)=>{
343
- if (data[0] === 0xfe && data[1] === 0xfe && data[2] === device && data[4] === parseInt(mybuddy.COMMAND.GET_JOINT_MAX_ANGLE, 16)) {
344
- data = mybuddy.processReceived(data);
396
+ return new Promise((resolve, reject)=>{
397
+ const timeoutId = setTimeout(()=>{
345
398
  connection.close();
346
- }
399
+ reject('TIMEOUT_READ_COMMANDS');
400
+ }, TIMEOUT_READ_COMMANDS);
401
+ connection.on('data', (data)=>{
402
+ if (data[0] === 0xfe && data[1] === 0xfe && data[2] === device && data[4] === parseInt(mybuddy.COMMAND.GET_JOINT_MAX_ANGLE, 16)) {
403
+ clearTimeout(timeoutId);
404
+ const result = mybuddy.processReceived(data);
405
+ connection.close();
406
+ resolve(result);
407
+ }
408
+ });
409
+ connection.write(mybuddy.getJointMax(device, joint_id));
347
410
  });
348
- connection.write(mybuddy.getJointMax(device, joint_id));
349
- return data;
350
411
  }
351
412
  async isServoEnable(params, _pinsSettingsList, context) {
352
413
  const { device, servo_id } = params;
353
- let data = null;
354
414
  const connection = await this.connect(params, context);
355
- connection.on('data', (data)=>{
356
- if (data[0] === 0xfe && data[1] === 0xfe && data[2] === device && data[4] === parseInt(mybuddy.COMMAND.IS_SERVO_ENABLE, 16)) {
357
- data = mybuddy.processReceived(data);
415
+ return new Promise((resolve, reject)=>{
416
+ const timeoutId = setTimeout(()=>{
358
417
  connection.close();
359
- }
418
+ reject('TIMEOUT_READ_COMMANDS');
419
+ }, TIMEOUT_READ_COMMANDS);
420
+ connection.on('data', (data)=>{
421
+ if (data[0] === 0xfe && data[1] === 0xfe && data[2] === device && data[4] === parseInt(mybuddy.COMMAND.IS_SERVO_ENABLE, 16)) {
422
+ clearTimeout(timeoutId);
423
+ const result = mybuddy.processReceived(data);
424
+ connection.close();
425
+ resolve(result);
426
+ }
427
+ });
428
+ connection.write(mybuddy.isServoEnable(device, servo_id));
360
429
  });
361
- connection.write(mybuddy.isServoEnable(device, servo_id));
362
- return data;
363
430
  }
364
431
  async isAllServoEnable(params, _pinsSettingsList, context) {
365
432
  const { device } = params;
366
- let data = null;
367
433
  const connection = await this.connect(params, context);
368
- connection.on('data', (data)=>{
369
- if (data[0] === 0xfe && data[1] === 0xfe && data[2] === device && data[4] === parseInt(mybuddy.COMMAND.IS_ALL_SERVO_ENABLE, 16)) {
370
- data = mybuddy.processReceived(data);
434
+ return new Promise((resolve, reject)=>{
435
+ const timeoutId = setTimeout(()=>{
371
436
  connection.close();
372
- }
437
+ reject('TIMEOUT_READ_COMMANDS');
438
+ }, TIMEOUT_READ_COMMANDS);
439
+ connection.on('data', (data)=>{
440
+ if (data[0] === 0xfe && data[1] === 0xfe && data[2] === device && data[4] === parseInt(mybuddy.COMMAND.IS_ALL_SERVO_ENABLE, 16)) {
441
+ clearTimeout(timeoutId);
442
+ const result = mybuddy.processReceived(data);
443
+ connection.close();
444
+ resolve(result);
445
+ }
446
+ });
447
+ connection.write(mybuddy.isAllServoEnable(device));
373
448
  });
374
- connection.write(mybuddy.isAllServoEnable(device));
375
- return data;
376
449
  }
377
450
  async getServodata(params, _pinsSettingsList, context) {
378
451
  const { device, servo_no, data_id } = params;
379
- let data = null;
380
452
  const connection = await this.connect(params, context);
381
- connection.on('data', (data)=>{
382
- if (data[0] === 0xfe && data[1] === 0xfe && data[2] === device && data[4] === parseInt(mybuddy.COMMAND.GET_SERVO_DATA, 16)) {
383
- data = mybuddy.processReceived(data);
453
+ return new Promise((resolve, reject)=>{
454
+ const timeoutId = setTimeout(()=>{
384
455
  connection.close();
385
- }
456
+ reject('TIMEOUT_READ_COMMANDS');
457
+ }, TIMEOUT_READ_COMMANDS);
458
+ connection.on('data', (data)=>{
459
+ if (data[0] === 0xfe && data[1] === 0xfe && data[2] === device && data[4] === parseInt(mybuddy.COMMAND.GET_SERVO_DATA, 16)) {
460
+ clearTimeout(timeoutId);
461
+ const result = mybuddy.processReceived(data);
462
+ connection.close();
463
+ resolve(result);
464
+ }
465
+ });
466
+ connection.write(mybuddy.getServodata(device, servo_no, data_id));
386
467
  });
387
- connection.write(mybuddy.getServodata(device, servo_no, data_id));
388
- return data;
389
468
  }
390
469
  async getDigitalInput(params, _pinsSettingsList, context) {
391
470
  const { device, pin_no } = params;
392
- let data = null;
393
471
  const connection = await this.connect(params, context);
394
- connection.on('data', (data)=>{
395
- if (data[0] === 0xfe && data[1] === 0xfe && data[2] === device && data[4] === parseInt(mybuddy.COMMAND.GET_DIGITAL_INPUT, 16)) {
396
- data = mybuddy.processReceived(data);
472
+ return new Promise((resolve, reject)=>{
473
+ const timeoutId = setTimeout(()=>{
397
474
  connection.close();
398
- }
475
+ reject('TIMEOUT_READ_COMMANDS');
476
+ }, TIMEOUT_READ_COMMANDS);
477
+ connection.on('data', (data)=>{
478
+ if (data[0] === 0xfe && data[1] === 0xfe && data[2] === device && data[4] === parseInt(mybuddy.COMMAND.GET_DIGITAL_INPUT, 16)) {
479
+ clearTimeout(timeoutId);
480
+ const result = mybuddy.processReceived(data);
481
+ connection.close();
482
+ resolve(result);
483
+ }
484
+ });
485
+ connection.write(mybuddy.getDigitalInput(device, pin_no));
399
486
  });
400
- connection.write(mybuddy.getDigitalInput(device, pin_no));
401
- return data;
402
487
  }
403
488
  async getGripperValue(params, _pinsSettingsList, context) {
404
489
  const { device } = params;
405
- let data = null;
406
490
  const connection = await this.connect(params, context);
407
- connection.on('data', (data)=>{
408
- if (data[0] === 0xfe && data[1] === 0xfe && data[2] === device && data[4] === parseInt(mybuddy.COMMAND.GET_GRIPPER_VALUE, 16)) {
409
- data = mybuddy.processReceived(data);
491
+ return new Promise((resolve, reject)=>{
492
+ const timeoutId = setTimeout(()=>{
410
493
  connection.close();
411
- }
494
+ reject('TIMEOUT_READ_COMMANDS');
495
+ }, TIMEOUT_READ_COMMANDS);
496
+ connection.on('data', (data)=>{
497
+ if (data[0] === 0xfe && data[1] === 0xfe && data[2] === device && data[4] === parseInt(mybuddy.COMMAND.GET_GRIPPER_VALUE, 16)) {
498
+ clearTimeout(timeoutId);
499
+ const result = mybuddy.processReceived(data);
500
+ connection.close();
501
+ resolve(result);
502
+ }
503
+ });
504
+ connection.write(mybuddy.getGripperValue(device));
412
505
  });
413
- connection.write(mybuddy.getGripperValue(device));
414
- return data;
415
506
  }
416
507
  async getBasicOutput(params, _pinsSettingsList, context) {
417
508
  const { device, pin_no } = params;
418
- let data = null;
419
509
  const connection = await this.connect(params, context);
420
- connection.on('data', (data)=>{
421
- if (data[0] === 0xfe && data[1] === 0xfe && data[2] === device && data[4] === parseInt(mybuddy.COMMAND.GET_BASIC_INPUT, 16)) {
422
- data = mybuddy.processReceived(data);
510
+ return new Promise((resolve, reject)=>{
511
+ const timeoutId = setTimeout(()=>{
423
512
  connection.close();
424
- }
513
+ reject('TIMEOUT_READ_COMMANDS');
514
+ }, TIMEOUT_READ_COMMANDS);
515
+ connection.on('data', (data)=>{
516
+ if (data[0] === 0xfe && data[1] === 0xfe && data[2] === device && data[4] === parseInt(mybuddy.COMMAND.GET_BASIC_INPUT, 16)) {
517
+ clearTimeout(timeoutId);
518
+ const result = mybuddy.processReceived(data);
519
+ connection.close();
520
+ resolve(result);
521
+ }
522
+ });
523
+ connection.write(mybuddy.getBasicOutput(device, pin_no));
425
524
  });
426
- connection.write(mybuddy.getBasicOutput(device, pin_no));
427
- return data;
428
525
  }
429
526
  async isGripperMoving(params, _pinsSettingsList, context) {
430
527
  const { device } = params;
431
- let data = null;
432
528
  const connection = await this.connect(params, context);
433
- connection.on('data', (data)=>{
434
- if (data[0] === 0xfe && data[1] === 0xfe && data[2] === device && data[4] === parseInt(mybuddy.COMMAND.IS_GRIPPER_MOVING, 16)) {
435
- data = mybuddy.processReceived(data);
529
+ return new Promise((resolve, reject)=>{
530
+ const timeoutId = setTimeout(()=>{
436
531
  connection.close();
437
- }
532
+ reject('TIMEOUT_READ_COMMANDS');
533
+ }, TIMEOUT_READ_COMMANDS);
534
+ connection.on('data', (data)=>{
535
+ if (data[0] === 0xfe && data[1] === 0xfe && data[2] === device && data[4] === parseInt(mybuddy.COMMAND.IS_GRIPPER_MOVING, 16)) {
536
+ clearTimeout(timeoutId);
537
+ const result = mybuddy.processReceived(data);
538
+ connection.close();
539
+ resolve(result);
540
+ }
541
+ });
542
+ connection.write(mybuddy.isGripperMoving(device));
438
543
  });
439
- connection.write(mybuddy.isGripperMoving(device));
440
- return data;
441
544
  }
442
545
  // TOOLS
443
546
  async sleep(params, _pinsSettingsList, context) {