Allow Mac to enumerate tty AND cu ports. Simply system port name returned on Linux systems.
This commit is contained in:
parent
3bcda2e64e
commit
83e70bf4b9
14
INSTALL
14
INSTALL
|
@ -123,31 +123,31 @@ Maven:
|
|||
<dependency>
|
||||
<groupId>com.fazecast</groupId>
|
||||
<artifactId>jSerialComm</artifactId>
|
||||
<version>1.3.0</version>
|
||||
<version>1.3.1</version>
|
||||
</dependency>
|
||||
|
||||
Ivy:
|
||||
|
||||
<dependency org="com.fazecast" name="jSerialComm" rev="1.3.0"/>
|
||||
<dependency org="com.fazecast" name="jSerialComm" rev="1.3.1"/>
|
||||
|
||||
Grape:
|
||||
|
||||
@Grapes(
|
||||
@Grab(group='com.fazecast', module='jSerialComm', version='1.3.0')
|
||||
@Grab(group='com.fazecast', module='jSerialComm', version='1.3.1')
|
||||
)
|
||||
|
||||
Gradle:
|
||||
|
||||
'com.fazecast:jSerialComm:1.3.0'
|
||||
'com.fazecast:jSerialComm:1.3.1'
|
||||
|
||||
Buildr:
|
||||
|
||||
'com.fazecast:jSerialComm:jar:1.3.0'
|
||||
'com.fazecast:jSerialComm:jar:1.3.1'
|
||||
|
||||
SBT:
|
||||
|
||||
libraryDependencies += "com.fazecast" % "jSerialComm" % "1.3.0"
|
||||
libraryDependencies += "com.fazecast" % "jSerialComm" % "1.3.1"
|
||||
|
||||
Leiningen:
|
||||
|
||||
[com.fazecast/jSerialComm "1.3.0"]
|
||||
[com.fazecast/jSerialComm "1.3.1"]
|
||||
|
|
|
@ -4,7 +4,7 @@ apply plugin: 'maven'
|
|||
|
||||
group = 'com.fazecast'
|
||||
archivesBaseName = 'jSerialComm'
|
||||
version = '1.3.0'
|
||||
version = '1.3.1'
|
||||
|
||||
sourceCompatibility = 1.6
|
||||
targetCompatibility = 1.6
|
||||
|
|
|
@ -3,7 +3,7 @@ COMPILE := gcc
|
|||
LINK := gcc
|
||||
CFLAGS :=
|
||||
LDFLAGS := -dynamiclib
|
||||
JDK_HOME = /Library/Java/JavaVirtualMachines/jdk1.8.0_45.jdk/Contents/Home
|
||||
JDK_HOME = `/usr/libexec/java_home`
|
||||
INCLUDES := -I"$(JDK_HOME)/include" -I"$(JDK_HOME)/include/darwin"
|
||||
LIBRARIES := -framework Cocoa -framework IOKit -framework JavaVM
|
||||
DELETE := @rm
|
||||
|
|
|
@ -28,6 +28,7 @@
|
|||
#define CMSPAR 010000000000
|
||||
#endif
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <CoreFoundation/CoreFoundation.h>
|
||||
#include <IOKit/IOKitLib.h>
|
||||
#include <IOKit/serial/IOSerialKeys.h>
|
||||
|
@ -61,7 +62,7 @@ JNIEXPORT jobjectArray JNICALL Java_com_fazecast_jSerialComm_SerialPort_getCommP
|
|||
io_object_t serialPort;
|
||||
io_iterator_t serialPortIterator;
|
||||
int numValues = 0;
|
||||
char portString[1024], comPort[1024];
|
||||
char portString[1024], comPortCu[1024], comPortTty[1024];
|
||||
|
||||
// Enumerate serial ports on machine
|
||||
IOServiceGetMatchingServices(kIOMasterPortDefault, IOServiceMatching(kIOSerialBSDServiceValue), &serialPortIterator);
|
||||
|
@ -71,7 +72,7 @@ JNIEXPORT jobjectArray JNICALL Java_com_fazecast_jSerialComm_SerialPort_getCommP
|
|||
IOObjectRelease(serialPort);
|
||||
}
|
||||
IOIteratorReset(serialPortIterator);
|
||||
jobjectArray arrayObject = (*env)->NewObjectArray(env, numValues, serialCommClass, 0);
|
||||
jobjectArray arrayObject = (*env)->NewObjectArray(env, numValues*2, serialCommClass, 0);
|
||||
for (int i = 0; i < numValues; ++i)
|
||||
{
|
||||
// Get serial port information
|
||||
|
@ -104,16 +105,26 @@ JNIEXPORT jobjectArray JNICALL Java_com_fazecast_jSerialComm_SerialPort_getCommP
|
|||
CFRelease(portStringRef);
|
||||
}
|
||||
CFStringRef comPortRef = (CFStringRef)IORegistryEntryCreateCFProperty(serialPort, CFSTR(kIOCalloutDeviceKey), kCFAllocatorDefault, 0);
|
||||
CFStringGetCString(comPortRef, comPort, sizeof(comPort), kCFStringEncodingUTF8);
|
||||
CFStringGetCString(comPortRef, comPortCu, sizeof(comPortCu), kCFStringEncodingUTF8);
|
||||
CFRelease(comPortRef);
|
||||
comPortRef = (CFStringRef)IORegistryEntryCreateCFProperty(serialPort, CFSTR(kIODialinDeviceKey), kCFAllocatorDefault, 0);
|
||||
CFStringGetCString(comPortRef, comPortTty, sizeof(comPortTty), kCFStringEncodingUTF8);
|
||||
CFRelease(comPortRef);
|
||||
|
||||
// Create new SerialComm object containing the enumerated values
|
||||
// Create new SerialComm callout object containing the enumerated values and add to array
|
||||
jobject serialCommObject = (*env)->NewObject(env, serialCommClass, serialCommConstructor);
|
||||
(*env)->SetObjectField(env, serialCommObject, portStringField, (*env)->NewStringUTF(env, portString));
|
||||
(*env)->SetObjectField(env, serialCommObject, comPortField, (*env)->NewStringUTF(env, comPort));
|
||||
(*env)->SetObjectField(env, serialCommObject, comPortField, (*env)->NewStringUTF(env, comPortCu));
|
||||
(*env)->SetObjectArrayElement(env, arrayObject, i*2, serialCommObject);
|
||||
(*env)->DeleteLocalRef(env, serialCommObject);
|
||||
|
||||
// Add new SerialComm object to array
|
||||
(*env)->SetObjectArrayElement(env, arrayObject, i, serialCommObject);
|
||||
// Create new SerialComm dialin object containing the enumerated values and add to array
|
||||
strcat(portString, " (Dial-In)");
|
||||
serialCommObject = (*env)->NewObject(env, serialCommClass, serialCommConstructor);
|
||||
(*env)->SetObjectField(env, serialCommObject, portStringField, (*env)->NewStringUTF(env, portString));
|
||||
(*env)->SetObjectField(env, serialCommObject, comPortField, (*env)->NewStringUTF(env, comPortTty));
|
||||
(*env)->SetObjectArrayElement(env, arrayObject, i*2 + 1, serialCommObject);
|
||||
(*env)->DeleteLocalRef(env, serialCommObject);
|
||||
IOObjectRelease(serialPort);
|
||||
}
|
||||
IOObjectRelease(serialPortIterator);
|
||||
|
|
|
@ -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.0
|
||||
* @version 1.3.1
|
||||
* @see java.io.InputStream
|
||||
* @see java.io.OutputStream
|
||||
*/
|
||||
|
@ -190,6 +190,8 @@ public final class SerialPort
|
|||
// Correct Windows port descriptor, if needed
|
||||
if (portDescriptor.contains("COM"))
|
||||
portDescriptor = "\\\\.\\" + portDescriptor.substring(portDescriptor.lastIndexOf('\\')+1);
|
||||
else
|
||||
portDescriptor = "/dev/" + portDescriptor.substring(portDescriptor.lastIndexOf('/')+1);
|
||||
|
||||
// Create SerialPort object
|
||||
SerialPort serialPort = new SerialPort();
|
||||
|
@ -657,7 +659,11 @@ public final class SerialPort
|
|||
*
|
||||
* @return The system-defined device name of this serial port.
|
||||
*/
|
||||
public final String getSystemPortName() { return comPort.substring(comPort.lastIndexOf('\\')+1); }
|
||||
public final String getSystemPortName()
|
||||
{
|
||||
return (comPort.lastIndexOf('\\') != -1) ?
|
||||
comPort.substring(comPort.lastIndexOf('\\')+1) : comPort.substring(comPort.lastIndexOf('/')+1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the current baud rate of the serial port.
|
||||
|
|
|
@ -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.0
|
||||
* @version 1.3.1
|
||||
* @see java.io.InputStream
|
||||
* @see java.io.OutputStream
|
||||
*/
|
||||
|
|
Loading…
Reference in New Issue