http://pyserial.readthedocs.io/en/latest/shortintro.html

	This calls the command line tool from pyserial to list the available
	serial ports.
429084
def listSerialPorts():
	
	cmd = 'python -m serial.tools.list_ports'
	err, ret = commands.getstatusoutput(cmd)
	if not err:
		r = ret.split('\n')
		ret = []
		for line in r:
			if line.find('/dev/') >= 0:
				line = line.replace(' ', '')
				ret.append(line)
	return err, ret
917117
def get_stopbits():
    
    stopbits = []
    s = pyserial.Serial()
    for name, value in s.getSupportedStopbits():
        stopbits.append((value, name,))
    return tuple(stopbits)
667125
def find_bled112_devices(cls):
        """"""
        found_devs = []

        ports = serial.tools.list_ports.comports()
        for port in ports:
            if not hasattr(port, 'pid') or not hasattr(port, 'vid'):
                continue

            # Check if the device matches the BLED112's PID/VID combination
            if port.pid == 1 and port.vid == 9304:
                found_devs.append(port.device)

        return found_devs
1255138
def autoscan():
    
    for port in serial.tools.list_ports.comports():
        if is_micropython_usb_device(port):
            connect_serial(port[0])
93353
def _create_serial_ports(serial_ports):
    '''
    
    '''
    ports = []
    keys = range(-9000, -9050, -1)
    if serial_ports:
        devs = [serial['adapter'] for serial in serial_ports]
        log.trace('Creating serial ports %s', devs)
        for port, key in zip(serial_ports, keys):
            serial_port_device = _apply_serial_port(port, key, 'add')
            ports.append(serial_port_device)
    return ports
623972
def _get_available_ports():
    
    if platform.system() == 'Darwin':
        return glob.glob('/dev/tty.usb*')

    elif platform.system() == 'Linux':
        return glob.glob('/dev/ttyACM*') + glob.glob('/dev/ttyUSB*') + glob.glob('/dev/ttyAMA*')

    elif sys.platform.lower() == 'cygwin':
        return glob.glob('/dev/com*')

    elif platform.system() == 'Windows':
        import _winreg
        import itertools

        ports = []
        path = 'HARDWARE\\DEVICEMAP\\SERIALCOMM'
        key = _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE, path)

        for i in itertools.count():
            try:
                ports.append(str(_winreg.EnumValue(key, i)[1]))
            except WindowsError:
                return ports
    else:
        raise EnvironmentError('{} is an unsupported platform, cannot find serial ports !'.format(platform.system()))
    return []
1344772
def list_ports(zone, permanent=True):
    '''
    
    '''
    cmd = '--zone={0} --list-ports'.format(zone)

    if permanent:
        cmd += ' --permanent'

    return __firewall_cmd(cmd).split()
107469
def get_iscsi_ports(state = nil)
      begin
        @port.get_iscsi_ports(state)
      rescue => ex
        Util.log_exception(ex, caller_locations(1, 1)[0].label)
        raise ex
      end
    end
796966
async function listDevices(showAll){
    // get all available serial ports
    const ports = (await _serialport.list()) || [];
    // just pass-through
    if (showAll){
        return ports;

    // filter by vendorIDs
    }else{
        return ports.filter(function(item){
            // 
            return knownVendorIDs.includes(item.vendorId && item.vendorId.toUpperCase());
        });
    }
}
1014858
def open_connection(self):
        
        if self.readthread is not None:
            raise DutConnectionError("Trying to open serial port which was already open")

        self.logger.info("Open Connection "
                         "for '%s' using '%s' baudrate: %d" % (self.dut_name,
                                                               self.comport,
                                                               self.serial_baudrate),
                         extra={'type': '<->'})
        if self.serial_xonxoff:
            self.logger.debug("Use software flow control for dut: %s" % self.dut_name)
        if self.serial_rtscts:
            self.logger.debug("Use hardware flow control for dut: %s" % self.dut_name)
        try:
            self.port = EnhancedSerial(self.comport)
            self.port.baudrate = self.serial_baudrate
            self.port.timeout = self.serial_timeout
            self.port.xonxoff = self.serial_xonxoff
            self.port.rtscts = self.serial_rtscts
            self.port.flushInput()
            self.port.flushOutput()
        except SerialException as err:
            self.logger.warning(err)
            raise DutConnectionError(str(err))
        except ValueError as err:
            self.logger.warning(err)
            raise ValueError(str(err))

        if self.ch_mode:
            self.logger.info("Use chunk-mode with size %d, delay: %.3f when write data" %
                             (self.ch_mode_chunk_size, self.ch_mode_ch_delay),
                             extra={'type': '<->'})
            time.sleep(self.ch_mode_start_delay)
        else:
            self.logger.info("Use normal serial write mode", extra={'type': '<->'})
        if self.params.reset:
            self.reset()
        # Start the serial reading thread
        self.readthread = Thread(name=self.name, target=self.run)
        self.readthread.start()
375258
def _get_serial_ports_windows():
    '''
    
    '''
    import six.moves.winreg as winreg

    reg_path = 'HARDWARE\\DEVICEMAP\\SERIALCOMM'
    try:
        key = winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE, reg_path)
    except WindowsError:
        # No serial ports. Return empty generator.
        return

    for i in itertools.count():
        try:
            val = winreg.EnumValue(key, i)
            yield str(val[1])
        except EnvironmentError:
            break
831759
def _get_serial_number(self):
        
        return usb.util.get_string(self._device.usb_dev, 64, self._device.usb_dev.iSerialNumber)
693576
def get_local_serial():
    ''' 
    '''
    return [x for x in [subprocess.Popen("system_profiler SPHardwareDataType |grep -v tray |awk '/Serial/ {print $4}'", shell=True, stdout=subprocess.PIPE).communicate()[0].strip()] if x]
738547
def midi_inputs(self):
        
        return self.client.get_ports(is_midi=True, is_physical=True, is_input=True)
1155881
def main():
    

    # Channel value list for channels 1-512
    cv = [0 for v in range(0, 512)]

    # Create an instance of the DMX controller and open it    
    print("Opening DMX controller...")
    dev = pyudmx.uDMXDevice()
    # This will automagically find a single Anyma-type USB DMX controller
    dev.open()
    # For informational purpose, display what we know about the DMX controller
    print(dev.Device)

    # Send messages to the light changing it to red, then green, then blue
    # This is the "hard way" to do it, but illustrates how it's done

    print("Setting to red...")
    cv[0] = 255  # red
    cv[6] = 128  # dimmer to half value
    sent = dev.send_multi_value(1, cv)
    print("Set to red")
    sleep(3.0)

    print("Setting to green...")
    cv[0] = 0  # red
    cv[1] = 255  # green
    cv[6] = 128  # dimmer to half value
    sent = dev.send_multi_value(1, cv)
    print("Set to green")
    sleep(3.0)

    print("Setting to blue...")
    cv[0] = 0  # red
    cv[1] = 0  # green
    cv[2] = 255  # blue
    cv[6] = 128  # dimmer to half value
    sent = dev.send_multi_value(1, cv)
    print("Set to blue")
    sleep(3.0)

    # Here's an easier way to do it

    print("And, again the easier way")
    send_rgb(dev, 255, 0, 0, 128)
    sleep(3.0)
    send_rgb(dev, 0, 255, 0, 128)
    sleep(3.0)
    send_rgb(dev, 0, 0, 255, 128)
    sleep(3.0)

    print("Reset all channels and close..")
    # Turns the light off
    cv = [0 for v in range(0, 512)]
    dev.send_multi_value(1, cv)
    dev.close()
573639
def command(self, cmd, *args):
        
        self._serial_interface.command(cmd)
        if len(args) > 0:
            self._serial_interface.data(list(args))
723331
function(callback) {
    var ports = [];
    var newPortToDevice = [];
    // get all devices
    var responses = 0;
    var devices = Espruino.Core.Serial.devices;
    if (!devices || devices.length==0) {
         portToDevice = newPortToDevice;
      return callback(ports, false);
    }
    var shouldCallAgain = false;
    devices.forEach(function (device) {
      //console.log("getPorts -->",device.name);
      device.getPorts(function(devicePorts, instantPorts) {
        //console.log("getPorts <--",device.name);
        if (instantPorts===false) shouldCallAgain = true;
        if (devicePorts) {
          devicePorts.forEach(function(port) {
            var ignored = false;
            if (Espruino.Config.SERIAL_IGNORE)
              Espruino.Config.SERIAL_IGNORE.split("|").forEach(function(wildcard) {
                var regexp = "^"+wildcard.replace(/\./g,"\\.").replace(/\*/g,".*")+"$";
                if (port.path.match(new RegExp(regexp)))
                  ignored = true;
              });

            if (!ignored) {
              if (port.usb && port.usb[0]==0x0483 && port.usb[1]==0x5740)
                port.description = "Espruino board";
              ports.push(port);
              newPortToDevice[port.path] = device;
            }
          });
        }
        responses++;
        if (responses == devices.length) {
          portToDevice = newPortToDevice;
          ports.sort(function(a,b) {
            if (a.unimportant && !b.unimportant) return 1;
            if (b.unimportant && !a.unimportant) return -1;
            return 0;
          });
          callback(ports, shouldCallAgain);
        }
      });
    });
  }