Fixed Mac OS bug of death.
This commit is contained in:
parent
e3525ab5b5
commit
bc7ae187f6
16
INSTALL
16
INSTALL
|
@ -84,33 +84,33 @@ Alternatively, you can automatically add jSerialComm to your project as a depend
|
||||||
Maven:
|
Maven:
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.fazecast.jSerialComm</groupId>
|
<groupId>com.fazecast</groupId>
|
||||||
<artifactId>jSerialComm</artifactId>
|
<artifactId>jSerialComm</artifactId>
|
||||||
<version>1.0.0</version>
|
<version>1.0.1</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
Ivy:
|
Ivy:
|
||||||
|
|
||||||
<dependency org="com.fazecast.jSerialComm" name="jSerialComm" rev="1.0.0"/>
|
<dependency org="com.fazecast" name="jSerialComm" rev="1.0.1"/>
|
||||||
|
|
||||||
Grape:
|
Grape:
|
||||||
|
|
||||||
@Grapes(
|
@Grapes(
|
||||||
@Grab(group='com.fazecast.jSerialComm', module='jSerialComm', version='1.0.0')
|
@Grab(group='com.fazecast', module='jSerialComm', version='1.0.1')
|
||||||
)
|
)
|
||||||
|
|
||||||
Gradle:
|
Gradle:
|
||||||
|
|
||||||
'com.fazecast.jSerialComm:jSerialComm:1.0.0'
|
'com.fazecast:jSerialComm:1.0.1'
|
||||||
|
|
||||||
Buildr:
|
Buildr:
|
||||||
|
|
||||||
'com.fazecast.jSerialComm:jSerialComm:jar:1.0.0'
|
'com.fazecast:jSerialComm:jar:1.0.1'
|
||||||
|
|
||||||
SBT:
|
SBT:
|
||||||
|
|
||||||
libraryDependencies += "com.fazecast.jSerialComm" % "jSerialComm" % "1.0.0"
|
libraryDependencies += "com.fazecast" % "jSerialComm" % "1.0.1"
|
||||||
|
|
||||||
Leiningen:
|
Leiningen:
|
||||||
|
|
||||||
[com.fazecast.jSerialComm/jSerialComm "1.0.0"]
|
[com.fazecast/jSerialComm "1.0.1"]
|
||||||
|
|
|
@ -2,9 +2,9 @@ apply plugin: 'java'
|
||||||
apply plugin: 'eclipse'
|
apply plugin: 'eclipse'
|
||||||
apply plugin: 'maven'
|
apply plugin: 'maven'
|
||||||
|
|
||||||
group = 'com.fazecast.jSerialComm'
|
group = 'com.fazecast'
|
||||||
archivesBaseName = 'jSerialComm'
|
archivesBaseName = 'jSerialComm'
|
||||||
version = '1.0.0'
|
version = '1.0.1'
|
||||||
|
|
||||||
sourceCompatibility = 1.6
|
sourceCompatibility = 1.6
|
||||||
targetCompatibility = 1.6
|
targetCompatibility = 1.6
|
||||||
|
|
|
@ -132,7 +132,7 @@ JNIEXPORT jboolean JNICALL Java_com_fazecast_jSerialComm_SerialPort_configPort(J
|
||||||
options.c_lflag = 0;
|
options.c_lflag = 0;
|
||||||
|
|
||||||
// Apply changes
|
// Apply changes
|
||||||
tcsetattr(portFD, TCSAFLUSH, &options);
|
tcsetattr(portFD, TCSANOW, &options);
|
||||||
ioctl(portFD, TIOCEXCL); // Block non-root users from using this port
|
ioctl(portFD, TIOCEXCL); // Block non-root users from using this port
|
||||||
|
|
||||||
// Allow custom baud rate (only for true serial ports)
|
// Allow custom baud rate (only for true serial ports)
|
||||||
|
@ -168,7 +168,7 @@ JNIEXPORT jboolean JNICALL Java_com_fazecast_jSerialComm_SerialPort_configFlowCo
|
||||||
options.c_lflag = 0;
|
options.c_lflag = 0;
|
||||||
|
|
||||||
// Apply changes
|
// Apply changes
|
||||||
tcsetattr(portFD, TCSAFLUSH, &options);
|
tcsetattr(portFD, TCSANOW, &options);
|
||||||
return JNI_TRUE;
|
return JNI_TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -221,7 +221,7 @@ JNIEXPORT jboolean JNICALL Java_com_fazecast_jSerialComm_SerialPort_configTimeou
|
||||||
|
|
||||||
// Apply changes
|
// Apply changes
|
||||||
fcntl(serialFD, F_SETFL, flags);
|
fcntl(serialFD, F_SETFL, flags);
|
||||||
return (tcsetattr(serialFD, TCSAFLUSH, &options) == 0) ? JNI_TRUE : JNI_FALSE;
|
return (tcsetattr(serialFD, TCSANOW, &options) == 0) ? JNI_TRUE : JNI_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
JNIEXPORT jboolean JNICALL Java_com_fazecast_jSerialComm_SerialPort_configEventFlags(JNIEnv *env, jobject obj)
|
JNIEXPORT jboolean JNICALL Java_com_fazecast_jSerialComm_SerialPort_configEventFlags(JNIEnv *env, jobject obj)
|
||||||
|
@ -244,7 +244,7 @@ JNIEXPORT jboolean JNICALL Java_com_fazecast_jSerialComm_SerialPort_configEventF
|
||||||
options.c_cc[VMIN] = 0;
|
options.c_cc[VMIN] = 0;
|
||||||
options.c_cc[VTIME] = 10;
|
options.c_cc[VTIME] = 10;
|
||||||
fcntl(serialFD, F_SETFL, flags);
|
fcntl(serialFD, F_SETFL, flags);
|
||||||
tcsetattr(serialFD, TCSAFLUSH, &options);
|
tcsetattr(serialFD, TCSANOW, &options);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
Java_com_fazecast_jSerialComm_SerialPort_configTimeouts(env, obj);
|
Java_com_fazecast_jSerialComm_SerialPort_configTimeouts(env, obj);
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
* SerialPort_OSX.cpp
|
* SerialPort_OSX.cpp
|
||||||
*
|
*
|
||||||
* Created on: Feb 25, 2012
|
* Created on: Feb 25, 2012
|
||||||
* Last Updated on: Feb 27, 2015
|
* Last Updated on: Mar 17, 2015
|
||||||
* Author: Will Hedgecock
|
* Author: Will Hedgecock
|
||||||
*
|
*
|
||||||
* Copyright (C) 2012-2015 Fazecast, Inc.
|
* Copyright (C) 2012-2015 Fazecast, Inc.
|
||||||
|
@ -119,8 +119,14 @@ JNIEXPORT jboolean JNICALL Java_com_fazecast_jSerialComm_SerialPort_configPort(J
|
||||||
if (portFD <= 0)
|
if (portFD <= 0)
|
||||||
return JNI_FALSE;
|
return JNI_FALSE;
|
||||||
|
|
||||||
|
// Block non-root users from using this port
|
||||||
|
if (ioctl(portFD, TIOCEXCL) == -1)
|
||||||
|
return JNI_FALSE;
|
||||||
|
|
||||||
// Set raw-mode to allow the use of tcsetattr() and ioctl()
|
// Set raw-mode to allow the use of tcsetattr() and ioctl()
|
||||||
fcntl(portFD, F_SETFL, 0);
|
if (fcntl(portFD, F_SETFL, 0) == -1)
|
||||||
|
return JNI_FALSE;
|
||||||
|
tcgetattr(portFD, &options);
|
||||||
cfmakeraw(&options);
|
cfmakeraw(&options);
|
||||||
|
|
||||||
// Get port parameters from Java class
|
// Get port parameters from Java class
|
||||||
|
@ -132,20 +138,16 @@ 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 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);
|
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);
|
||||||
|
|
||||||
// Retrieve existing port configuration
|
|
||||||
tcgetattr(portFD, &options);
|
|
||||||
|
|
||||||
// Set updated port parameters
|
// Set updated port parameters
|
||||||
options.c_cflag = (B38400 | byteSize | stopBits | parity | CLOCAL | CREAD);
|
cfsetspeed(&options, B38400);
|
||||||
|
options.c_cflag |= (byteSize | stopBits | parity | CLOCAL | CREAD);
|
||||||
if (parityInt == com_fazecast_jSerialComm_SerialPort_SPACE_PARITY)
|
if (parityInt == com_fazecast_jSerialComm_SerialPort_SPACE_PARITY)
|
||||||
options.c_cflag &= ~PARODD;
|
options.c_cflag &= ~PARODD;
|
||||||
options.c_iflag = ((parityInt > 0) ? (INPCK | ISTRIP) : IGNPAR);
|
options.c_iflag |= ((parityInt > 0) ? (INPCK | ISTRIP) : IGNPAR);
|
||||||
options.c_oflag = 0;
|
|
||||||
options.c_lflag = 0;
|
|
||||||
|
|
||||||
// Apply changes
|
// Apply changes
|
||||||
tcsetattr(portFD, TCSAFLUSH, &options);
|
if (tcsetattr(portFD, TCSANOW, &options) == -1)
|
||||||
ioctl(portFD, TIOCEXCL); // Block non-root users from using this port
|
return JNI_FALSE;
|
||||||
return (ioctl(portFD, IOSSIOSPEED, &baudRate) == -1) ? JNI_FALSE : JNI_TRUE;
|
return (ioctl(portFD, IOSSIOSPEED, &baudRate) == -1) ? JNI_FALSE : JNI_TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -159,8 +161,8 @@ JNIEXPORT jboolean JNICALL Java_com_fazecast_jSerialComm_SerialPort_configFlowCo
|
||||||
|
|
||||||
// Get port parameters from Java class
|
// Get port parameters from Java class
|
||||||
int flowControl = env->GetIntField(obj, env->GetFieldID(serialCommClass, "flowControl", "I"));
|
int flowControl = env->GetIntField(obj, env->GetFieldID(serialCommClass, "flowControl", "I"));
|
||||||
tcflag_t CTSRTSEnabled = (((flowControl & com_fazecast_jSerialComm_SerialPort_FLOW_CONTROL_CTS_ENABLED) > 0) ||
|
tcflag_t CTSRTSEnabled = ((flowControl & com_fazecast_jSerialComm_SerialPort_FLOW_CONTROL_CTS_ENABLED) > 0) ? CCTS_OFLOW : 0;
|
||||||
((flowControl & com_fazecast_jSerialComm_SerialPort_FLOW_CONTROL_RTS_ENABLED) > 0)) ? CRTSCTS : 0;
|
CTSRTSEnabled |= ((flowControl & com_fazecast_jSerialComm_SerialPort_FLOW_CONTROL_RTS_ENABLED) > 0) ? CRTS_IFLOW : 0;
|
||||||
tcflag_t XonXoffInEnabled = ((flowControl & com_fazecast_jSerialComm_SerialPort_FLOW_CONTROL_XONXOFF_IN_ENABLED) > 0) ? IXOFF : 0;
|
tcflag_t XonXoffInEnabled = ((flowControl & com_fazecast_jSerialComm_SerialPort_FLOW_CONTROL_XONXOFF_IN_ENABLED) > 0) ? IXOFF : 0;
|
||||||
tcflag_t XonXoffOutEnabled = ((flowControl & com_fazecast_jSerialComm_SerialPort_FLOW_CONTROL_XONXOFF_OUT_ENABLED) > 0) ? IXON : 0;
|
tcflag_t XonXoffOutEnabled = ((flowControl & com_fazecast_jSerialComm_SerialPort_FLOW_CONTROL_XONXOFF_OUT_ENABLED) > 0) ? IXON : 0;
|
||||||
|
|
||||||
|
@ -169,13 +171,10 @@ JNIEXPORT jboolean JNICALL Java_com_fazecast_jSerialComm_SerialPort_configFlowCo
|
||||||
|
|
||||||
// Set updated port parameters
|
// Set updated port parameters
|
||||||
options.c_cflag |= CTSRTSEnabled;
|
options.c_cflag |= CTSRTSEnabled;
|
||||||
options.c_iflag |= XonXoffInEnabled | XonXoffOutEnabled;
|
options.c_iflag |= (XonXoffInEnabled | XonXoffOutEnabled);
|
||||||
options.c_oflag = 0;
|
|
||||||
options.c_lflag = 0;
|
|
||||||
|
|
||||||
// Apply changes
|
// Apply changes
|
||||||
tcsetattr(portFD, TCSAFLUSH, &options);
|
return (tcsetattr(portFD, TCSANOW, &options) == -1) ? JNI_FALSE : JNI_TRUE;
|
||||||
return JNI_TRUE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
JNIEXPORT jboolean JNICALL Java_com_fazecast_jSerialComm_SerialPort_configTimeouts(JNIEnv *env, jobject obj)
|
JNIEXPORT jboolean JNICALL Java_com_fazecast_jSerialComm_SerialPort_configTimeouts(JNIEnv *env, jobject obj)
|
||||||
|
@ -227,7 +226,7 @@ JNIEXPORT jboolean JNICALL Java_com_fazecast_jSerialComm_SerialPort_configTimeou
|
||||||
|
|
||||||
// Apply changes
|
// Apply changes
|
||||||
fcntl(serialFD, F_SETFL, flags);
|
fcntl(serialFD, F_SETFL, flags);
|
||||||
return (tcsetattr(serialFD, TCSAFLUSH, &options) == 0) ? JNI_TRUE : JNI_FALSE;
|
return (tcsetattr(serialFD, TCSANOW, &options) == 0) ? JNI_TRUE : JNI_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
JNIEXPORT jboolean JNICALL Java_com_fazecast_jSerialComm_SerialPort_configEventFlags(JNIEnv *env, jobject obj)
|
JNIEXPORT jboolean JNICALL Java_com_fazecast_jSerialComm_SerialPort_configEventFlags(JNIEnv *env, jobject obj)
|
||||||
|
@ -239,6 +238,7 @@ JNIEXPORT jboolean JNICALL Java_com_fazecast_jSerialComm_SerialPort_configEventF
|
||||||
|
|
||||||
// Get event flags from Java class
|
// Get event flags from Java class
|
||||||
int eventsToMonitor = env->GetIntField(obj, env->GetFieldID(serialCommClass, "eventFlags", "I"));
|
int eventsToMonitor = env->GetIntField(obj, env->GetFieldID(serialCommClass, "eventFlags", "I"));
|
||||||
|
jboolean retVal = JNI_FALSE;
|
||||||
|
|
||||||
// Change read timeouts if we are monitoring data received
|
// Change read timeouts if we are monitoring data received
|
||||||
if ((eventsToMonitor & com_fazecast_jSerialComm_SerialPort_LISTENING_EVENT_DATA_RECEIVED) > 0)
|
if ((eventsToMonitor & com_fazecast_jSerialComm_SerialPort_LISTENING_EVENT_DATA_RECEIVED) > 0)
|
||||||
|
@ -250,13 +250,12 @@ JNIEXPORT jboolean JNICALL Java_com_fazecast_jSerialComm_SerialPort_configEventF
|
||||||
options.c_cc[VMIN] = 0;
|
options.c_cc[VMIN] = 0;
|
||||||
options.c_cc[VTIME] = 10;
|
options.c_cc[VTIME] = 10;
|
||||||
fcntl(serialFD, F_SETFL, flags);
|
fcntl(serialFD, F_SETFL, flags);
|
||||||
tcsetattr(serialFD, TCSAFLUSH, &options);
|
retVal = (tcsetattr(serialFD, TCSANOW, &options) == 0) ? JNI_TRUE : JNI_FALSE;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
Java_com_fazecast_jSerialComm_SerialPort_configTimeouts(env, obj);
|
retVal = Java_com_fazecast_jSerialComm_SerialPort_configTimeouts(env, obj);
|
||||||
|
|
||||||
// Apply changes
|
return retVal;
|
||||||
return JNI_TRUE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
JNIEXPORT jint JNICALL Java_com_fazecast_jSerialComm_SerialPort_waitForEvent(JNIEnv *env, jobject obj)
|
JNIEXPORT jint JNICALL Java_com_fazecast_jSerialComm_SerialPort_waitForEvent(JNIEnv *env, jobject obj)
|
||||||
|
@ -285,6 +284,7 @@ JNIEXPORT jboolean JNICALL Java_com_fazecast_jSerialComm_SerialPort_closePortNat
|
||||||
int portFD = (int)env->GetLongField(obj, env->GetFieldID(env->GetObjectClass(obj), "portHandle", "J"));
|
int portFD = (int)env->GetLongField(obj, env->GetFieldID(env->GetObjectClass(obj), "portHandle", "J"));
|
||||||
if (portFD <= 0)
|
if (portFD <= 0)
|
||||||
return JNI_TRUE;
|
return JNI_TRUE;
|
||||||
|
tcdrain(portFD);
|
||||||
close(portFD);
|
close(portFD);
|
||||||
env->SetLongField(obj, env->GetFieldID(env->GetObjectClass(obj), "portHandle", "J"), -1l);
|
env->SetLongField(obj, env->GetFieldID(env->GetObjectClass(obj), "portHandle", "J"), -1l);
|
||||||
env->SetBooleanField(obj, env->GetFieldID(env->GetObjectClass(obj), "isOpened", "Z"), JNI_FALSE);
|
env->SetBooleanField(obj, env->GetFieldID(env->GetObjectClass(obj), "isOpened", "Z"), JNI_FALSE);
|
||||||
|
@ -391,7 +391,7 @@ JNIEXPORT jint JNICALL Java_com_fazecast_jSerialComm_SerialPort_readBytes(JNIEnv
|
||||||
JNIEXPORT jint JNICALL Java_com_fazecast_jSerialComm_SerialPort_writeBytes(JNIEnv *env, jobject obj, jbyteArray buffer, jlong bytesToWrite)
|
JNIEXPORT jint JNICALL Java_com_fazecast_jSerialComm_SerialPort_writeBytes(JNIEnv *env, jobject obj, jbyteArray buffer, jlong bytesToWrite)
|
||||||
{
|
{
|
||||||
int serialPortFD = (int)env->GetLongField(obj, env->GetFieldID(env->GetObjectClass(obj), "portHandle", "J"));
|
int serialPortFD = (int)env->GetLongField(obj, env->GetFieldID(env->GetObjectClass(obj), "portHandle", "J"));
|
||||||
if (serialPortFD == -1)
|
if (serialPortFD <= 0)
|
||||||
return -1;
|
return -1;
|
||||||
jbyte *writeBuffer = env->GetByteArrayElements(buffer, 0);
|
jbyte *writeBuffer = env->GetByteArrayElements(buffer, 0);
|
||||||
int numBytesWritten;
|
int numBytesWritten;
|
||||||
|
|
Loading…
Reference in New Issue