Skip to content

Exception when response empty #44

@Arzeg

Description

@Arzeg

Hi,
After a few minutes with the Dobot Magician Lite I'm getting this exception, because of an empty response:

Traceback (most recent call last):
  File "direct_cords_read.py", line 81, in <module>
    device.move_to(current_x, y + draw_start_y, z_down, 0.0, wait=True)
  File "/home/pi/.local/lib/python3.7/site-packages/pydobot/dobot.py", line 315, in move_to
    self._set_ptp_cmd(x, y, z, r, mode=PTPMode.MOVL_XYZ, wait=wait)
  File "/home/pi/.local/lib/python3.7/site-packages/pydobot/dobot.py", line 240, in _set_ptp_cmd
    return self._send_command(msg, wait)
  File "/home/pi/.local/lib/python3.7/site-packages/pydobot/dobot.py", line 103, in _send_command
    expected_idx = struct.unpack_from('L', response.params, 0)[0]
AttributeError: 'NoneType' object has no attribute 'params'

I found this solution, and added the if clause in the middle:

    def _send_command(self, msg, wait=False):
        self.lock.acquire()
        self._send_message(msg)
        response = self._read_message()
        self.lock.release()
        if response is None:
            print("Receive empty response")
            return

        if not wait:
            return response

Best regards

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions