在使用CH34XUAR 1.7時候出現(xiàn)掉包

安卓在數(shù)據(jù)回調(diào)時出現(xiàn)的掉包情況,(registerDataCallback被調(diào)用的次數(shù)和預(yù)期的不符)

private?void?registerDataCallback(UsbDevice?usbDevice){
????try?{
????????WCHUARTManager.getInstance().registerDataCallback(usbDevice,?new?IDataCallback()?{
????????????@Override
????????????public?void?onData(int?serialNumber,?byte[]?buffer,?int?length)?{
????????????????LogUtil.d(String.format(Locale.getDefault(),"serial?%d?receive?data?%d:%s",?serialNumber,length,?FormatUtil.bytesToHexString(buffer,?length)));
????????????????//1.注意回調(diào)的執(zhí)行線程與調(diào)用回調(diào)方法的線程屬于同一線程
????????????????//2.此處所在的線程將是線程池中多個端點的讀取線程,可打印線程id查看
????????????????//3.buffer是底層數(shù)組,如果此處將其傳給其他線程使用,例如通過runOnUiThread顯示數(shù)據(jù)在界面上,
????????????????//涉及到線程切換需要一定時間,buffer可能被讀到的新數(shù)據(jù)覆蓋,可以新建一個臨時數(shù)組保存數(shù)據(jù)

????????????????byte[]?data=new?byte[length];
????????????????System.arraycopy(buffer,0,data,0,data.length);
????????????????if(FILE_TEST){
????????????????????updateReadDataToFile(usbDevice,serialNumber,data,length);
????????????????}else?{
????????????????????updateReadData(usbDevice,serialNumber,data,length);
????????????????}


????????????}
????????});
????}?catch?(Exception?e)?{
????????LogUtil.d(e.getMessage());
????}
}

請問這個是什么原因

已解決


安卓的效率比較低,高波特率不開硬件流控容易緩沖區(qū)溢出,115200以上就需要流控


只有登錄才能回復(fù),可以選擇微信賬號登錄

国产91精品新入口,国产成人综合网在线播放,九热这里只有精品,本道在线观看,美女视频a美女视频,韩国美女激情视频,日本美女pvp视频