Android Bluetooth Serial/RFCOMM/SPP, How to Change the BAUD RATE?

走远了吗. 提交于 2019-11-27 14:30:09

Presumably some Bluetooth to serial converter is attached to the legacy devices? If so you should be able to program it once to always use a particular bit rate. Then there would be no need for the Bluetooth client to set the bit rate...

Edit: Fixed some errors.

There's no good information on the internet about this - and lots of it is wrong - don't trust anyone!

In particular, these two things are not true:

  • RFCOMM and SPP (Serial Port Profile) are two names for the same thing. (They are however very closely related.)
  • There's no need to set the baud rate of an RFCOMM / SPP connection.

Here is what I have found:

Bluetooth serial connections are made as described in the SPP using RFCOMM. RFCOMM is a connection that runs over L2CAP and allows sending serial data and control parameters in frames. It is heavily based on an ancient standard called TS 07.10. SPP is the bluetooth profile.

This framing also allows you to send out-of-band data for things like controlling serial signals (DTR, CTS, etc) and for setting the baud rate.

From the SPP specification:

DevA may inform DevB of RS232 port settings with the Remote Port Negotiation Command, directly before DLC establishment. There is a requirement to do so if the API to the RFCOMM adaptation layer exposes those settings (e.g. baud rate, parity).

Sadly Android doesn't expose this functionality at all. I suppose it may be possible to send the Remote Port Negotiation command ourselves but I'm pretty sure that would require reimplementing RFCOMM which requires access to L2CAP that we don't have.

The Remote Port Negotiation command is detailed here page 31. Note "There are default values assigned on all parameters, if no negotiation is performed, the default value is chosen."

Therefore it is impossible to set the baud rate as desired on Android. It will use the default baud rate that your bluetooth adapter uses (probably 9600).

Also note that Windows does support setting the baud rate of bluetooth adapters.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!