Move latency timer fix for FTDI inside of check for existing port

This commit is contained in:
Will Hedgecock 2022-01-18 17:24:38 -06:00
parent ef19f61ef6
commit 375c1bb45b
5 changed files with 7 additions and 6 deletions

View File

@ -2,7 +2,7 @@
* SerialPort_Windows.c * SerialPort_Windows.c
* *
* Created on: Feb 25, 2012 * Created on: Feb 25, 2012
* Last Updated on: Jan 17, 2022 * Last Updated on: Jan 18, 2022
* Author: Will Hedgecock * Author: Will Hedgecock
* *
* Copyright (C) 2012-2022 Fazecast, Inc. * Copyright (C) 2012-2022 Fazecast, Inc.
@ -278,15 +278,15 @@ JNIEXPORT jobjectArray JNICALL Java_com_fazecast_jSerialComm_SerialPort_getCommP
LONG comPortNumber = 0; LONG comPortNumber = 0;
if ((FT_Open(i, &devInfo[i].ftHandle) == FT_OK) && (FT_GetComPortNumber(devInfo[i].ftHandle, &comPortNumber) == FT_OK)) if ((FT_Open(i, &devInfo[i].ftHandle) == FT_OK) && (FT_GetComPortNumber(devInfo[i].ftHandle, &comPortNumber) == FT_OK))
{ {
// Reduce latency timer to minimum value of 2 // Check if COM port is actually connected and present in the port list
FT_SetLatencyTimer(devInfo[i].ftHandle, 2);
// Update port description if COM port is actually connected and present in the port list
FT_Close(devInfo[i].ftHandle);
swprintf(comPort, sizeof(comPort) / sizeof(wchar_t), L"COM%ld", comPortNumber); swprintf(comPort, sizeof(comPort) / sizeof(wchar_t), L"COM%ld", comPortNumber);
for (int j = 0; j < serialPorts.length; ++j) for (int j = 0; j < serialPorts.length; ++j)
if (wcscmp(serialPorts.ports[j]->portPath, comPort) == 0) if (wcscmp(serialPorts.ports[j]->portPath, comPort) == 0)
{ {
// Reduce latency timer to minimum value of 2
FT_SetLatencyTimer(devInfo[i].ftHandle, 2);
// Update the port description
serialPorts.ports[j]->enumerated = 1; serialPorts.ports[j]->enumerated = 1;
size_t descLength = 8+strlen(devInfo[i].Description); size_t descLength = 8+strlen(devInfo[i].Description);
wchar_t *newMemory = (wchar_t*)realloc(serialPorts.ports[j]->portDescription, descLength*sizeof(wchar_t)); wchar_t *newMemory = (wchar_t*)realloc(serialPorts.ports[j]->portDescription, descLength*sizeof(wchar_t));
@ -298,6 +298,7 @@ JNIEXPORT jobjectArray JNICALL Java_com_fazecast_jSerialComm_SerialPort_getCommP
memcpy(serialPorts.ports[j]->serialNumber, devInfo[i].SerialNumber, sizeof(serialPorts.ports[j]->serialNumber)); memcpy(serialPorts.ports[j]->serialNumber, devInfo[i].SerialNumber, sizeof(serialPorts.ports[j]->serialNumber));
break; break;
} }
FT_Close(devInfo[i].ftHandle);
} }
} }
} }