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