CH341A安卓平板OTG连接成功但读取不到数据

使用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);


}

}


                                     

使用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);


}

}


           

icon_rar.gifCH34xUARTDemo.rar 用下这个老版本的APK试一下,和官网的新版本对比下测试。最好做下自发自收测试;



只有登录才能回复,可以选择微信账号登录