使用CH341A開(kāi)發(fā)的STM32板子,在win下使用超級(jí)終端連接Serial Com口會(huì)有數(shù)據(jù)返回,
但是在支持OTG的安卓平板(ONDA VX610W)上使用OTG線(xiàn)連接,使用官網(wǎng)下載的apk安裝,點(diǎn)open按鈕能連接上,顯示“Device Has Attached to Android”,參數(shù)配置得與win一樣,但是讀取數(shù)據(jù)的線(xiàn)程始終沒(méi)有數(shù)據(jù)返回,跟蹤代碼發(fā)現(xiàn)MyApp.driver.ReadData函數(shù)返回的長(zhǎng)度length是0。請(qǐng)問(wèn)如何解決?
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);
}
}