import gnu.io.*;import java.io.*;import java.util.*;
@SuppressWarnings("rawtypes")public class SerialReader extends Observable implementsRunnable,SerialPortEventListener{staticCommPortIdentifier portId;int delayRead = 100;int numBytes; //buffer中的实际数据字节数
private static byte[] readBuffer = new byte[1024]; //缓存串口读入的数据
staticEnumeration portList;
InputStream inputStream;
OutputStream outputStream;staticSerialPort serialPort;
HashMap serialParams;
Thread readThread;//端口是否打开了
boolean isOpen = false;//端口读入数据事件触发后,等待n毫秒后再读取,以便让数据一次性读完
public static final String PARAMS_DELAY = "delay read"; //延时等待端口数据准备的时间
public static final String PARAMS_TIMEOUT = "timeout"; //超时时间
public static final String PARAMS_PORT = "port name"; //端口名称
public static final String PARAMS_DATABITS = "data bits"; //数据位
public static final String PARAMS_STOPBITS = "stop bits"; //停止位
public static final String PARAMS_PARITY = "parity"; //奇偶校验
public static final String PARAMS_RATE = "rate"; //波特率
public booleanisOpen(){returnisOpen;
}/*** 初始化端口操作的参数.
*@throwsSerialPortException
*
*@see
*/
publicSerialReader(){
isOpen= false;
}public voidopen(HashMap p