【发布时间】:2015-06-16 05:44:08
【问题描述】:
我正在做一个应用程序,其中包括从 android 向微控制器发送接收数据,在接收端,从微控制器到 android 我使用字节缓冲区来存储数据。但在这里我遇到问题我想在不同阶段接收多个字节的数据为此我想清除字节缓冲区并再次重新使用相同的字节缓冲区谁能告诉我如何清除字节缓冲区
这是我的接收代码:
ByteBuffer buffer = ByteBuffer.allocate(64);
byte[] length = buffer.array();
byte[] Recevied_Data = new byte[64];
UsbRequest request = new UsbRequest();
while (true)
{
request.initialize(UsbDriver.USB_Device_Connection, UsbDriver.Data_In_End_Point);
request.queue(buffer, 64);
if (UsbDriver.USB_Device_Connection.requestWait() == request)
{
for(int i=0;i<length.length;i++)
{
Recevied_Data[i]=buffer.get(i);
if(Recevied_Data[0]==0x02 && Recevied_Data[1]==0x3B && Recevied_Data[2]==0x3B && Recevied_Data[3]==0x00 && Recevied_Data[4]==0x03){
Communication_Ok=true;
// **I want to clear the Buffer Here**
}
}
}
}
【问题讨论】:
-
请尝试阅读stackoverflow.com/questions/8462200/… 可能对您有所帮助。
-
你试过了吗:buffer.clear()?
-
但是在这里我将字节缓冲区分配给 Received_data[i] 我没有使用那个家伙@TheTanic
-
你能在你的代码中标记你想清除缓冲区的地方吗?
-
我想在communication_ok=true标志我编辑后清除它请检查它
标签: android bytebuffer