How to use the odrive.protocol.DeviceInitException function in odrive

To help you get started, we’ve selected a few odrive examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github madcowswe / ODrive / tools / odrive / core.py View on Github external
printer("Connecting to device on " + channel._name)
    try:
        json_bytes = channel.remote_endpoint_read_buffer(0)
    except (odrive.protocol.TimeoutException, odrive.protocol.ChannelBrokenException):
        raise odrive.protocol.DeviceInitException("no response - probably incompatible")
    json_crc16 = odrive.protocol.calc_crc16(odrive.protocol.PROTOCOL_VERSION, json_bytes)
    channel._interface_definition_crc = json_crc16
    try:
        json_string = json_bytes.decode("ascii")
    except UnicodeDecodeError:
        raise odrive.protocol.DeviceInitException("device responded on endpoint 0 with something that is not ASCII")
    printer("JSON: " + json_string)
    try:
        json_data = json.loads(json_string)
    except json.decoder.JSONDecodeError:
        raise odrive.protocol.DeviceInitException("device responded on endpoint 0 with something that is not JSON")
    json_data = {"name": "odrive", "members": json_data}
    return create_object("odrive", json_data, None, channel, printer=printer)
github madcowswe / ODrive / tools / odrive / core.py View on Github external
"""
    Inits an object from a given channel.
    This queries the endpoint 0 on that channel to gain information
    about the interface, which is then used to init the corresponding object.
    """
    printer("Connecting to device on " + channel._name)
    try:
        json_bytes = channel.remote_endpoint_read_buffer(0)
    except (odrive.protocol.TimeoutException, odrive.protocol.ChannelBrokenException):
        raise odrive.protocol.DeviceInitException("no response - probably incompatible")
    json_crc16 = odrive.protocol.calc_crc16(odrive.protocol.PROTOCOL_VERSION, json_bytes)
    channel._interface_definition_crc = json_crc16
    try:
        json_string = json_bytes.decode("ascii")
    except UnicodeDecodeError:
        raise odrive.protocol.DeviceInitException("device responded on endpoint 0 with something that is not ASCII")
    printer("JSON: " + json_string)
    try:
        json_data = json.loads(json_string)
    except json.decoder.JSONDecodeError:
        raise odrive.protocol.DeviceInitException("device responded on endpoint 0 with something that is not JSON")
    json_data = {"name": "odrive", "members": json_data}
    return create_object("odrive", json_data, None, channel, printer=printer)