|
从http://code.google.com/p/android-serialport-api/下载的代码,
CB端可以发送数据了.
CB发送,PC接收, OK.
但是PC发送, CB端接收到数据.也就是没有进入到
protected void onDataReceived(byte[] buffer, int size),
不知道原因.
使用该API的,都有遇到过这样的情况吗?
是不是下面的代码有问题
private class ReadThread extends Thread {
@Override
public void run() {
super.run();
while(!isInterrupted()) {
int size;
try {
byte [] buffer = new byte[64];
if (mInputStream == null) return;
size = mInputStream.read(buffer);
if (size > 0) {
Toast.makeText(SerialPortActivity.this,"onDataReceived", Toast.LENGTH_LONG).show();
onDataReceived(buffer, size);
}
} catch (IOException e) {
e.printStackTrace();
DisplayErrorMessage(e.getMessage());
return;
}
}
}
}
其次,在SerialPortActivity.java 里的onCreate里面,有下面的代码 // Create a receiving thread
mReadThread = new ReadThread();
mReadThread.start();
证明已经启动,数据接收线程了!
|
|