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

KeyError exception on cam.get_focus_mode() with Birddog X1 camera #29

Open
DanTappan opened this issue Oct 24, 2024 · 1 comment
Open

Comments

@DanTappan
Copy link

Problem:
calling the get_focus_mode() method with Birddog X1 camera results in a KeyError exception

Diagnosis:
The Birddog X1 does not currently implement the GETFOCUSMODE (0x04 0x38) INQUIRY. Instead it returns a generic reply. Doing a dict lookup based on the last byte of the reply (which seems to be an ascii 'A') causes a KeyError.

Possible fix:
Adding a try/except around the dict index makes the code more robust and avoids the problem

def get_focus_mode(self) -> str:
    """:return: either 'auto' or 'manual'"""
    modes = {2: 'auto', 3: 'manual'}
    response = self._send_command('04 38', query=True)
    try:
        mode = modes[response[-1]]
    except KeyError:
        mode = 'unknown'
    return mode
@misterhay
Copy link
Owner

Great suggestion

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