Skip to content

Commit

Permalink
fix bug
Browse files Browse the repository at this point in the history
  • Loading branch information
anla-xu committed Dec 1, 2023
1 parent 79bcb94 commit 5088495
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
10 changes: 8 additions & 2 deletions pymycobot/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,9 @@ def write(self, command, method=None):
if method == "socket":
log_command = []
for i in command:
if isinstance(i, str):
if isinstance(command, str):
log_command.append(command)
elif isinstance(i, str):
log_command.append(i)
else:
log_command.append(hex(i))
Expand All @@ -477,7 +479,11 @@ def write(self, command, method=None):
if py_version == 2:
self.sock.sendall("".join([chr(b) for b in command]))
else:
self.sock.sendall(bytes(command))
if isinstance(command, str):
command = command.encode()
else:
command = bytes(command)
self.sock.sendall(command)
else:
self._serial_port.reset_input_buffer()
self.log.debug("_write: {}".format([hex(i) for i in command]))
Expand Down
5 changes: 3 additions & 2 deletions pymycobot/mybuddysocket.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,9 @@ def _mesg(self, genre, *args, **kwargs):
"""
real_command, has_reply = super(
MyBuddySocket, self)._mesg(genre, *args, **kwargs)
data = self._write(self._flatten(real_command), "socket")
if data:
self._write(self._flatten(real_command), "socket")
if has_reply:
data = self._read(genre, 'socket')
res = self._process_received(data, genre, arm=12)
if genre in [
ProtocolCode.ROBOT_VERSION,
Expand Down

0 comments on commit 5088495

Please sign in to comment.