Fix bug where reconfiguring ports after setting timeouts negates the timeout settings.
This commit is contained in:
parent
cbc7f952b4
commit
6a3cc212db
14
INSTALL
14
INSTALL
|
@ -123,29 +123,29 @@ Maven:
|
|||
<dependency>
|
||||
<groupId>com.fazecast</groupId>
|
||||
<artifactId>jSerialComm</artifactId>
|
||||
<version>1.3.11</version>
|
||||
<version>[1.0.0,2.0.0)</version>
|
||||
</dependency>
|
||||
|
||||
Ivy:
|
||||
|
||||
<dependency org="com.fazecast" name="jSerialComm" rev="1.3.11"/>
|
||||
<dependency org="com.fazecast" name="jSerialComm" rev="[1.0.0,2.0.0)"/>
|
||||
|
||||
Groovy:
|
||||
|
||||
@Grab(group='com.fazecast', module='jSerialComm', version='1.3.11')
|
||||
@Grab(group='com.fazecast', module='jSerialComm', version='[1.0.0,2.0.0)')
|
||||
|
||||
Gradle:
|
||||
|
||||
compile 'com.fazecast:jSerialComm:1.3.11'
|
||||
compile 'com.fazecast:jSerialComm:[1.0.0,2.0.0)'
|
||||
|
||||
Buildr:
|
||||
|
||||
compile.with 'com.fazecast:jSerialComm:jar:1.3.11'
|
||||
compile.with 'com.fazecast:jSerialComm:jar:[1.0.0,2.0.0)'
|
||||
|
||||
Scala/SBT:
|
||||
|
||||
libraryDependencies += "com.fazecast" % "jSerialComm" % "1.3.11"
|
||||
libraryDependencies += "com.fazecast" % "jSerialComm" % "[1.0.0,2.0.0)"
|
||||
|
||||
Leiningen:
|
||||
|
||||
[com.fazecast/jSerialComm "1.3.11"]
|
||||
[com.fazecast/jSerialComm "[1.0.0,2.0.0)"]
|
||||
|
|
|
@ -119,6 +119,9 @@ 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
|
||||
fcntl(serialPortFD, F_SETFL, 0);
|
||||
|
||||
// Configure the port parameters and timeouts
|
||||
if (Java_com_fazecast_jSerialComm_SerialPort_configPort(env, obj, serialPortFD) && Java_com_fazecast_jSerialComm_SerialPort_configFlowControl(env, obj, serialPortFD) &&
|
||||
Java_com_fazecast_jSerialComm_SerialPort_configEventFlags(env, obj, serialPortFD))
|
||||
|
@ -154,9 +157,6 @@ JNIEXPORT jboolean JNICALL Java_com_fazecast_jSerialComm_SerialPort_configPort(J
|
|||
tcflag_t stopBits = ((stopBitsInt == com_fazecast_jSerialComm_SerialPort_ONE_STOP_BIT) || (stopBitsInt == com_fazecast_jSerialComm_SerialPort_ONE_POINT_FIVE_STOP_BITS)) ? 0 : CSTOPB;
|
||||
tcflag_t parity = (parityInt == com_fazecast_jSerialComm_SerialPort_NO_PARITY) ? 0 : (parityInt == com_fazecast_jSerialComm_SerialPort_ODD_PARITY) ? (PARENB | PARODD) : (parityInt == com_fazecast_jSerialComm_SerialPort_EVEN_PARITY) ? PARENB : (parityInt == com_fazecast_jSerialComm_SerialPort_MARK_PARITY) ? (PARENB | CMSPAR | PARODD) : (PARENB | CMSPAR);
|
||||
|
||||
// Clear any serial port flags
|
||||
fcntl(serialPortFD, F_SETFL, 0);
|
||||
|
||||
// Set raw-mode to allow the use of tcsetattr() and ioctl()
|
||||
tcgetattr(serialPortFD, &options);
|
||||
cfmakeraw(&options);
|
||||
|
|
|
@ -170,6 +170,9 @@ 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
|
||||
fcntl(serialPortFD, F_SETFL, 0);
|
||||
|
||||
// Configure the port parameters and timeouts
|
||||
if (Java_com_fazecast_jSerialComm_SerialPort_configPort(env, obj, serialPortFD) && Java_com_fazecast_jSerialComm_SerialPort_configFlowControl(env, obj, serialPortFD) &&
|
||||
Java_com_fazecast_jSerialComm_SerialPort_configEventFlags(env, obj, serialPortFD))
|
||||
|
@ -204,9 +207,6 @@ JNIEXPORT jboolean JNICALL Java_com_fazecast_jSerialComm_SerialPort_configPort(J
|
|||
tcflag_t stopBits = ((stopBitsInt == com_fazecast_jSerialComm_SerialPort_ONE_STOP_BIT) || (stopBitsInt == com_fazecast_jSerialComm_SerialPort_ONE_POINT_FIVE_STOP_BITS)) ? 0 : CSTOPB;
|
||||
tcflag_t parity = (parityInt == com_fazecast_jSerialComm_SerialPort_NO_PARITY) ? 0 : (parityInt == com_fazecast_jSerialComm_SerialPort_ODD_PARITY) ? (PARENB | PARODD) : (parityInt == com_fazecast_jSerialComm_SerialPort_EVEN_PARITY) ? PARENB : (parityInt == com_fazecast_jSerialComm_SerialPort_MARK_PARITY) ? (PARENB | CMSPAR | PARODD) : (PARENB | CMSPAR);
|
||||
|
||||
// Clear any serial port flags
|
||||
fcntl(serialPortFD, F_SETFL, 0);
|
||||
|
||||
// Set raw-mode to allow the use of tcsetattr() and ioctl()
|
||||
tcgetattr(serialPortFD, &options);
|
||||
cfmakeraw(&options);
|
||||
|
|
|
@ -40,7 +40,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 1.3.11
|
||||
* @version 1.3.12
|
||||
* @see java.io.InputStream
|
||||
* @see java.io.OutputStream
|
||||
*/
|
||||
|
@ -165,21 +165,29 @@ public final class SerialPort
|
|||
try
|
||||
{
|
||||
InputStream fileContents = SerialPort.class.getResourceAsStream("/" + libraryPath + "/" + fileName);
|
||||
FileOutputStream destinationFileContents = new FileOutputStream(tempNativeLibrary);
|
||||
byte transferBuffer[] = new byte[4096];
|
||||
int numBytesRead;
|
||||
|
||||
while ((numBytesRead = fileContents.read(transferBuffer)) > 0)
|
||||
destinationFileContents.write(transferBuffer, 0, numBytesRead);
|
||||
|
||||
fileContents.close();
|
||||
destinationFileContents.close();
|
||||
if (fileContents == null)
|
||||
{
|
||||
System.err.println("Could not locate or access the native jSerialComm shared library.");
|
||||
System.err.println("If you are using multiple projects with interdependencies, you may need to fix your build settings to ensure that library resources are copied properly.");
|
||||
}
|
||||
else
|
||||
{
|
||||
FileOutputStream destinationFileContents = new FileOutputStream(tempNativeLibrary);
|
||||
byte transferBuffer[] = new byte[4096];
|
||||
int numBytesRead;
|
||||
|
||||
while ((numBytesRead = fileContents.read(transferBuffer)) > 0)
|
||||
destinationFileContents.write(transferBuffer, 0, numBytesRead);
|
||||
|
||||
fileContents.close();
|
||||
destinationFileContents.close();
|
||||
|
||||
// Load native library
|
||||
System.load(tempFileName);
|
||||
initializeLibrary();
|
||||
}
|
||||
}
|
||||
catch (Exception e) { e.printStackTrace(); }
|
||||
|
||||
// Load native library
|
||||
System.load(tempFileName);
|
||||
initializeLibrary();
|
||||
}
|
||||
|
||||
// Static symbolic link testing function
|
||||
|
@ -337,7 +345,7 @@ public final class SerialPort
|
|||
}
|
||||
}
|
||||
|
||||
try { Thread.sleep(500); } catch (Exception e) { e.printStackTrace(); }
|
||||
try { Thread.sleep(1000); } catch (Exception e) { e.printStackTrace(); }
|
||||
if ((portHandle = openPortNative()) > 0)
|
||||
{
|
||||
inputStream = new SerialPortInputStream();
|
||||
|
|
|
@ -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 1.3.11
|
||||
* @version 1.3.12
|
||||
* @see java.util.EventListener
|
||||
*/
|
||||
public interface SerialPortDataListener extends EventListener
|
||||
|
|
|
@ -31,7 +31,7 @@ import java.util.EventObject;
|
|||
* This class describes an asynchronous serial port event.
|
||||
*
|
||||
* @author Will Hedgecock <will.hedgecock@fazecast.com>
|
||||
* @version 1.3.11
|
||||
* @version 1.3.12
|
||||
* @see java.util.EventObject
|
||||
*/
|
||||
public final class SerialPortEvent extends EventObject
|
||||
|
|
|
@ -31,7 +31,7 @@ package com.fazecast.jSerialComm;
|
|||
* <i>Note</i>: 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 1.3.11
|
||||
* @version 1.3.12
|
||||
* @see com.fazecast.jSerialComm.SerialPortDataListener
|
||||
* @see java.util.EventListener
|
||||
*/
|
||||
|
|
|
@ -32,7 +32,7 @@ import java.util.Scanner;
|
|||
* This class provides a test case for the jSerialComm library.
|
||||
*
|
||||
* @author Will Hedgecock <will.hedgecock@gmail.com>
|
||||
* @version 1.3.11
|
||||
* @version 1.3.12
|
||||
* @see java.io.InputStream
|
||||
* @see java.io.OutputStream
|
||||
*/
|
||||
|
|
Loading…
Reference in New Issue