
Computer Engineering
1999ꡡ259ڡVol.25 No.9  1999



ھӦJavaʵԶն˵Ŀ
޻
ժҪڼҪJavaԺPCL839ĻϣͨʵֶܽڵPCL839Զ̿ƣ
ؼʣavaPCL839Զ̿ƣط
Remote Controlling the Intelligent Terminal by Java Based on LAN
Zou Huajun, Zeng Yuxing
(Dept. of Mechanical  Electronical Engineering, Guangdong Industrial University, Guangzhou 510090)
AbstractBased on briefly introducing Java and PCL839 card, a method of remote controlling the intelligent terminal (PCL 839 card) is describe.
Key wordJava; PCL839; Remote control; Mative Method
ǰInternetļչ쳣ѸͣInternetҲݱ༯ΪһĲűʹһ磬ȻЩûԶԶûгַInternetǱ,ڿĿǰSUN˾һ"Ǽ"ſӦ缼Ľһоӭµһ"ǿ"ԴΪ㣬оĻϣӦJavaԣʵֶܻɱԶն˵ĿơԿɱ̵PCL839ΪʵԶ̿Ƶһַ
1 Java
JavaSUN˾19955ƳһļͨñԣǼWWW֮һ䶯ĲƷJavaԵصǿƽ̨ǿ̹ܡJavaԵ֮ǰInternetѴڣJavaԱͷװ˴̵⣬ʹ̹ǿͬʱ̵ּĲJavaԿԿǿӦó
2 PCL839
л˾PCL839һָٲùǿI/OڣԲֳݵȡ˲ĿơPCL839ڲ3巢ܹͬ3ÿ巢ÿԲ116k塣
3 Զ̿
3.1 Զ̿ƻֳػĻ
оϹɵĻϵͳͼ1ʵԶ̿ƣȱʵԶ̿ƻֳػĿƣɹػPCL839Կơ
ӦJavaԽĿԲȡ3ַURL(ͳһԴλ)Socket(׽)Datagram(ݰ)URLһWebĳһضԴĻȡʺڵײӦóĿDatagramԲɿЭUDPΪģֳеݣ뱣֤Ŀɿ׼ȷ˶ڸͨųһûڿɿЭTCPϵSocket̼ʵ֡

ͼ1 Զ̿ƻֳػṹͼ
ԱӦóĿServer/ClientʽԶ̿ΪÿػΪͻˡͻĳ򿪷ʾ
public class agnetclass 
{public static void main(String args[])
{try {
Socket agentsocket=new Socket
("remotecontrolcomputer",5555);
PrintStream os=new PrintStream(agentsocket.getOutputStream());
DataInputStream is=new DataInputStream(agentsocket.getInputStream());
StringBuffer buf=new stringBuffer(50);
................
}catch(IOException e){};
}
}
ڸó,ȶһͻsocket,ͨagent socketԶ̿ƻremote control computerӣָʹõĶ˿ںţö˿ںӦ1024ԱϵͳĶ˿ںŷͻȻosis ǴӿͻϢͨǷͻͲ;ٶݻڰѷͲνнtry catch쳣
εĳӦͻ˳ıӦһԶ̿ƻԿƶֳ̨ػԷö̻߳ƣҲJavaԵһɫ˵ĳд£
public class serverclass 
{public static void main(String args[])
{ boolean listen;
try {
ServerSocket serversocket =new ServerSocket(5555);
}catch(IOException e){};
while(listen)
{
Socket agentsocket=serversocket.accept();
}catch(IOException e){};
new serverthread(agentsocket).start();
..........
}}
class serverthread extends Thread{
Socket socket=null;
serverthread(Socket socket)
{super("serverthread");
this.socket=socket;}
public void run(){
try{
DataInputStreamis=newDataInputStream(new BufferedOutputStream (socket. getOutputStream()));
PrintStream os=new PrintStream (new BufferedOutputStream (socket.getOutputStream (),5555),false);
..........
}catch(IOException e){}; }
óɣ߳ࡣฺ׽server socket˿ںűͻĶ˿ںһ£Ȼͨserver socketacceptһ׽ֽӿڣרŴͻͨţ߳ڴһµֳ̣߳ػ߳Уȴһ췽ڳʼһµ̣߳Ȼٶһ÷Ըͻͬһ˿ں󣬷ڶ˿ڴͻ󣬴̣߳δȻͻҲԲòͬĶ˿ں󣬷ӦҲͬ˿ںŵ߳˿ںһµĿͻ˽ͨš
Զ̿ݿж̬ݿдŴֳԼֳĲȡеĳһ߳帺ݿĴȡ޸ĺάȲJavaͨJDBCʵݿӣùʵַ£
public class database 
{public void drivedata()
{String url="JDBC:odbc:component";
..........
try{
Class.forName("sun.jdbc.odbc.JDBCODBCDriver");
Connection con=DriverManager.getConnection(url);
..........
}catch(SQLException se){};
}
óҪĹǼJDBCݿʹJavaܹͨݿ⡣
4 JavaԵıط
JavaԵĿƽ̨ԣʹJava޷ӲܽڵĿֻܲõԽУCԡػͨŲJavaԱдΪʵԶܽڵĿƣͱʵJavaԵĽϡοJavaⷽĹܣCC++ȱؽȻĳ̶ֲֳԣȴʹJavaܹ;Ļ򽻵߱Ӳڱ۵УPCL839ӦúCԿģJava԰CԱƵĳɱط壬ӶʵֶPCL839Ŀơ
ܽڵCԱд,õĺ󲿷л˾C⺯Щ⺯ԿЧӦóɸֲ˰Щ򼯳ΪJavaط壬ΪJavaʵԶ̿ƵĹؼ£
int pcl839dirve()
{ 
int i ;
clrscr();
set_base(0x2c0); /* pcl839Ļַ*/
set_mode(CH1,DIR); /* pcl839ͨ1 "Direction" mode */
set_mode(CH2,DIR); /* pcl839ͨ2 "Direction" mode */
set_mode(CH3,PUS); /* pcl839ͨ3"Pulse" mode */
set_speed(CH123,600,3000,600); /* pcl839ͨٶ */
pmove(CH123 , P_DIR,FH,4000 , N_DIR,FH,2000 , P_DIR,FH,4000);
waitrdy(CH123); /* ȴͨ*/
cmove(CH123 , N_DIR,FH , N_DIR,FH , N_DIR,FH);
/*оֳ,µĳΪʾ*/
printf("κμ...");
getch();
printf("\n");
slowdown(CH123); /* ͨ1,2,3ٵ״̬*/
for(i=2999;i>-1;i--)
{ cprintf("%d \r",i);
delay(1);
}
stop(CH123); /* ֹͨͣ*/
return(0);
}
ڹػJavaıд뼯ɱطڱطļɲȡ²裺һJavaжһصķJava룻ȻJDKµJavaHһCԵͷļʱעеṹͺ壬ŴһStubļStubļаCṹϵһC룻StubļԺ󣬱дӦC룬ԭеCǰϡstubpreamble.h͡drive.hͷļ
VC++ȼɿCԳDLLʵ˱طļɡڹػıسϲԺ󣬹ػ£
public class main 
{public static void main(String args[])
{ .............
/*Զ̿ͨŲֵĳ
new drive().pcl839drive();
.............
}}
public class dirve
{public native void pcl839drive();
.........
static{
System.loadLibrary("drive");
.........} }
öγͱطɣͨŲֵĳ⣬ʵط࣬ҵñططڶ屾طʱϹؼnativeҳһξ̬룬þ̬ͨϵͳΪطdrive⡣
ͨJavaԱ̼ͿʵֱطļɺͨţЧذѿԶͨʵԶ̿ơ׷бؾĻϽɵģJava̺ͼɱطļоʵݺ͸Чص㡣Javaƽ̨޹ԣʹJava뱾طļ˴ļϸڡһJavaĹؼչоֺ͸ЧһɫԣʵֶԵײܽڵĿƣﵽصĿģһǳĿ⡣
߼飺޻(1973)УозҵϢͿƻԶ̿ƣ
ߵλ㶫ҵѧϵ 510090
ο
1 ,.JavaԻӦ.ѧ ,1998-07
2 Rodley J,.WebIntranetݿ⿪.е ҵ,1997-08
ոڣ1999-01-06
