finding bluetooth serial port

Discussion in 'Python' started by Paul Sijben, Nov 7, 2007.

  1. Paul Sijben

    Paul Sijben Guest

    To automate/ease configuration in my app I am trying to find out to
    which serial port a certain bluetooth device is connected. With pybluez
    I can find out which bluetooth devices I have, but it will not tell me
    the serial port they are mapped to.

    Is there a way to figure this out from python? (I am insterested in the
    platforms WinXP and linux primarily)

    Paul Sijben
    Paul Sijben, Nov 7, 2007
    #1
    1. Advertising

  2. On 2007-11-07, Paul Sijben <> wrote:

    > To automate/ease configuration in my app I am trying to find
    > out to which serial port a certain bluetooth device is
    > connected. With pybluez I can find out which bluetooth devices
    > I have, but it will not tell me the serial port they are
    > mapped to.
    >
    > Is there a way to figure this out from python? (I am
    > insterested in the platforms WinXP and linux primarily)


    Under linux, the "right" thing to do is to write a udev rule so
    that the device has a predictiable name (or symlink).

    http://reactivated.net/writing_udev_rules.html

    If you don't want to write a udev rule, you'll need to bascally
    re-implement udev by parsing the sysfs directory tree until you
    find the device you're looking for. Here's how to do it for USB
    (I assume BT works in a similar fashion).

    Let's say I know the device has vendor ID 0403, product ID
    6001, and serial number 123456.

    I search through the directories under /sys/devices until I
    find a directory containing three files named

    idProduct
    idVendor
    serial

    Which contain the three strings I'm looking for.

    In this case:

    # cat /sys/devices/pci0000:00/0000:00:10.3/usb5/5-1/idVendor
    0403
    # cat /sys/devices/pci0000:00/0000:00:10.3/usb5/5-1/idProduct
    6001
    # cat /sys/devices/pci0000:00/0000:00:10.3/usb5/5-1/serial
    12345678

    Once you've found that directory, you can look at the other
    entries to find out whatever you want to know about the device:

    /sys/devices/pci0000:00/0000:00:10.3/usb5/5-1/
    |-- 5-1:1.0
    | |-- bAlternateSetting
    | |-- bInterfaceClass
    | |-- bInterfaceNumber
    | |-- bInterfaceProtocol
    | |-- bInterfaceSubClass
    | |-- bNumEndpoints
    | |-- bus -> ../../../../../../bus/usb
    | |-- driver -> ../../../../../../bus/usb/drivers/ftdi_sio
    | |-- ep_02 -> ../../../../../../devices/pci0000:00/0000:00:10.3/usb5/5-1/5-1:1.0/usbdev5.42_ep02
    | |-- ep_81 -> ../../../../../../devices/pci0000:00/0000:00:10.3/usb5/5-1/5-1:1.0/usbdev5.42_ep81
    | |-- interface
    | |-- modalias
    | |-- power
    | | |-- state
    | | `-- wakeup
    | |-- subsystem -> ../../../../../../bus/usb
    | |-- ttyUSB0
    | | |-- bus -> ../../../../../../../bus/usb-serial
    | | |-- driver -> ../../../../../../../bus/usb-serial/drivers/ftdi_sio
    | | |-- power
    | | | |-- state
    | | | `-- wakeup
    | | |-- subsystem -> ../../../../../../../bus/usb-serial
    | | |-- tty:ttyUSB0 -> ../../../../../../../class/tty/ttyUSB0
    | | `-- uevent
    | |-- uevent
    | |-- usb_endpoint:usbdev5.42_ep02 -> ../../../../../../devices/pci0000:00/0000:00:10.3/usb5/5-1/5-1:1.0/usbdev5.42_ep02
    | |-- usb_endpoint:usbdev5.42_ep81 -> ../../../../../../devices/pci0000:00/0000:00:10.3/usb5/5-1/5-1:1.0/usbdev5.42_ep81
    | |-- usbdev5.42_ep02
    | | |-- bEndpointAddress
    | | |-- bInterval
    | | |-- bLength
    | | |-- bmAttributes
    | | |-- dev
    | | |-- device -> ../../../../../../../devices/pci0000:00/0000:00:10.3/usb5/5-1/5-1:1.0
    | | |-- direction
    | | |-- interval
    | | |-- power
    | | | |-- state
    | | | `-- wakeup
    | | |-- subsystem -> ../../../../../../../class/usb_endpoint
    | | |-- type
    | | |-- uevent
    | | `-- wMaxPacketSize
    | `-- usbdev5.42_ep81
    | |-- bEndpointAddress
    | |-- bInterval
    | |-- bLength
    | |-- bmAttributes
    | |-- dev
    | |-- device -> ../../../../../../../devices/pci0000:00/0000:00:10.3/usb5/5-1/5-1:1.0
    | |-- direction
    | |-- interval
    | |-- power
    | | |-- state
    | | `-- wakeup
    | |-- subsystem -> ../../../../../../../class/usb_endpoint
    | |-- type
    | |-- uevent
    | `-- wMaxPacketSize
    |-- bConfigurationValue
    |-- bDeviceClass
    |-- bDeviceProtocol
    |-- bDeviceSubClass
    |-- bMaxPacketSize0
    |-- bMaxPower
    |-- bNumConfigurations
    |-- bNumInterfaces
    |-- bcdDevice
    |-- bmAttributes
    |-- bus -> ../../../../../bus/usb
    |-- configuration
    |-- devnum
    |-- driver -> ../../../../../bus/usb/drivers/usb
    |-- ep_00 -> ../../../../../devices/pci0000:00/0000:00:10.3/usb5/5-1/usbdev5.42_ep00
    |-- event_char
    |-- idProduct
    |-- idVendor
    |-- manufacturer
    |-- maxchild
    |-- power
    | |-- state
    | `-- wakeup
    |-- product
    |-- serial
    |-- speed
    |-- subsystem -> ../../../../../bus/usb
    |-- uevent
    |-- usb_device:usbdev5.42 -> ../../../../../class/usb_device/usbdev5.42
    |-- usb_endpoint:usbdev5.42_ep00 -> ../../../../../devices/pci0000:00/0000:00:10.3/usb5/5-1/usbdev5.42_ep00
    |-- usbdev5.42_ep00
    | |-- bEndpointAddress
    | |-- bInterval
    | |-- bLength
    | |-- bmAttributes
    | |-- dev
    | |-- device -> ../../../../../../devices/pci0000:00/0000:00:10.3/usb5/5-1
    | |-- direction
    | |-- interval
    | |-- power
    | | |-- state
    | | `-- wakeup
    | |-- subsystem -> ../../../../../../class/usb_endpoint
    | |-- type
    | |-- uevent
    | `-- wMaxPacketSize
    `-- version


    If you want to search by something other than the product id,
    vendor id and serial number, then pick some other of the files
    above that will have identifiable contents and look for that.

    --
    Grant Edwards grante Yow! We just joined the
    at civil hair patrol!
    visi.com
    Grant Edwards, Nov 7, 2007
    #2
    1. Advertising

  3. Paul Sijben

    Paul Sijben Guest

    thanks very much!


    Grant Edwards wrote:
    > On 2007-11-07, Paul Sijben <> wrote:
    >
    >> To automate/ease configuration in my app I am trying to find
    >> out to which serial port a certain bluetooth device is
    >> connected. With pybluez I can find out which bluetooth devices
    >> I have, but it will not tell me the serial port they are
    >> mapped to.
    >>
    >> Is there a way to figure this out from python? (I am
    >> insterested in the platforms WinXP and linux primarily)

    >
    > Under linux, the "right" thing to do is to write a udev rule so
    > that the device has a predictiable name (or symlink).
    >
    > http://reactivated.net/writing_udev_rules.html
    >
    > If you don't want to write a udev rule, you'll need to bascally
    > re-implement udev by parsing the sysfs directory tree until you
    > find the device you're looking for. Here's how to do it for USB
    > (I assume BT works in a similar fashion).
    >
    > Let's say I know the device has vendor ID 0403, product ID
    > 6001, and serial number 123456.
    >
    > I search through the directories under /sys/devices until I
    > find a directory containing three files named
    >
    > idProduct
    > idVendor
    > serial
    >
    > Which contain the three strings I'm looking for.
    >
    > In this case:
    >
    > # cat /sys/devices/pci0000:00/0000:00:10.3/usb5/5-1/idVendor
    > 0403
    > # cat /sys/devices/pci0000:00/0000:00:10.3/usb5/5-1/idProduct
    > 6001
    > # cat /sys/devices/pci0000:00/0000:00:10.3/usb5/5-1/serial
    > 12345678
    >
    > Once you've found that directory, you can look at the other
    > entries to find out whatever you want to know about the device:
    >
    > /sys/devices/pci0000:00/0000:00:10.3/usb5/5-1/
    > |-- 5-1:1.0
    > | |-- bAlternateSetting
    > | |-- bInterfaceClass
    > | |-- bInterfaceNumber
    > | |-- bInterfaceProtocol
    > | |-- bInterfaceSubClass
    > | |-- bNumEndpoints
    > | |-- bus -> ../../../../../../bus/usb
    > | |-- driver -> ../../../../../../bus/usb/drivers/ftdi_sio
    > | |-- ep_02 -> ../../../../../../devices/pci0000:00/0000:00:10.3/usb5/5-1/5-1:1.0/usbdev5.42_ep02
    > | |-- ep_81 -> ../../../../../../devices/pci0000:00/0000:00:10.3/usb5/5-1/5-1:1.0/usbdev5.42_ep81
    > | |-- interface
    > | |-- modalias
    > | |-- power
    > | | |-- state
    > | | `-- wakeup
    > | |-- subsystem -> ../../../../../../bus/usb
    > | |-- ttyUSB0
    > | | |-- bus -> ../../../../../../../bus/usb-serial
    > | | |-- driver -> ../../../../../../../bus/usb-serial/drivers/ftdi_sio
    > | | |-- power
    > | | | |-- state
    > | | | `-- wakeup
    > | | |-- subsystem -> ../../../../../../../bus/usb-serial
    > | | |-- tty:ttyUSB0 -> ../../../../../../../class/tty/ttyUSB0
    > | | `-- uevent
    > | |-- uevent
    > | |-- usb_endpoint:usbdev5.42_ep02 -> ../../../../../../devices/pci0000:00/0000:00:10.3/usb5/5-1/5-1:1.0/usbdev5.42_ep02
    > | |-- usb_endpoint:usbdev5.42_ep81 -> ../../../../../../devices/pci0000:00/0000:00:10.3/usb5/5-1/5-1:1.0/usbdev5.42_ep81
    > | |-- usbdev5.42_ep02
    > | | |-- bEndpointAddress
    > | | |-- bInterval
    > | | |-- bLength
    > | | |-- bmAttributes
    > | | |-- dev
    > | | |-- device -> ../../../../../../../devices/pci0000:00/0000:00:10.3/usb5/5-1/5-1:1.0
    > | | |-- direction
    > | | |-- interval
    > | | |-- power
    > | | | |-- state
    > | | | `-- wakeup
    > | | |-- subsystem -> ../../../../../../../class/usb_endpoint
    > | | |-- type
    > | | |-- uevent
    > | | `-- wMaxPacketSize
    > | `-- usbdev5.42_ep81
    > | |-- bEndpointAddress
    > | |-- bInterval
    > | |-- bLength
    > | |-- bmAttributes
    > | |-- dev
    > | |-- device -> ../../../../../../../devices/pci0000:00/0000:00:10.3/usb5/5-1/5-1:1.0
    > | |-- direction
    > | |-- interval
    > | |-- power
    > | | |-- state
    > | | `-- wakeup
    > | |-- subsystem -> ../../../../../../../class/usb_endpoint
    > | |-- type
    > | |-- uevent
    > | `-- wMaxPacketSize
    > |-- bConfigurationValue
    > |-- bDeviceClass
    > |-- bDeviceProtocol
    > |-- bDeviceSubClass
    > |-- bMaxPacketSize0
    > |-- bMaxPower
    > |-- bNumConfigurations
    > |-- bNumInterfaces
    > |-- bcdDevice
    > |-- bmAttributes
    > |-- bus -> ../../../../../bus/usb
    > |-- configuration
    > |-- devnum
    > |-- driver -> ../../../../../bus/usb/drivers/usb
    > |-- ep_00 -> ../../../../../devices/pci0000:00/0000:00:10.3/usb5/5-1/usbdev5.42_ep00
    > |-- event_char
    > |-- idProduct
    > |-- idVendor
    > |-- manufacturer
    > |-- maxchild
    > |-- power
    > | |-- state
    > | `-- wakeup
    > |-- product
    > |-- serial
    > |-- speed
    > |-- subsystem -> ../../../../../bus/usb
    > |-- uevent
    > |-- usb_device:usbdev5.42 -> ../../../../../class/usb_device/usbdev5.42
    > |-- usb_endpoint:usbdev5.42_ep00 -> ../../../../../devices/pci0000:00/0000:00:10.3/usb5/5-1/usbdev5.42_ep00
    > |-- usbdev5.42_ep00
    > | |-- bEndpointAddress
    > | |-- bInterval
    > | |-- bLength
    > | |-- bmAttributes
    > | |-- dev
    > | |-- device -> ../../../../../../devices/pci0000:00/0000:00:10.3/usb5/5-1
    > | |-- direction
    > | |-- interval
    > | |-- power
    > | | |-- state
    > | | `-- wakeup
    > | |-- subsystem -> ../../../../../../class/usb_endpoint
    > | |-- type
    > | |-- uevent
    > | `-- wMaxPacketSize
    > `-- version
    >
    >
    > If you want to search by something other than the product id,
    > vendor id and serial number, then pick some other of the files
    > above that will have identifiable contents and look for that.
    >
    Paul Sijben, Nov 8, 2007
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Edwin van den Oetelaar
    Replies:
    0
    Views:
    823
    Edwin van den Oetelaar
    Nov 3, 2006
  2. Pom
    Replies:
    2
    Views:
    1,636
    Bas-i
    Jan 31, 2007
  3. Replies:
    1
    Views:
    3,001
    Michael DOUBEZ
    Mar 4, 2009
  4. izzahmeor
    Replies:
    0
    Views:
    770
    izzahmeor
    Feb 3, 2010
  5. msalerno
    Replies:
    3
    Views:
    407
    Ilmari Karonen
    Jul 14, 2005
Loading...

Share This Page