Java 語言能夠流行於網路昌行的今天,很大的原因是因為其很好的駕馭了串流輸出入。網路程式多半時間都在處理簡單的輸入和輸出,也就是從一個系統向另一個系統的移動位元組。串流是一個抽像的觀念,當程式需要輸入資料,或輸出資料,則就會開啟一個輸入或輸出的資料源的串流。而通常有三種不同的I/O需要考慮:檔案,控制台,網路連接。Java 所處理的串流分為兩種:位元組串流與字元串流。分別用4個抽像類別來表示:InputStream、OutputStream、Reader、Writer。前二者專門處理位元組串流,後二者處理則處理字元串流。
如下程式:
public class IOStream {
public static void main(String[] args) throws FileNotFoundException、IOException、 ClassNotFoundException{
FileOutputStream fos = new FileOutputStream("t.tmp"); //檔案輸出串流
ObjectOutputStream oos = new ObjectOutputStream(fos);
// 透過物件序列化的方式傳送資料
oos.writeInt(12345); //傳送不同的資料型態
oos.writeObject("Today");
oos.writeObject(new Date());
oos.close();
FileInputStream fis = new FileInputStream("t.tmp");
ObjectInputStream ois = new ObjectInputStream(fis);
//透過物件序列化的方式接收資料
int i = ois.readInt();
System.out.println("i="+i);
String today = (String) ois.readObject();
System.out.println(today);
Date date = (Date) ois.readObject();
System.out.println(date.toString());
ois.close();
}
}
使用了Java "物件序列化;(Object Serialization) 功能實現了Serializable 介面的物件,將其轉化為一個位元組序列,並且再完全回復原來的樣子。
其好處在於:不限於檔案,在網路上也能夠進行,因此如果在Windows建立一個物件,將其序列化,然後透過網路送給Linux機器,可以準確無誤地重新裝配回來。
2010年1月1日 星期五
2009年12月24日 星期四
Embedded Linux Kernel Module using Hello Wolrd
Most people thought Linux is difficult and especially embedded Linux,as they required to porting a linux driver,hey,it choked their throats. But it is really simple if you know the rule,let me show you the rope using the "Hello world" example. Let us check the code as below:
#include
#include
#include
MODULE_LICENSE("Dual BSD/GPL");
MODULE_AUTHOR("Henry");
static int hello_int(void)
{
printk(KERN_ALERT "Hello、world\n");
return 0;
}
static void hello_exit(void)
{
printk(KERN_ALERT "Goodbye、cruel world!\n");
}
module_init(hello_exit);
module_exit(hello_ext);
It is the simplest linux kernel module example
if you have a ARM base embedded board、you coul make it a hello.ko module and then
load the module into kernel :insmod ./hello.ko
then you can see Hello、world
you can check if the module being installed correctly or not by lsmod
then you remove the module: rmmod hello,
the message come out: Goodby cruel world
As typical Makefile you can refer as below:
ifeq($KERNELRELEASE),)
KERNELDIR ?=/lib/modules/$(shell uname -r)/build
PWD := $(shell pwd)
modules:
$(MAKE) -C $(KERNELDIR) M=$(PWD) modules
modules_install:
$(MAKE) -C $(KERNELDIR) M=$(PWD) module_install
clean:
rm -rf *.o *~core .depend .*.cmd *.ko *.mod,c .tmp_versions
.PHONY: modules modules_install clean
else
obj -m :=hello.o
endif
#include
#include
#include
MODULE_LICENSE("Dual BSD/GPL");
MODULE_AUTHOR("Henry");
static int hello_int(void)
{
printk(KERN_ALERT "Hello、world\n");
return 0;
}
static void hello_exit(void)
{
printk(KERN_ALERT "Goodbye、cruel world!\n");
}
module_init(hello_exit);
module_exit(hello_ext);
It is the simplest linux kernel module example
if you have a ARM base embedded board、you coul make it a hello.ko module and then
load the module into kernel :insmod ./hello.ko
then you can see Hello、world
you can check if the module being installed correctly or not by lsmod
then you remove the module: rmmod hello,
the message come out: Goodby cruel world
As typical Makefile you can refer as below:
ifeq($KERNELRELEASE),)
KERNELDIR ?=/lib/modules/$(shell uname -r)/build
PWD := $(shell pwd)
modules:
$(MAKE) -C $(KERNELDIR) M=$(PWD) modules
modules_install:
$(MAKE) -C $(KERNELDIR) M=$(PWD) module_install
clean:
rm -rf *.o *~core .depend .*.cmd *.ko *.mod,c .tmp_versions
.PHONY: modules modules_install clean
else
obj -m :=hello.o
endif
2009年12月22日 星期二
Embedded Linux and ARM

Embedded Linux 支援許多CPU平台包括MIPS,尤其在工業電腦流行ARM平台,而Samsung 的S3C2410 更是其中佼佼者。國內有業者http://www.kaise.com.tw/做出並販賣發展板稱為KS2410具備了3.8"TFT LCD 320x240解析度,並含SDK ,支援一組GPIO附有4顆LED與4顆toggle switch、10Mbpps 的往路線與1個具onboard connector的RS-232和兩組USB1.1(12Mbps) 與Debug interface JTAG.
感覺有點low end 嗎?畢竟在嵌入式系統,具32位元與多達117個GPIO (multiplexed)並有SD interface ,32MB RAM and 32MB flash 這樣的平台作為許多工業應用或研究所大學生作為專題使用,已經綽綽有餘。如果一昧使用intel x86平台不但成本無法降低,且產品週期與散熱,能耗都需額外資源。
感覺有點low end 嗎?畢竟在嵌入式系統,具32位元與多達117個GPIO (multiplexed)並有SD interface ,32MB RAM and 32MB flash 這樣的平台作為許多工業應用或研究所大學生作為專題使用,已經綽綽有餘。如果一昧使用intel x86平台不但成本無法降低,且產品週期與散熱,能耗都需額外資源。
2009年12月17日 星期四
A Simple Android Program
最近完成SCJP課程進修
,也嘗試寫幾個Java小程式,而,目前當紅的Android手機,更是引人入勝,信手寫了一個BMI的小程式,輸入身高體重,便可以告訴你你的 BMI值,並會給你飲食的忠告。經過金鑰驗證後便可安裝到Android手機使用。如圖:
Android 實在是有趣的工作平台,尤其是Emulator作的就像真實的手機,令人愛不釋手,可以完成你很快的有趣的小程式,而不需要瞭解Linux Kernel 或makeImage 等一些繁瑣的問題。
Android 官網:
http:///www.android.com/
要寫Android程式需要先熟悉Java語言與HTML網頁語法。
學Java 語言與取得昇陽原廠認證,聯成http://www.lccnet.com.tw/是不錯的選擇。推薦一名好老師:PianoMan,有趣的藝名,是業界兼職的老師化名,講課有趣,親切,互動性高,非常的敬職與有耐性,就算是很笨的學生,他還是不厭其詳地教你,確定把你跟上進度。程度好的同學就要忍耐一下,老師的進度會非常的慢,雖然是程式認證課程,還是穿插許多有趣的實作程式。
當然你需要有開發工具:eclipse 是非常powerful的IDE整合開發工具,有很好的debug 環境。剛開始會有些陌生,但越用會越順手,但是寫Code 沒有NetBean的自動排版功能,美中不足。
Android 官網:
http:///www.android.com/
要寫Android程式需要先熟悉Java語言與HTML網頁語法。
學Java 語言與取得昇陽原廠認證,聯成http://www.lccnet.com.tw/是不錯的選擇。推薦一名好老師:PianoMan,有趣的藝名,是業界兼職的老師化名,講課有趣,親切,互動性高,非常的敬職與有耐性,就算是很笨的學生,他還是不厭其詳地教你,確定把你跟上進度。程度好的同學就要忍耐一下,老師的進度會非常的慢,雖然是程式認證課程,還是穿插許多有趣的實作程式。
當然你需要有開發工具:eclipse 是非常powerful的IDE整合開發工具,有很好的debug 環境。剛開始會有些陌生,但越用會越順手,但是寫Code 沒有NetBean的自動排版功能,美中不足。
訂閱:
文章 (Atom)