diff --git a/build.gradle b/build.gradle index 3451242..b92bdd3 100644 --- a/build.gradle +++ b/build.gradle @@ -5,7 +5,7 @@ apply plugin: 'osgi' group = 'com.fazecast' archivesBaseName = 'jSerialComm' -version = '2.4.1' +version = '2.4.2' ext.moduleName = 'com.fazecast.jSerialComm' assert hasProperty('java6Home'): "Set the property 'java6Home' in your gradle.properties file pointing to a Java 6 JDK installation" diff --git a/src/main/c/Android/jni/SerialPort_Android.c b/src/main/c/Android/jni/SerialPort_Android.c index 91313e1..c86d727 100644 --- a/src/main/c/Android/jni/SerialPort_Android.c +++ b/src/main/c/Android/jni/SerialPort_Android.c @@ -2,7 +2,7 @@ * SerialPort_Android.c * * Created on: Mar 13, 2015 - * Last Updated on: Feb 11, 2019 + * Last Updated on: Mar 07, 2019 * Author: Will Hedgecock * * Copyright (C) 2012-2019 Fazecast, Inc. @@ -671,4 +671,12 @@ JNIEXPORT jboolean JNICALL Java_com_fazecast_jSerialComm_SerialPort_getDSR(JNIEn return (ioctl(serialPortFD, TIOCMGET, &modemBits) == 0) && (modemBits & TIOCM_LE); } +JNIEXPORT jboolean JNICALL Java_com_fazecast_jSerialComm_SerialPort_getDCD(JNIEnv *env, jobject obj, jlong serialPortFD) +{ + if (serialPortFD <= 0) + return JNI_FALSE; + int modemBits = 0; + return (ioctl(serialPortFD, TIOCMGET, &modemBits) == 0) && (modemBits & TIOCM_CAR); +} + #endif diff --git a/src/main/c/Android/jni/com_fazecast_jSerialComm_SerialPort.h b/src/main/c/Android/jni/com_fazecast_jSerialComm_SerialPort.h index 0adfdf4..0efc55c 100644 --- a/src/main/c/Android/jni/com_fazecast_jSerialComm_SerialPort.h +++ b/src/main/c/Android/jni/com_fazecast_jSerialComm_SerialPort.h @@ -253,6 +253,14 @@ JNIEXPORT jboolean JNICALL Java_com_fazecast_jSerialComm_SerialPort_getCTS JNIEXPORT jboolean JNICALL Java_com_fazecast_jSerialComm_SerialPort_getDSR (JNIEnv *, jobject, jlong); +/* + * Class: com_fazecast_jSerialComm_SerialPort + * Method: getDCD + * Signature: (J)Z + */ +JNIEXPORT jboolean JNICALL Java_com_fazecast_jSerialComm_SerialPort_getDCD + (JNIEnv *, jobject, jlong); + #ifdef __cplusplus } #endif diff --git a/src/main/c/Posix/SerialPort_Posix.c b/src/main/c/Posix/SerialPort_Posix.c index bdf9b90..f83cc55 100644 --- a/src/main/c/Posix/SerialPort_Posix.c +++ b/src/main/c/Posix/SerialPort_Posix.c @@ -2,10 +2,10 @@ * SerialPort_Posix.c * * Created on: Feb 25, 2012 - * Last Updated on: Dec 07, 2018 + * Last Updated on: Mar 07, 2019 * Author: Will Hedgecock * - * Copyright (C) 2012-2018 Fazecast, Inc. + * Copyright (C) 2012-2019 Fazecast, Inc. * * This file is part of jSerialComm. * @@ -28,6 +28,7 @@ #include #include #include +#include #include #include #include @@ -247,35 +248,44 @@ JNIEXPORT jlong JNICALL Java_com_fazecast_jSerialComm_SerialPort_openPortNative( int serialPortFD = -1; if ((serialPortFD = open(portName, O_RDWR | O_NOCTTY | O_NONBLOCK)) > 0) { - // Clear any serial port flags and set up raw, non-canonical port parameters - struct termios options = { 0 }; - fcntl(serialPortFD, F_SETFL, 0); - tcgetattr(serialPortFD, &options); -#if defined(__sun__) - options.c_iflag &= ~(IGNBRK | BRKINT | PARMRK | ISTRIP | INLCR | IGNCR | ICRNL | IXON); - options.c_oflag &= ~OPOST; - options.c_lflag &= ~(ECHO | ECHONL | ICANON | ISIG | IEXTEN); - options.c_cflag &= ~(CSIZE | PARENB); - options.c_cflag |= CS8; -#else - cfmakeraw(&options); -#endif - if (!isDtrEnabled || !isRtsEnabled) - options.c_cflag &= ~HUPCL; - options.c_iflag |= BRKINT; - tcsetattr(serialPortFD, TCSANOW, &options); - - // Configure the port parameters and timeouts - if (Java_com_fazecast_jSerialComm_SerialPort_configPort(env, obj, serialPortFD)) - (*env)->SetBooleanField(env, obj, isOpenedField, JNI_TRUE); - else + // Ensure that multiple root users cannot access the device simultaneously + if (flock(serialPortFD, LOCK_EX | LOCK_NB) == -1) { - // Close the port if there was a problem setting the parameters - ioctl(serialPortFD, TIOCNXCL); - tcdrain(serialPortFD); while ((close(serialPortFD) == -1) && (errno != EBADF)); serialPortFD = -1; - (*env)->SetBooleanField(env, obj, isOpenedField, JNI_FALSE); + } + else + { + // Clear any serial port flags and set up raw, non-canonical port parameters + struct termios options = { 0 }; + fcntl(serialPortFD, F_SETFL, 0); + tcgetattr(serialPortFD, &options); +#if defined(__sun__) + options.c_iflag &= ~(IGNBRK | BRKINT | PARMRK | ISTRIP | INLCR | IGNCR | ICRNL | IXON); + options.c_oflag &= ~OPOST; + options.c_lflag &= ~(ECHO | ECHONL | ICANON | ISIG | IEXTEN); + options.c_cflag &= ~(CSIZE | PARENB); + options.c_cflag |= CS8; +#else + cfmakeraw(&options); +#endif + if (!isDtrEnabled || !isRtsEnabled) + options.c_cflag &= ~HUPCL; + options.c_iflag |= BRKINT; + tcsetattr(serialPortFD, TCSANOW, &options); + + // Configure the port parameters and timeouts + if (Java_com_fazecast_jSerialComm_SerialPort_configPort(env, obj, serialPortFD)) + (*env)->SetBooleanField(env, obj, isOpenedField, JNI_TRUE); + else + { + // Close the port if there was a problem setting the parameters + ioctl(serialPortFD, TIOCNXCL); + tcdrain(serialPortFD); + while ((close(serialPortFD) == -1) && (errno != EBADF)); + serialPortFD = -1; + (*env)->SetBooleanField(env, obj, isOpenedField, JNI_FALSE); + } } } @@ -482,6 +492,7 @@ JNIEXPORT jboolean JNICALL Java_com_fazecast_jSerialComm_SerialPort_closePortNat tcsetattr(serialPortFD, TCSANOW, &options); // Close the port + flock(serialPortFD, LOCK_UN); while ((close(serialPortFD) == -1) && (errno != EBADF)); (*env)->SetLongField(env, obj, serialPortFdField, -1l); return JNI_TRUE; @@ -782,3 +793,11 @@ JNIEXPORT jboolean JNICALL Java_com_fazecast_jSerialComm_SerialPort_getDSR(JNIEn int modemBits = 0; return (ioctl(serialPortFD, TIOCMGET, &modemBits) == 0) && (modemBits & TIOCM_LE); } + +JNIEXPORT jboolean JNICALL Java_com_fazecast_jSerialComm_SerialPort_getDCD(JNIEnv *env, jobject obj, jlong serialPortFD) +{ + if (serialPortFD <= 0) + return JNI_FALSE; + int modemBits = 0; + return (ioctl(serialPortFD, TIOCMGET, &modemBits) == 0) && (modemBits & TIOCM_CAR); +} diff --git a/src/main/c/Windows/Makefile b/src/main/c/Windows/Makefile index 89eae9d..3e7210b 100644 --- a/src/main/c/Windows/Makefile +++ b/src/main/c/Windows/Makefile @@ -3,7 +3,7 @@ COMPILE = cl LINK = link CFLAGS = /c /O2 /GF /GL /MT /EHsc /fp:precise /J /nologo /TP LDFLAGS = /DLL /LTCG /NOASSEMBLY /NOLOGO -INCLUDES = /I"$(JDK_HOME)/include" /I"$(JDK_HOME)/include/win32" +INCLUDES = /I"$(JDK_HOME)\include" /I"$(JDK_HOME)\include\win32" LIBRARIES = Advapi32.lib SetupAPI.lib DELETE = @del /q /f RMDIR = @rd /q /s diff --git a/src/main/c/Windows/SerialPort_Windows.c b/src/main/c/Windows/SerialPort_Windows.c index 40146aa..0a5f923 100644 --- a/src/main/c/Windows/SerialPort_Windows.c +++ b/src/main/c/Windows/SerialPort_Windows.c @@ -2,10 +2,10 @@ * SerialPort_Windows.c * * Created on: Feb 25, 2012 - * Last Updated on: Oct 31, 2018 + * Last Updated on: Mar 07, 2019 * Author: Will Hedgecock * - * Copyright (C) 2012-2018 Fazecast, Inc. + * Copyright (C) 2012-2019 Fazecast, Inc. * * This file is part of jSerialComm. * @@ -895,4 +895,13 @@ JNIEXPORT jboolean JNICALL Java_com_fazecast_jSerialComm_SerialPort_getDSR(JNIEn return GetCommModemStatus(serialPortHandle, &modemStatus) && (modemStatus & MS_DSR_ON); } +JNIEXPORT jboolean JNICALL Java_com_fazecast_jSerialComm_SerialPort_getDCD(JNIEnv *env, jobject obj, jlong serialPortFD) +{ + HANDLE serialPortHandle = (HANDLE)serialPortFD; + if (serialPortHandle == INVALID_HANDLE_VALUE) + return JNI_FALSE; + DWORD modemStatus = 0; + return GetCommModemStatus(serialPortHandle, &modemStatus) && (modemStatus & MS_RLSD_ON); +} + #endif diff --git a/src/main/java/com/fazecast/jSerialComm/SerialPort.java b/src/main/java/com/fazecast/jSerialComm/SerialPort.java index 6b13591..92d77f2 100644 --- a/src/main/java/com/fazecast/jSerialComm/SerialPort.java +++ b/src/main/java/com/fazecast/jSerialComm/SerialPort.java @@ -2,7 +2,7 @@ * SerialPort.java * * Created on: Feb 25, 2012 - * Last Updated on: Feb 11, 2019 + * Last Updated on: Mar 07, 2019 * Author: Will Hedgecock * * Copyright (C) 2012-2019 Fazecast, Inc. @@ -42,7 +42,7 @@ import java.util.Date; * This class provides native access to serial ports and devices without requiring external libraries or tools. * * @author Will Hedgecock <will.hedgecock@fazecast.com> - * @version 2.4.1 + * @version 2.4.2 * @see java.io.InputStream * @see java.io.OutputStream */ @@ -520,6 +520,7 @@ public final class SerialPort private final native boolean preclearDTR(); // Clear DTR line to 0 prior to opening private final native boolean getCTS(long portHandle); // Returns whether the CTS signal is 1 private final native boolean getDSR(long portHandle); // Returns whether the DSR signal is 1 + private final native boolean getDCD(long portHandle); // Returns whether the DCD signal is 1 /** * Returns the number of bytes available without blocking if {@link #readBytes(byte[], long)} were to be called immediately @@ -663,6 +664,12 @@ public final class SerialPort * @return Whether or not the DSR line is asserted. */ public final boolean getDSR() { return getDSR(portHandle); } + + /** + * Returns whether the DCD line is currently asserted. + * @return Whether or not the DCD line is asserted. + */ + public final boolean getDCD() { return getDCD(portHandle); } // Default Constructor private SerialPort() {} diff --git a/src/main/java/com/fazecast/jSerialComm/SerialPortDataListener.java b/src/main/java/com/fazecast/jSerialComm/SerialPortDataListener.java index fb94bfd..0a08fec 100644 --- a/src/main/java/com/fazecast/jSerialComm/SerialPortDataListener.java +++ b/src/main/java/com/fazecast/jSerialComm/SerialPortDataListener.java @@ -31,7 +31,7 @@ import java.util.EventListener; * This interface must be implemented to enable simple event-based serial port I/O. * * @author Will Hedgecock <will.hedgecock@fazecast.com> - * @version 2.4.1 + * @version 2.4.2 * @see java.util.EventListener */ public interface SerialPortDataListener extends EventListener diff --git a/src/main/java/com/fazecast/jSerialComm/SerialPortEvent.java b/src/main/java/com/fazecast/jSerialComm/SerialPortEvent.java index 4603204..4bff745 100644 --- a/src/main/java/com/fazecast/jSerialComm/SerialPortEvent.java +++ b/src/main/java/com/fazecast/jSerialComm/SerialPortEvent.java @@ -31,7 +31,7 @@ import java.util.EventObject; * This class describes an asynchronous serial port event. * * @author Will Hedgecock <will.hedgecock@fazecast.com> - * @version 2.4.1 + * @version 2.4.2 * @see java.util.EventObject */ public final class SerialPortEvent extends EventObject diff --git a/src/main/java/com/fazecast/jSerialComm/SerialPortIOException.java b/src/main/java/com/fazecast/jSerialComm/SerialPortIOException.java index bb78eaa..65f1dfb 100644 --- a/src/main/java/com/fazecast/jSerialComm/SerialPortIOException.java +++ b/src/main/java/com/fazecast/jSerialComm/SerialPortIOException.java @@ -31,7 +31,7 @@ import java.io.IOException; * This class describes a serial port IO exception. * * @author Will Hedgecock <will.hedgecock@fazecast.com> - * @version 2.4.1 + * @version 2.4.2 * @see java.io.IOException */ public final class SerialPortIOException extends IOException diff --git a/src/main/java/com/fazecast/jSerialComm/SerialPortPacketListener.java b/src/main/java/com/fazecast/jSerialComm/SerialPortPacketListener.java index d3e456c..de8994c 100644 --- a/src/main/java/com/fazecast/jSerialComm/SerialPortPacketListener.java +++ b/src/main/java/com/fazecast/jSerialComm/SerialPortPacketListener.java @@ -31,7 +31,7 @@ package com.fazecast.jSerialComm; * Note: Using this interface will negate any serial port read timeout settings since they make no sense in an asynchronous context. * * @author Will Hedgecock <will.hedgecock@fazecast.com> - * @version 2.4.1 + * @version 2.4.2 * @see com.fazecast.jSerialComm.SerialPortDataListener * @see java.util.EventListener */ diff --git a/src/main/java/com/fazecast/jSerialComm/SerialPortTimeoutException.java b/src/main/java/com/fazecast/jSerialComm/SerialPortTimeoutException.java index 2c1c634..c70965d 100644 --- a/src/main/java/com/fazecast/jSerialComm/SerialPortTimeoutException.java +++ b/src/main/java/com/fazecast/jSerialComm/SerialPortTimeoutException.java @@ -31,7 +31,7 @@ import java.io.InterruptedIOException; * This class describes a serial port timeout exception. * * @author Will Hedgecock <will.hedgecock@fazecast.com> - * @version 2.4.1 + * @version 2.4.2 * @see java.io.InterruptedIOException */ public final class SerialPortTimeoutException extends InterruptedIOException diff --git a/src/main/resources/Android/arm64-v8a/libjSerialComm.so b/src/main/resources/Android/arm64-v8a/libjSerialComm.so index 6b32082..b2ea0f4 100644 Binary files a/src/main/resources/Android/arm64-v8a/libjSerialComm.so and b/src/main/resources/Android/arm64-v8a/libjSerialComm.so differ diff --git a/src/main/resources/Android/armeabi-v7a/libjSerialComm.so b/src/main/resources/Android/armeabi-v7a/libjSerialComm.so index 06c6a38..3b03273 100644 Binary files a/src/main/resources/Android/armeabi-v7a/libjSerialComm.so and b/src/main/resources/Android/armeabi-v7a/libjSerialComm.so differ diff --git a/src/main/resources/Android/armeabi/libjSerialComm.so b/src/main/resources/Android/armeabi/libjSerialComm.so index 8e13754..82d3752 100644 Binary files a/src/main/resources/Android/armeabi/libjSerialComm.so and b/src/main/resources/Android/armeabi/libjSerialComm.so differ diff --git a/src/main/resources/Android/mips/libjSerialComm.so b/src/main/resources/Android/mips/libjSerialComm.so index 5793720..ff9b6e7 100644 Binary files a/src/main/resources/Android/mips/libjSerialComm.so and b/src/main/resources/Android/mips/libjSerialComm.so differ diff --git a/src/main/resources/Android/mips64/libjSerialComm.so b/src/main/resources/Android/mips64/libjSerialComm.so index cda1288..328a30a 100644 Binary files a/src/main/resources/Android/mips64/libjSerialComm.so and b/src/main/resources/Android/mips64/libjSerialComm.so differ diff --git a/src/main/resources/Android/x86/libjSerialComm.so b/src/main/resources/Android/x86/libjSerialComm.so index 19dcfbb..8c90d93 100644 Binary files a/src/main/resources/Android/x86/libjSerialComm.so and b/src/main/resources/Android/x86/libjSerialComm.so differ diff --git a/src/main/resources/Android/x86_64/libjSerialComm.so b/src/main/resources/Android/x86_64/libjSerialComm.so index 30be8f1..4290e90 100644 Binary files a/src/main/resources/Android/x86_64/libjSerialComm.so and b/src/main/resources/Android/x86_64/libjSerialComm.so differ diff --git a/src/main/resources/Linux/armv5/libjSerialComm.so b/src/main/resources/Linux/armv5/libjSerialComm.so index 2b69806..3623407 100644 Binary files a/src/main/resources/Linux/armv5/libjSerialComm.so and b/src/main/resources/Linux/armv5/libjSerialComm.so differ diff --git a/src/main/resources/Linux/armv6-hf/libjSerialComm.so b/src/main/resources/Linux/armv6-hf/libjSerialComm.so index 8030703..c907e10 100644 Binary files a/src/main/resources/Linux/armv6-hf/libjSerialComm.so and b/src/main/resources/Linux/armv6-hf/libjSerialComm.so differ diff --git a/src/main/resources/Linux/armv6/libjSerialComm.so b/src/main/resources/Linux/armv6/libjSerialComm.so index fac8918..4a50e7c 100644 Binary files a/src/main/resources/Linux/armv6/libjSerialComm.so and b/src/main/resources/Linux/armv6/libjSerialComm.so differ diff --git a/src/main/resources/Linux/armv7-hf/libjSerialComm.so b/src/main/resources/Linux/armv7-hf/libjSerialComm.so index 8030703..c907e10 100644 Binary files a/src/main/resources/Linux/armv7-hf/libjSerialComm.so and b/src/main/resources/Linux/armv7-hf/libjSerialComm.so differ diff --git a/src/main/resources/Linux/armv7/libjSerialComm.so b/src/main/resources/Linux/armv7/libjSerialComm.so index ed17238..830aaf2 100644 Binary files a/src/main/resources/Linux/armv7/libjSerialComm.so and b/src/main/resources/Linux/armv7/libjSerialComm.so differ diff --git a/src/main/resources/Linux/armv8_32/libjSerialComm.so b/src/main/resources/Linux/armv8_32/libjSerialComm.so index aedfbc5..14a7db0 100644 Binary files a/src/main/resources/Linux/armv8_32/libjSerialComm.so and b/src/main/resources/Linux/armv8_32/libjSerialComm.so differ diff --git a/src/main/resources/Linux/armv8_64/libjSerialComm.so b/src/main/resources/Linux/armv8_64/libjSerialComm.so index e4fbe88..4f1e548 100644 Binary files a/src/main/resources/Linux/armv8_64/libjSerialComm.so and b/src/main/resources/Linux/armv8_64/libjSerialComm.so differ diff --git a/src/main/resources/Linux/x86/libjSerialComm.so b/src/main/resources/Linux/x86/libjSerialComm.so index 28af3cf..e5502ee 100644 Binary files a/src/main/resources/Linux/x86/libjSerialComm.so and b/src/main/resources/Linux/x86/libjSerialComm.so differ diff --git a/src/main/resources/Linux/x86_64/libjSerialComm.so b/src/main/resources/Linux/x86_64/libjSerialComm.so index f98f1b1..352a68e 100644 Binary files a/src/main/resources/Linux/x86_64/libjSerialComm.so and b/src/main/resources/Linux/x86_64/libjSerialComm.so differ diff --git a/src/main/resources/OSX/x86_64/libjSerialComm.jnilib b/src/main/resources/OSX/x86_64/libjSerialComm.jnilib index 5e65379..7ea79a8 100755 Binary files a/src/main/resources/OSX/x86_64/libjSerialComm.jnilib and b/src/main/resources/OSX/x86_64/libjSerialComm.jnilib differ diff --git a/src/main/resources/Solaris/sparcv8plus_32/libjSerialComm.so b/src/main/resources/Solaris/sparcv8plus_32/libjSerialComm.so index e6ca801..813c9f9 100644 Binary files a/src/main/resources/Solaris/sparcv8plus_32/libjSerialComm.so and b/src/main/resources/Solaris/sparcv8plus_32/libjSerialComm.so differ diff --git a/src/main/resources/Solaris/sparcv9_64/libjSerialComm.so b/src/main/resources/Solaris/sparcv9_64/libjSerialComm.so index 0e71a7e..460aad3 100644 Binary files a/src/main/resources/Solaris/sparcv9_64/libjSerialComm.so and b/src/main/resources/Solaris/sparcv9_64/libjSerialComm.so differ diff --git a/src/main/resources/Solaris/x86/libjSerialComm.so b/src/main/resources/Solaris/x86/libjSerialComm.so index a70d30b..c81dcf5 100644 Binary files a/src/main/resources/Solaris/x86/libjSerialComm.so and b/src/main/resources/Solaris/x86/libjSerialComm.so differ diff --git a/src/main/resources/Solaris/x86_64/libjSerialComm.so b/src/main/resources/Solaris/x86_64/libjSerialComm.so index b748a41..31eab25 100644 Binary files a/src/main/resources/Solaris/x86_64/libjSerialComm.so and b/src/main/resources/Solaris/x86_64/libjSerialComm.so differ diff --git a/src/main/resources/Windows/x86/jSerialComm.dll b/src/main/resources/Windows/x86/jSerialComm.dll index 07c87c4..922d759 100644 Binary files a/src/main/resources/Windows/x86/jSerialComm.dll and b/src/main/resources/Windows/x86/jSerialComm.dll differ diff --git a/src/main/resources/Windows/x86_64/jSerialComm.dll b/src/main/resources/Windows/x86_64/jSerialComm.dll index 266f47a..716161b 100644 Binary files a/src/main/resources/Windows/x86_64/jSerialComm.dll and b/src/main/resources/Windows/x86_64/jSerialComm.dll differ