Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def channel_from_usb_device(usb_device, printer=noprint):
"""
Inits an ODrive Protocol channel from a PyUSB device object.
"""
bulk_device = odrive.usbbulk_transport.USBBulkTransport(usb_device, printer)
printer(bulk_device.info())
bulk_device.init()
return odrive.protocol.Channel(
"USB device bus {} device {}".format(usb_device.bus, usb_device.address),
bulk_device, bulk_device)
def channel_from_serial_port(port, baud, packet_based, printer=noprint):
"""
Inits an ODrive Protocol channel from a serial port name and baudrate.
"""
if packet_based == True:
# TODO: implement packet based transport over serial
raise NotImplementedError("not supported yet")
serial_device = odrive.serial_transport.SerialStreamTransport(port, baud)
input_stream = odrive.protocol.PacketFromStreamConverter(serial_device)
output_stream = odrive.protocol.PacketToStreamConverter(serial_device)
return odrive.protocol.Channel(
"serial port {}@{}".format(port, baud),
input_stream, output_stream)