Как читать данные с устройства GPS?Чтение данных с устройства GPS с использованием DataInputStream/socket
Я чтение данных с GPS устройства, используя разъем & DataInputStream
, но пока я выборки данных, я получаю что-то ASCII кодированные строки и в конце этой строки у меня есть мой ответ строки, которые я хочу использовать. Итак, как я могу получить непрерывные данные без такого сложного набора символов и получить точную строку. Я также попытался использовать последовательный порт.
Вот что я пробовал.
//Using Serial Port //
CommPortIdentifier portId = CommPortIdentifier.getPortIdentifier(portname);
System.out.println("fired");
// Open port
// Requires owner name and timeout
CommPort port = portId.open("Java Printing", 3000);
// Setup reading from file
FileInputStream fis = new FileInputStream(filename);
BufferedInputStream bis = new BufferedInputStream(fis);
// Setup output
OutputStream os = port.getOutputStream();
BufferedOutputStream bos = new BufferedOutputStream(os);
int c;
while ((c = bis.read()) != -1)
{
bos.write(c);
System.out.print((char)c);
}
// Close
bos.close();`enter code here`
bis.close();
port.close();
//Using Normal Socket //
char[] inputChars = new char[1024];
byte[] data = new byte[1024];
int charsRead = 0;
BufferedReader inputStream = null;
System.out.println("1 1 1 1 1");
InputStreamReader isr = new InputStreamReader(s1.getInputStream());
System.out.println("2 2 2 2 2 2");
inputStream = new BufferedReader(isr);
//Read 1024 characters. Note: This will pause the thread when stream is empty.
System.out.println("Reading from stream:");
while ((charsRead = inputStream.read(inputChars)) != -1)
{
System.out.println("Chars read from stream: " + charsRead);
System.out.println("inputChars = "+inputChars);
data = new String(inputChars).getBytes("US-ASCII");
System.out.flush();
}
byte[] decodedBytes = Base64.encodeBase64(data);
System.out.println("decodedBytes " + new String(decodedBytes));
Приведите несколько примеров того, что вы получаете от чипа – AlexWien