How to connect android device via bluetooth with matlab 'Instrument Control'-Toolbox? Ask Question Asked 4 years, 6 months ago. Browse other questions tagged android matlab sockets bluetooth serial-port or ask your own question. Are soldered electrical connections code-compliant? More hot questions Question feed.
Instrument Control Toolbox™ can communicate with Bluetooth devicesvia an adaptor. You can discover your devices and view their properties.
You can read and write both text data (ASCII based)and binary data over the Bluetooth interface.
You can enhance the power and flexibility of yourinstrument communication by using events and callbacks.
The Bluetooth interface is supported for usein the Test & Measurement Tool, and includes the same functionalitythat is available in the core toolbox.
The Instrument Control Toolbox Bluetooth interfacelets you connect to devices over the Bluetooth interface andto transmit and receive ASCII and binary data.
These tips and guidelines may be relevant to youruse of the Bluetooth interface.
These properties are available in the toolbox.
Troubleshooting Bluetooth Interface
The Instrument Control Toolbox™ Bluetooth® interface letsyou connect to devices over the Bluetooth interface and to transmitand receive ASCII and binary data. Instrument Control Toolbox supportsthe Bluetooth Serial Port Profile (SPP). You can identify anySPP Bluetooth device and establish a two-way connection withthat device.
Bluetooth is an open wireless technology standard for exchangingdata over short distances using short wavelength radio transmissionsfrom fixed and mobile devices over a packet-based protocol. Bluetooth providesa secure way to connect and exchange information between devices suchas Lego Mindstorm NXT robots, USB Bluetooth adaptors (dongles),wireless sensors, mobile phones, faxes, laptops, computers, printers,GPS receivers, etc.
Supported Platforms
The Bluetooth interface is supported on these platforms:
Adaptor Requirements
Instrument Control Toolbox supports the Bluetooth SerialPort Profile (SPP). You can identify any SPP Bluetooth deviceand establish a two-way connection with that device.
Instrument Control Toolbox can communicate with Bluetooth devicesvia an adaptor. In this example, a USB Bluetooth adaptor is pluggedinto the computer. It can identify Bluetooth devices within rangewhen queried. In order to communicate with instruments, you need toperform a pairing in the adaptor software. Note that some devices,such as many laptop computers, do not need to use an adaptor sincethey have one built in.
The following shows the software interface of an adaptor wheretwo of the devices in range have been paired – a smart phonewith Bluetooth enabled, and a Lego Mindstorm NXT robot. As youcan see, the “friendly name” or display name of thesmart phone is simply
iPhone
and the name of theNXT robot is C3PO
. In Instrument Control Toolbox thisfriendly name is the Bluetooth RemoteName
property.On Windows 7 64-bit platforms, you can use only one Bluetooth adaptorat a time. If you connect another adaptor, it will fail with a “DeviceDriver Installation Failed” error.
Some adaptors support multiple devices:
- The Bluetooth adaptor that comes with the LEGOMindstorm kit (Abe – Model: UB22S) supports connection to onlyone Bluetooth device at a time.
- IO Gear – Models GBU421 and GBU311 supportcommunication with multiple Bluetooth devices.
- Targus – Model ACB10US supports communicationwith multiple Bluetooth devices.
- Motorola – Model SYN1244B supports communicationwith multiple Bluetooth devices.
- D-Link – Model DBT-120 supports communicationwith multiple Bluetooth devices.
If a Bluetooth adaptor is removed and a different one pluggedin, all Bluetooth devices have to be paired again with your PC.If the same adaptor is removed and plugged back in, then you do notneed to pair the devices again. If another adaptor of the same vendoris plugged in, then the devices which had been cached when that adaptorwas used are seen in the cache.
Configuration and Connection
- Make sure that you have the correct instrument driverinstalled for your device. Refer to your device’s documentationand the vendor’s web site.
- Make sure your device is supported in Instrument Control Toolbox.See Is My Hardware Supported?.
- Make sure that the Bluetooth service on the deviceis turned on.
- Instrument Control Toolbox can communicate with Bluetooth devicesvia an adaptor, either a USB Bluetooth adaptor that is pluggedinto the computer, or a built in adaptor in the device. See Adaptor Requirements.Make sure you have performed the pairing between the deviceand the computer running MATLAB® by using either a USB adaptoror a built-in adaptor.
- You can verify that MATLAB can see your device byusing the
instrhwinfo
function with theBluetooth
interfacename.In this example,instrhwinfo
returned a cellarray of five Bluetooth devices that are in the range of theadaptor on the computer running Instrument Control Toolbox. Thenindexing into theRemoteNames
property shows thefive devices. You can see thatiPhone
andC3PO
appearin the list.If a device shows an empty character vector forRemoteName
,then that device does not have a friendly name associated with it.To communicate with that device, you need to use theRemoteID
property.TheRemoteIDs
display in the same order astheRemoteNames
, so in this case, the fourth IDin the list,'0021BA74F3DD'
, could be used forthe device that shows noRemoteName
. You can useeitherRemoteName
orRemoteID
tocommunicate with a device.You can verify that MATLAB can see your device by using theinstrhwinfo
functionwith theRemoteName
property. In this example,C3PO
isthe remote name of the NXT robot and is shown in the output.The Instrument Control Toolbox displays the device information. - Make sure you can create the
Bluetooth
object.You must provide two arguments to create the object, either theRemoteName
ortheRemoteID
, and a channel number. You can getthe channel number from your device’s documentation or fromlooking at the Bluetooth node in the Test &Measurement Tool. For example, create a Bluetooth object calledbt
usingchannel1
of the NXT device.If you do not get an error, the object was created successfully. - Make sure you can connect to the device, using the
fopen
functionwith the object name.If you do not get an error, the connection was made successfully.If you do get an error, follow the steps in the error message and/orcheck the previous steps listed here. - When you have connected, you can communicate withyour device. See in Transmitting Data Over the Bluetooth Interface for an example of communicatingwith a device. See Other Troubleshooting Tips for Bluetooth for tips about communicationissues after initial connection.
Other Troubleshooting Tips for Bluetooth
These tips may be relevant to your use of this feature.
Remove or change adaptors
If a Bluetooth adaptor is removed and a different one pluggedin, all Bluetooth devices have to be paired again with your PC.If the same adaptor is removed and plugged back in, then you do notneed to pair the devices again. If another adaptor of the same vendoris plugged in, then the devices which had been cached when that adaptorwas used are seen in the cache.
Use of instrhwinfo
If a Bluetooth device is already cached, but it is OFFwhen MATLAB is started, and if
instrhwinfo
iscalled on this device, then ObjectConstructorName
and Channel
arereturned as a null character vector.If a Bluetooth device is already cached and is ON when MATLAB isstarted, and it is later switched OFF, if
instrhwinfo
iscalled on this device, then ObjectConstructorName
and Channel
returnthe correct values.Device out of range
If you create a Bluetooth object for any Bluetooth deviceand the connection is open, and then the device goes out of range,the status of the object would still be
open
. Whenthe device comes into range again, you need to fclose
theobject and fopen
it again for communication tocontinue.Change batteries on device
If you create a Bluetooth object, for a Lego MindstormNXT robot for example, and the connection is open, and then the batteriesof robot run out, then the status of the object would still be
open
.If you then replace the batteries, you need to fclose
theobject and fopen
it again for communication tocontinue.Restart device after scan in Test &Measurement Tool
![Simulation Simulation](/uploads/1/2/6/5/126523636/705429910.gif)
When using the Bluetooth support in the Test & MeasurementTool, please note that you may need to restart your device after youhave done the scan. For any Lego Mindstorm robot to be identifiedcorrectly, it has to be restarted after scanning. You may also haveto restart other Bluetooth devices after the scan as well.
Troubleshoot Bluetooth Interface in Test & Measurement Tool
To use the Bluetooth support in the Test & MeasurementTool, select the Bluetooth node in the instrumenttree and right-click Scan for bluetooth devices.
Note
When using the Bluetooth support in the Test & MeasurementTool, please note that you may need to restart your device after youhave done the scan. For any Lego Mindstorm robot to be identifiedcorrectly, it has to be restarted after scanning. You may also haveto restart other Bluetooth devices after the scan as well.
If you are having trouble using the Bluetooth interfacein the Test & Measurement Tool, try these steps.
- Check that the Bluetooth device supports theSerial Port Profile (SPP). We do not support other Bluetooth profilessuch as File Transfer Profile (FTP).
- Make sure that the Bluetooth service on the deviceis turned on.
- Make sure that the Bluetooth device is pairedwith your computer.
- If you are using a Lego Mindstorm NXT brick, notethat the NXT brick has to be restarted after scanning for Bluetooth devicesfrom the Test & Measurement Tool.
- If you still cannot connect to the Bluetooth device,try unplugging and replugging the Bluetooth adaptor.