No need for Java to load FTDI library

This commit is contained in:
hedgecrw85 2018-04-03 11:57:48 -05:00
parent a6684950fa
commit aa312b3a75
5 changed files with 21 additions and 22 deletions

View File

@ -5,7 +5,7 @@ apply plugin: 'osgi'
group = 'com.fazecast'
archivesBaseName = 'jSerialComm'
version = '2.0.1'
version = '2.0.2'
ext.moduleName = 'com.fazecast.jSerialComm'
assert hasProperty('java6Home'): "Set the property 'java6Home' in your gradle.properties file pointing to a Java 6 JDK installation"

View File

@ -42,7 +42,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 2.0.1
* @version 2.0.2
* @see java.io.InputStream
* @see java.io.OutputStream
*/
@ -181,20 +181,16 @@ public final class SerialPort
}
// Get path of native library and copy file to working directory
String tempFileName = tempFileDirectory + (new Date()).getTime() + "-" + fileName, ftdiFileName = "";
File tempNativeLibrary = new File(tempFileName), tempFtdiLibrary = null;
String tempFileName = tempFileDirectory + (new Date()).getTime() + "-" + fileName;
File tempNativeLibrary = new File(tempFileName);
tempNativeLibrary.deleteOnExit();
if (isWindows)
{
ftdiFileName = tempFileDirectory + "ftd2xx.dll";
tempFtdiLibrary = new File(ftdiFileName);
tempFtdiLibrary.deleteOnExit();
}
try
{
// Load the FTDI library if on Windows
// Copy the FTDI driver library to the system temp directory if on Windows
if (isWindows)
{
String ftdiFileName = tempFileDirectory + "ftd2xx.dll";
File tempFtdiLibrary = new File(ftdiFileName);
InputStream ftdiContents = SerialPort.class.getResourceAsStream("/" + libraryPath + "/ftd2xx.dll");
if (ftdiContents != null)
{
@ -211,7 +207,6 @@ public final class SerialPort
catch (FileNotFoundException e) {};
ftdiContents.close();
}
System.load(ftdiFileName);
}
// Load the native jSerialComm library
@ -223,15 +218,19 @@ public final class SerialPort
}
else
{
FileOutputStream destinationFileContents = new FileOutputStream(tempNativeLibrary);
byte transferBuffer[] = new byte[4096];
int numBytesRead;
while ((numBytesRead = fileContents.read(transferBuffer)) > 0)
destinationFileContents.write(transferBuffer, 0, numBytesRead);
// Copy the native library to the system temp directory
try
{
FileOutputStream destinationFileContents = new FileOutputStream(tempNativeLibrary);
byte transferBuffer[] = new byte[4096];
int numBytesRead;
while ((numBytesRead = fileContents.read(transferBuffer)) > 0)
destinationFileContents.write(transferBuffer, 0, numBytesRead);
destinationFileContents.close();
}
catch (FileNotFoundException e) {};
fileContents.close();
destinationFileContents.close();
// Load and initialize native library
System.load(tempFileName);

View File

@ -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 2.0.1
* @version 2.0.2
* @see java.util.EventListener
*/
public interface SerialPortDataListener extends EventListener

View File

@ -31,7 +31,7 @@ import java.util.EventObject;
* This class describes an asynchronous serial port event.
*
* @author Will Hedgecock <will.hedgecock@fazecast.com>
* @version 2.0.1
* @version 2.0.2
* @see java.util.EventObject
*/
public final class SerialPortEvent extends EventObject

View File

@ -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 &lt;will.hedgecock@fazecast.com&gt;
* @version 2.0.1
* @version 2.0.2
* @see com.fazecast.jSerialComm.SerialPortDataListener
* @see java.util.EventListener
*/