java
串口通讯程序
1
、
下载
java Communications api
开发包。
|
是
Sun
公司提供的,用于开发平台独立的通讯应用程序的扩展
API
。
2
、将拷贝入
C:\j2sdk1.4.2_04\bin
3
、将拷贝入
C:\j2sdk1.4.2_04\jre\lib\ext
4
、将拷贝入
C:\j2sdk1.4.2_04\jre\lib
5
、编译文件
import .*;
import .*;
import .*;
public class CommTest{
public static void main(String[] args){
SerialPort serialPort=null;
DataOutputStream doutput=null;
InputStream inputStream;
CommPortIdentifier portId=null;
String messageString="hello \n";
try{
portId=("COM1");
}catch(NoSuchPortException ne) {
"ne"); ();
}
try{
serialPort=(SerialPort) ("TestComm", 5);
OutputStream output = ();
doutput=new DataOutputStream(output);
inputStream = ();
}catch(PortInUseException ex) {
"ex");
();
}catch(IOException ie) {
"ie");
();
//();
}
try {
(9600, , , ;
} catch (UnsupportedCommOperationException e) {}
}
try {
());
} catch (IOException e) {}