Module comscan
[hide private]
[frames] | no frames]

Module comscan

source code

Detect and enumerate com(serial) ports

You should close all com ports you have open before calling any
functions in this module.  If you don't they will be detected as in
use.

Call the comscan() function It returns a list with each entry being a
dictionary of useful information.  See the platform notes for what is
in each one.

For your convenience the entries in the list are also sorted into
an order that would make sense to the user.

Platform Notes:
===============

w  Windows9x
W  WindowsNT/2K/XP
L  Linux
M  Mac

wWLM name               string   Serial device name
wWLM available          Bool     True if it is possible to open this device
wW   active             Bool     Is the driver actually running?  An example of when this is False
                                 is USB devices or Bluetooth etc that aren't currently plugged in.
                                 If you are presenting stuff for users, do not show entries where
                                 this is false
w    driverstatus       dict     status is some random number, problem is non-zero if there is some
                                 issue (eg device disabled)
wW   hardwareinstance   string   instance of the device in the registry as named by Windows
wWLM description        string   a friendly name to show users
wW   driverdate         tuple    (year, month, day)
 W   driverversion      string   version string
wW   driverprovider     string   the manufacturer of the device driver
wW   driverdescription  string   some generic description of the driver
  L  device             tuple    (major, minor) device specification
  L  driver             string   the driver name from /proc/devices (eg ttyS or ttyUSB)

Classes [hide private]
  RegistryAccess
A class that is significantly easier to use to access the Registry
Functions [hide private]
 
_IsWindows() source code
 
_IsLinux() source code
 
_IsMac() source code
 
_comscanwindows()
Get detail about all com ports on Windows
source code
 
_comscanlinux(maxnum=9)
Get all the ports on Linux
source code
 
_comscanmac()
Get all the ports on Mac
source code
 
_stringint(str)
Seperate a string and trailing number into a tuple
source code
 
_cmpfunc(a, b)
Comparison function for two port names
source code
 
comscan(*args, **kwargs)
Call platform specific version of comscan function
source code
Variables [hide private]
  version = '$Revision: 4368 $'
Function Details [hide private]

_comscanwindows()

source code 

Get detail about all com ports on Windows

This code functions on both win9x and nt/2k/xp

_comscanlinux(maxnum=9)

source code 

Get all the ports on Linux

Note that Linux doesn't actually provide any way to enumerate actual ports. Consequently we just look for device nodes. It still isn't possible to establish if there are actual device drivers behind them. The availability testing is done however.

Parameters:
  • maxnum - The highest numbered device to look for (eg maxnum of 17 will look for ttyS0 ... ttys17)

_comscanmac()

source code 

Get all the ports on Mac

Just look for /dev/cu.* entries, they all seem to populate here whether USB->Serial, builtin, bluetooth, etc...

_stringint(str)

source code 

Seperate a string and trailing number into a tuple

For example "com10" returns ("com", 10)

_cmpfunc(a, b)

source code 

Comparison function for two port names

In particular it looks for a number on the end, and sorts by the prefix (as a string operation) and then by the number. This function is needed because "com9" needs to come before "com10"