日期:2014-05-20  浏览次数:20717 次

java串口通讯问题
我用 commapi中的例子读不到串口,不管是物理串口还是虚拟串口都读不到。记得第一次的时候是可以读到的,但不知道什么时候开始就读不到了,而且配置什么的我都有按照网上做啊,就是把那三个文件挪到jdk,jre相关目录下啊,可是就是读不到串口。。。portList.hasMoreElements()为false..哪个大侠帮帮忙啊

------解决方案--------------------
还有dll文件,貌似要放到C:\WINDOWS\system32下
------解决方案--------------------
    /**************************************************************************
     * 获得所有串口实例列表
     * 
     * @param
     * @return ParallelPorts
     * @since 2012011.28
     * @author wangjl
     **************************************************************************/


    /**************************************************************************
     * 获得所有串口实例列表
     * 
     * @param
     * @return serialPorts
     * @since 2012011.28
     * @author wangjl
     **************************************************************************/

    public static List<SerialPort> getSerialPorts()
    {
        List<SerialPort> serialPorts = new ArrayList<SerialPort>();
        Enumeration en = CommPortIdentifier.getPortIdentifiers();// 获得所有串口
        CommPortIdentifier portId;
        while (en.hasMoreElements())
        {
            portId = (CommPortIdentifier) en.nextElement();

            if(portId.getPortType() == CommPortIdentifier.PORT_SERIAL)
            {
                SerialPort serialPort = null;
                try
                {
                    serialPort = (SerialPort) portId.open("smsapp", 500);
                    serialPorts.add(serialPort);
                }
                catch (PortInUseException e)
                {
                    e.printStackTrace();
                }
                finally
                {