日期:2014-05-20 浏览次数:21540 次
package send;
public class SerialBuffer
{
public String Content = "";
private String CurrentMsg;
private boolean available = false;
private int LengthNeeded = 2;
public boolean isTimeOut=false;
public synchronized String getMsg(long timeOut)//获得所读取的前两个字符
{
while (Content.equals("")||Content==null)
{
try
{
wait(timeOut);
}catch(InterruptedException e){
e.printStackTrace();
}
if(Content.equals("")||Content==null)
{
isTimeOut=true;
Content="aa";
}
else
{
break;
}
}
CurrentMsg = Content.substring(0, LengthNeeded);
Content = Content.substring(LengthNeeded, Content.length());
notifyAll();
return CurrentMsg;
}
public synchronized void putChar(int c)//得到串口读过来的数据存到字符变量中
{
String t="";
t=Integer.toHexString(c);
if(t.length()<2)
{
t="0"+t;
}
Content = Content.concat(t);
if (LengthNeeded < Content.length())
{
available = true;
}
notifyAll();
}
public synchronized void cleanBuff()
{
Content="";
notifyAll();
}public synchronized boolean getIsTimeOut()
{
notifyAll();
return isTimeOut;
}
}
------解决方案--------------------
是windows和Linux下的回车换行的问题, 0D 0A是标准的回车换行符
------解决方案--------------------