Sei sulla pagina 1di 2

1/16/14

Create Bluetooth object - MATLAB bluetooth - MathWorks India

bluetooth
Create Bluetooth object Syntax
B=B l u e t o o t h ( ' R e m o t e N a m e ' ,C h a n n e l ) B=B l u e t o o t h ( ' R e m o t e I D ' ,C h a n n e l ) B=B l u e t o o t h ( ' R e m o t e I D ' ,C h a n n e l ,' P 1 ' , V 1 , ' P 2 ' , V 2 , . . . )

Description
The Instrument Control Toolbox Bluetooth interface lets you connect to devices over the Bluetooth interface and to transmit and receive ASCII and binary data. Instrument Control Toolbox supports the Bluetooth Serial Port Profile (SPP). You can identify any SPP Bluetooth device and establish a tw o-w ay connection w ith that device. B=B l u e t o o t h ( ' R e m o t e N a m e ' ,C h a n n e l )constructs a Bluetooth object associated w ith the R e m o t e N a m eand C h a n n e l .R e m o t e N a m eis a friendly w ay to identify the R e m o t e I D . If a channel is not specified, it w ill default to 0 . B=B l u e t o o t h ( ' R e m o t e I D ' ,C h a n n e l )constructs a Bluetooth object directly from the R e m o t e I Dand C h a n n e l . In order to communicate w ith the Bluetooth device, use the f o p e nfunction. When the Bluetooth object is constructed, the object's s t a t u sproperty is c l o s e d . Once the object is connected to the remote device w ith the f o p e nfunction, the s t a t u sproperty is configured to o p e n . B=B l u e t o o t h ( ' R e m o t e I D ' ,C h a n n e l ,' P 1 ' , V 1 , ' P 2 ' , V 2 , . . . )constructs a Bluetooth object associated w ith the R e m o t e I D ,C h a n n e land w ith the specified property values. If an invalid property name or property value is specified the object w ill not be created. The property value pairs can be in any format supported by the s e tfunction, i.e., param-value string pairs, structures, and param-value cell array pairs. For information on other functions that can be used w ith B l u e t o o t h , a full example using the Bluetooth interface, events and callbacks, and usage guidelines see Bluetooth Interface Overview . Properties that can be used w ith the B l u e t o o t hobject include:
Property Description

C h a n n e l R e m o t e N a m e

Use to specify a channel if the device has channels. If none is provided, it defaults to 0 . "Friendly name" for the Bluetooth device. For example, in the case of an iPhone, it might be simply ' i P h o n e 'or a name like ' Z o r ' . This property is a string and can be empty. If it is empty, you must use the R e m o t e I Dto communicate w ith the device. Internal ID of the Bluetooth device, equivalent to the Device ID. This is usually a 12-digit string that starts w ith b t s p p : / / . For example, ' b t s p p : / / 0 0 1 6 5 3 0 F D 6 5 F ' This property is a string and every device has one. You can use this or the R e m o t e N a m eto communicate w ith the device.

R e m o t e I D

Examples
Find available Bluetooth devices. i n s t r h w i n f o ( ' B l u e t o o t h ' ) ; i n s t r h w i n f o ( ' B l u e t o o t h ' ,R e m o t e N a m e ) ; Construct a Bluetooth object called busing channel 3of a Lego Mindstorm robot w ith R e m o t e N a m eof N X T . b=B l u e t o o t h ( ' N X T ' ,3 ) ; Connect to the remote device. f o p e n ( b ) Send a message to the remote device using the f w r i t efunction.
www.mathworks.in/help/instrument/bluetooth.html 1/2

1/16/14

Create Bluetooth object - MATLAB bluetooth - MathWorks India

f w r i t e ( b ,u i n t 8 ( [ 2 , 0 , 1 , 1 5 5 ] ) ) ; Read data from the remote device using the f r e a dfunction. n a m e=f r e a d ( b , 3 5 ) ; Disconnect the Bluetooth device. f c l o s e ( b ) ; Clean up by deleting and clearing the object. f c l o s e ( b ) ; c l e a r ( b ) ;

More About
Bluetooth Interface Overview

www.mathworks.in/help/instrument/bluetooth.html

2/2

Potrebbero piacerti anche