Create Bluetooth object
B = Bluetooth('RemoteName', Channel)
B = Bluetooth('RemoteID', Channel)
B = Bluetooth('RemoteID', Channel, 'P1',V1,'P2',V2,...)
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 two-way connection with that device.
B = Bluetooth('RemoteName', Channel) constructs a Bluetooth object associated with the RemoteName and Channel. RemoteName is a friendly way to identify the RemoteID. If a channel is not specified, it will default to 0.
B = Bluetooth('RemoteID', Channel) constructs a Bluetooth object directly from the RemoteID and Channel.
In order to communicate with the Bluetooth device, use the fopen function. When the Bluetooth object is constructed, the object's status property is closed. Once the object is connected to the remote device with the fopen function, the status property is configured to open.
B = Bluetooth('RemoteID', Channel, 'P1',V1,'P2',V2,...) constructs a Bluetooth object associated with the RemoteID, Channel and with the specified property values. If an invalid property name or property value is specified the object will not be created. The property value pairs can be in any format supported by the set function, i.e., param-value string pairs, structures, and param-value cell array pairs.
For information on other functions that can be used with Bluetooth, a full example using the Bluetooth interface, events and callbacks, and usage guidelines see Bluetooth Interface Overview.
Properties that can be used with the Bluetooth object include:
|Channel||Use to specify a channel if the device has channels. If none is provided, it defaults to 0.|
|RemoteName||"Friendly name" for the Bluetooth device. For
example, in the case of an iPhone, it might be simply 'iPhone' or
a name like 'Zor'. |
This property is a string and can be empty. If it is empty, you must use the RemoteID to communicate with the device.
|RemoteID||Internal ID of the Bluetooth device, equivalent to the Device
ID. This is usually a 12-digit string that starts with btspp://.
For example, 'btspp://0016530FD65F'|
This property is a string and every device has one. You can use this or the RemoteName to communicate with the device.
Find available Bluetooth devices.
instrhwinfo('Bluetooth'); instrhwinfo('Bluetooth', RemoteName);
Construct a Bluetooth object called b using channel 3 of a Lego Mindstorm robot with RemoteName of NXT.
b = Bluetooth('NXT', 3);
Connect to the remote device.
Send a message to the remote device using the fwrite function.
Read data from the remote device using the fread function.
name = fread(b,35);
Disconnect the Bluetooth device.
Clean up by deleting and clearing the object.