473,717 Members | 2,021 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

finding bluetooth serial port

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
Nov 7 '07 #1
2 7025
On 2007-11-07, Paul Sijben <pa*********@xs 4all.nlwrote:
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
| |-- bAlternateSetti ng
| |-- bInterfaceClass
| |-- bInterfaceNumbe r
| |-- bInterfaceProto col
| |-- bInterfaceSubCl ass
| |-- 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:us bdev5.42_ep02 -../../../../../../devices/pci0000:00/0000:00:10.3/usb5/5-1/5-1:1.0/usbdev5.42_ep02
| |-- usb_endpoint:us bdev5.42_ep81 -../../../../../../devices/pci0000:00/0000:00:10.3/usb5/5-1/5-1:1.0/usbdev5.42_ep81
| |-- usbdev5.42_ep02
| | |-- bEndpointAddres s
| | |-- 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
| |-- bEndpointAddres s
| |-- 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
|-- bConfigurationV alue
|-- bDeviceClass
|-- bDeviceProtocol
|-- bDeviceSubClass
|-- bMaxPacketSize0
|-- bMaxPower
|-- bNumConfigurati ons
|-- 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:usbd ev5.42 -../../../../../class/usb_device/usbdev5.42
|-- usb_endpoint:us bdev5.42_ep00 -../../../../../devices/pci0000:00/0000:00:10.3/usb5/5-1/usbdev5.42_ep00
|-- usbdev5.42_ep00
| |-- bEndpointAddres s
| |-- 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
Nov 7 '07 #2
thanks very much!
Grant Edwards wrote:
On 2007-11-07, Paul Sijben <pa*********@xs 4all.nlwrote:
>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
| |-- bAlternateSetti ng
| |-- bInterfaceClass
| |-- bInterfaceNumbe r
| |-- bInterfaceProto col
| |-- bInterfaceSubCl ass
| |-- 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:us bdev5.42_ep02 -../../../../../../devices/pci0000:00/0000:00:10.3/usb5/5-1/5-1:1.0/usbdev5.42_ep02
| |-- usb_endpoint:us bdev5.42_ep81 -../../../../../../devices/pci0000:00/0000:00:10.3/usb5/5-1/5-1:1.0/usbdev5.42_ep81
| |-- usbdev5.42_ep02
| | |-- bEndpointAddres s
| | |-- 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
| |-- bEndpointAddres s
| |-- 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
|-- bConfigurationV alue
|-- bDeviceClass
|-- bDeviceProtocol
|-- bDeviceSubClass
|-- bMaxPacketSize0
|-- bMaxPower
|-- bNumConfigurati ons
|-- 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:usbd ev5.42 -../../../../../class/usb_device/usbdev5.42
|-- usb_endpoint:us bdev5.42_ep00 -../../../../../devices/pci0000:00/0000:00:10.3/usb5/5-1/usbdev5.42_ep00
|-- usbdev5.42_ep00
| |-- bEndpointAddres s
| |-- 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.
Nov 8 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
2280
by: Helge Jensen | last post by:
Having posted in microsoft.public.dotnet.framework.sdk and microsoft.public.dotnet.framework.wmi without receiving any response, I posthere on the off-chance that someone who isn't following those groups knows a solution. I'm using code (roughly like): using System; using System.Management; public class Foo {
2
5766
by: Alvin Lau | last post by:
Can I write pocket PC bluetooth program by using C# ? It seems so difficult to find the library? If it is possible , where can i find the reference of these kind of program ? *** Sent via Developersdex http://www.developersdex.com *** Don't just participate in USENET...get rewarded for it!
1
2050
by: Nathan Young | last post by:
Hello. I have a .net application that utilizes COM ports to communicate with serial devices (namely a GPS). This may not be the right group for this question, but bear with me as I am not sure where else to ask. (I would appreciate any NG pointers). Anyway, my application uses CreateFile and ReadFile to setup a COM port for the GPS, and then to read the data from the GPS.
1
10917
by: henrycortezwu | last post by:
Hi All, I'm trying to connect to a virtual port (COM19, OUTGOING, "Bluetooth Serial Port") using VS2005 System.IO.Ports. When I ran the ff code below here's what happens. 1) VS2005 Compiles w/o errors 2) My Nokia 6600 prompted me the message "Accept Connection request from DEMON?" note: DEMON is my computers name. 3) Using my Nokia 6600, I hit the button that refers to the "Yes"
4
2233
by: Boki | last post by:
Hi All, I am going to use some Bluetotoh API, should I include some special DLL or just call it directly? Best regards, Boki.
2
5430
by: colin | last post by:
Hi, Im having a tiresome amount of trouble with using a bluetooth serial link. The receiving end is a bluetooth-rs232 module conected to my embeded system. The PC has a little usb bluetooth dongle, ive tried a another dongle with widicom software as I was having problems with the IVT bluesoleil software. that seems to have got rid of some other problems,
2
1997
by: Dave Harry | last post by:
I'm using the following code to determine the available serial ports: ComboBoxPort.Items.Clear() For Each sp As String In My.Computer.Ports.SerialPortNames ComboBoxPort.Items.Add(sp) Next It worked well in XP, but under Vista (now with SP1) the Bluetooth ports don't show correctly. We have half a dozen different brands and types of Bluetooth on various
1
4027
by: arthurclucas | last post by:
Hi everyone, I'm have two iPac Devices and I'm trying send some bytes from one to another via Bluetooth communication. I use the CreateFile command to send the data and the ReadFile command to read the data. In booth commands I use the appropriate COM port. When I try to send the bytes, it appears to work (the return is 1). When I try to read the bytes, it also appears to work (the return is 1).
0
1665
by: lakshmiRam | last post by:
hi i have a code which was supposed to read data from serial com (bluetooth) and save in a file. but when i send a audio file from my mobile to pc the program will not read the port i have configured the bluetooth connection for serial communication (i.e from system stray selecting bluetooth icon and from quick connect selecting serial connection). instead it shows that connection is succesfull for PIM transfer, so do i need to write a...
0
8823
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8719
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9348
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9109
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7981
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6648
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5970
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4739
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2545
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.