⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 getgpsdata.java

📁 Palm 串行通讯GPS数据读取的实现源码GetGpsData.java
💻 JAVA
字号:
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;
		}
	}

//Close the serial Port
public boolean closePort(){
	try {
		is.close();
		serialPort.close();
		return true;
		}
		catch (Exception ex) {
		return false;
		}
	}
//Read the GPS data 
//Mark is "$GPRMC 
//rdLen is the buffer length 
//getlen is the return length
public String readGpsData(String mark,int rdlen,int getlen){
	byte[] readBuffer = new byte[rdlen];
	String rawGpsData;
	String Gprmc;
while (true){
	try{
		 //Read raw GPS data into a buffer
		 is.read(readBuffer);
		 rawGpsData=new String(readBuffer);
		 //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
}

⌨️ 快捷键说明

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