Skip to content

Commit a74f45e

Browse files
author
Leonid Fedorenchik
committed
fix(mycobotpro630): 🐛
1 parent 3fc5d95 commit a74f45e

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

pymycobot/mycobotpro630.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -591,11 +591,16 @@ def _send_can(self, data, can_id=0x007, timeout=0.5):
591591
except can.CanError:
592592
print("Error: Cannot send can message")
593593

594-
def _receive_can(self, msg_data=None, timeout=0.5, num_tries=1000):
594+
def _receive_can(
595+
self, msg_data=None, timeout=0.5, num_tries=1000, destroy_can=True
596+
):
595597
"""Receives next message from CAN bus.
596598
597599
Args:
600+
msg_data (None | List[int], optional): message to look for. Defaults to None (look for any message).
598601
timeout (float, optional): How long time to receive message. Defaults to 0.5.
602+
num_tries (int, optional): how many times to try to receive specified message. Defaults to 1000.
603+
destroy_can (bool, optional): if need to destroy CAN BUS instance after receiving message. Defaults to True.
599604
600605
Returns:
601606
Message | None: CAN message or None (if no message could be received).
@@ -615,7 +620,8 @@ def _receive_can(self, msg_data=None, timeout=0.5, num_tries=1000):
615620
msg_found = False
616621
if msg_found:
617622
break
618-
self._destroy_can()
623+
if destroy_can:
624+
self._destroy_can()
619625
if not msg_found:
620626
msg = None
621627
return msg
@@ -2918,10 +2924,10 @@ def tool_serial_read_data(self, n):
29182924
"""
29192925
self._send_can([0x02, 0xB4, n])
29202926
data = []
2921-
msg = self._receive_can()
2927+
msg = self._receive_can(destroy_can=False)
29222928
data.extend(msg.data[3:])
29232929
while msg is not None and len(data) < n:
2924-
msg = self._receive_can()
2930+
msg = self._receive_can(destroy_can=False)
29252931
data.extend(msg.data[3:])
29262932
return data
29272933

0 commit comments

Comments
 (0)