
實作環境:
Ubuntu 10.10
Java 1.6.0_23
gcc 4.4.5
(本次實作同樣還是在PC上執行)
步驟一、確認的是USB轉RS-232是否完整讓Ubuntu系統抓到並指定成一個Device。
1.執行 lsusb檢查是否連結USB轉RS-232

由上圖我們看到下列訊息確認系統有抓到:
Bus 004 Device 002: ID 067b:2303 Prolific Technology, Inc. PL2303 Serial Port
2.執行 ls -l /dev/ttyUSB*確認 PL2303 Serial Port 指定 /dev/ttyUSB0

3.測試一下是否如同作業系統課程內容說到在Unix中的device都可以當成檔案進行I/O讀寫
cat /dev/ttyUSB0

由上圖所示,確認目前環境是正確且可以抓到GPS座標。
步驟二、JAVA程式 (Location.java)

步驟三、C程式 (jni.c)


執行結果:

編譯部分清參考觀念篇JAVA呼叫C部分說明。
參考:
Serial Programming Guide for POSIX Operating Systems
http://www.easysw.com/~mike/serial/serial.html
http://www.linux.org.tw/CLDP/OLD/Serial-Programming-HOWTO-3.html
http://www.vr.ncue.edu.tw/esa/EmbeddedSystemProgramming2010/ch06.htm
將GPS訊息字串轉換成可實際使用的經緯度數字
http://www.csie.nuk.edu.tw/~brchang/實驗3.pdf
===========延伸閱讀========================================
Java Native Interface (JNI) 的使用時機及影響
Java Native Interface (JNI)入門 -- 觀念篇
Java Native Interface (JNI) 實戰篇
Java Native Interface (JNI) Android實戰篇(使用NDK) -- HelloUart
Java Native Interface (JNI) Android算數篇(使用NDK) -- Fibonacci Sequence
沒有留言:
張貼留言