1
我在我的Java項目中使用rxtx library來讀取來自我的gps芯片的串行數據。現在,我嘗試將其移植到我的Android設備,這是一款帶有Android 4.0.3股票ROM的根源Galaxy Nexus。Android上的RXTX串行端口庫
我已經創建了一個項目並將我的類移植到Android版本。它使用rxtx library for android這樣的:
public void init() {
try {
Enumeration portIdentifiers = CommPortIdentifier.getPortIdentifiers();
///See what ports are available. and latch on desired port
while (portIdentifiers.hasMoreElements()) {
CommPortIdentifier pid = (CommPortIdentifier) portIdentifiers.nextElement();
if (pid.getPortType() == CommPortIdentifier.PORT_SERIAL && pid.getName().equals(PORT)) {
portId = pid;
break;
}
}
serialPort = (SerialPort) portId.open("test", 5000);
in = serialPort.getInputStream();
dis = new DataInputStream(in);
serialPort.addEventListener(this);
serialPort.setSerialPortParams(BAUDRATE, SerialPort.DATABITS_8, SerialPort.STOPBITS_1,
SerialPort.PARITY_NONE);
serialPort.notifyOnDataAvailable(true);
} catch (PortInUseException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (TooManyListenersException e) {
e.printStackTrace();
} catch (UnsupportedCommOperationException e) {
e.printStackTrace();
}
}
在此之後我嘗試用serialEvent(SerialPortEvent event)
- 方法來讀取輸入數據。
但是我不會讀取數據,因爲庫的本地實現存在一些問題。這是我的logcat輸出:
11-14 11:24:49.793: I/GNU.IO(15496): JNI_OnLoad called.
11-14 11:24:49.793: I/GNU.IO(15496): Testing the version.
11-14 11:24:49.800: I/GNU.IO(15496): entering RXTXCommDriver:getDeviceDirectory
11-14 11:24:49.800: I/GNU.IO(15496): TestREAD.
11-14 11:24:49.808: I/GNU.IO(15496): /dev/ttyO0
11-14 11:24:49.808: I/GNU.IO(15496): entering RXTXPort:testRead
11-14 11:24:49.808: I/GNU.IO(15496): RXTX Warning: Removing stale lock file. /data/local/tmp/LCK..ttyO0
11-14 11:24:49.816: I/GNU.IO(15496): leaving RXTXPort:testRead
11-14 11:24:49.832: I/GNU.IO(15496): entering RXTXCommDriver:getDeviceDirectory
11-14 11:24:49.840: I/GNU.IO(15496): TestREAD.
11-14 11:24:49.847: I/GNU.IO(15496): /dev/ttyO0
11-14 11:24:49.847: I/GNU.IO(15496): entering RXTXPort:testRead
11-14 11:24:49.847: I/GNU.IO(15496): leaving RXTXPort:testRead
11-14 11:24:49.871: I/GNU.IO(15496): entering RXTXPort:Initialize
11-14 11:24:49.879: I/GNU.IO(15496): entering RXTXPort:open
11-14 11:24:49.886: I/GNU.IO(15496): leaving RXTXPort:open
11-14 11:24:49.886: I/GNU.IO(15496): entering eventLoop
11-14 11:24:49.886: I/GNU.IO(15496):
11-14 11:24:49.886: I/GNU.IO(15496): entering send_event
11-14 11:24:49.886: I/GNU.IO(15496): send_event: !eventloop_interupted
11-14 11:24:49.886: I/GNU.IO(15496): send_event: jclazz
11-14 11:24:49.886: I/GNU.IO(15496): send_event: calling
11-14 11:24:49.886: I/GNU.IO(15496): send_event: called
11-14 11:24:49.886: I/GNU.IO(15496): leaving send_event
11-14 11:24:49.886: I/GNU.IO(15496): entering check_tiocmget_changes
11-14 11:24:49.886: I/GNU.IO(15496): leaving check_tiocmget_changes
11-14 11:24:49.886: I/GNU.IO(15496): port_has_changed_fionread: change is 0
11-14 11:24:49.886: I/GNU.IO(15496): entering send_event
11-14 11:24:49.886: I/GNU.IO(15496): send_event: !eventloop_interupted
11-14 11:24:49.886: I/GNU.IO(15496): send_event: jclazz
11-14 11:24:49.886: I/GNU.IO(15496): send_event: calling
11-14 11:24:49.886: I/GNU.IO(15496): send_event: called
11-14 11:24:49.886: I/GNU.IO(15496): leaving send_event
11-14 11:24:49.886: I/GNU.IO(15496): entering check_tiocmget_changes
11-14 11:24:49.886: I/GNU.IO(15496): leaving check_tiocmget_changes
11-14 11:24:49.886: I/GNU.IO(15496): port_has_changed_fionread: change is 0
11-14 11:24:49.894: I/GNU.IO(15496): entering send_event
11-14 11:24:49.894: I/GNU.IO(15496): send_event: !eventloop_interupted
11-14 11:24:49.894: I/GNU.IO(15496): send_event: jclazz
11-14 11:24:49.910: I/GNU.IO(15496): leaving RXTXPort:translate_speed
11-14 11:24:49.910: I/GNU.IO(15496): entering RXTXPort:nativeSetSerialPortParams
11-14 11:24:49.910: I/GNU.IO(15496): entering translate_date_bits
11-14 11:24:49.910: I/GNU.IO(15496): entering translate_stop_bits
11-14 11:24:49.910: I/GNU.IO(15496): leaving RXTXPort:translate_stop_bits
11-14 11:24:49.910: I/GNU.IO(15496): entering translate_parity
11-14 11:24:49.910: I/GNU.IO(15496): leaving translate_parity
11-14 11:24:49.910: I/GNU.IO(15496): leaving RXTXPort:nativeSetSerialPortParams
11-14 11:24:49.910: I/GNU.IO(15496): send_event: calling
11-14 11:24:49.910: I/GNU.IO(15496): send_event: called
11-14 11:24:49.910: I/GNU.IO(15496): leaving send_event
11-14 11:24:49.910: I/GNU.IO(15496): entering check_tiocmget_changes
11-14 11:24:49.910: I/GNU.IO(15496): leaving check_tiocmget_changes
11-14 11:24:49.910: I/GNU.IO(15496): port_has_changed_fionread: change is 0
11-14 11:24:49.910: I/GNU.IO(15496): entering send_event
11-14 11:24:49.910: I/GNU.IO(15496): send_event: !eventloop_interupted
11-14 11:24:49.910: I/GNU.IO(15496): send_event: jclazz
11-14 11:24:49.910: I/GNU.IO(15496): send_event: calling
11-14 11:24:49.910: I/GNU.IO(15496): send_event: called
11-14 11:24:49.910: I/GNU.IO(15496): leaving send_event
11-14 11:24:49.910: I/GNU.IO(15496): entering check_tiocmget_changes
11-14 11:24:49.910: I/GNU.IO(15496): leaving check_tiocmget_changes
11-14 11:24:49.910: I/GNU.IO(15496): port_has_changed_fionread: change is 0
11-14 11:24:49.910: I/GNU.IO(15496): entering check_tiocmget_changes
11-14 11:24:49.910: I/GNU.IO(15496): leaving check_tiocmget_changes
11-14 11:24:49.910: I/GNU.IO(15496): port_has_changed_fionread: change is 0
11-14 11:24:49.918: I/GNU.IO(15496): entering check_tiocmget_changes
11-14 11:24:49.918: I/GNU.IO(15496): leaving check_tiocmget_changes
11-14 11:24:49.918: I/GNU.IO(15496): port_has_changed_fionread: change is 0
11-14 11:24:49.918: I/GNU.IO(15496): entering check_tiocmget_changes
11-14 11:24:49.918: I/GNU.IO(15496): leaving check_tiocmget_changes
11-14 11:24:49.918: I/GNU.IO(15496): port_has_changed_fionread: change is 0
最後三行重複,直到我殺死我的手機上的過程。串口上沒有數據,實際上它似乎還沒有被初始化。對此有何建議?
我想在我的android項目中使用rxtx庫。你能幫我設置它嗎? –