使用CH341A开发的STM32板子,在win下使用超级终端连接Serial Com口会有数据返回,
但是在支持OTG的安卓平板(ONDA VX610W)上使用OTG线连接,使用官网下载的apk安装,点open按钮能连接上,显示“Device Has Attached to Android”,参数配置得与win一样,但是读取数据的线程始终没有数据返回,跟踪代码发现MyApp.driver.ReadData函数返回的长度length是0。请问如何解决?
private class readThread extends Thread {
public void run() {
byte[] buffer = new byte[4096];
while (true) {
Message msg = Message.obtain();
if (!isOpen) {
msg.obj = "not open!";
handler.sendMessage(msg);
break;
}
int length = MyApp.driver.ReadData(buffer, 4096);//length返回0
if (length >= 0) {
String recv = toHexString(buffer, length);
//String recv = new String(buffer, 0, length);
msg.obj = recv;
handler.sendMessage(msg);
}
else
{
msg.obj = "length < 0";
handler.sendMessage(msg);
}
}
Message msg2 = Message.obtain();
msg2.obj = "Thread End";
handler.sendMessage(msg2);
}
}