Cleared SerialPortList class
This commit is contained in:
parent
f3cec9a1d0
commit
1d6724ca12
|
@ -168,15 +168,6 @@ public class SerialPortList {
|
||||||
return getUnixBasedPortNames();
|
return getUnixBasedPortNames();
|
||||||
}
|
}
|
||||||
//<- since 2.1.0
|
//<- since 2.1.0
|
||||||
/*if(SerialNativeInterface.getOsType() == SerialNativeInterface.OS_LINUX){
|
|
||||||
return getLinuxPortNames();
|
|
||||||
}
|
|
||||||
else if(SerialNativeInterface.getOsType() == SerialNativeInterface.OS_SOLARIS){//since 0.9.0 ->
|
|
||||||
return getSolarisPortNames();
|
|
||||||
}
|
|
||||||
else if(SerialNativeInterface.getOsType() == SerialNativeInterface.OS_MAC_OS_X){
|
|
||||||
return getMacOSXPortNames();
|
|
||||||
}//<-since 0.9.0*/
|
|
||||||
String[] portNames = serialInterface.getSerialPortNames();
|
String[] portNames = serialInterface.getSerialPortNames();
|
||||||
if(portNames == null){
|
if(portNames == null){
|
||||||
return new String[]{};
|
return new String[]{};
|
||||||
|
@ -221,108 +212,4 @@ public class SerialPortList {
|
||||||
}
|
}
|
||||||
return returnArray;
|
return returnArray;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get serial port names in Linux OS (This method was completely rewrited in 0.8-tb4)
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
private static String[] getLinuxPortNames() {
|
|
||||||
String[] returnArray = new String[]{};
|
|
||||||
try {
|
|
||||||
Process dmesgProcess = Runtime.getRuntime().exec("dmesg");
|
|
||||||
BufferedReader reader = new BufferedReader(new InputStreamReader(dmesgProcess.getInputStream()));
|
|
||||||
TreeSet<String> portsTree = new TreeSet<String>();
|
|
||||||
ArrayList<String> portsList = new ArrayList<String>();
|
|
||||||
String buffer = "";
|
|
||||||
while((buffer = reader.readLine()) != null && !buffer.isEmpty()){
|
|
||||||
if(buffer.matches(".*(ttyS|ttyUSB)[0-9]{1,3}.*")){
|
|
||||||
String[] tmp = buffer.split(" ");
|
|
||||||
for(String value : tmp){
|
|
||||||
if(value.matches("(ttyS|ttyUSB)[0-9]{1,3}")){
|
|
||||||
portsTree.add("/dev/" + value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for(String portName : portsTree){
|
|
||||||
SerialPort serialPort = new SerialPort(portName);
|
|
||||||
try {
|
|
||||||
if(serialPort.openPort()){
|
|
||||||
portsList.add(portName);
|
|
||||||
serialPort.closePort();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (SerialPortException ex) {
|
|
||||||
//since 0.9.0 ->
|
|
||||||
if(ex.getExceptionType().equals(SerialPortException.TYPE_PORT_BUSY)){
|
|
||||||
portsList.add(portName);
|
|
||||||
}
|
|
||||||
//<- since 0.9.0
|
|
||||||
}
|
|
||||||
}
|
|
||||||
returnArray = portsList.toArray(returnArray);
|
|
||||||
reader.close();
|
|
||||||
}
|
|
||||||
catch (IOException ex) {
|
|
||||||
//Do nothing
|
|
||||||
}
|
|
||||||
return returnArray;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get serial port names in Solaris OS
|
|
||||||
*
|
|
||||||
* @since 0.9.0
|
|
||||||
*/
|
|
||||||
private static String[] getSolarisPortNames() {
|
|
||||||
String[] returnArray = new String[]{};
|
|
||||||
File dir = new File("/dev/term");
|
|
||||||
if(dir.exists() && dir.isDirectory()){
|
|
||||||
File[] files = dir.listFiles();
|
|
||||||
if(files.length > 0){
|
|
||||||
TreeSet<String> portsTree = new TreeSet<String>();
|
|
||||||
ArrayList<String> portsList = new ArrayList<String>();
|
|
||||||
for(File file : files){
|
|
||||||
if(!file.isDirectory() && !file.isFile() && file.getName().matches("[0-9]*|[a-z]*")){
|
|
||||||
portsTree.add("/dev/term/" + file.getName());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for(String portName : portsTree){
|
|
||||||
portsList.add(portName);
|
|
||||||
}
|
|
||||||
returnArray = portsList.toArray(returnArray);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return returnArray;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get serial port names in Mac OS X
|
|
||||||
*
|
|
||||||
* @since 0.9.0
|
|
||||||
*/
|
|
||||||
private static String[] getMacOSXPortNames() {
|
|
||||||
String[] returnArray = new String[]{};
|
|
||||||
File dir = new File("/dev");
|
|
||||||
if(dir.exists() && dir.isDirectory()){
|
|
||||||
File[] files = dir.listFiles();
|
|
||||||
if(files.length > 0){
|
|
||||||
TreeSet<String> portsTree = new TreeSet<String>();
|
|
||||||
ArrayList<String> portsList = new ArrayList<String>();
|
|
||||||
for(File file : files){
|
|
||||||
if(!file.isDirectory() && !file.isFile() && file.getName().matches("tty.(serial.*|usbserial.*)")){
|
|
||||||
portsTree.add("/dev/" + file.getName());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for(String portName : portsTree){
|
|
||||||
portsList.add(portName);
|
|
||||||
}
|
|
||||||
returnArray = portsList.toArray(returnArray);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return returnArray;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue