예제 #1
0
def get_driver(use_ftdi=False,
               port=SERIAL_PORT,
               baud=SERIAL_BAUD,
               file=False,
               rtscts=False):
    """
    Get a driver based on configuration options

    Parameters
    ----------
    use_ftdi : bool
      For serial driver, use the pyftdi driver, otherwise use the pyserial driver.
    port : string
      Serial port to read.
    baud : int
      Serial port baud rate to set.
    """
    try:
        if use_ftdi:
            return PyFTDIDriver(baud)
        if file:
            return FileDriver(open(port, 'rb'))
    # HACK - if we are on OSX and the device appears to be a CDC device, open as a binary file
        for each in serial.tools.list_ports.comports():
            if port == each[0] and sys.platform == "darwin":
                if each[1].startswith("Gadget Serial") or each[1].startswith(
                        "Piksi"):
                    print("Opening a file driver")
                    return CdcDriver(open(port, 'w+b', 0))
        return PySerialDriver(port, baud, rtscts=rtscts)
    # if finding the driver fails we should exit with a return code
    # currently sbp's py serial driver raises SystemExit, so we trap it
    # here
    except SystemExit:
        sys.exit(1)
예제 #2
0
def get_driver(use_ftdi=False, port=SERIAL_PORT, baud=SERIAL_BAUD):
  """
  Get a driver based on configuration options

  Parameters
  ----------
  use_ftdi : bool
    For serial driver, use the pyftdi driver, otherwise use the pyserial driver.
  port : string
    Serial port to read.
  baud : int
    Serial port baud rate to set.
  """
  if use_ftdi:
    return PyFTDIDriver(baud)
  return PySerialDriver(port, baud)
예제 #3
0
def get_driver(use_ftdi=False, port=SERIAL_PORT, baud=SERIAL_BAUD):
    """
  Get a driver based on configuration options

  Parameters
  ----------
  use_ftdi : bool
    For serial driver, use the pyftdi driver, otherwise use the pyserial driver.
  port : string
    Serial port to read.
  baud : int
    Serial port baud rate to set.
  """
    try:
        if use_ftdi:
            return PyFTDIDriver(baud)
        return PySerialDriver(port, baud)
    # if finding the driver fails we should exit with a return code
    # currently sbp's py serial driver raises SystemExit, so we trap it
    # here
    except SystemExit:
        sys.exit(1)
예제 #4
0
def driver_start(use_ftdi=False):
    if use_ftdi:
        return PyFTDIDriver(SERIAL_BAUD)
    return PySerialDriver(SERIAL_PORT, SERIAL_BAUD)