only:Let's admit it's time to move to gradle fix #3014

This commit is contained in:
Andrey 2023-07-04 12:05:19 -04:00
parent fa35138cf7
commit adc0a08624
9 changed files with 0 additions and 2581 deletions

Binary file not shown.

View File

@ -1 +0,0 @@
this is custom build of JSSC with additional logging - it's only useful during debugging.

View File

@ -1,486 +0,0 @@
/* jSSC (Java Simple Serial Connector) - serial port communication library.
* © Alexey Sokolov (scream3r), 2010-2014.
*
* This file is part of jSSC.
*
* jSSC is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* jSSC is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with jSSC. If not, see <http://www.gnu.org/licenses/>.
*
* If you use jSSC in public project you can inform me about this by e-mail,
* of course if you want it.
*
* e-mail: scream3r.org@gmail.com
* web-site: http://scream3r.org | http://code.google.com/p/java-simple-serial-connector/
*/
package jssc;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.InputStreamReader;
/**
*
* @author scream3r
*/
public class SerialNativeInterface {
private static final String libVersion = "2.8"; //jSSC-2.8.0 Release from 24.01.2014
private static final String libMinorSuffix = "0"; //since 0.9.0
public static final int OS_LINUX = 0;
public static final int OS_WINDOWS = 1;
public static final int OS_SOLARIS = 2;//since 0.9.0
public static final int OS_MAC_OS_X = 3;//since 0.9.0
private static int osType = -1;
/**
* @since 2.3.0
*/
public static final long ERR_PORT_BUSY = -1;
/**
* @since 2.3.0
*/
public static final long ERR_PORT_NOT_FOUND = -2;
/**
* @since 2.3.0
*/
public static final long ERR_PERMISSION_DENIED = -3;
/**
* @since 2.3.0
*/
public static final long ERR_INCORRECT_SERIAL_PORT = -4;
/**
* @since 2.6.0
*/
public static final String PROPERTY_JSSC_NO_TIOCEXCL = "JSSC_NO_TIOCEXCL";
/**
* @since 2.6.0
*/
public static final String PROPERTY_JSSC_IGNPAR = "JSSC_IGNPAR";
/**
* @since 2.6.0
*/
public static final String PROPERTY_JSSC_PARMRK = "JSSC_PARMRK";
static {
String libFolderPath;
String libName;
String osName = System.getProperty("os.name");
String architecture = System.getProperty("os.arch");
String userHome = System.getProperty("user.home");
String fileSeparator = System.getProperty("file.separator");
String tmpFolder = System.getProperty("java.io.tmpdir");
//since 2.3.0 ->
String libRootFolder = new File(userHome).canWrite() ? userHome : tmpFolder;
//<- since 2.3.0
String javaLibPath = System.getProperty("java.library.path");//since 2.1.0
if(osName.equals("Linux")){
osName = "linux";
osType = OS_LINUX;
}
else if(osName.startsWith("Win")){
osName = "windows";
osType = OS_WINDOWS;
}//since 0.9.0 ->
else if(osName.equals("SunOS")){
osName = "solaris";
osType = OS_SOLARIS;
}
else if(osName.equals("Mac OS X") || osName.equals("Darwin")){//os.name "Darwin" since 2.6.0
osName = "mac_os_x";
osType = OS_MAC_OS_X;
}//<- since 0.9.0
if(architecture.equals("i386") || architecture.equals("i686")){
architecture = "x86";
}
else if(architecture.equals("amd64") || architecture.equals("universal")){//os.arch "universal" since 2.6.0
architecture = "x86_64";
}
else if(architecture.equals("arm")) {//since 2.1.0
String floatStr = "sf";
if(javaLibPath.toLowerCase().contains("gnueabihf") || javaLibPath.toLowerCase().contains("armhf")){
floatStr = "hf";
}
else {
try {
Process readelfProcess = Runtime.getRuntime().exec("readelf -A /proc/self/exe");
BufferedReader reader = new BufferedReader(new InputStreamReader(readelfProcess.getInputStream()));
String buffer = "";
while((buffer = reader.readLine()) != null && !buffer.isEmpty()){
if(buffer.toLowerCase().contains("Tag_ABI_VFP_args".toLowerCase())){
floatStr = "hf";
break;
}
}
reader.close();
}
catch (Exception ex) {
//Do nothing
}
}
architecture = "arm" + floatStr;
}
libFolderPath = libRootFolder + fileSeparator + ".jssc" + fileSeparator + osName;
libName = "jSSC-" + libVersion + "_" + architecture;
libName = System.mapLibraryName(libName);
if(libName.endsWith(".dylib")){//Since 2.1.0 MacOSX 10.8 fix
libName = libName.replace(".dylib", ".jnilib");
}
boolean loadLib = false;
if(isLibFolderExist(libFolderPath)){
if(isLibFileExist(libFolderPath + fileSeparator + libName)){
loadLib = true;
}
else {
if(extractLib((libFolderPath + fileSeparator + libName), osName, libName)){
loadLib = true;
}
}
}
else {
if(new File(libFolderPath).mkdirs()){
if(extractLib((libFolderPath + fileSeparator + libName), osName, libName)){
loadLib = true;
}
}
}
if (loadLib) {
System.load(libFolderPath + fileSeparator + libName);
String versionBase = getLibraryBaseVersion();
String versionNative = getNativeLibraryVersion();
if (!versionBase.equals(versionNative)) {
System.err.println("Warning! jSSC Java and Native versions mismatch (Java: " + versionBase + ", Native: " + versionNative + ")");
}
}
}
/**
* Is library folder exists
*
* @param libFolderPath
*
* @since 0.8
*/
private static boolean isLibFolderExist(String libFolderPath) {
boolean returnValue = false;
File folder = new File(libFolderPath);
if(folder.exists() && folder.isDirectory()){
returnValue = true;
}
return returnValue;
}
/**
* Is library file exists
*
* @param libFilePath
*
* @since 0.8
*/
private static boolean isLibFileExist(String libFilePath) {
boolean returnValue = false;
File folder = new File(libFilePath);
if(folder.exists() && folder.isFile()){
returnValue = true;
}
return returnValue;
}
/**
* Extract lib to lib folder
*
* @param libFilePath
* @param osName
* @param libName
*
* @since 0.8
*/
private static boolean extractLib(String libFilePath, String osName, String libName) {
boolean returnValue = false;
File libFile = new File(libFilePath);
InputStream input = null;
FileOutputStream output = null;
input = SerialNativeInterface.class.getResourceAsStream("/libs/" + osName + "/" + libName);
if(input != null){
int read;
byte[] buffer = new byte[4096];
try {
output = new FileOutputStream(libFilePath);
while((read = input.read(buffer)) != -1){
output.write(buffer, 0, read);
}
output.close();
input.close();
returnValue = true;
}
catch (Exception ex) {
try {
output.close();
if(libFile.exists()){
libFile.delete();
}
}
catch (Exception ex_out) {
//Do nothing
}
try {
input.close();
}
catch (Exception ex_in) {
//Do nothing
}
}
}
return returnValue;
}
/**
* Get OS type (OS_LINUX || OS_WINDOWS || OS_SOLARIS)
*
* @since 0.8
*/
public static int getOsType() {
return osType;
}
/**
* Get jSSC version. The version of library is <b>Base Version</b> + <b>Minor Suffix</b>
*
* @since 0.8
*/
public static String getLibraryVersion() {
return libVersion + "." + libMinorSuffix;
}
/**
* Get jSSC Base Version
*
* @since 0.9.0
*/
public static String getLibraryBaseVersion() {
return libVersion;
}
/**
* Get jSSC minor suffix. For example in version 0.8.1 - <b>1</b> is a minor suffix
*
* @since 0.9.0
*/
public static String getLibraryMinorSuffix() {
return libMinorSuffix;
}
/**
* Get jSSC native library version
*
* @return native lib version (for jSSC-2.8.0 should be 2.8 for example)
*
* @since 2.8.0
*/
public static native String getNativeLibraryVersion();
/**
* Open port
*
* @param portName name of port for opening
* @param useTIOCEXCL enable/disable using of <b>TIOCEXCL</b>. Take effect only on *nix based systems
*
* @return handle of opened port or -1 if opening of the port was unsuccessful
*/
public native long openPort(String portName, boolean useTIOCEXCL);
/**
* Setting the parameters of opened port
*
* @param handle handle of opened port
* @param baudRate data transfer rate
* @param dataBits number of data bits
* @param stopBits number of stop bits
* @param parity parity
* @param setRTS initial state of RTS line (ON/OFF)
* @param setDTR initial state of DTR line (ON/OFF)
* @param flags additional Native settings. Take effect only on *nix based systems
*
* @return If the operation is successfully completed, the method returns true, otherwise false
*/
public native boolean setParams(long handle, int baudRate, int dataBits, int stopBits, int parity, boolean setRTS, boolean setDTR, int flags);
/**
* Purge of input and output buffer
*
* @param handle handle of opened port
* @param flags flags specifying required actions for purgePort method
*
* @return If the operation is successfully completed, the method returns true, otherwise false
*/
public native boolean purgePort(long handle, int flags);
/**
* Close port
*
* @param handle handle of opened port
*
* @return If the operation is successfully completed, the method returns true, otherwise false
*/
public native boolean closePort(long handle);
/**
* Set events mask
*
* @param handle handle of opened port
* @param mask events mask
*
* @return If the operation is successfully completed, the method returns true, otherwise false
*/
public native boolean setEventsMask(long handle, int mask);
/**
* Get events mask
*
* @param handle handle of opened port
*
* @return Method returns event mask as a variable of <b>int</b> type
*/
public native int getEventsMask(long handle);
/**
* Wait events
*
* @param handle handle of opened port
*
* @return Method returns two-dimensional array containing event types and their values
* (<b>events[i][0] - event type</b>, <b>events[i][1] - event value</b>).
*/
public native int[][] waitEvents(long handle);
/**
* Change RTS line state
*
* @param handle handle of opened port
* @param value <b>true - ON</b>, <b>false - OFF</b>
*
* @return If the operation is successfully completed, the method returns true, otherwise false
*/
public native boolean setRTS(long handle, boolean value);
/**
* Change DTR line state
*
* @param handle handle of opened port
* @param value <b>true - ON</b>, <b>false - OFF</b>
*
* @return If the operation is successfully completed, the method returns true, otherwise false
*/
public native boolean setDTR(long handle, boolean value);
/**
* Read data from port
*
* @param handle handle of opened port
* @param byteCount count of bytes required to read
*
* @return Method returns the array of read bytes
*/
public native byte[] readBytes(long handle, int byteCount);
/**
* Write data to port
*
* @param handle handle of opened port
* @param buffer array of bytes to write
*
* @return If the operation is successfully completed, the method returns true, otherwise false
*/
public native boolean writeBytes(long handle, byte[] buffer);
/**
* Get bytes count in buffers of port
*
* @param handle handle of opened port
*
* @return Method returns the array that contains info about bytes count in buffers:
* <br><b>element 0</b> - input buffer</br>
* <br><b>element 1</b> - output buffer</br>
*
* @since 0.8
*/
public native int[] getBuffersBytesCount(long handle);
/**
* Set flow control mode
*
* @param handle handle of opened port
* @param mask mask of flow control mode
*
* @return If the operation is successfully completed, the method returns true, otherwise false
*
* @since 0.8
*/
public native boolean setFlowControlMode(long handle, int mask);
/**
* Get flow control mode
*
* @param handle handle of opened port
*
* @return Mask of setted flow control mode
*
* @since 0.8
*/
public native int getFlowControlMode(long handle);
/**
* Get serial port names like an array of String
*
* @return unsorted array of String with port names
*/
public native String[] getSerialPortNames();
/**
* Getting lines states
*
* @param handle handle of opened port
*
* @return Method returns the array containing information about lines in following order:
* <br><b>element 0</b> - <b>CTS</b> line state</br>
* <br><b>element 1</b> - <b>DSR</b> line state</br>
* <br><b>element 2</b> - <b>RING</b> line state</br>
* <br><b>element 3</b> - <b>RLSD</b> line state</br>
*/
public native int[] getLinesStatus(long handle);
/**
* Send Break singnal for setted duration
*
* @param handle handle of opened port
* @param duration duration of Break signal
* @return If the operation is successfully completed, the method returns true, otherwise false
*
* @since 0.8
*/
public native boolean sendBreak(long handle, int duration);
}

File diff suppressed because it is too large Load Diff

View File

@ -1,193 +0,0 @@
/* jSSC (Java Simple Serial Connector) - serial port communication library.
* © Alexey Sokolov (scream3r), 2010-2014.
*
* This file is part of jSSC.
*
* jSSC is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* jSSC is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with jSSC. If not, see <http://www.gnu.org/licenses/>.
*
* If you use jSSC in public project you can inform me about this by e-mail,
* of course if you want it.
*
* e-mail: scream3r.org@gmail.com
* web-site: http://scream3r.org | http://code.google.com/p/java-simple-serial-connector/
*/
package jssc;
/**
*
* @author scream3r
*/
public class SerialPortEvent {
private String portName;
private int eventType;
private int eventValue;
public static final int RXCHAR = 1;
public static final int RXFLAG = 2;
public static final int TXEMPTY = 4;
public static final int CTS = 8;
public static final int DSR = 16;
public static final int RLSD = 32;
public static final int BREAK = 64;
public static final int ERR = 128;
public static final int RING = 256;
public SerialPortEvent(String portName, int eventType, int eventValue){
SerialPort.log("SerialPortEvent " + portName + " " + eventType + " " + eventValue);
this.portName = portName;
this.eventType = eventType;
this.eventValue = eventValue;
}
/**
* Getting port name which sent the event
*/
public String getPortName() {
return portName;
}
/**
* Getting event type
*/
public int getEventType() {
return eventType;
}
/**
* Getting event value
* <br></br>
* <br><u><b>Event values depending on their types:</b></u></br>
* <br><b>RXCHAR</b> - bytes count in input buffer</br>
* <br><b>RXFLAG</b> - bytes count in input buffer (Not supported in Linux)</br>
* <br><b>TXEMPTY</b> - bytes count in output buffer</br>
* <br><b>CTS</b> - state of CTS line (0 - OFF, 1 - ON)</br>
* <br><b>DSR</b> - state of DSR line (0 - OFF, 1 - ON)</br>
* <br><b>RLSD</b> - state of RLSD line (0 - OFF, 1 - ON)</br>
* <br><b>BREAK</b> - 0</br>
* <br><b>RING</b> - state of RING line (0 - OFF, 1 - ON)</br>
* <br><b>ERR</b> - mask of errors</br>
*/
public int getEventValue() {
return eventValue;
}
/**
* Method returns true if event of type <b>"RXCHAR"</b> is received and otherwise false
*/
public boolean isRXCHAR() {
if(eventType == RXCHAR){
return true;
}
else {
return false;
}
}
/**
* Method returns true if event of type <b>"RXFLAG"</b> is received and otherwise false
*/
public boolean isRXFLAG() {
if(eventType == RXFLAG){
return true;
}
else {
return false;
}
}
/**
* Method returns true if event of type <b>"TXEMPTY"</b> is received and otherwise false
*/
public boolean isTXEMPTY() {
if(eventType == TXEMPTY){
return true;
}
else {
return false;
}
}
/**
* Method returns true if event of type <b>"CTS"</b> is received and otherwise false
*/
public boolean isCTS() {
if(eventType == CTS){
return true;
}
else {
return false;
}
}
/**
* Method returns true if event of type <b>"DSR"</b> is received and otherwise false
*/
public boolean isDSR() {
if(eventType == DSR){
return true;
}
else {
return false;
}
}
/**
* Method returns true if event of type <b>"RLSD"</b> is received and otherwise false
*/
public boolean isRLSD() {
if(eventType == RLSD){
return true;
}
else {
return false;
}
}
/**
* Method returns true if event of type <b>"BREAK"</b> is received and otherwise false
*/
public boolean isBREAK() {
if(eventType == BREAK){
return true;
}
else {
return false;
}
}
/**
* Method returns true if event of type <b>"ERR"</b> is received and otherwise false
*/
public boolean isERR() {
if(eventType == ERR){
return true;
}
else {
return false;
}
}
/**
* Method returns true if event of type <b>"RING"</b> is received and otherwise false
*/
public boolean isRING() {
if(eventType == RING){
return true;
}
else {
return false;
}
}
}

View File

@ -1,34 +0,0 @@
/* jSSC (Java Simple Serial Connector) - serial port communication library.
* © Alexey Sokolov (scream3r), 2010-2014.
*
* This file is part of jSSC.
*
* jSSC is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* jSSC is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with jSSC. If not, see <http://www.gnu.org/licenses/>.
*
* If you use jSSC in public project you can inform me about this by e-mail,
* of course if you want it.
*
* e-mail: scream3r.org@gmail.com
* web-site: http://scream3r.org | http://code.google.com/p/java-simple-serial-connector/
*/
package jssc;
/**
*
* @author scream3r
*/
public interface SerialPortEventListener {
public abstract void serialEvent(SerialPortEvent serialPortEvent);
}

View File

@ -1,95 +0,0 @@
/* jSSC (Java Simple Serial Connector) - serial port communication library.
* © Alexey Sokolov (scream3r), 2010-2014.
*
* This file is part of jSSC.
*
* jSSC is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* jSSC is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with jSSC. If not, see <http://www.gnu.org/licenses/>.
*
* If you use jSSC in public project you can inform me about this by e-mail,
* of course if you want it.
*
* e-mail: scream3r.org@gmail.com
* web-site: http://scream3r.org | http://code.google.com/p/java-simple-serial-connector/
*/
package jssc;
/**
*
* @author scream3r
*/
public class SerialPortException extends Exception {
final public static String TYPE_PORT_ALREADY_OPENED = "Port already opened";
final public static String TYPE_PORT_NOT_OPENED = "Port not opened";
final public static String TYPE_CANT_SET_MASK = "Can't set mask";
final public static String TYPE_LISTENER_ALREADY_ADDED = "Event listener already added";
final public static String TYPE_LISTENER_THREAD_INTERRUPTED = "Event listener thread interrupted";
final public static String TYPE_CANT_REMOVE_LISTENER = "Can't remove event listener, because listener not added";
/**
* @since 0.8
*/
final public static String TYPE_PARAMETER_IS_NOT_CORRECT = "Parameter is not correct";
/**
* @since 0.8
*/
final public static String TYPE_NULL_NOT_PERMITTED = "Null not permitted";
/**
* @since 0.9.0
*/
final public static String TYPE_PORT_BUSY = "Port busy";
/**
* @since 0.9.0
*/
final public static String TYPE_PORT_NOT_FOUND = "Port not found";
/**
* @since 2.2.0
*/
final public static String TYPE_PERMISSION_DENIED = "Permission denied";
/**
* @since 2.3.0
*/
final public static String TYPE_INCORRECT_SERIAL_PORT = "Incorrect serial port";
private String portName;
private String methodName;
private String exceptionType;
public SerialPortException(String portName, String methodName, String exceptionType){
super("Port name - " + portName + "; Method name - " + methodName + "; Exception type - " + exceptionType + ".");
this.portName = portName;
this.methodName = methodName;
this.exceptionType = exceptionType;
}
/**
* Getting port name during operation with which the exception was called
*/
public String getPortName(){
return portName;
}
/**
* Getting method name during execution of which the exception was called
*/
public String getMethodName(){
return methodName;
}
/**
* Getting exception type
*/
public String getExceptionType(){
return exceptionType;
}
}

View File

@ -1,348 +0,0 @@
/* jSSC (Java Simple Serial Connector) - serial port communication library.
* © Alexey Sokolov (scream3r), 2010-2014.
*
* This file is part of jSSC.
*
* jSSC is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* jSSC is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with jSSC. If not, see <http://www.gnu.org/licenses/>.
*
* If you use jSSC in public project you can inform me about this by e-mail,
* of course if you want it.
*
* e-mail: scream3r.org@gmail.com
* web-site: http://scream3r.org | http://code.google.com/p/java-simple-serial-connector/
*/
package jssc;
import java.io.File;
import java.util.Comparator;
import java.util.TreeSet;
import java.util.regex.Pattern;
/**
*
* @author scream3r
*/
public class SerialPortList {
private static SerialNativeInterface serialInterface;
private static final Pattern PORTNAMES_REGEXP;
private static final String PORTNAMES_PATH;
static {
serialInterface = new SerialNativeInterface();
switch (SerialNativeInterface.getOsType()) {
case SerialNativeInterface.OS_LINUX: {
PORTNAMES_REGEXP = Pattern.compile("(ttyS|ttyUSB|ttyACM|ttyAMA|rfcomm|ttyO)[0-9]{1,3}");
PORTNAMES_PATH = "/dev/";
break;
}
case SerialNativeInterface.OS_SOLARIS: {
PORTNAMES_REGEXP = Pattern.compile("[0-9]*|[a-z]*");
PORTNAMES_PATH = "/dev/term/";
break;
}
case SerialNativeInterface.OS_MAC_OS_X: {
PORTNAMES_REGEXP = Pattern.compile("tty.(serial|usbserial|usbmodem).*");
PORTNAMES_PATH = "/dev/";
break;
}
case SerialNativeInterface.OS_WINDOWS: {
PORTNAMES_REGEXP = Pattern.compile("");
PORTNAMES_PATH = "";
break;
}
default: {
PORTNAMES_REGEXP = null;
PORTNAMES_PATH = null;
break;
}
}
}
//since 2.1.0 -> Fully rewrited port name comparator
private static final Comparator<String> PORTNAMES_COMPARATOR = new Comparator<String>() {
@Override
public int compare(String valueA, String valueB) {
if(valueA.equalsIgnoreCase(valueB)){
return valueA.compareTo(valueB);
}
int minLength = Math.min(valueA.length(), valueB.length());
int shiftA = 0;
int shiftB = 0;
for(int i = 0; i < minLength; i++){
char charA = valueA.charAt(i - shiftA);
char charB = valueB.charAt(i - shiftB);
if(charA != charB){
if(Character.isDigit(charA) && Character.isDigit(charB)){
int[] resultsA = getNumberAndLastIndex(valueA, i - shiftA);
int[] resultsB = getNumberAndLastIndex(valueB, i - shiftB);
if(resultsA[0] != resultsB[0]){
return resultsA[0] - resultsB[0];
}
if(valueA.length() < valueB.length()){
i = resultsA[1];
shiftB = resultsA[1] - resultsB[1];
}
else {
i = resultsB[1];
shiftA = resultsB[1] - resultsA[1];
}
}
else {
if(Character.toLowerCase(charA) - Character.toLowerCase(charB) != 0){
return Character.toLowerCase(charA) - Character.toLowerCase(charB);
}
}
}
}
return valueA.compareToIgnoreCase(valueB);
}
/**
* Evaluate port <b>index/number</b> from <b>startIndex</b> to the number end. For example:
* for port name <b>serial-123-FF</b> you should invoke this method with <b>startIndex = 7</b>
*
* @return If port <b>index/number</b> correctly evaluated it value will be returned<br>
* <b>returnArray[0] = index/number</b><br>
* <b>returnArray[1] = stopIndex</b><br>
*
* If incorrect:<br>
* <b>returnArray[0] = -1</b><br>
* <b>returnArray[1] = startIndex</b><br>
*
* For this name <b>serial-123-FF</b> result is:
* <b>returnArray[0] = 123</b><br>
* <b>returnArray[1] = 10</b><br>
*/
private int[] getNumberAndLastIndex(String str, int startIndex) {
String numberValue = "";
int[] returnValues = {-1, startIndex};
for(int i = startIndex; i < str.length(); i++){
returnValues[1] = i;
char c = str.charAt(i);
if(Character.isDigit(c)){
numberValue += c;
}
else {
break;
}
}
try {
returnValues[0] = Integer.valueOf(numberValue);
}
catch (Exception ex) {
//Do nothing
}
return returnValues;
}
};
//<-since 2.1.0
/**
* Get sorted array of serial ports in the system using default settings:<br>
*
* <b>Search path</b><br>
* Windows - ""(always ignored)<br>
* Linux - "/dev/"<br>
* Solaris - "/dev/term/"<br>
* MacOSX - "/dev/"<br>
*
* <b>RegExp</b><br>
* Windows - ""<br>
* Linux - "(ttyS|ttyUSB|ttyACM|ttyAMA|rfcomm)[0-9]{1,3}"<br>
* Solaris - "[0-9]*|[a-z]*"<br>
* MacOSX - "tty.(serial|usbserial|usbmodem).*"<br>
*
* @return String array. If there is no ports in the system String[]
* with <b>zero</b> length will be returned (since jSSC-0.8 in previous versions null will be returned)
*/
public static String[] getPortNames() {
return getPortNames(PORTNAMES_PATH, PORTNAMES_REGEXP, PORTNAMES_COMPARATOR);
}
/**
* Get sorted array of serial ports in the system located on searchPath
*
* @param searchPath Path for searching serial ports <b>(not null)</b><br>
* The default search paths:<br>
* Linux, MacOSX: <b>/dev/</b><br>
* Solaris: <b>/dev/term/</b><br>
* Windows: <b>this parameter ingored</b>
*
* @return String array. If there is no ports in the system String[]
*
* @since 2.3.0
*/
public static String[] getPortNames(String searchPath) {
return getPortNames(searchPath, PORTNAMES_REGEXP, PORTNAMES_COMPARATOR);
}
/**
* Get sorted array of serial ports in the system matched pattern
*
* @param pattern RegExp pattern for matching port names <b>(not null)</b>
*
* @return String array. If there is no ports in the system String[]
*
* @since 2.3.0
*/
public static String[] getPortNames(Pattern pattern) {
return getPortNames(PORTNAMES_PATH, pattern, PORTNAMES_COMPARATOR);
}
/**
* Get sorted array of serial ports in the system matched pattern
*
* @param comparator Comparator for sotring port names <b>(not null)</b>
*
* @return String array. If there is no ports in the system String[]
*
* @since 2.3.0
*/
public static String[] getPortNames(Comparator<String> comparator) {
return getPortNames(PORTNAMES_PATH, PORTNAMES_REGEXP, comparator);
}
/**
* Get sorted array of serial ports in the system located on searchPath, matched pattern
*
* @param searchPath Path for searching serial ports <b>(not null)</b><br>
* The default search paths:<br>
* Linux, MacOSX: <b>/dev/</b><br>
* Solaris: <b>/dev/term/</b><br>
* Windows: <b>this parameter ingored</b>
* @param pattern RegExp pattern for matching port names <b>(not null)</b>
*
* @return String array. If there is no ports in the system String[]
*
* @since 2.3.0
*/
public static String[] getPortNames(String searchPath, Pattern pattern) {
return getPortNames(searchPath, pattern, PORTNAMES_COMPARATOR);
}
/**
* Get sorted array of serial ports in the system located on searchPath and sorted by comparator
*
* @param searchPath Path for searching serial ports <b>(not null)</b><br>
* The default search paths:<br>
* Linux, MacOSX: <b>/dev/</b><br>
* Solaris: <b>/dev/term/</b><br>
* Windows: <b>this parameter ingored</b>
* @param comparator Comparator for sotring port names <b>(not null)</b>
*
* @return String array. If there is no ports in the system String[]
*
* @since 2.3.0
*/
public static String[] getPortNames(String searchPath, Comparator<String> comparator) {
return getPortNames(searchPath, PORTNAMES_REGEXP, comparator);
}
/**
* Get sorted array of serial ports in the system matched pattern and sorted by comparator
*
* @param pattern RegExp pattern for matching port names <b>(not null)</b>
* @param comparator Comparator for sotring port names <b>(not null)</b>
*
* @return String array. If there is no ports in the system String[]
*
* @since 2.3.0
*/
public static String[] getPortNames(Pattern pattern, Comparator<String> comparator) {
return getPortNames(PORTNAMES_PATH, pattern, comparator);
}
/**
* Get sorted array of serial ports in the system located on searchPath, matched pattern and sorted by comparator
*
* @param searchPath Path for searching serial ports <b>(not null)</b><br>
* The default search paths:<br>
* Linux, MacOSX: <b>/dev/</b><br>
* Solaris: <b>/dev/term/</b><br>
* Windows: <b>this parameter ingored</b>
* @param pattern RegExp pattern for matching port names <b>(not null)</b>
* @param comparator Comparator for sotring port names <b>(not null)</b>
*
* @return String array. If there is no ports in the system String[]
*
* @since 2.3.0
*/
public static String[] getPortNames(String searchPath, Pattern pattern, Comparator<String> comparator) {
if(searchPath == null || pattern == null || comparator == null){
return new String[]{};
}
if(SerialNativeInterface.getOsType() == SerialNativeInterface.OS_WINDOWS){
return getWindowsPortNames(pattern, comparator);
}
return getUnixBasedPortNames(searchPath, pattern, comparator);
}
/**
* Get serial port names in Windows
*
* @since 2.3.0
*/
private static String[] getWindowsPortNames(Pattern pattern, Comparator<String> comparator) {
String[] portNames = serialInterface.getSerialPortNames();
if(portNames == null){
return new String[]{};
}
TreeSet<String> ports = new TreeSet<String>(comparator);
for(String portName : portNames){
if(pattern.matcher(portName).find()){
ports.add(portName);
}
}
return ports.toArray(new String[ports.size()]);
}
/**
* Universal method for getting port names of _nix based systems
*/
private static String[] getUnixBasedPortNames(String searchPath, Pattern pattern, Comparator<String> comparator) {
searchPath = (searchPath.equals("") ? searchPath : (searchPath.endsWith("/") ? searchPath : searchPath + "/"));
String[] returnArray = new String[]{};
File dir = new File(searchPath);
if(dir.exists() && dir.isDirectory()){
File[] files = dir.listFiles();
if(files.length > 0){
TreeSet<String> portsTree = new TreeSet<String>(comparator);
for(File file : files){
String fileName = file.getName();
if(!file.isDirectory() && !file.isFile() && pattern.matcher(fileName).find()){
String portName = searchPath + fileName;
long portHandle = serialInterface.openPort(portName, false);//Open port without TIOCEXCL
if(portHandle < 0 && portHandle != SerialNativeInterface.ERR_PORT_BUSY){
continue;
}
else if(portHandle != SerialNativeInterface.ERR_PORT_BUSY) {
serialInterface.closePort(portHandle);
}
portsTree.add(portName);
}
}
returnArray = portsTree.toArray(returnArray);
}
}
return returnArray;
}
}

View File

@ -1,64 +0,0 @@
/* jSSC (Java Simple Serial Connector) - serial port communication library.
* © Alexey Sokolov (scream3r), 2010-2014.
*
* This file is part of jSSC.
*
* jSSC is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* jSSC is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with jSSC. If not, see <http://www.gnu.org/licenses/>.
*
* If you use jSSC in public project you can inform me about this by e-mail,
* of course if you want it.
*
* e-mail: scream3r.org@gmail.com
* web-site: http://scream3r.org | http://code.google.com/p/java-simple-serial-connector/
*/
package jssc;
/**
*
* @author scream3r
*/
public class SerialPortTimeoutException extends Exception {
private String portName;
private String methodName;
private int timeoutValue;
public SerialPortTimeoutException(String portName, String methodName, int timeoutValue) {
super("Port name - " + portName + "; Method name - " + methodName + "; Serial port operation timeout (" + timeoutValue + " ms).");
this.portName = portName;
this.methodName = methodName;
this.timeoutValue = timeoutValue;
}
/**
* Getting port name during operation with which the exception was called
*/
public String getPortName(){
return portName;
}
/**
* Getting method name during execution of which the exception was called
*/
public String getMethodName(){
return methodName;
}
/**
* Getting timeout value in millisecond
*/
public int getTimeoutValue(){
return timeoutValue;
}
}