Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exception when response empty #44

Open
Arzeg opened this issue Sep 8, 2021 · 1 comment
Open

Exception when response empty #44

Arzeg opened this issue Sep 8, 2021 · 1 comment

Comments

@Arzeg
Copy link

Arzeg commented Sep 8, 2021

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

@jonascj
Copy link

jonascj commented Dec 4, 2021

@Arzeg Thank you for reporting this and thank you for your proposed solution. We will aim to fix this in the next release which will hopefully come during december.

The solution is unfortnuately not as simple as your proposal. If the optional parameter wait is set to True then your solution skips the rest of the _send_command() function body. Other functions such as pose() relies on the message not being empty, so even if _send_command() does not raise an exception, so will other functions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants