Added 3 constants to SerialNativeInterface class, and made a little refactoring of SerialPort and SerialPortList classes
This commit is contained in:
parent
1043354ec1
commit
df65d88787
|
@ -46,6 +46,19 @@ public class SerialNativeInterface {
|
||||||
|
|
||||||
private static int osType = -1;
|
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 {
|
static {
|
||||||
String libFolderPath;
|
String libFolderPath;
|
||||||
String libName;
|
String libName;
|
||||||
|
|
|
@ -151,13 +151,13 @@ public class SerialPort {
|
||||||
else {
|
else {
|
||||||
throw new SerialPortException(portName, "openPort()", SerialPortException.TYPE_NULL_NOT_PERMITTED);//since 2.1.0 -> NULL port name fix
|
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);
|
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);
|
throw new SerialPortException(portName, "openPort()", SerialPortException.TYPE_PORT_NOT_FOUND);
|
||||||
}//<- since 0.9.0
|
}//<- 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);
|
throw new SerialPortException(portName, "openPort()", SerialPortException.TYPE_PERMISSION_DENIED);
|
||||||
}//<- since 2.2.0
|
}//<- since 2.2.0
|
||||||
portOpened = true;
|
portOpened = true;
|
||||||
|
|
|
@ -332,7 +332,7 @@ public class SerialPortList {
|
||||||
String portName = searchPath + fileName;
|
String portName = searchPath + fileName;
|
||||||
if(SerialNativeInterface.getOsType() == SerialNativeInterface.OS_LINUX){
|
if(SerialNativeInterface.getOsType() == SerialNativeInterface.OS_LINUX){
|
||||||
int portHandle = serialInterface.openPort(portName, false);//Open port without TIOCEXCL
|
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;
|
continue;
|
||||||
}
|
}
|
||||||
else if(portHandle != -1) {
|
else if(portHandle != -1) {
|
||||||
|
|
Loading…
Reference in New Issue