作者fake01 (code)
看板AndroidDev
標題[問題] 藍芽接值 掉值問題
時間Thu Jan 31 02:58:52 2013
使用手機藍芽接值,而接的值是由硬體端不斷丟值,
通常一秒丟一串字串 例如 123$456# or 455$123$
但是藍芽這邊接一次有時候會漏掉值 123456# 或 123$56,
但有時候又會正常接,是無法判斷硬體這邊丟一次的字串是甚麼,
請問該如何解決呢
case MESSAGE_READ:
byte[] readBuf = (byte[]) msg.obj;
// construct a string from the valid bytes in the buffer
String readMessage = null;
try {
readMessage = new String(readBuf, 0,msg.arg1,"GBK");
}
catch (UnsupportedEncodingException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
break;
// 以上就是藍芽抓值的code,麻煩各位了
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 61.58.82.128
→ fireslayer:你可能要查查錯誤檢查碼 或是TCP的傳輸機制模仿看看 01/31 11:06
→ fake01:F大什麼意思搞不太懂? 線再的問題是藍芽傳過的封包 有時候 01/31 17:53
→ fake01:會有遺失的問題,想要正確的一次抓取正確的值 01/31 17:54
→ fireslayer:你查error detection code我論藍芽傳輸沒有檢查漏封包 01/31 21:15
→ fireslayer:所以你要自己檢查 01/31 21:15
→ fireslayer:TCP三次握手機制也可以模仿 01/31 21:15
→ fireslayer:以上是我的猜測 你可以試試看 01/31 21:16
推 sdyy:好詭異 之前做藍芽都沒遇過這種情況 倒是會有丟兩次值被合成 01/31 22:36
→ sdyy:一次 01/31 22:36
→ ChonPiggy:應該貼 socket 那邊的 code 吧.. 01/31 23:21