palmserialforgps.txt

来自「关于gps通信的代码 串行通讯参数为: 波特律=4800 数据位=8位 停止」· 文本 代码 · 共 70 行

TXT
70
字号
<CODE>package earth_survy;
import java.util.*;
import javax.microedition.io.*;
import java.io.*;
import com.sun.kjava.*;
import com.sun.cldc.io.palm.comm.*;
public class GetGpsData extends Spotlet {
        static Graphics g=Graphics.getGraphics();
        static Protocol serialPort = new Protocol();
 static String url="0;baudrate=4800;bitsperchar=8;stopbits=1;parity=none";
        static InputStream is;
// Open the serial Port for Gps Data Input
public boolean openPort(){
      try {
           serialPort.open(url,1, true);
           is=serialPort.openInputStream();
          return true;
      }
      catch (Exception ex) {
          return false;
      }
 }

 file://Close the serial Port

 public boolean closePort(){
   try {
         is.close();
         serialPort.close();
         return true;
   }
   catch (Exception ex) {
         return false;
   }
 }
 file://Read the GPS data
 file://Mark is "$GPRMC
 file://rdLen is the buffer length
 file://getlen is the return lenth;

 public String readGpsData(String mark,int rdlen,int getlen){
    byte[] readBuffer = new byte[rdlen];
    String rawGpsData;
    String Gprmc;

 while (true){
    try{
         file://Read raw GPS data into a buffer;
          is.read(readBuffer);
          rawGpsData=new String(readBuffer);
         file://determin the positon of  the Mark==> $GPRMC;
         int pos=rawGpsData.indexOf(mark);
         if (pos>-1)
            {
               Gprmc=rawGpsData.substring(pos);
               if (Gprmc.length()>getlen)
                {
                  Gprmc=Gprmc.substring(0,getlen);
                 break;
                 }
                }
       }
    catch(Exception e){
               }
}
return Gprmc;
//end loop
}//end method
}</CODE>

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?