MATLAB Answers

0

MATLAB serial communication via Bluetooth SPP

Asked by Christopher on 22 Jun 2011
Latest activity Answered by Roberto
on 8 Jun 2016
I have some sensors with Bluetooth SPP connections. I cannot seem to get MATLAB Serial IO to work with them. The 'Standard Serial over Bluetooth link' COM port entries are available in Device Manager, the port settings (in Device Manager and the MATLAB serial function call) are correct. On using fopen() the error seen is that the requested com port is not available. This is confirmed using instrhwinfo('serial') as the requested COM port is not in the list.
I know the Bluetooth SPP is working because the only way I could get the devices working with MATLAB was to use a third party com2tcp forwarder, then use MATLAB's tcpip function to access the port. However, this is not ideal since the com2tcp forwarder is not that reliable. I'd rather be using MATLAB's serial io.
Could this be an issue with the java version being used? version('-java') gives 'Java 1.6.0_24-b07 with Sun Microsystems Inc. Java HotSpot™ 64-Bit Server VM mixed mode'.
My set up is Windows 7 Enterprise 64-bit, MATLAB 7.11.0 (R2010b) 64-bit.

  1 Comment

Could you try and access the serial port from hyperterminal?

Sign in to comment.

3 Answers

Answer by Eric Wetjen on 14 Sep 2011

Hi Christopher,
Bluetooth SPP support was added to Instrument Control Toolbox in R2011b. See the documentation here for details.
Eric

  1 Comment

Excellent! Good things come to those who wait.

Sign in to comment.


Answer by Gerd
on 22 Jun 2011

HI Christopher,
did you connect the sensors after Matlab is running. It is always a problem for Matlab to show the correct Serial Ports if they were connected after starting Matlab
Gerd

  2 Comments

Gerd,
no, they are already visible in device manager before starting Matlab.
Chris
Did you solve this problem? I have the same.
Using bluetooth object isn`t suitable for me because I use Simulink model. But there is no block with bluetooth support.

Sign in to comment.


Answer by Roberto
on 8 Jun 2016

I have some problems running Bluetooth with matlab
I´m trying to use the SSP port as a COM port, so when I try to connect, then the bluetooth port freezes and I need to turn off and on the bluetooth module...
So after trying a lot to use COM port itself(because sometimes the connection works) so i change my aproach and use the Bluetooth interface
follow this and be happy
1) Finding the Bluetooth
>> mydevices = instrhwinfo('Bluetooth')
mydevices =
HardwareInfo with properties:
RemoteNames: {4x1 cell}
RemoteIDs: {4x1 cell}
BluecoveVersion: 'BlueCove-2.1.1-SNAPSHOT'
JarFileVersion: 'Version 3.7'
2) If you have more than one Bluetooth paired, they will show something weird in de RemoteName with the number of devices ... you can list all doing:
>> mydevices.RemoteName
myDevices =
'MY_DEVICE'
'OTHER_DEVICE1'
'OTHER_DEVICE2'
'OTHER_DEVICE3'
3) So you can discover the Channels to connect
>> instrhwinfo('Bluetooth', 'MY_DEVICE')
myDevices =
HardwareInfo with properties:
RemoteName: 'MY_DEVICE'
RemoteID: 'btspp://201603085239'
ObjectConstructorName: {'Bluetooth('MY_DEVICE', 1);'}
Channels: {'1'}
4) Now start a link... but the status still "closed"
>> b = Bluetooth('BASE_IA',1)
Bluetooth Object : Bluetooth-MY_DEVICE:1
Communication Settings
RemoteName: MY_DEVICE
RemoteID: btspp://201603085239
Channel: 1
Terminator: 'LF'
Communication State
Status: closed
RecordStatus: off
Read/Write State
TransferStatus: idle
BytesAvailable: 0
ValuesReceived: 0
ValuesSent: 0
5) Now open the connection
>> fopen(b)
6) Send data
>> fwrite(b, 'Text to send')
7) Close
>> fclose(b)

  0 Comments

Sign in to comment.