我在java中编写用于解码gps的代码,gps向我发送我可以在我的代码中看到的继续字符串但是当我解码它时,只有一个字符串被解码并且由于我的字符串必须为下一个字符串为空而停止工作我尝试这样做但没有得到成功。任何人都知道这种情况
package communication;
import javax.comm.*;
import java.util.*;
import java.io.*;
import new8.*;
class Serial
{
public static void main(String args[]) throws UnsupportedCommOperationException, IOException, TooManyListenersException
{
int c=1;
String wantedPortName = "COM6";
Enumeration portIdentifiers = CommPortIdentifier.getPortIdentifiers();
CommPortIdentifier portId = null;
while(portIdentifiers.hasMoreElements())
{
CommPortIdentifier pid = (CommPortIdentifier) portIdentifiers.nextElement();
if(pid.getPortType() == CommPortIdentifier.PORT_SERIAL &&
pid.getName().equals(wantedPortName))
{
portId = pid;
break;
}
}
if(portId == null)
{
System.err.println("Could not find serial port " + wantedPortName);
System.exit(1);
}
else
{
System.out.println("system find gps reciever");
}
SerialPort port = null;
try {
port = (SerialPort) portId.open(
"RMC",
1);
System.out.println("all are ok");
} catch(PortInUseException e) {
System.err.println("Port already in use: " + e);
System.exit(1);
}
port.setSerialPortParams(
4800,
SerialPort.DATABITS_8,
SerialPort.STOPBITS_1,
SerialPort.PARITY_NONE);
BufferedReader is = null;
try {
is = new BufferedReader(new InputStreamReader(port.getInputStream()));
System.out.println("data is ok");
} catch (IOException e) {
System.err.println("Can't open input stream: write-only");
is = null;
}
String pt=null;
while(true)
{
is.readLine();
is.readLine();
String st = is.readLine();
System.out.print("("+c+")");
c++;
new8 obj1=new new8();
obj1.decode(st);
System.out.println(st);
st=st.replace(st, "");
}
if (is != null) is.close();
/*if (os != null) os.close();*/
if (port != null) port.close();
}
}