Added 3 constants to SerialNativeInterface class, and made a little refactoring of SerialPort and SerialPortList classes

This commit is contained in:
scream3r 2013-04-22 09:59:59 +04:00
parent 1043354ec1
commit df65d88787
3 changed files with 17 additions and 4 deletions

View File

@ -46,6 +46,19 @@ public class SerialNativeInterface {
private static int osType = -1;
/**
* @since 2.3.0
*/
public static final int ERR_PORT_BUSY = -1;
/**
* @since 2.3.0
*/
public static final int ERR_PORT_NOT_FOUND = -2;
/**
* @since 2.3.0
*/
public static final int ERR_PERMISSION_DENIED = -3;
static {
String libFolderPath;
String libName;

View File

@ -151,13 +151,13 @@ public class SerialPort {
else {
throw new SerialPortException(portName, "openPort()", SerialPortException.TYPE_NULL_NOT_PERMITTED);//since 2.1.0 -> NULL port name fix
}
if(portHandle == -1){//since 0.9.0 ->
if(portHandle == SerialNativeInterface.ERR_PORT_BUSY){//since 0.9.0 ->
throw new SerialPortException(portName, "openPort()", SerialPortException.TYPE_PORT_BUSY);
}
else if(portHandle == -2){
else if(portHandle == SerialNativeInterface.ERR_PORT_NOT_FOUND){
throw new SerialPortException(portName, "openPort()", SerialPortException.TYPE_PORT_NOT_FOUND);
}//<- since 0.9.0
else if(portHandle == -3){//since 2.2.0 ->
else if(portHandle == SerialNativeInterface.ERR_PERMISSION_DENIED){//since 2.2.0 ->
throw new SerialPortException(portName, "openPort()", SerialPortException.TYPE_PERMISSION_DENIED);
}//<- since 2.2.0
portOpened = true;

View File

@ -332,7 +332,7 @@ public class SerialPortList {
String portName = searchPath + fileName;
if(SerialNativeInterface.getOsType() == SerialNativeInterface.OS_LINUX){
int portHandle = serialInterface.openPort(portName, false);//Open port without TIOCEXCL
if(portHandle < 0 && portHandle != -1){//If port handle == -1 it's mean that it's busy
if(portHandle < 0 && portHandle != SerialNativeInterface.ERR_PORT_BUSY){//If port handle == -1 it's mean that it's busy
continue;
}
else if(portHandle != -1) {