作者barry0123 (阿里布达)
看板AndroidDev
标题[问题] 蓝芽传值
时间Mon Nov 16 21:16:59 2015
最近使用蓝芽的时候,想用蓝芽传大笔资料出去
使用STREAM的方式,一次大约1k Byte左右
(档案最小大约25K,大的话差不多3Mb左右)
为何传完都要DELAY一小段时间,对方才能收到
才能继续往下传
如何让传递速度增加?手机用蓝芽传输的速度还蛮快的
想试试看可以可以跟手机都速度差不多
接收端我用ARDUINO+HC06模组
String path = Environment.getExternalStorageDirectory().getPath();
File file = new File(path + "/" + "data.txt");
int i = 0;
try {
fin = new FileInputStream(file);
ByteArrayOutputStream byteBuffer = new
ByteArrayOutputStream();
//byte[] wrong=new byte[2048];
byte[] data = new byte[1000];
//byte[] test=new byte[100];
int length = 0;
while ((length = fin.read(data)) != -1) {
byteBuffer.write(data, 0, length);
mmOutStream.write(data);
try {
Thread.sleep(3000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
//mmOutStream.flush();
android.util.Log.i("DATA MESSAGE", "" + data +
"------------" + i);
i++;
}
fin.close();
android.util.Log.i("TAG OVER", "OK OK OK OK OK OK OK
OK OK");
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
startSend = false;
android.util.Log.i("TAG OVER", "" + count);String path = E
nv
File file = new File(path + "/" + "data.txt");
int i = 0;
try {
fin = new FileInputStream(file);
ByteArrayOutputStream byteBuffer = new
ByteArrayOutputStream();
//byte[] wrong=new byte[2048];
byte[] data = new byte[1000];
//byte[] test=new byte[100];
int length = 0;
while ((length = fin.read(data)) != -1) {
byteBuffer.write(data, 0, length);
mmOutStream.write(data);
try {
Thread.sleep(3000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
//mmOutStream.flush();
android.util.Log.i("DATA MESSAGE", "" + data +
"------------" + i);
i++;
}
fin.close();
android.util.Log.i("TAG OVER", "OK OK OK OK OK OK OK
OK OK");
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
startSend = false;
android.util.Log.i("TAG OVER", "" + count);
--
※ 发信站: 批踢踢实业坊(ptt.cc), 来自: 114.44.150.234
※ 文章网址: https://webptt.com/cn.aspx?n=bbs/AndroidDev/M.1447679821.A.59F.html
1F:→ kevin31a2: 改个错字吧...11/16 21:28
※ 编辑: barry0123 (223.140.23.96), 11/16/2015 21:59:18
2F:→ hans5300609: 有试过调高频率吗? Arduino和蓝牙模组之间的频率 11/20 08:16
3F:→ hans5300609: 现在有Printer3D板可以问Arduino,要去问问吗? 11/20 08:30
4F:→ hans5300609: 记得先看板龟,Arduino方面要用 [程式] 这个分类 11/20 08:31