Skip to content

Commit a74720f

Browse files
committed
Fix m5 network communication bug
1 parent 557cd83 commit a74720f

File tree

5 files changed

+35
-12
lines changed

5 files changed

+35
-12
lines changed

CHANGELOG.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
# ChangeLog for pymycobot
22

3-
## v2.7.2.1 (2021-12-15)
3+
## v2.7.4 (2021-12-15)
4+
5+
- release v2.7.4
6+
- Fix m5 network communication bug
7+
8+
## v2.7.3 (2021-12-15)
49

510
- release v2.7.3
611
- fix get_tof_distance() no return problem.

docs/README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ We support Python2, Python3.5 or later.
8080
- [utils (Module)](#utils-module)
8181
- [get_port_list](#get_port_list)
8282
- [detect_port_of_basic](#detect_port_of_basic)
83-
- [MyCobotSocket](#mycobotsocket)
83+
- [MyCobotSocket](#mycobotsocket)
8484
- [Client](#client)
8585
- [Server](#server)
8686
- [socket control](#socket-control)
@@ -89,6 +89,7 @@ We support Python2, Python3.5 or later.
8989
- [set_gpio_out](#set_gpio_out)
9090
- [set_gpio_output](#set_gpio_output)
9191
- [get_gpio_in](#get_gpio_in)
92+
9293

9394
<!-- vim-markdown-toc -->
9495
</details>
@@ -788,10 +789,10 @@ from pymycobot import utils
788789
mycobot = MyCobot(port, 115200)
789790
```
790791

791-
## MyCobotSocket
792+
# MyCobotSocket
792793

793794
> Note:
794-
> Only supports python3
795+
> raspberryPi version Only supports python3
795796
> The robotic arm that uses this class of premise has a server and has been turned on.
796797
797798
Use TCP/IP to control the robotic arm

pymycobot/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
"MyCobotSocket"
2121
]
2222

23-
__version__ = "2.7.3"
23+
__version__ = "2.7.4"
2424
__author__ = "Elephantrobotics"
2525
__email__ = "weiquan.xu@elephantrobotics.com"
2626
__git_url__ = "https://github.com/elephantrobotics/pymycobot"

pymycobot/common.py

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -196,23 +196,31 @@ def _process_single(self, data):
196196

197197
def write(self, command, method=None):
198198
if method == "socket":
199-
if command[3] == 176 and len(command) > 5:
199+
data = b""
200+
if len(command)>3 and command[3] == 176 and len(command) > 5:
200201
command = "'"+command[4]+"'"+"("+command[5]+")"
201202
command = command.encode()
202-
self.sock.sendall(bytes(command))
203-
if command[-2] == 177:
203+
if self.rasp:
204+
self.sock.sendall(str(command).encode())
205+
else:
206+
self.sock.sendall(bytes(command))
207+
208+
if len(command) > 3 and command[3] == 177:
204209
while True:
205210
data = self.sock.recv(1024)
206211
if b'password' in data:
207212
break
208-
if command[-2] == 192:
209-
data = b''
213+
elif len(command) > 3 and command[3] == 192:
210214
while True:
211215
data += self.sock.recv(1024)
212216
if len(data) == 6:
213217
break
214218
else:
215-
data = self.sock.recv(1024)
219+
try:
220+
self.sock.settimeout(0.1)
221+
data = self.sock.recv(1024)
222+
except:
223+
data = b''
216224
return data
217225
else:
218226
self.log.debug("_write: {}".format(command))

pymycobot/mycobotsocket.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,18 @@ def __init__(self, ip, netport=9000):
5858
self.calibration_parameters = calibration_parameters
5959
self.SERVER_IP = ip
6060
self.SERVER_PORT = netport
61+
self.rasp = False
6162
self.sock = self.connect_socket()
6263

6364
def connect(self, serialport="/dev/ttyAMA0", baudrate="1000000", timeout='0.1'):
65+
"""Interface to connect to the built-in system such as Raspberry Pi
66+
Args:
67+
serialport:
68+
baudrate:
69+
timeout:
70+
71+
"""
72+
self.rasp = True
6473
self._write(serialport, "socket")
6574
self._write(baudrate, "socket")
6675
self._write(timeout, "socket")
@@ -86,7 +95,7 @@ def _mesg(self, genre, *args, **kwargs):
8695
MyCobotSocket, self)._mesg(genre, *args, **kwargs)
8796
# [254,...,255]
8897
data = self._write(self._flatten(real_command), "socket")
89-
if data != b'None':
98+
if data:
9099
res = self._process_received(data, genre)
91100
if genre in [
92101
ProtocolCode.IS_POWER_ON,

0 commit comments

Comments
 (0)