我是用javacomm20-win32来开发串口通讯,有三个文件:comm.jar、javax.comm.properties、win32com.dll
我在装有Eclipse3.2+JDK1.6+JRE1.6的Win XP SP2的机子上双击jar文件可以正常运行,可以打开读取串口数据,但是我在另一台装有JRE1.6的Win XP SP2的机子上双击可以运行jar文件,也可以打开串口,但是一读取串口数据就出现:java.lang.NullPointerExtion错误,是怎么回事呢,那三个文件我也拷到JRE相应的目录下了,环境变量也设置了,我的代码如下:
PortClass.java源码如下:
package Sampel;
import java.io.*;
import java.util.*;
import javax.comm.*;
public class PortClass {
static CommPortIdentifier portId;
static Enumeration portList;
InputStream inputStream;
SerialPort serialPort;
private Thread thread = null;
private boolean pPortOpen = false;
public byte[] readBuffer = new byte[16888];
public PortClass() {
}
public void MyOpenPort()
{
if(OpenPort())
{
pPortOpen = true;
thread = new Thread(new PortTest());
thread.start();
}
else
{
pPortOpen = false;
}
}
public void MyClosePort()
{
if(pPortOpen)
{
serialPort.close();
}
}
private boolean OpenPort()
{
portList = CommPortIdentifier.getPortIdentifiers();
while (portList.hasMoreElements())
{
portId = (CommPortIdentifier) portList.nextElement();
if (portId.getPortType() == CommPortIdentifier.PORT_SERIAL)