Serial Port & Bluetooth

5 views (last 30 days)
Hans
Hans on 7 Jul 2011
Hello All,
My last question http://www.mathworks.com/matlabcentral/answers/9630-bluetooth-communication helped me a lot and I've made some progress in establishing a connection.
I've downloaded a Bluetooth driver for my USB dongle and now I can create a Serial Port for my Bluetooth connection. However, I've created only one COM port, is it possible to read and write to the same COM port?
The reason for this question, is that I'm currently not receiving anything on this COM port. I can write without errors, but I don't know how to check if it is received on my Bluetooth Device. Does anyone have any tips or ideas?
Greetings,
Hans

Accepted Answer

Chirag Gupta
Chirag Gupta on 7 Jul 2011
You can read/write on the same COM port. The trick to checking whether data is being sent or received by the serial port and your device is to use some sort of serial port monitor. Googling for it, should give you plenty of hits.
The serial port monitor can confirm whether the data is being sent to the device and vice-versa. Once you can confirm data is being sent and received, you would have to then check whether its the correct data (i.e: you are sending out the exact commands that your device expects)
  2 Comments
Hans
Hans on 7 Jul 2011
So this does include the Virtual Serial Port? Because my USB Bluetooth dongle is not actually a RS232 for example.
Chirag Gupta
Chirag Gupta on 7 Jul 2011
yes,virtual ports should show up as well

Sign in to comment.

More Answers (2)

Iman
Iman on 14 Aug 2013
Edited: Iman on 14 Aug 2013
Hi
I have this bluetooth device powered by an arduino which I can connect via COM port in a serial monitor such as putty. However I cannot do this in matlab.
I set this up as a normal com port as follows:
s = serial('COM6','BaudRate',9600,'DataBits',8,'StopBits',1,'Parity','None','FlowControl','None','ByteOrder','bigEndian','DataTerminalReady','off');
fopen(s);
I usually get an error at fopen like this:
Error using serial/fopen (line 72) Open failed: Cannot connect to the COM6 port. Possible reasons are another application is connected to the port or the port does not exist.
Error in arduino2matlab (line 13) fopen(s);
Or sometimes it states that port is not open and then lists that same port as an available port. I'm sure I've closed it in the serial monitor and nothing else should be using it. And when I use this code for hard-wire usb it works fine in matlab. I just don't understand why I cannot open the port in matlab but can in putty.
Thanks

Hans
Hans on 15 Aug 2013
Hello Iman,
Have you connected the Bluetooth device with the Bluetooth program provided by Windows?
This was my first error, after I connected it first to the computer and then opened it with Matlab, it worked just fine.
Greetings,
Hans

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!