標(biāo)題:
Android藍(lán)牙通信字節(jié)數(shù)組的數(shù)據(jù)類型轉(zhuǎn)換求教!
[打印本頁]
作者:
dsj0430
時(shí)間:
2018-4-20 15:39
標(biāo)題:
Android藍(lán)牙通信字節(jié)數(shù)組的數(shù)據(jù)類型轉(zhuǎn)換求教!
課程設(shè)計(jì)單片機(jī)和安卓手機(jī)進(jìn)行藍(lán)牙通信,發(fā)送電壓數(shù)據(jù)到手機(jī),恰好每次8位數(shù)據(jù)(1字節(jié))傳給上位機(jī)。采用以下代碼獲得16進(jìn)制字符輸出,以下是藍(lán)牙通信接收并顯示數(shù)據(jù)部分代碼
case Constants.MESSAGE_READ:
// construct a string from the valid bytes in the buffer
byte[] readBuf = (byte[]) msg.obj;
String readMessage = new String(readBuf, 0, msg.arg1);
mConversationArrayAdapter.add(mConnectedDeviceName + ": " + readMessage);
break;
復(fù)制代碼
我想將字節(jié)數(shù)組數(shù)據(jù)轉(zhuǎn)換為十進(jìn)制,做進(jìn)一步計(jì)算,計(jì)算結(jié)果以十進(jìn)制打印輸出。代碼如下:
case Constants.MESSAGE_READ:
if (!msg.obj.equals(null)) {
byte[] readBuf = (byte[]) msg.obj;
for (int i = 0; i < readBuf.length; i++) {
int[] a = new int[readBuf.length];
a[i] = readBuf[i] * 5000 / 255;
mConversationArrayAdapter.add(mConnectedDeviceName + ": ");
System.out.print(a[i]);
}
}
break;
復(fù)制代碼
上面的第二段代碼編譯無錯(cuò)誤,但在手機(jī)上執(zhí)行后只顯示mConnectedDeviceName 和": ",a
輸出為空白!
調(diào)試顯示以下error:com.example.android.bluetoothchat E/dalvikvm: Could not find class 'android.support.v4.app.ActivityCompat$SharedElementCallback23Impl',
第一次接觸JAVA編程,還請多多指教!
歡迎光臨 (http://www.torrancerestoration.com/bbs/)
Powered by Discuz! X3.1