使用android蓝牙的Buffer出现问题
我正在使用 Android 手机的蓝牙将一些数据(字符串)发送到带有蓝牙设备的 arduino。
一切都很顺利……但我只能发送 325 串! (每个字符串仅包含 2 个正 int 数字)。
此后,在 Eclipse 的 logcat 上,每次 Android 尝试发送新数据时,都会出现以下消息:“缓冲区的 rfc_setup_rx_bufout:缓冲区的 rfc_setup_rx_bufout:缓冲区不足”。
我无法在应用程序期间关闭蓝牙套接字并重新打开它(或连接),因为我需要非常快地发送数据以达到我的目的(大约 100-200 毫秒一个接一个),但没有时间这样做。我怎样才能“清除”缓冲区?难道真的是buffer的问题??
我使用的部分代码:
<code>
private BluetoothSocket btSocket = null;
try {
btSocket = device.createRfcommSocketToServiceRecord(MY_UUID);
} catch (IOException e) {
}
try {
outStream = btSocket.getOutputStream();
} catch (IOException e) {
Log.e(TAG, "ON RESUME: Output stream creation failed.", e);
}
byte[] msgBuffer = message.getBytes();
try {
outStream.write(msgBuffer);
} catch (IOException e) {
Log.e(TAG, "ON RESUME: Exception during write.", e);
}
</code>
The "message" in message.getBytes();实际上是我发送的字符串。
另一件事:我正在使用一个数组(byte[] msgBuffer)。无论如何,我可以在发送数据后创建一个“循环”来到达 [0] 或 [1] 索引,这样这个字符串就永远不会满,因为我只会使用 2 个值。
或者问题出在我的手机(三星 GT-I5500)的内部缓冲区上,而代码没有?
A 非常感谢任何帮助,因为我陷入了困境。
I'm using the bluetooth of an android phone to send some data (strings) to an arduino with bluetooth device.
All works like charm... but I can only send 325 strings!!! (each string only contains 2 positive int numbers).
After this, at the logcat of eclipse, appears me this message: "rfc_setup_rx_bufout of buffer: rfc_setup_rx_bufout of buffer: Out of Buffers" each time that the android tries to send a new data.
I can't close the bluetoothsocket and reopen it (or connect) during the application cause I need to send data very fast for my purpose(about 100-200 ms one after another) and there's no time for that. How can I "clear" the buffer? Is it really the problem with the buffer??
Part of the code I'm ussing this:
<code>
private BluetoothSocket btSocket = null;
try {
btSocket = device.createRfcommSocketToServiceRecord(MY_UUID);
} catch (IOException e) {
}
try {
outStream = btSocket.getOutputStream();
} catch (IOException e) {
Log.e(TAG, "ON RESUME: Output stream creation failed.", e);
}
byte[] msgBuffer = message.getBytes();
try {
outStream.write(msgBuffer);
} catch (IOException e) {
Log.e(TAG, "ON RESUME: Exception during write.", e);
}
</code>
The "message" in message.getBytes(); is actually the string that I'm sending.
Another thing: I'm ussing an array (byte[] msgBuffer). Is there anyway I can make a "loop" to get to the [0] or [1] index after sending the data so this string will never be full cause I would only use 2 values.
Or the problem is with an internal buffer of my phone (samsung GT-I5500) and no with the code?
A will really apreciate any help cause I'm stuck in this.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论