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
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 ();
}
}
}
}
}
As the code is sent over the serial port has been not receiving data, printing information when using the tools, the information is sent successfully.<-! Main posts under Banner (D4) -><-! Posts under the main text (D5) ->
Reply:
Own more than DEBUG, the amount of volume with an oscilloscope
Reply:
Oscilloscope is normal. .
int tempv = in.read (buf); breakpoint will end here. . Not execute down. . I call ReadString () when this method is invoked on the thread inside. .
Reply:
Give me
Reply:
Posted all end up. . . Wood took part in it. . . Ha ha ha. .
Reply:
Later resolved yet? I have encountered this problem
No comments:
Post a Comment