Skip to content

Commit 48d57b7

Browse files
authored
Fix/280 api (#234)
* fix(280-api):Fixed an issue where the get_servo_data(4, 85) interface could not read servo parameters on 280 PI and JN version machines. * fix(280-api):When fixing packet loss issues, the read command was garbled. * perf(280-api): opt get_servo_data() api read data * feat(280-api):Add support for pin 39 to the terminal I/O pin.
1 parent c71f6e8 commit 48d57b7

File tree

4 files changed

+21
-7
lines changed

4 files changed

+21
-7
lines changed

pymycobot/common.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1199,6 +1199,9 @@ def read(self, genre, method=None, command=None, _class=None, timeout=None, real
11991199
break
12001200
elif len(datas) == 2:
12011201
data_len = struct.unpack("b", data)[0]
1202+
if data_len < 0 or data_len > 30:
1203+
data_len = -1
1204+
continue
12021205
datas += data
12031206
elif len(datas) > 2 and data_len > 0:
12041207
datas += data

pymycobot/error.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,7 @@ def public_check(
418418
check_0_or_1(
419419
parameter,
420420
value,
421-
[19, 22, 23, 33],
421+
[19, 22, 23, 33, 39],
422422
value_type,
423423
exception_class,
424424
int,

pymycobot/mycobot280.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -150,12 +150,18 @@ def _res(self, real_command, has_reply, genre):
150150
data = self._read(genre)
151151
else:
152152
try_count = 0
153+
expected_genre = genre
153154
while try_count < 3:
155+
self._serial_port.reset_input_buffer()
154156
self._write(self._flatten(real_command))
155157
data = self._read(genre)
156-
if data is not None and data != b'':
157-
break
158-
try_count += 1
158+
if not data or len(data) < 4:
159+
try_count += 1
160+
continue
161+
if data[3] != expected_genre:
162+
try_count += 1
163+
continue
164+
break
159165
else:
160166
return -1
161167
if genre == ProtocolCode.SET_SSID_PWD:

pymycobot/mycobot280socket.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -140,12 +140,17 @@ def _res(self, real_command, has_reply, genre):
140140
data = self._read(genre, method='socket')
141141
else:
142142
try_count = 0
143+
expected_genre = genre
143144
while try_count < 3:
144145
self._write(self._flatten(real_command), "socket")
145146
data = self._read(genre, method='socket')
146-
if data is not None and data != b'':
147-
break
148-
try_count += 1
147+
if not data or len(data) < 4:
148+
try_count += 1
149+
continue
150+
if data[3] != expected_genre:
151+
try_count += 1
152+
continue
153+
break
149154
else:
150155
return -1
151156
if genre == ProtocolCode.SET_SSID_PWD:

0 commit comments

Comments
 (0)