0
如何从GPS设备读取数据?使用DataInputStream /套接字从GPS设备读取数据
我从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