Fixed problem with IOSSIOSPEED not working on some drivers under Mac.
This commit is contained in:
parent
6ae1b1e98c
commit
422304c2d0
14
INSTALL
14
INSTALL
|
@ -123,29 +123,29 @@ Maven:
|
|||
<dependency>
|
||||
<groupId>com.fazecast</groupId>
|
||||
<artifactId>jSerialComm</artifactId>
|
||||
<version>1.3.6</version>
|
||||
<version>1.3.7</version>
|
||||
</dependency>
|
||||
|
||||
Ivy:
|
||||
|
||||
<dependency org="com.fazecast" name="jSerialComm" rev="1.3.6"/>
|
||||
<dependency org="com.fazecast" name="jSerialComm" rev="1.3.7"/>
|
||||
|
||||
Groovy:
|
||||
|
||||
@Grab(group='com.fazecast', module='jSerialComm', version='1.3.6')
|
||||
@Grab(group='com.fazecast', module='jSerialComm', version='1.3.7')
|
||||
|
||||
Gradle:
|
||||
|
||||
compile 'com.fazecast:jSerialComm:1.3.6'
|
||||
compile 'com.fazecast:jSerialComm:1.3.7'
|
||||
|
||||
Buildr:
|
||||
|
||||
compile.with 'com.fazecast:jSerialComm:jar:1.3.6'
|
||||
compile.with 'com.fazecast:jSerialComm:jar:1.3.7'
|
||||
|
||||
Scala/SBT:
|
||||
|
||||
libraryDependencies += "com.fazecast" % "jSerialComm" % "1.3.6"
|
||||
libraryDependencies += "com.fazecast" % "jSerialComm" % "1.3.7"
|
||||
|
||||
Leiningen:
|
||||
|
||||
[com.fazecast/jSerialComm "1.3.6"]
|
||||
[com.fazecast/jSerialComm "1.3.7"]
|
||||
|
|
|
@ -4,7 +4,7 @@ apply plugin: 'maven'
|
|||
|
||||
group = 'com.fazecast'
|
||||
archivesBaseName = 'jSerialComm'
|
||||
version = '1.3.6'
|
||||
version = '1.3.7'
|
||||
|
||||
sourceCompatibility = 1.6
|
||||
targetCompatibility = 1.6
|
||||
|
|
|
@ -16,7 +16,7 @@ JAVAC := javac
|
|||
JAVAH := javah -jni
|
||||
JFLAGS := -source 1.6 -target 1.6 -Xlint:-options
|
||||
LIBRARY_NAME := libjSerialComm.jnilib
|
||||
SOURCES := SerialPort_OSX.c
|
||||
SOURCES := SerialPort_OSX.c OSXHelperFunctions.c
|
||||
JAVA_SOURCE_DIR = ../../../../src/main/java/com/fazecast/jSerialComm
|
||||
RESOURCE_DIR = ../../../../src/main/resources/OSX
|
||||
BUILD_DIR = ../../../../bin/OSX
|
||||
|
|
|
@ -0,0 +1,85 @@
|
|||
/*
|
||||
* OSXHelperFunctions.c
|
||||
*
|
||||
* Created on: Jul 1, 2015
|
||||
* Last Updated on: Jul 1, 2015
|
||||
* Author: Will Hedgecock
|
||||
*
|
||||
* Copyright (C) 2012-2015 Fazecast, Inc.
|
||||
*
|
||||
* This file is part of jSerialComm.
|
||||
*
|
||||
* jSerialComm 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.
|
||||
*
|
||||
* jSerialComm 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 jSerialComm. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifdef __APPLE__
|
||||
#include <sys/types.h>
|
||||
#include <fcntl.h>
|
||||
#include <asm/termios.h>
|
||||
#include <asm/ioctls.h>
|
||||
#include "OSXHelperFunctions.h"
|
||||
|
||||
speed_t getBaudRateCode(speed_t baudRate)
|
||||
{
|
||||
switch (baudRate)
|
||||
{
|
||||
case 50:
|
||||
return B50;
|
||||
case 75:
|
||||
return B75;
|
||||
case 110:
|
||||
return B110;
|
||||
case 134:
|
||||
return B134;
|
||||
case 150:
|
||||
return B150;
|
||||
case 200:
|
||||
return B200;
|
||||
case 300:
|
||||
return B300;
|
||||
case 600:
|
||||
return B600;
|
||||
case 1200:
|
||||
return B1200;
|
||||
case 1800:
|
||||
return B1800;
|
||||
case 2400:
|
||||
return B2400;
|
||||
case 4800:
|
||||
return B4800;
|
||||
case 9600:
|
||||
return B9600;
|
||||
case 19200:
|
||||
return B19200;
|
||||
case 38400:
|
||||
return B38400;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void setBaudRate(int portFD, speed_t baudRate)
|
||||
{
|
||||
struct termios2 options = { 0 };
|
||||
ioctl(portFD, TCGETS2, &options);
|
||||
options.c_cflag &= ~CBAUD;
|
||||
options.c_cflag |= BOTHER;
|
||||
options.c_ispeed = baudRate;
|
||||
options.c_ospeed = baudRate;
|
||||
ioctl(portFD, TCSETS2, &options);
|
||||
}
|
||||
|
||||
#endif
|
|
@ -0,0 +1,34 @@
|
|||
/*
|
||||
* OSXHelperFunctions.h
|
||||
*
|
||||
* Created on: Jul 1, 2015
|
||||
* Last Updated on: Jul 1, 2015
|
||||
* Author: Will Hedgecock
|
||||
*
|
||||
* Copyright (C) 2012-2015 Fazecast, Inc.
|
||||
*
|
||||
* This file is part of jSerialComm.
|
||||
*
|
||||
* jSerialComm 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.
|
||||
*
|
||||
* jSerialComm 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 jSerialComm. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef __OSX_HELPER_FUNCTIONS_HEADER_H__
|
||||
#define __OSX_HELPER_FUNCTIONS_HEADER_H__
|
||||
|
||||
#include <termios.h>
|
||||
|
||||
speed_t getBaudRateCode(speed_t baudRate);
|
||||
void setBaudRate(int portFD, speed_t baudRate);
|
||||
|
||||
#endif // #ifndef __OSX_HELPER_FUNCTIONS_HEADER_H__
|
|
@ -2,7 +2,7 @@
|
|||
* SerialPort_OSX.c
|
||||
*
|
||||
* Created on: Feb 25, 2012
|
||||
* Last Updated on: May 19, 2015
|
||||
* Last Updated on: July 1, 2015
|
||||
* Author: Will Hedgecock
|
||||
*
|
||||
* Copyright (C) 2012-2015 Fazecast, Inc.
|
||||
|
@ -192,17 +192,6 @@ JNIEXPORT jboolean JNICALL Java_com_fazecast_jSerialComm_SerialPort_configPort(J
|
|||
return JNI_FALSE;
|
||||
struct termios options = { 0 };
|
||||
|
||||
// Block non-root users from using this port
|
||||
if (ioctl(serialPortFD, TIOCEXCL) == -1)
|
||||
return JNI_FALSE;
|
||||
|
||||
// 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);
|
||||
|
||||
// Get port parameters from Java class
|
||||
speed_t baudRate = (*env)->GetIntField(env, obj, baudRateField);
|
||||
int byteSizeInt = (*env)->GetIntField(env, obj, dataBitsField);
|
||||
|
@ -212,8 +201,14 @@ 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);
|
||||
|
||||
// Set updated port parameters
|
||||
cfsetspeed(&options, B38400);
|
||||
options.c_cflag = (byteSize | stopBits | parity | CLOCAL | CREAD);
|
||||
if (parityInt == com_fazecast_jSerialComm_SerialPort_SPACE_PARITY)
|
||||
options.c_cflag &= ~PARODD;
|
||||
|
@ -223,10 +218,22 @@ JNIEXPORT jboolean JNICALL Java_com_fazecast_jSerialComm_SerialPort_configPort(J
|
|||
if (parityInt != 0)
|
||||
options.c_iflag |= (INPCK | IGNPAR);
|
||||
|
||||
// Set baud rate
|
||||
speed_t baudRateCode = getBaudRateCode(baudRate);
|
||||
if (baudRateCode != 0)
|
||||
{
|
||||
cfsetispeed(&options, baudRateCode);
|
||||
cfsetospeed(&options, baudRateCode);
|
||||
}
|
||||
else
|
||||
{
|
||||
cfsetispeed(&options, baudRate);
|
||||
cfsetospeed(&options, baudRate);
|
||||
}
|
||||
|
||||
// Apply changes
|
||||
if (tcsetattr(serialPortFD, TCSANOW, &options) == -1)
|
||||
return JNI_FALSE;
|
||||
return (ioctl(serialPortFD, IOSSIOSPEED, &baudRate) == -1) ? JNI_FALSE : JNI_TRUE;
|
||||
ioctl(serialPortFD, TIOCEXCL); // Block other non-root users from using this port
|
||||
return ((tcsetattr(serialPortFD, TCSANOW, &options) == 0) ? JNI_TRUE : JNI_FALSE);
|
||||
}
|
||||
|
||||
JNIEXPORT jboolean JNICALL Java_com_fazecast_jSerialComm_SerialPort_configFlowControl(JNIEnv *env, jobject obj, jlong serialPortFD)
|
||||
|
|
|
@ -38,7 +38,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.6
|
||||
* @version 1.3.7
|
||||
* @see java.io.InputStream
|
||||
* @see java.io.OutputStream
|
||||
*/
|
||||
|
|
|
@ -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.6
|
||||
* @version 1.3.7
|
||||
* @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.6
|
||||
* @version 1.3.7
|
||||
* @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.6
|
||||
* @version 1.3.7
|
||||
* @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.6
|
||||
* @version 1.3.7
|
||||
* @see java.io.InputStream
|
||||
* @see java.io.OutputStream
|
||||
*/
|
||||
|
|
Loading…
Reference in New Issue