I'm trying to build an macOS application on masOS to communicate with FTDI D2XX device. I used gcc to compile a simple console app with C code and it works well and get expected device count. But when I tried to import the FTDI into Xcode and built an application with Swift 5. The application can be built and executed successfully but it always return 0 for FTDI device count. I tried to use two methods to import FTDI D2XX static library (ftd2xx.a) into Xcode. But both of them have same results.
The C code to call FTDI D2XX API is:
int queryDeviceCount(void)
{
FT_STATUS ftStatus;
DWORD numDevs = 999;
ftStatus = FT_CreateDeviceInfoList(&numDevs);
if (ftStatus == FT_OK) {
return numDevs;
}
return 0;
}
When FT_CreateDeviceInfoList is called, it returned FT_OK in ftStatus. But the numDevs is always zero (it should get 2 in my setup). I think the FTDI D2XX driver should be OK in my MacBookPro because it works well in command-line console. So, I'm wondering is there any difference in calling FTDI API between command-line console and GUI application. I'm pretty sure that the FTDI API is called correctly in GUI application.
Thanks!
I found in macOS GUI App, the system resource is protected. I need to enable the USB access ability in "App Sandbox" to use USB access APIs.
App Sandbox appears in the Signing & Capabilities pane of Xcode revealing additional controls to configure the capability.