android蓝芽问题
时间:2011-12-10
来源:互联网
我在做android蓝芽的测试
主要原始码为官方的Bluetooth Chat下去修改的
我是用的android手机维ViewSonic 的 ViewPad 7 平板电脑 android版本为2.2
就是我拿view pad去跟一台测量仪器(全测站)沟通
仪器如果刚开机,根view pad刚配对成功时,我会收到一个问号的讯息
之后我就开始丢指令
如果我送单一字元
例如(关机指令)
b<CR/LF> 给仪器,仪器会有反应(关机),然后回传一个问号回来
但是如果我送别的指令
例如(取得水平度盘读数)
SET/M/WI21<CR/LF> 这时候全测站就完全没有反应
感觉好像是仪器没有收到值,因为也没有收到错误讯息的指令
想请问一下会是哪里出了问题
主要原始码为官方的Bluetooth Chat下去修改的
我是用的android手机维ViewSonic 的 ViewPad 7 平板电脑 android版本为2.2
就是我拿view pad去跟一台测量仪器(全测站)沟通
仪器如果刚开机,根view pad刚配对成功时,我会收到一个问号的讯息
之后我就开始丢指令
如果我送单一字元
例如(关机指令)
b<CR/LF> 给仪器,仪器会有反应(关机),然后回传一个问号回来
但是如果我送别的指令
例如(取得水平度盘读数)
SET/M/WI21<CR/LF> 这时候全测站就完全没有反应
感觉好像是仪器没有收到值,因为也没有收到错误讯息的指令
想请问一下会是哪里出了问题
1 |
private class ConnectedThread extends Thread { private final BluetoothSocket mmSocket; private final InputStream mmInStream; private final OutputStream mmOutStream; public ConnectedThread(BluetoothSocket socket) { Log.d(TAG, "create ConnectedThread"); mmSocket = socket; InputStream tmpIn = null; OutputStream tmpOut = null; // Get the BluetoothSocket input and output streams try { tmpIn = socket.getInputStream(); tmpOut = socket.getOutputStream(); } catch (IOException e) { Log.e(TAG, "temp sockets not created", e); } mmInStream = tmpIn; mmOutStream = tmpOut; } public void run() { Log.i(TAG, "BEGIN mConnectedThread"); byte[] buffer = new byte[1024]; int bytes; // Keep listening to the InputStream while connected while (true) { try { // Read from the InputStream bytes = mmInStream.read(buffer); // Send the obtained bytes to the UI Activity mHandler.obtainMessage(bluetooth_edit.MESSAGE_READ, bytes, -1, buffer) .sendToTarget(); } catch (IOException e) { Log.e(TAG, "disconnected", e); connectionLost(); break; } } } /** * Write to the connected OutStream. * @param buffer The bytes to write */ public void write(byte[] buffer) { try { mmOutStream.write(buffer); // Share the sent message back to the UI Activity mHandler.obtainMessage(bluetooth_edit.MESSAGE_WRITE, -1, -1, buffer) .sendToTarget(); } catch (IOException e) { Log.e(TAG, "Exception during write", e); } } public void cancel() { try { mmSocket.close(); } catch (IOException e) { Log.e(TAG, "close() of connect socket failed", e); } } } |
1 |
// The Handler that gets information back from the BluetoothChatService private final Handler mHandler = new Handler() { @Override public void handleMessage(Message msg) { switch (msg.what) { case MESSAGE_STATE_CHANGE: if(D) Log.i(TAG, "MESSAGE_STATE_CHANGE: " + msg.arg1); switch (msg.arg1) { case BluetoothChatService.STATE_CONNECTED: mTitle.setText(R.string.title_connected_to); mTitle.append(mConnectedDeviceName); mConversationArrayAdapter.clear(); break; case BluetoothChatService.STATE_CONNECTING: mTitle.setText(R.string.title_connecting); break; case BluetoothChatService.STATE_LISTEN: case BluetoothChatService.STATE_NONE: mTitle.setText(R.string.title_not_connected); break; } break; case MESSAGE_WRITE: byte[] writeBuf = (byte[]) msg.obj; // construct a string from the buffer String writeMessage = new String(writeBuf); view.append(writeMessage); // mConversationArrayAdapter.add("Me: " + writeMessage); break; case MESSAGE_READ: byte[] readBuf = (byte[]) msg.obj; // construct a string from the valid bytes in the buffer String readMessage = new String(readBuf, 0, msg.arg1); view.append(readMessage); // mConversationArrayAdapter.add(mConnectedDeviceName+": " + readMessage); break; case MESSAGE_DEVICE_NAME: // save the connected device's name mConnectedDeviceName = msg.getData().getString(DEVICE_NAME); Toast.makeText(getApplicationContext(), "Connected to " + mConnectedDeviceName, Toast.LENGTH_SHORT).show(); break; case MESSAGE_TOAST: Toast.makeText(getApplicationContext(), msg.getData().getString(TOAST), Toast.LENGTH_SHORT).show(); break; } } }; |
作者: z884128 发布时间: 2011-12-10
BluetoothChat应该是双方都使用这个程式才有用吧(还没试过),
因为po的code看起来没有什么修改过,所以大大的全测站应该也
要使用android系统吧
因为po的code看起来没有什么修改过,所以大大的全测站应该也
要使用android系统吧
作者: linkery 发布时间: 2011-12-15
相关阅读 更多
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28