Allow Windows lib to read FTDI string description
This commit is contained in:
parent
b7c1440840
commit
fc3a85f377
|
@ -47,6 +47,7 @@ all :
|
|||
win32 : checkdirs $(BUILD_DIR)\x86\$(LIBRARY_NAME)
|
||||
$(DELETE) $(BUILD_DIR)\x86\*.obj
|
||||
$(COPY) $(BUILD_DIR)\x86\*.* $(RESOURCE_DIR)\x86
|
||||
$(COPY) ftdi\ftd2xx32.dll $(RESOURCE_DIR)\x86\ftd2xx.dll
|
||||
$(DELETE) ..\*.h
|
||||
$(RMDIR) $(BUILD_DIR)\..
|
||||
|
||||
|
@ -54,6 +55,7 @@ win32 : checkdirs $(BUILD_DIR)\x86\$(LIBRARY_NAME)
|
|||
win64 : checkdirs $(BUILD_DIR)\x86_64\$(LIBRARY_NAME)
|
||||
$(DELETE) $(BUILD_DIR)\x86_64\*.obj
|
||||
$(COPY) $(BUILD_DIR)\x86_64\*.* $(RESOURCE_DIR)\x86_64
|
||||
$(COPY) ftdi\ftd2xx64.dll $(RESOURCE_DIR)\x86_64\ftd2xx.dll
|
||||
$(DELETE) ..\*.h
|
||||
$(RMDIR) $(BUILD_DIR)\..
|
||||
|
||||
|
@ -66,11 +68,11 @@ $(BUILD_DIR)\x86_64 :
|
|||
|
||||
# Rule to build 32-bit library
|
||||
$(BUILD_DIR)\x86\$(LIBRARY_NAME) : $(JNI_HEADER) $(OBJECTSx86)
|
||||
$(LINK) $(LDFLAGS) /MACHINE:X86 /OUT:$@ $(OBJECTSx86) $(LIBRARIES)
|
||||
$(LINK) $(LDFLAGS) /MACHINE:X86 /OUT:$@ $(OBJECTSx86) $(LIBRARIES) ftdi/ftd2xx32.lib
|
||||
|
||||
# Rule to build 64-bit library
|
||||
$(BUILD_DIR)\x86_64\$(LIBRARY_NAME) : $(JNI_HEADER) $(OBJECTSx86_64)
|
||||
$(LINK) $(LDFLAGS) /MACHINE:X64 /OUT:$@ $(OBJECTSx86_64) $(LIBRARIES)
|
||||
$(LINK) $(LDFLAGS) /MACHINE:X64 /OUT:$@ $(OBJECTSx86_64) $(LIBRARIES) ftdi/ftd2xx64.lib
|
||||
|
||||
# Suffix rules to get from *.c -> *.obj
|
||||
$(OBJECTSx86_64) :
|
||||
|
|
|
@ -34,6 +34,7 @@
|
|||
#include <string.h>
|
||||
#include <setupapi.h>
|
||||
#include <devpkey.h>
|
||||
#include "ftdi/ftd2xx.h"
|
||||
#include "../com_fazecast_jSerialComm_SerialPort.h"
|
||||
#include "WindowsHelperFunctions.h"
|
||||
|
||||
|
@ -251,6 +252,38 @@ JNIEXPORT jobjectArray JNICALL Java_com_fazecast_jSerialComm_SerialPort_getCommP
|
|||
SetupDiDestroyDeviceInfoList(devList);
|
||||
}
|
||||
|
||||
// Attempt to locate any FTDI-specified port descriptions
|
||||
DWORD numDevs;
|
||||
if ((FT_CreateDeviceInfoList(&numDevs) == FT_OK) && (numDevs > 0))
|
||||
{
|
||||
FT_DEVICE_LIST_INFO_NODE *devInfo = (FT_DEVICE_LIST_INFO_NODE*)malloc(sizeof(FT_DEVICE_LIST_INFO_NODE)*numDevs);
|
||||
if (FT_GetDeviceInfoList(devInfo, &numDevs) == FT_OK)
|
||||
{
|
||||
int i, j;
|
||||
wchar_t comPortString[128];
|
||||
for (i = 0; i < numDevs; ++i)
|
||||
{
|
||||
LONG comPortNumber = 0;
|
||||
if ((FT_Open(i, &devInfo[i].ftHandle) == FT_OK) && (FT_GetComPortNumber(devInfo[i].ftHandle, &comPortNumber) == FT_OK))
|
||||
{
|
||||
// Update port description if COM port is actually connected and present in the port list
|
||||
FT_Close(devInfo[i].ftHandle);
|
||||
swprintf(comPortString, sizeof(comPortString) / sizeof(wchar_t), L"COM%ld", comPortNumber);
|
||||
for (j = 0; j < serialCommPorts.length; ++j)
|
||||
if (wcscmp(serialCommPorts.first[j], comPortString) == 0)
|
||||
{
|
||||
size_t descLength = strlen(devInfo[i].Description);
|
||||
free(serialCommPorts.third[j]);
|
||||
serialCommPorts.third[j] = (wchar_t*)malloc((descLength+1)*sizeof(wchar_t));
|
||||
MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, devInfo[i].Description, -1, serialCommPorts.third[j], descLength);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
free(devInfo);
|
||||
}
|
||||
|
||||
// Get relevant SerialComm methods and fill in com port array
|
||||
jobjectArray arrayObject = env->NewObjectArray(serialCommPorts.length, serialCommClass, 0);
|
||||
wchar_t systemPortName[128];
|
||||
|
|
File diff suppressed because it is too large
Load Diff
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -180,11 +180,37 @@ public final class SerialPort
|
|||
}
|
||||
|
||||
// Get path of native library and copy file to working directory
|
||||
String tempFileName = tempFileDirectory + (new Date()).getTime() + "-" + fileName;
|
||||
File tempNativeLibrary = new File(tempFileName);
|
||||
String tempFileName = tempFileDirectory + (new Date()).getTime() + "-" + fileName, ftdiFileName = "";
|
||||
File tempNativeLibrary = new File(tempFileName), tempFtdiLibrary = null;
|
||||
tempNativeLibrary.deleteOnExit();
|
||||
if (isWindows)
|
||||
{
|
||||
ftdiFileName = tempFileDirectory + (new Date()).getTime() + "-ftd2xx.dll";
|
||||
tempFtdiLibrary = new File(ftdiFileName);
|
||||
tempFtdiLibrary.deleteOnExit();
|
||||
}
|
||||
try
|
||||
{
|
||||
// Load the FTDI library if on Windows
|
||||
if (isWindows)
|
||||
{
|
||||
InputStream ftdiContents = SerialPort.class.getResourceAsStream("/" + libraryPath + "/ftd2xx.dll");
|
||||
if (ftdiContents != null)
|
||||
{
|
||||
FileOutputStream destinationFileContents = new FileOutputStream(tempFtdiLibrary);
|
||||
byte transferBuffer[] = new byte[4096];
|
||||
int numBytesRead;
|
||||
|
||||
while ((numBytesRead = ftdiContents.read(transferBuffer)) > 0)
|
||||
destinationFileContents.write(transferBuffer, 0, numBytesRead);
|
||||
|
||||
ftdiContents.close();
|
||||
destinationFileContents.close();
|
||||
System.load(ftdiFileName);
|
||||
}
|
||||
}
|
||||
|
||||
// Load the native jSerialComm library
|
||||
InputStream fileContents = SerialPort.class.getResourceAsStream("/" + libraryPath + "/" + fileName);
|
||||
if (fileContents == null)
|
||||
{
|
||||
|
@ -203,7 +229,7 @@ public final class SerialPort
|
|||
fileContents.close();
|
||||
destinationFileContents.close();
|
||||
|
||||
// Load native library
|
||||
// Load and initialize native library
|
||||
System.load(tempFileName);
|
||||
initializeLibrary();
|
||||
}
|
||||
|
|
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.
Loading…
Reference in New Issue