From 6d542e09a167471a51460e66e22af3db39e82b43 Mon Sep 17 00:00:00 2001 From: scream3r Date: Wed, 17 Apr 2013 17:26:26 +0400 Subject: [PATCH] Fixed "openPort()" invocations in considering of last changes --- src/java/jssc/SerialPort.java | 2 +- src/java/jssc/SerialPortList.java | 21 ++++++++++++++------- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/src/java/jssc/SerialPort.java b/src/java/jssc/SerialPort.java index b7fd849..54a1330 100644 --- a/src/java/jssc/SerialPort.java +++ b/src/java/jssc/SerialPort.java @@ -146,7 +146,7 @@ public class SerialPort { throw new SerialPortException(portName, "openPort()", SerialPortException.TYPE_PORT_ALREADY_OPENED); } if(portName != null){ - portHandle = serialInterface.openPort(portName); + portHandle = serialInterface.openPort(portName, true, false); } else { throw new SerialPortException(portName, "openPort()", SerialPortException.TYPE_NULL_NOT_PERMITTED);//since 2.1.0 -> NULL port name fix diff --git a/src/java/jssc/SerialPortList.java b/src/java/jssc/SerialPortList.java index c29bb95..9237f31 100644 --- a/src/java/jssc/SerialPortList.java +++ b/src/java/jssc/SerialPortList.java @@ -191,15 +191,22 @@ public class SerialPortList { String portName = PORTNAMES_PATH + fileName; if(SerialNativeInterface.getOsType() == SerialNativeInterface.OS_LINUX){ SerialPort serialPort = new SerialPort(portName); - try { - serialPort.openPort(); - serialPort.closePort(); - } - catch (SerialPortException ex) { - if(!ex.getExceptionType().equals(SerialPortException.TYPE_PORT_BUSY)){ + //try { + /*serialPort.openPort(); + serialPort.closePort();*/ + int portHandle = serialInterface.openPort(portName, false, true); + if(portHandle < 0 && portHandle != -1){ continue; } - } + else if(portHandle != -1) { + serialInterface.closePort(portHandle); + } + //} + //catch (SerialPortException ex) { + // if(!ex.getExceptionType().equals(SerialPortException.TYPE_PORT_BUSY)){ + // continue; + // } + //} } portsTree.add(portName); }