No need for Java to load FTDI library
This commit is contained in:
parent
a6684950fa
commit
aa312b3a75
|
@ -5,7 +5,7 @@ apply plugin: 'osgi'
|
||||||
|
|
||||||
group = 'com.fazecast'
|
group = 'com.fazecast'
|
||||||
archivesBaseName = 'jSerialComm'
|
archivesBaseName = 'jSerialComm'
|
||||||
version = '2.0.1'
|
version = '2.0.2'
|
||||||
ext.moduleName = 'com.fazecast.jSerialComm'
|
ext.moduleName = 'com.fazecast.jSerialComm'
|
||||||
|
|
||||||
assert hasProperty('java6Home'): "Set the property 'java6Home' in your gradle.properties file pointing to a Java 6 JDK installation"
|
assert hasProperty('java6Home'): "Set the property 'java6Home' in your gradle.properties file pointing to a Java 6 JDK installation"
|
||||||
|
|
|
@ -42,7 +42,7 @@ import java.util.Date;
|
||||||
* This class provides native access to serial ports and devices without requiring external libraries or tools.
|
* This class provides native access to serial ports and devices without requiring external libraries or tools.
|
||||||
*
|
*
|
||||||
* @author Will Hedgecock <will.hedgecock@fazecast.com>
|
* @author Will Hedgecock <will.hedgecock@fazecast.com>
|
||||||
* @version 2.0.1
|
* @version 2.0.2
|
||||||
* @see java.io.InputStream
|
* @see java.io.InputStream
|
||||||
* @see java.io.OutputStream
|
* @see java.io.OutputStream
|
||||||
*/
|
*/
|
||||||
|
@ -181,20 +181,16 @@ public final class SerialPort
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get path of native library and copy file to working directory
|
// Get path of native library and copy file to working directory
|
||||||
String tempFileName = tempFileDirectory + (new Date()).getTime() + "-" + fileName, ftdiFileName = "";
|
String tempFileName = tempFileDirectory + (new Date()).getTime() + "-" + fileName;
|
||||||
File tempNativeLibrary = new File(tempFileName), tempFtdiLibrary = null;
|
File tempNativeLibrary = new File(tempFileName);
|
||||||
tempNativeLibrary.deleteOnExit();
|
tempNativeLibrary.deleteOnExit();
|
||||||
if (isWindows)
|
|
||||||
{
|
|
||||||
ftdiFileName = tempFileDirectory + "ftd2xx.dll";
|
|
||||||
tempFtdiLibrary = new File(ftdiFileName);
|
|
||||||
tempFtdiLibrary.deleteOnExit();
|
|
||||||
}
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
// Load the FTDI library if on Windows
|
// Copy the FTDI driver library to the system temp directory if on Windows
|
||||||
if (isWindows)
|
if (isWindows)
|
||||||
{
|
{
|
||||||
|
String ftdiFileName = tempFileDirectory + "ftd2xx.dll";
|
||||||
|
File tempFtdiLibrary = new File(ftdiFileName);
|
||||||
InputStream ftdiContents = SerialPort.class.getResourceAsStream("/" + libraryPath + "/ftd2xx.dll");
|
InputStream ftdiContents = SerialPort.class.getResourceAsStream("/" + libraryPath + "/ftd2xx.dll");
|
||||||
if (ftdiContents != null)
|
if (ftdiContents != null)
|
||||||
{
|
{
|
||||||
|
@ -211,7 +207,6 @@ public final class SerialPort
|
||||||
catch (FileNotFoundException e) {};
|
catch (FileNotFoundException e) {};
|
||||||
ftdiContents.close();
|
ftdiContents.close();
|
||||||
}
|
}
|
||||||
System.load(ftdiFileName);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Load the native jSerialComm library
|
// Load the native jSerialComm library
|
||||||
|
@ -223,15 +218,19 @@ public final class SerialPort
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
FileOutputStream destinationFileContents = new FileOutputStream(tempNativeLibrary);
|
// Copy the native library to the system temp directory
|
||||||
byte transferBuffer[] = new byte[4096];
|
try
|
||||||
int numBytesRead;
|
{
|
||||||
|
FileOutputStream destinationFileContents = new FileOutputStream(tempNativeLibrary);
|
||||||
while ((numBytesRead = fileContents.read(transferBuffer)) > 0)
|
byte transferBuffer[] = new byte[4096];
|
||||||
destinationFileContents.write(transferBuffer, 0, numBytesRead);
|
int numBytesRead;
|
||||||
|
|
||||||
|
while ((numBytesRead = fileContents.read(transferBuffer)) > 0)
|
||||||
|
destinationFileContents.write(transferBuffer, 0, numBytesRead);
|
||||||
|
destinationFileContents.close();
|
||||||
|
}
|
||||||
|
catch (FileNotFoundException e) {};
|
||||||
fileContents.close();
|
fileContents.close();
|
||||||
destinationFileContents.close();
|
|
||||||
|
|
||||||
// Load and initialize native library
|
// Load and initialize native library
|
||||||
System.load(tempFileName);
|
System.load(tempFileName);
|
||||||
|
|
|
@ -31,7 +31,7 @@ import java.util.EventListener;
|
||||||
* This interface must be implemented to enable simple event-based serial port I/O.
|
* This interface must be implemented to enable simple event-based serial port I/O.
|
||||||
*
|
*
|
||||||
* @author Will Hedgecock <will.hedgecock@fazecast.com>
|
* @author Will Hedgecock <will.hedgecock@fazecast.com>
|
||||||
* @version 2.0.1
|
* @version 2.0.2
|
||||||
* @see java.util.EventListener
|
* @see java.util.EventListener
|
||||||
*/
|
*/
|
||||||
public interface SerialPortDataListener extends EventListener
|
public interface SerialPortDataListener extends EventListener
|
||||||
|
|
|
@ -31,7 +31,7 @@ import java.util.EventObject;
|
||||||
* This class describes an asynchronous serial port event.
|
* This class describes an asynchronous serial port event.
|
||||||
*
|
*
|
||||||
* @author Will Hedgecock <will.hedgecock@fazecast.com>
|
* @author Will Hedgecock <will.hedgecock@fazecast.com>
|
||||||
* @version 2.0.1
|
* @version 2.0.2
|
||||||
* @see java.util.EventObject
|
* @see java.util.EventObject
|
||||||
*/
|
*/
|
||||||
public final class SerialPortEvent extends 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.
|
* <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>
|
* @author Will Hedgecock <will.hedgecock@fazecast.com>
|
||||||
* @version 2.0.1
|
* @version 2.0.2
|
||||||
* @see com.fazecast.jSerialComm.SerialPortDataListener
|
* @see com.fazecast.jSerialComm.SerialPortDataListener
|
||||||
* @see java.util.EventListener
|
* @see java.util.EventListener
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Reference in New Issue