JAVA中可以利用SUN公司提供的comm包提供的类型来实现,下面为在windows下的环境搭建过程和简单实例程序:
1、下载 javacomm20-win32 开发包,网上都有提供,随便下一个
2、 配置:(如果使用的是Myeclipse,注意其是自带有jdk的安装目录的,需要在其下配置)
javax.comm.properties放在java_home\jre\lib\下
comm.jar放在java_home\jre\lib\ext\下
win32com.dll放在java_home\jre\bin\下
3、 简单例程(更深入理解可看包下提供的例子):
package com.function;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.util.Enumeration;
import javax.comm.CommPortIdentifier;
import javax.comm.SerialPort;
import javax.comm.SerialPortEvent;
import javax.comm.SerialPortEventListener;
import org.json.JSONObject;
public class SerialDemo2 implements SerialPortEventListener{
private SerialPort