예제 #1
0
def open_interface(tty, bitrate, logger=None):
    if logger:
        logger.debug("open_interface: {} {:d}".format(tty, bitrate))

    # Different procedures are required for PyFTDI and PySerial
    if len(tty) > 4 and tty[:4] == "ftdi":
        from pyftdi.ftdi import Ftdi
        import pyftdi.serialext

        for pid in FTDI_PRODUCT_IDS:
            try:
                Ftdi.add_custom_product(Ftdi.DEFAULT_VENDOR, pid)
            except ValueError:
                pass

        if logger:
            logger.info("Using pyftdi")

        Ftdi.show_devices()
        ser = pyftdi.serialext.serial_for_url(tty,
                                              baudrate=bitrate,
                                              timeout=DEFAULT_TIMEOUT_SECONDS)
        # XXX should raise exception for illegal caudrate
    else:
        import serial
        if logger:
            logger.debug("Using pyserial")
        try:
            ser = serial.Serial(tty, bitrate, timeout=DEFAULT_TIMEOUT_SECONDS)
        except serial.SerialException:
            raise

    return ser
예제 #2
0
    def __init__(self, idVendor=None, idProduct=None, serialNumber=None, portPath=None, port=None):
        CommunicationPort.__init__(self)

        try:
            Ftdi.add_custom_product(vid=4930, pid=1, pidname="Sutter")
        except:
            pass

        if idVendor is not None and portPath is None:
            portPath = SerialPort.matchAnyPort(idVendor, idProduct, serialNumber)

        if portPath is not None:
            self.portPath = portPath
        else:
            self.portPath = None

        if port is not None and port.is_open:
            port.close()

        self.port = None # direct port, must be closed.
예제 #3
0
    You have to make your own time out like :
    bb = ''
    start_time = time.time()
    while (not bool(bb) and (time.time() - start_time) < timeout_sec):
        bb = motor_stageXY.read(90) 
    
    You also have to use "write_data" and "read_data" instead of 'write' and 'read'
    
    It's better also to use time.sleep(0.1) between commands
    '''

    timeout_sec = 2
    from pyftdi.ftdi import Ftdi

    # PID seems to be FAF0 in device manager
    Ftdi.add_custom_product(0x403, 0xfaf0)
    try:
        motor_stageXY = Ftdi.create_from_url('ftdi://0x403:0xfaf0/1')
        motor_stageXY.open_from_url(url='ftdi://0x403:0xfaf0/1')

        motor_stageXY.set_baudrate(115200)
        motor_stageXY.set_line_property(8, 1, 'N',
                                        break_=0)  # 'N' = parity_none
        time.sleep(50e-3)  # pre-purge
        motor_stageXY.purge_buffers()  # purge RX and TX buffers
        time.sleep(50e-3)  # post-purge
        motor_stageXY._reset_device(
        )  # private module, unlock it to public if no access
        motor_stageXY.set_flowctrl('hw')  # 'hw' means RTS/CTS UART lines

        # f1.set_rts(state) # not sure for this one, the doc does not specify the 'state'