我搞顶了。这个是反编译的CommPortIdentifier类(部分)
但用JAVA读串口还是有点问题读,读的数据会丢失,而且对长度不同的数据很难处理,因为SerialPortEventListener这个接口只有一个方法,而且没有返回值,现在我用VC写了一个串口通讯的程序,然后用JAVA调用,全部解决,如果想要,就留EMAIL
public class CommPortIdentifier
{
    public static Enumeration getPortIdentifiers(){
……    }    public static CommPortIdentifier getPortIdentifier(String s)
        throws NoSuchPortException
    {
        SecurityManager securitymanager = System.getSecurityManager();
        if(securitymanager != null)
            securitymanager.checkDelete(propfilename);
        CommPortIdentifier commportidentifier = null;
        synchronized(lock)
        {
            for(commportidentifier = masterIdList; commportidentifier != null; commportidentifier = commportidentifier.next)
                if(commportidentifier.name.equals(s))
                    break;        }
        if(commportidentifier != null)
            return commportidentifier;
        else
            throw new NoSuchPortException();
    }    public static CommPortIdentifier getPortIdentifier(CommPort commport)
        throws NoSuchPortException
    {
        SecurityManager securitymanager = System.getSecurityManager();
        if(securitymanager != null)
            securitymanager.checkDelete(propfilename);
        CommPortIdentifier commportidentifier = null;
        synchronized(lock)
        {
            for(commportidentifier = masterIdList; commportidentifier != null; commportidentifier = commportidentifier.next)
                if(commportidentifier.port == commport)
                    break;        }
        if(commportidentifier != null)
            return commportidentifier;
        else
            throw new NoSuchPortException();
    }    private static void addPort(CommPort commport, int i)
    {……}    public static void addPortName(String s, int i, CommDriver commdriver)
    {……}    public String getName()
    {return name;}    public int getPortType()
    {return portType;}    private native int nCreateMutex(String s);
    private native int nCreateEvent(String s);
    private native boolean nClaimMutex(int i, int j);
    private native boolean nReleaseMutex(int i);
    private native boolean nPulseEvent(int i);
    private native boolean nSetEvent(int i);
    private native boolean nCloseHandle(int i);
    private void createNativeObjects()
    {……}    public synchronized CommPort open(String s, int i)
        throws PortInUseException
    {
        if(!nativeObjectsCreated)
            createNativeObjects();
        if(owned)
        {
            maskOwnershipEvents = true;
            fireOwnershipEvent(3);
            maskOwnershipEvents = false;
            if(owned)
                throw new PortInUseException(owner);
        }
        port = driver.getCommPort(name, portType);
        if(port == null)
        {
            nSetEvent(ownershipRequestedEvent);
            for(int j = i <= 200 ? 200 : i; j > 0; j -= 200)
            {
                try
                {
                    wait(200L);
                }
                catch(InterruptedException _ex) { }
                port = driver.getCommPort(name, portType);
                if(port != null)
                    break;
            }            if(port == null)
            {
                String s1 = nGetOwner(shname);
                if(s1 == null || s1.length() == 0)
                    s1 = "Unknown Windows Application";
                throw new PortInUseException(s1);
            }
        }
        owned = true;
        owner = s;
        if(s == null || s.length() == 0)
            shmem = nSetOwner(shname, "Unspecified Java Application", true);
        else
            shmem = nSetOwner(shname, s, true);
        if(!nSetEvent(ownedEvent))
            System.err.println("Error pulsing ownedEvent");
        return port;
    }    private native int nSetOwner(String s, String s1, boolean flag);    private native String nGetOwner(String s);    private native void nUnsetOwner(String s);    public String getCurrentOwner()
    {…}    public boolean isCurrentlyOwned()
    {……}    public void addPortOwnershipListener(CommPortOwnershipListener commportownershiplistener)
    {……}    public void removePortOwnershipListener(CommPortOwnershipListener commportownershiplistener)
    {……}    private native int nWaitForEvents(int i, int j, int k);    void ownershipThreadWaiter()
    {……}    synchronized void internalClosePort()
    {……}    CommPortIdentifier(String s, CommPort commport, int i, CommDriver commdriver)
    {
        cpoList = new CpoList();
        name = s;
        port = commport;
        portType = i;
        next = null;
        driver = commdriver;
        shname = "javax.comm-" + s;
        shmem = nSetOwner(shname, "", false);
    }    void fireOwnershipEvent(int i)
    {……}    private static String[] parsePropsFile(InputStream inputstream)
    {……}    private static void loadDriver(String s)
        throws IOException
    {
        File file = new File(s);
        BufferedInputStream bufferedinputstream = new BufferedInputStream(new FileInputStream(file));
        String as[] = parsePropsFile(bufferedinputstream);
        if(as != null)
        {
            for(int i = 0; i < as.length; i++)
                if(as[i].regionMatches(true, 0, "driver=", 0, 7))
                {
                    String s1 = as[i].substring(7);
                    s1.trim();
                    try
                    {
                        CommDriver commdriver = (CommDriver)Class.forName(s1).newInstance();
                        commdriver.initialize();
                    }
                    catch(Throwable throwable)
                    {
                        System.err.println("Caught " + throwable + " while loading driver " + s1);
                    }
                }
        }
    }    private static String findPropFile()
    {……}    public CommPort open(FileDescriptor filedescriptor)
        throws UnsupportedCommOperationException
    {
        throw new UnsupportedCommOperationException();
    }    String name;
    private int portType;
    public static final int PORT_SERIAL = 1;
    public static final int PORT_PARALLEL = 2;
    private boolean nativeObjectsCreated;
    private int ownedEvent;
    private int unownedEvent;
    private int ownershipRequestedEvent;
    private int shmem;
    private String shname;
    private boolean maskOwnershipEvents;
    OwnershipEventThread oeThread;
    CpoList cpoList;
    CommPortIdentifier next;
    private CommPort port;
    private CommDriver driver;
    static Object lock = new Object();
    static String propfilename;
    static CommPortIdentifier masterIdList;
    boolean owned;
    String owner;    static 
    {
        String s;
        if((s = System.getProperty("javax.comm.properties")) != null)
            System.err.println("Comm Drivers: " + s);
        String s1 = System.getProperty("java.home") + File.separator + "lib" + File.separator + "javax.comm.properties";
        try
        {
            loadDriver(s1);
            propfilename = new String(s1);
        }
        catch(IOException _ex)
        {
            propfilename = findPropFile();
            try
            {
                if(propfilename != null)
                    loadDriver(propfilename);
            }
            catch(IOException ioexception)
            {
                propfilename = new String(" ");
                System.err.println(ioexception);
            }
        }
    }
}

解决方案 »

  1.   

    给兄弟一份,[email protected]
      

  2.   

    这位仁兄,可否给兄弟一份,兄弟正在忙这个东东[email protected]另外请教下载了JAVAX.COMM后如何配置啊,我用的是JBuilder 6,内置jdk 1.3.1小弟原来用VC写过一个的,不过很简单,现在也准备用JAVA调用,但是不是很明白,兄弟能不能给小弟发一份啊,不胜感激!!!
      

  3.   

    这位兄弟:IBM网站上有篇文章,你到JAVA专区搜索一下,叫做全双工的串口通讯,如果你没看过的话,我想对你有点帮助的!如果找不到我可以发给你
    在楼上我留了联系方式了,兄弟的问题对你来说应该不是问题,还望指点,如何配置JAVAX.COMM
    谢谢了!
      

  4.   

    eBeerlu(k7)
    哪个文章我早就看了,但存在一个问题,就是我每次读的数据如果不一样长的话,就不好处理,因为他在读取数据的时候需要一个长度的参数,而我每次读取的数据是不定长的,所以就没有办法了。至于你的问题很简单,把配置和.dll文件复制到jre/lib/ext. jar复制到jre/lib就可以了
      

  5.   

    to:zceast
    在JB 6的JDK 1.3.1下的jre/lib下没有ext这个文件夹啊,你是用的JB6吗
    能认识一下吗,我做的东西和你的有很多共同之处,向高人学习啊,我在上海!
    能留个联系方式吗,如果不方便的话,可以发个邮件给我啊!
      

  6.   

    老大:
    编译还是通不过啊,真奇怪了,完全按照SUN的配置来的place the win32com.dll in <jdk>\jre\bin directory. Place the comm.jar in <jdk>\jre\lib\ext. Place the javax.comm.properties in <jdk>\jre\lib . Do not alter the CLASSPATH. 又麻烦你了,真不好意思 !