package peter.amlogic.serial;import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;import peter.amlogic.player.PanelItemEventType;
import peter.amlogic.player.PlayerEvent;
import peter.amlogic.serial.message.BaseRecMessage;
import peter.amlogic.serial.message.BaseSendMessage;
import peter.amlogic.utility.DeviceInfo;import android.util.Log;public class SerailProcess 
{
private static final String TAG = "Serial";
private static final String DEV = "/dev/ttyS1";
private static byte[] buf = new byte[1024];
private static FileInputStream in = null;
public static void ReadString()
{
FileReader fr = null;
// FileInputStream in = null;
FileOutputStream out = null;
try {
if(in == null)
{
in = new FileInputStream(DEV);
}

int tempv = in.read(buf);
//in.close();
//in = null;
if(tempv > 0)
{
Log.d(TAG, "the tempv is: " + tempv);
int i = 0;
/*
while(i < tempv)
{
Log.d(TAG, " the " + i + " value is: " + (int)buf[i]);
i++;
}
*/
int flag = 0;
while((tempv - flag) > 0)
{
BaseRecMessage brm = new BaseRecMessage();

int leng = brm.ParseMessage(buf, flag);
if(leng > 0)
{
PlayerEvent pe = new PlayerEvent();
pe.setEventType(PanelItemEventType.SERIAL_MSG);
pe.setEventArgs(brm);
DeviceInfo.getInstance().getPlayerEvent().offer(pe);
Log.d(TAG, "the cmd " + brm.getCmd() + " leng is: " + leng);

}
else
{
Log.d(TAG, "parse message occur error");
}
try
{
out = new FileOutputStream(DEV);
BaseSendMessage bsm = brm.getSendMessage();
if(bsm != null)
{
out.write(bsm.getSendBuf());
}
out.close();
out = null;
}
catch(Throwable te)
{
te.printStackTrace();
}
finally
{
if(out != null)
{
try
{
out.close();
out = null;
}
catch(IOException e)
{
e.printStackTrace();
}
}
}

flag += leng;
}
}
else
{
sleep(100);
}
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
finally
{
if(fr != null)
{
try {
fr.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}/////////////
}
if(in != null)
{
// try {
// in.close();
// in = null;
// } catch (IOException e) {
// // TODO Auto-generated catch block
// e.printStackTrace();
// }
}
if(out != null)
{
try
{
out.close();
out = null;
}
catch(IOException e)
{
e.printStackTrace();
}////////////
}
}
}

private static void sleep(int i) {
// TODO Auto-generated method stub

} public static void WriteString()
{
FileWriter fw = null;
byte tempv = 'a';
try {
fw = new FileWriter(DEV);
for(int i=0; i<10; i++)
{
fw.write(tempv + i);
}

} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
finally
{
if(fw != null)
{
try {
fw.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}




}
代码如上就是一直接收不到串口发过来的数据,用工具打印信息的时候,信息是发送成功的。