當前位置: 首頁>>代碼示例>>Python>>正文


Python serial.tools方法代碼示例

本文整理匯總了Python中serial.tools方法的典型用法代碼示例。如果您正苦於以下問題:Python serial.tools方法的具體用法?Python serial.tools怎麽用?Python serial.tools使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在serial的用法示例。


在下文中一共展示了serial.tools方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: is_micropython_usb_device

# 需要導入模塊: import serial [as 別名]
# 或者: from serial import tools [as 別名]
def is_micropython_usb_device(port):
    """Checks a USB device to see if it looks like a MicroPython device.
    """
    if type(port).__name__ == 'Device':
        # Assume its a pyudev.device.Device
        if ('ID_BUS' not in port or port['ID_BUS'] != 'usb' or
            'SUBSYSTEM' not in port or port['SUBSYSTEM'] != 'tty'):
            return False
        usb_id = 'usb vid:pid={}:{}'.format(port['ID_VENDOR_ID'], port['ID_MODEL_ID'])
    else:
        # Assume its a port from serial.tools.list_ports.comports()
        usb_id = port[2].lower()
    # We don't check the last digit of the PID since there are 3 possible
    # values.
    if usb_id.startswith('usb vid:pid=f055:980'):
        return True
    # Check for Teensy VID:PID
    if usb_id.startswith('usb vid:pid=16c0:0483'):
        return True
    return False 
開發者ID:dhylands,項目名稱:rshell,代碼行數:22,代碼來源:main.py

示例2: _find_serial_port

# 需要導入模塊: import serial [as 別名]
# 或者: from serial import tools [as 別名]
def _find_serial_port(self, vid, pid, name):
        """Find a serial port by VID, PID and text name

        :param vid: USB vendor ID to locate
        :param pid: USB product ID to locate
        :param name: USB device name to find where VID/PID match fails

        """

        check_for = "USB VID:PID={vid:04x}:{pid:04x}".format(vid=vid,pid=pid).upper()
        ports = serial.tools.list_ports.comports()

        for check_port in ports:
            if hasattr(serial.tools,'list_ports_common'):
                if (check_port.vid, check_port.pid) == (VID, PID):
                    return check_port.device
                continue

            if check_for in check_port[2].upper() or name == check_port[1]:
                return check_port[0]

        return None 
開發者ID:pimoroni,項目名稱:mote,代碼行數:24,代碼來源:__init__.py

示例3: _find_port

# 需要導入模塊: import serial [as 別名]
# 或者: from serial import tools [as 別名]
def _find_port(self):
        from serial.tools import list_ports
        import serial
        import os
        all_port_tuples = list_ports.comports()
        logging.info("listing serial ports")
        all_ports = set()
        for ap, _, _ in all_port_tuples:
            p = os.path.basename(ap)
            print(p)
            if p.startswith("ttyUSB") or p.startswith("ttyACM"):
                all_ports |= {ap}
                logging.info("\t%s", str(ap))

        if len(all_ports) == 0:
            logging.error("No valid port detected!. Possibly, device not plugged/detected.")
            raise NoValidPortError()

        elif len(all_ports) > 2:
            logging.info("Several port detected, using first one: %s", str(all_ports))
        return all_ports.pop() 
開發者ID:gilestrolab,項目名稱:ethoscope,代碼行數:23,代碼來源:optomotor.py

示例4: listports

# 需要導入模塊: import serial [as 別名]
# 或者: from serial import tools [as 別名]
def listports():
    """listports will display a list of all of the serial ports.
    """
    detected = False
    for port in serial.tools.list_ports.comports():
        detected = True
        if port.vid:
            micropythonPort = ''
            if is_micropython_usb_device(port):
                micropythonPort = ' *'
            print('USB Serial Device {:04x}:{:04x}{} found @{}{}\r'.format(
                  port.vid, port.pid,
                  extra_info(port), port.device, micropythonPort))
        else:
            print('Serial Device:', port.device)
    if not detected:
        print('No serial devices detected') 
開發者ID:dhylands,項目名稱:rshell,代碼行數:19,代碼來源:main.py

示例5: detect_ports

# 需要導入模塊: import serial [as 別名]
# 或者: from serial import tools [as 別名]
def detect_ports(self):
        ports = list(serial.tools.list_ports.comports())
        if(len(ports) == 0):
            print("No ports detected")
        else:
            for i in ports:
                print(i.device) 
開發者ID:Korving-F,項目名稱:ublox,代碼行數:9,代碼來源:ubx.py

示例6: _find_port

# 需要導入模塊: import serial [as 別名]
# 或者: from serial import tools [as 別名]
def _find_port(self):
        from serial.tools import list_ports
        import serial
        import os
        all_port_tuples = list_ports.comports()
        logging.info("listing serial ports")
        all_ports = set()
        for ap, _, _  in all_port_tuples:
            p = os.path.basename(ap)
            print(p)
            if p.startswith("ttyUSB") or p.startswith("ttyACM"):
                all_ports |= {ap}
                logging.info("\t%s", str(ap))

        if len(all_ports) == 0:
            logging.error("No valid port detected!. Possibly, device not plugged/detected.")
            raise NoValidPortError()

        elif len(all_ports) > 2:
            logging.info("Several port detected, using first one: %s", str(all_ports))
        return  all_ports.pop()
            # for ap in list(all_ports):
        #     logging.info("trying port %s", str(ap))
        #
        #     try:
        #         #here we use a recursive strategy to find the good port (ap).
        #         SimpleLynxMotionInterface(ap)
        #         return ap
        #     except (WrongSerialPortError, serial.SerialException):
        #         warn_str = "Tried to use port %s. Failed." % ap
        #         logging.warning(warn_str)
        #         pass 
開發者ID:gilestrolab,項目名稱:ethoscope,代碼行數:34,代碼來源:lynx_motion.py

示例7: is_micropython_usb_port

# 需要導入模塊: import serial [as 別名]
# 或者: from serial import tools [as 別名]
def is_micropython_usb_port(portName):
    """Checks to see if the indicated portname is a MicroPython device
       or not.
    """
    for port in serial.tools.list_ports.comports():
        if port.device == portName:
            return is_micropython_usb_device(port)
    return False 
開發者ID:dhylands,項目名稱:rshell,代碼行數:10,代碼來源:main.py

示例8: autoscan

# 需要導入模塊: import serial [as 別名]
# 或者: from serial import tools [as 別名]
def autoscan():
    """autoscan will check all of the serial ports to see if they have
       a matching VID:PID for a MicroPython board.
    """
    for port in serial.tools.list_ports.comports():
        if is_micropython_usb_device(port):
            connect_serial(port[0]) 
開發者ID:dhylands,項目名稱:rshell,代碼行數:9,代碼來源:main.py

示例9: _find_serial_port

# 需要導入模塊: import serial [as 別名]
# 或者: from serial import tools [as 別名]
def _find_serial_port(self):
        check_for = "USB VID:PID={vid:04x}:{pid:04x}".format(vid=VID,pid=PID).upper()
        ports = serial.tools.list_ports.comports()

        for check_port in ports:
            if hasattr(serial.tools,'list_ports_common'):
                if (check_port.vid, check_port.pid) == (VID, PID):
                    return check_port.device
                continue

            if check_for in check_port[2].upper():
                return check_port[0]

        raise AttributeError(LANG_COULD_NOT_FIND) 
開發者ID:pimoroni,項目名稱:flotilla-python,代碼行數:16,代碼來源:__init__.py


注:本文中的serial.tools方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。