iocp (v2.0b1)

::iocp::btTop, Main, Index

The iocp_bt package implements Bluetooth support and is loaded as

package require iocp_bt

The commands are broken into the following namespaces:

::iocp::btCore commands for Bluetooth communication.
::iocp::bt::sdrCommands for handling Bluetooth service discovery records.
::iocp::bt::namesCommands for mapping Bluetooth UUIDs and names.

Note the current limitations:

This documentation is a reference for the package. For an introductory guide, see the tutorials.

Device discoveryTop, Main, Index

Remote Bluetooth devices are discovered through devices command. It is generally recommended that a new device inquiry be initiated with the -inquire option when using this command as otherwise newly reachable devices will not be discovered. The device printn command will print the information related to each device in human-readable form.

Bluetooth radios on the local system can be enumerated with the radios command. There is however rarely a need to do this as it is not required for a establishing a Bluetooth connection.

Service discoveryTop, Main, Index

A device will generally host multiple services. The device services commands will retrieve information about the services advertised by the device. This information is in the form of service discovery records. Commands for parsing these records are contained in the sdr namespace.

Services and service classes are identified with UUID's. Most commands will however accept mnemonics for services defined in the standard as they are easier to remember than the UUID's. The names::print command will print the list of mnemonics and the corresponding UUID's.

Connection establishmentTop, Main, Index

Establishing a Bluetooth connection involves the following steps.

First, the device name has to be mapped to its physical address. Unlike the TCP sockets in Tcl, Bluetooth sockets require physical addresses to be specified as device names are ambiguous. The device addresses command can be used to obtain the physical addresses corresponding to a name. Note that there can be multiple devices with the same name so the command returns a list of addresses, one per device. When the list contains more than one address, generally the user needs to be prompted to pick one though below we just assume there is a single address in the list.

set addrs [iocp::bt::device addresses "APN Phone"]
set addr  [lindex $addrs 0]

Next, the port the service is listening on needs to be resolved with the device port command. In the example below, OBEXObjectPush is the service of interest.

set port [iocp::bt::service port $addr OBEXObjectPush]

Finally, a connection is established to the service using the socket command.

set so [iocp::bt::socket $addr $port]

Other commands in the namespace provide supporting functions such as device and service discovery.

CommandsTop, Main, Index

device [::iocp::bt]Top, Main, Index

A command ensemble.

device subcommand ...
Description

The ensemble supports the following subcommands:

addressReturns a Bluetooth address for a given name.
addressesReturns a list of Bluetooth addresses for a given name.
portResolve the port for a Bluetooth service running over RFCOMM.
printPrints device information in human-readable form to stdout.
printnPrints device information in human-readable form to stdout.
removeRemoves cached authentication information for a device from the system cache.
service_referencesRetrieve service discovery records that refer to a specified service.
servicesRetrieve the service discovery records for top level services advertised by a device.

Refer to the documentation of each subcommand for details.

device address [::iocp::bt]Top, Main, Index

Returns a Bluetooth address for a given name.

device address name ?args?
Parameters
nameName of device of interest.
argsOptions to control device enquiry. See devices.
Description

If a device has multiple addresses, the command may return any one them. If no addresses are found for the device, an error is raised.

Return value

Returns a Bluetooth address for a given name.

device addresses [::iocp::bt]Top, Main, Index

Returns a list of Bluetooth addresses for a given name.

device addresses name ?args?
Parameters
nameName of device of interest.
argsOptions to control device enquiry. See devices.
Return value

Returns a list of Bluetooth addresses for a given name.

device port [::iocp::bt]Top, Main, Index

Resolve the port for a Bluetooth service running over RFCOMM.

device port device service_class
Parameters
deviceBluetooth address or name of a device. If specified as a name, it must resolve to a single address.
service_classUUID or name of service class of interest. Note the service name cannot be used for lookup.
Description

In case multiple services of the same service class are available on the device, the port for the first one discovered is returned.

Return value

Returns the port number for the service or raises an error if it cannot be resolved.

device print [::iocp::bt]Top, Main, Index

Prints device information in human-readable form to stdout.

device print devinfo
Parameters
devinfoA device information record as returned by the devices command.

device printn [::iocp::bt]Top, Main, Index

Prints device information in human-readable form to stdout.

device printn dinfolist ?detailed?
Parameters
dinfolistA list of device information records as returned by the devices command.
detailedIf a true value, detailed information about the device is printed. If false (default), only the address and name are printed in compact form. Optional, default false.

device remove [::iocp::bt]Top, Main, Index

Removes cached authentication information for a device from the system cache.

device remove device
Parameters
deviceBluetooth address or name of a device. if specified as a name, it must resolve to a single address.
Description

The command will raise an error if $device is a name that cannot be resolved.

device service_references [::iocp::bt]Top, Main, Index

Retrieve service discovery records that refer to a specified service.

device service_references device service
Parameters
deviceBluetooth address or name of a device. If specified as a name, it must resolve to a single address.
serviceThe UUID of a service or service class or its mnemonic.
Description

The command will return all service discovery records that contain an attribute referring to the specified service. The returned service discovery records should be treated as opaque and accessed through the service record decoding commands.

Return value

Returns a list of service discovery records.

device services [::iocp::bt]Top, Main, Index

Retrieve the service discovery records for top level services advertised by a device.

device services device
Parameters
deviceBluetooth address or name of a device. If specified as a name, it must resolve to a single address.
Description

The command will return all service discovery records that reference the PublicBrowseRoot service class. This is not necessarily all the services on the device, only those the device advertises as the top-level services.

The returned service discovery records should be treated as opaque and accessed through the service record decoding commands.

Return value

Returns a list of service dscovery records.

devices [::iocp::bt]Top, Main, Index

Discover Bluetooth devices.

devices ?args?
Parameters
-authenticatedFilter for authenticated devices.
-connectedFilter for connected devices.
-inquireIssue a new inquiry. Without this option, devices that are not already known to the system will not be discovered.
-rememberedFilter for remembered devices.
-timeout MSTimeout for the inquiry in milliseconds. Defaults to 10240ms. Ignored if -inquire is not specified.
-unknownFilter for unknown devices.
Description

Each device information element is returned as a dictionary with the following keys:

AuthenticatedBoolean value indicating whether the device has been authenticated.
AddressBluetooth address of the devicec.
ClassDevice class as a numeric value.
ConnectedBoolean value indicating whether the device is connected.
DeviceClassesHuman readable list of general device class categories.
LastSeenTime when device was last seen. The format is a list of year, month, day, hour, minutes, seconds and milliseconds.
LastUsedTime when device was last used. The format is a list of year, month, day, hour, minutes, seconds and milliseconds.
MajorClassNameHuman readable major device class name.
MinorClassNameHuman readable minor device class name.
NameHuman readable name of the device.
RememberedBoolean value indicating whether the device is connected.

The filtering options may be specified to limit the devices returned. If none are specified, all devices are returned.

Return value

Returns a list of device information dictionaries.

radio [::iocp::bt]Top, Main, Index

A command ensemble.

radio subcommand ...
Description

The ensemble supports the following subcommands:

configureGets or modifies a radio configuration.
devicesDiscover devices accessible through the specified radio.
infoGet detailed information about a radio on the system.

Refer to the documentation of each subcommand for details.

radio configure [::iocp::bt]Top, Main, Index

Gets or modifies a radio configuration.

radio configure radio ?args?
Parameters
radioThe address or name associated with a radio on the system.
argsSee below.
Description

If no arguments are given to the command, it returns the current values of all options in the form of a dictionary.

If exactly one argument is given, it must be the name of an option and the command returns the value of the option.

Otherwise, the arguments must be a list of option name and values. The radio's options are set accordingly. The command returns an empty string for this case. Note that in case of raised exceptions the state of the radio options is indeterminate.

Return value

Returns an option value, a dictionary of options and values, or an empty string.

radio devices [::iocp::bt]Top, Main, Index

Discover devices accessible through the specified radio.

radio devices radio ?args?
Parameters
radioName or address of Bluetooth radio.
argsPassed on to devices
Description

This command has the same functionality as the devices command except that it restricts discovery only to those devices accessible through the specified radio.

Return value

Returns a list of device information dictionaries. See devices for the dictionary format.

radio info [::iocp::bt]Top, Main, Index

Get detailed information about a radio on the system

radio info ?radio?
Parameters
radioThe address or name associated with a radio on the system. If unspecified or the empty string, information about the first radio found is returned. Optional, default "".
Description

The returned dictionary has the following keys:

AddressThe Bluetooth address of the radio.
NameName assigned to the local system as advertised by the radio.
ClassDevice class as a numeric value.
DeviceClassesHuman readable list of general device class categories.
SubversionInteger value whose interpretation is manufacturer-specific.
ManufacturerInteger identifier assigned to the manufacturer.
MajorClassNameHuman readable major device class name.
MinorClassNameHuman readable minor device class name.
Return value

Returns a dictionary containing information about the radio.

radios [::iocp::bt]Top, Main, Index

Enumerate Bluetooth radios on the local system.

radios ?detailed?
Parameters
detailedIf true, detailed information about each radio is returned. If false (default), only the radio addresses are returned. Optional, default false.
Description

When $detailed is passed as a boolean false value, a list of radio addresses is returned.

When $detailed is passed as a boolean true value, each element of the returned list contains the following keys:

AddressThe Bluetooth address of the radio.
NameName assigned to the local system as advertised by the radio.
ClassDevice class as a numeric value.
DeviceClassesHuman readable list of general device class categories.
SubversionInteger value whose interpretation is manufacturer-specific.
ManufacturerInteger identifier assigned to the manufacturer.
MajorClassNameHuman readable major device class name.
MinorClassNameHuman readable minor device class name.
Return value

Returns a list of radio addresses or radio information elements.

socket [::iocp::bt]Top, Main, Index

Returns a client Bluetooth RFCOMM channel.

socket ?args?
Parameters
argsSee below.
Description

The command takes the form

socket ?-async? device port

where device is the Bluetooth hardware address of the remote device and port is the RFCOMM port (channel). The -async option has the same effect as in the Tcl socket command. It returns immediately without waiting for the connection to complete.

Once the connection is established, Bluetooth channel operation is identical to that of Tcl sockets except that half closes are not supported.

The returned channel must be closed with the Tcl close or chan close command.

Return value

Returns a client Bluetooth RFCOMM channel.