Updated to Version 1.2.2
This commit is contained in:
parent
6b08b2150e
commit
f49e8803a4
14
INSTALL
14
INSTALL
|
@ -106,31 +106,31 @@ Maven:
|
|||
<dependency>
|
||||
<groupId>com.fazecast</groupId>
|
||||
<artifactId>jSerialComm</artifactId>
|
||||
<version>1.2.0</version>
|
||||
<version>1.2.2</version>
|
||||
</dependency>
|
||||
|
||||
Ivy:
|
||||
|
||||
<dependency org="com.fazecast" name="jSerialComm" rev="1.2.0"/>
|
||||
<dependency org="com.fazecast" name="jSerialComm" rev="1.2.2"/>
|
||||
|
||||
Grape:
|
||||
|
||||
@Grapes(
|
||||
@Grab(group='com.fazecast', module='jSerialComm', version='1.2.0')
|
||||
@Grab(group='com.fazecast', module='jSerialComm', version='1.2.2')
|
||||
)
|
||||
|
||||
Gradle:
|
||||
|
||||
'com.fazecast:jSerialComm:1.2.0'
|
||||
'com.fazecast:jSerialComm:1.2.2'
|
||||
|
||||
Buildr:
|
||||
|
||||
'com.fazecast:jSerialComm:jar:1.2.0'
|
||||
'com.fazecast:jSerialComm:jar:1.2.2'
|
||||
|
||||
SBT:
|
||||
|
||||
libraryDependencies += "com.fazecast" % "jSerialComm" % "1.2.0"
|
||||
libraryDependencies += "com.fazecast" % "jSerialComm" % "1.2.2"
|
||||
|
||||
Leiningen:
|
||||
|
||||
[com.fazecast/jSerialComm "1.2.0"]
|
||||
[com.fazecast/jSerialComm "1.2.2"]
|
||||
|
|
|
@ -4,7 +4,7 @@ apply plugin: 'maven'
|
|||
|
||||
group = 'com.fazecast'
|
||||
archivesBaseName = 'jSerialComm'
|
||||
version = '1.1.1'
|
||||
version = '1.2.2'
|
||||
|
||||
sourceCompatibility = 1.6
|
||||
targetCompatibility = 1.6
|
||||
|
|
|
@ -74,6 +74,39 @@ void getFriendlyName(const char* productFile, char* friendlyName)
|
|||
}
|
||||
}
|
||||
|
||||
void getDriverName(const char* directoryToSearch, char* friendlyName)
|
||||
{
|
||||
friendlyName[0] = '\0';
|
||||
|
||||
// Open the directory
|
||||
DIR *directoryIterator = opendir(directoryToSearch);
|
||||
if (!directoryIterator)
|
||||
return;
|
||||
|
||||
// Read all sub-directories in the current directory
|
||||
struct dirent *directoryEntry = readdir(directoryIterator);
|
||||
while (directoryEntry)
|
||||
{
|
||||
// Check if entry is a valid sub-directory
|
||||
if (directoryEntry->d_name[0] != '.')
|
||||
{
|
||||
// Get the readable part of the driver name
|
||||
strcpy(friendlyName, "USB-to-Serial Port (");
|
||||
char *startingPoint = strchr(directoryEntry->d_name, ':');
|
||||
if (startingPoint != NULL)
|
||||
strcat(friendlyName, startingPoint+1);
|
||||
else
|
||||
strcat(friendlyName, directoryEntry->d_name);
|
||||
strcat(friendlyName, ")");
|
||||
break;
|
||||
}
|
||||
directoryEntry = readdir(directoryIterator);
|
||||
}
|
||||
|
||||
// Close the directory
|
||||
closedir(directoryIterator);
|
||||
}
|
||||
|
||||
void recursiveSearchForComPorts(charPairVector* comPorts, const char* fullPathToSearch)
|
||||
{
|
||||
// Open the directory
|
||||
|
@ -106,7 +139,17 @@ void recursiveSearchForComPorts(charPairVector* comPorts, const char* fullPathTo
|
|||
strcat(productFile, directoryEntry->d_name);
|
||||
strcat(productFile, "/device/../product");
|
||||
getFriendlyName(productFile, friendlyName);
|
||||
if (friendlyName[0] != '\0')
|
||||
if (friendlyName[0] == '\0')
|
||||
{
|
||||
// Get friendly name based on the driver loaded
|
||||
strcpy(productFile, fullPathToSearch);
|
||||
strcat(productFile, directoryEntry->d_name);
|
||||
strcat(productFile, "/driver/module/drivers");
|
||||
getDriverName(productFile, friendlyName);
|
||||
if (friendlyName[0] != '\0')
|
||||
push_back(comPorts, systemName, friendlyName);
|
||||
}
|
||||
else
|
||||
push_back(comPorts, systemName, friendlyName);
|
||||
|
||||
// Clean up memory
|
||||
|
|
|
@ -33,6 +33,7 @@ typedef struct charPairVector
|
|||
} charPairVector;
|
||||
void push_back(struct charPairVector* vector, const char* firstString, const char* secondString);
|
||||
|
||||
void getDriverName(const char* directoryToSearch, char* friendlyName);
|
||||
void recursiveSearchForComPorts(charPairVector* comPorts, const char* fullPathToSearch);
|
||||
void getFriendlyName(const char* productFile, char* friendlyName);
|
||||
unsigned int getBaudRateCode(int baudRate);
|
||||
|
|
|
@ -72,6 +72,39 @@ void getFriendlyName(const char* productFile, char* friendlyName)
|
|||
}
|
||||
}
|
||||
|
||||
void getDriverName(const char* directoryToSearch, char* friendlyName)
|
||||
{
|
||||
friendlyName[0] = '\0';
|
||||
|
||||
// Open the directory
|
||||
DIR *directoryIterator = opendir(directoryToSearch);
|
||||
if (!directoryIterator)
|
||||
return;
|
||||
|
||||
// Read all sub-directories in the current directory
|
||||
struct dirent *directoryEntry = readdir(directoryIterator);
|
||||
while (directoryEntry)
|
||||
{
|
||||
// Check if entry is a valid sub-directory
|
||||
if (directoryEntry->d_name[0] != '.')
|
||||
{
|
||||
// Get the readable part of the driver name
|
||||
strcpy(friendlyName, "USB-to-Serial Port (");
|
||||
char *startingPoint = strchr(directoryEntry->d_name, ':');
|
||||
if (startingPoint != NULL)
|
||||
strcat(friendlyName, startingPoint+1);
|
||||
else
|
||||
strcat(friendlyName, directoryEntry->d_name);
|
||||
strcat(friendlyName, ")");
|
||||
break;
|
||||
}
|
||||
directoryEntry = readdir(directoryIterator);
|
||||
}
|
||||
|
||||
// Close the directory
|
||||
closedir(directoryIterator);
|
||||
}
|
||||
|
||||
void recursiveSearchForComPorts(charPairVector* comPorts, const char* fullPathToSearch)
|
||||
{
|
||||
// Open the directory
|
||||
|
@ -104,21 +137,31 @@ void recursiveSearchForComPorts(charPairVector* comPorts, const char* fullPathTo
|
|||
strcat(productFile, directoryEntry->d_name);
|
||||
strcat(productFile, "/device/../product");
|
||||
getFriendlyName(productFile, friendlyName);
|
||||
if (friendlyName[0] == '\0') // Must be a physical platform port
|
||||
if (friendlyName[0] == '\0') // Must be a physical (or emulated) port
|
||||
{
|
||||
// Ensure that the platform port is actually open
|
||||
struct serial_struct serialInfo = { 0 };
|
||||
int fd = open(systemName, O_RDWR | O_NONBLOCK | O_NOCTTY);
|
||||
if (fd >= 0)
|
||||
// See if this is a USB-to-Serial converter based on the driver loaded
|
||||
strcpy(productFile, fullPathToSearch);
|
||||
strcat(productFile, directoryEntry->d_name);
|
||||
strcat(productFile, "/driver/module/drivers");
|
||||
getDriverName(productFile, friendlyName);
|
||||
if (friendlyName[0] == '\0') // Must be a physical port
|
||||
{
|
||||
if ((ioctl(fd, TIOCGSERIAL, &serialInfo) == 0) && (serialInfo.type != PORT_UNKNOWN))
|
||||
// Ensure that the platform port is actually open
|
||||
struct serial_struct serialInfo = { 0 };
|
||||
int fd = open(systemName, O_RDWR | O_NONBLOCK | O_NOCTTY);
|
||||
if (fd >= 0)
|
||||
{
|
||||
strcpy(friendlyName, "Physical Port ");
|
||||
strcat(friendlyName, directoryEntry->d_name+3);
|
||||
push_back(comPorts, systemName, friendlyName);
|
||||
if ((ioctl(fd, TIOCGSERIAL, &serialInfo) == 0) && (serialInfo.type != PORT_UNKNOWN))
|
||||
{
|
||||
strcpy(friendlyName, "Physical Port ");
|
||||
strcat(friendlyName, directoryEntry->d_name+3);
|
||||
push_back(comPorts, systemName, friendlyName);
|
||||
}
|
||||
close(fd);
|
||||
}
|
||||
close(fd);
|
||||
}
|
||||
else
|
||||
push_back(comPorts, systemName, friendlyName);
|
||||
}
|
||||
else
|
||||
push_back(comPorts, systemName, friendlyName);
|
||||
|
|
|
@ -33,6 +33,7 @@ typedef struct charPairVector
|
|||
} charPairVector;
|
||||
void push_back(struct charPairVector* vector, const char* firstString, const char* secondString);
|
||||
|
||||
void getDriverName(const char* directoryToSearch, char* friendlyName);
|
||||
void recursiveSearchForComPorts(charPairVector* comPorts, const char* fullPathToSearch);
|
||||
void getFriendlyName(const char* productFile, char* friendlyName);
|
||||
unsigned int getBaudRateCode(int baudRate);
|
||||
|
|
|
@ -38,13 +38,14 @@ 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.2.0
|
||||
* @version 1.2.2
|
||||
* @see java.io.InputStream
|
||||
* @see java.io.OutputStream
|
||||
*/
|
||||
public final class SerialPort
|
||||
{
|
||||
// Static initializer loads correct native library for this machine
|
||||
private static boolean isAndroid = false;
|
||||
static
|
||||
{
|
||||
String OS = System.getProperty("os.name").toLowerCase();
|
||||
|
@ -75,6 +76,7 @@ public final class SerialPort
|
|||
}
|
||||
catch (Exception e) { e.printStackTrace(); }
|
||||
|
||||
isAndroid = true;
|
||||
if (libraryPath.isEmpty())
|
||||
libraryPath = "Android/armeabi";
|
||||
fileName = "libjSerialComm.so";
|
||||
|
@ -249,6 +251,17 @@ public final class SerialPort
|
|||
*/
|
||||
public final boolean openPort()
|
||||
{
|
||||
// If this is an Android application, we must explicitly allow serial port access to this library
|
||||
if (isAndroid)
|
||||
{
|
||||
try
|
||||
{
|
||||
String grantPermissions = "chmod 666 " + getSystemPortName() + "\nexit\n";
|
||||
Process process = Runtime.getRuntime().exec("su -c " + grantPermissions);
|
||||
process.waitFor();
|
||||
} catch (Exception e) { return false; }
|
||||
}
|
||||
|
||||
try { Thread.sleep(500); } catch (Exception e) {}
|
||||
if (!isOpened && openPortNative())
|
||||
{
|
||||
|
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -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.0
|
||||
* @version 2.0
|
||||
* @see java.io.InputStream
|
||||
* @see java.io.OutputStream
|
||||
*/
|
||||
|
|
Loading…
Reference in New Issue