How to connect to the bluetooth Serial Port?
4 次查看(过去 30 天)
显示 更早的评论
I am trying to use the SSP as a COM port to receive data from MCU. I have to try many times to connect to the COM port, but it often failed to open.The version is R2013a and the codes are as below:
s=serial('COM4');
fopen(s);
Sometimes it would work,but usually failed and get errors:
Open failed: Port: COM4 is not available. Available ports: COM4, COM5. Use INSTRFIND to determine if other instrument objects are connected to the requested device.
Sometime I get this:
Open failed: Cannot connect to the COM4 port. Possible reasons are another application is connected to the port or the port does not exist.
I use instrhwinfo('serial') to check whether the COM4 is available, and I could find the COM4 is in AvailableSerialPorts list.Even when the COM4 is not in AvailableSerialPorts list, sometimes I can still connect. I was so confused.
Here describe a similar problem, but I can't get any data using data=fgets(b);
What's more I need to configure the COM ports like BaudRate,DataBits,StopBits.....But I can't find these properties in bluetooth!
0 个评论
回答(1 个)
Mark O'Sullivan
2016-12-6
This may be because you're not closing the serial connection after using it. After you open a serial connection and read from it, you need to close it before you can open and read from it again.
So something like this should work every time:
s=serial('COM4');
fopen(s);
fgets(s);
fclose(s);
If you have an error and your script stops before reaching the fclose line, then you can use the following 2 commands to clear the open serial ports.
newobjs = instrfind;
fclose(newobjs)
That should fix that problem. :)
1 个评论
María Itzel Marroquín Ram
2019-10-2
hi, im 3 years late and you should have solved this issue by now, but i found this for if you or anyone else needs it again
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Source Control 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!