Python serial.tools() Examples
The following are 9
code examples of serial.tools().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
serial
, or try the search function
.
Example #1
Source File: optomotor.py From ethoscope with GNU General Public License v3.0 | 7 votes |
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()
Example #2
Source File: __init__.py From mote with MIT License | 6 votes |
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
Example #3
Source File: main.py From rshell with MIT License | 6 votes |
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
Example #4
Source File: main.py From rshell with MIT License | 6 votes |
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')
Example #5
Source File: ubx.py From ublox with MIT License | 5 votes |
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)
Example #6
Source File: lynx_motion.py From ethoscope with GNU General Public License v3.0 | 5 votes |
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
Example #7
Source File: main.py From rshell with MIT License | 5 votes |
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
Example #8
Source File: main.py From rshell with MIT License | 5 votes |
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])
Example #9
Source File: __init__.py From flotilla-python with MIT License | 5 votes |
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)