DWORD CDriverInterface::GetDevicesInfoList(FT_DEVICE_LIST_INFO_NODE **pptDevicesInfo) { FT_STATUS ftStatus = FT_OK; DWORD dwNumDevices = 0; ftStatus = FT_CreateDeviceInfoList(&dwNumDevices); if (FT_FAILED(ftStatus)) { return 0; } *pptDevicesInfo = (FT_DEVICE_LIST_INFO_NODE*)malloc(sizeof(FT_DEVICE_LIST_INFO_NODE) * dwNumDevices); if (!(*pptDevicesInfo)) { return 0; } ftStatus = FT_GetDeviceInfoList(*pptDevicesInfo, &dwNumDevices); if (FT_FAILED(ftStatus)) { free(*pptDevicesInfo); *pptDevicesInfo = NULL; return 0; } return dwNumDevices; }
QList<DMXInterface *> FTD2XXInterface::interfaces(QList<DMXInterface *> discoveredList) { QList <DMXInterface*> interfacesList; int id = 0; /* Find out the number of FTDI devices present */ DWORD num = 0; FT_STATUS status = FT_CreateDeviceInfoList(&num); if (status != FT_OK || num <= 0) { qWarning() << Q_FUNC_INFO << "[FTD2XXInterface] Error in FT_CreateDeviceInfoList:" << status; return interfacesList; } // Allocate storage for list based on numDevices FT_DEVICE_LIST_INFO_NODE* devInfo = new FT_DEVICE_LIST_INFO_NODE[num]; // Get the device information list if (FT_GetDeviceInfoList(devInfo, &num) == FT_OK) { for (DWORD i = 0; i < num; i++) { QString vendor, name, serial; quint16 VID, PID; FT_STATUS s = get_interface_info(i, vendor, name, serial, VID, PID); if (s != FT_OK || name.isEmpty() || serial.isEmpty()) { // Seems that some otherwise working devices don't provide // FT_PROGRAM_DATA struct used by get_interface_info(). name = QString(devInfo[i].Description); serial = QString(devInfo[i].SerialNumber); vendor = QString(); } qDebug() << "serial: " << serial << "name:" << name << "vendor:" << vendor; bool found = false; for (int c = 0; c < discoveredList.count(); c++) { if (discoveredList.at(c)->checkInfo(serial, name, vendor) == true) { found = true; break; } } if (found == false) { FTD2XXInterface *iface = new FTD2XXInterface(serial, name, vendor, VID, PID, id); interfacesList << iface; } id++; } } delete [] devInfo; return interfacesList; }
/** * Обзор всех портов микросхемы ftdi */ QString FtdiDevices::showPorts( int i, DWORD *numDevs, QString *serialNum ) { /* Запись в лог сообщения */ appLogger.sendDataToViewer( appLogger.INFO_MSG_TYPE,QString(" Создание списка устройств "), appLogger.SYSTEM_LOGGER ); ftStatus = FT_CreateDeviceInfoList( numDevs ); if ( ftStatus != FT_OK ) { /* Запись в лог сообщения */ appLogger.sendDataToViewer( appLogger.INFO_MSG_TYPE," Операция создания списка не прошла! ", appLogger.SYSTEM_LOGGER );; return ""; } QString msg = QString(" Количество ftdi = %1 ").arg( *numDevs ); appLogger.sendDataToViewer( appLogger.INFO_MSG_TYPE, msg, appLogger.SYSTEM_LOGGER ); if ( numDevs > 0 ) { devInfo = (FT_DEVICE_LIST_INFO_NODE*)malloc( sizeof(FT_DEVICE_LIST_INFO_NODE) * (*numDevs) ); ftStatus = FT_GetDeviceInfoList( devInfo, numDevs ); if ( ftStatus == FT_OK ) { // for ( DWORD i = 0; i < numDevs; i++ ) { // appLogger.sendDataToViewer( appLogger.INFO_MSG_TYPE," =========================== " ); // appLogger.sendDataToViewer( appLogger.INFO_MSG_TYPE,QString("Device number \t%1").arg( i,0,10 ) ); // appLogger.sendDataToViewer( appLogger.INFO_MSG_TYPE,QString("Flags \t= 0x%1").arg( (int)devInfo[i].Flags, 0, 16 ) ); // appLogger.sendDataToViewer( appLogger.INFO_MSG_TYPE,QString("Type \t= 0x%1").arg( (int)devInfo[i].Type, 0, 16 ) ); // appLogger.sendDataToViewer( appLogger.INFO_MSG_TYPE,QString("ID \t= 0x%1").arg( (int)devInfo[i].ID, 0, 16 ) ); // appLogger.sendDataToViewer( appLogger.INFO_MSG_TYPE,QString("LocId \t= 0x%1").arg( (int)devInfo[i].LocId, 0, 16 ) ); // appLogger.sendDataToViewer( appLogger.INFO_MSG_TYPE,QString("SerialNumber \t= %1").arg( devInfo[i].SerialNumber ) ); // appLogger.sendDataToViewer( appLogger.INFO_MSG_TYPE,QString("Description \t= %1").arg( devInfo[i].Description ) ); // appLogger.sendDataToViewer( appLogger.INFO_MSG_TYPE,QString("ftHandle \t= 0x%1").arg( (int)devInfo[i].ftHandle, 0, 16 ) ); // } } } QString deviceInfo; deviceInfo = "<table><tr><td> "+ QString("Device number \t%1").arg( i,0,10 ) + " </td></tr>"\ "<tr><td>" + QString("Flags \t= 0x%1").arg( (int)devInfo[i].Flags, 0, 16 ) + "</td></tr>"\ "<tr><td>" + QString("Type \t= 0x%1").arg( (int)devInfo[i].Type, 0, 16 ) + "</td></tr>"\ "<tr><td>" + QString("ID \t= 0x%1").arg( (int)devInfo[i].ID, 0, 16 ) + "</td></tr>"\ "<tr><td>" + QString("LocId \t= 0x%1").arg( (int)devInfo[i].LocId, 0, 16 ) + "</td></tr>"\ "<tr><td>" + QString("SerialNumber \t= %1").arg( devInfo[i].SerialNumber) + "</td></tr>"\ "<tr><td>" + QString("Description \t= %1").arg( devInfo[i].Description ) + "</td></tr>"\ "<tr><td>" + QString("ftHandle \t= 0x%1").arg( (int)devInfo[i].ftHandle, 0, 16 ) + "</td></tr>"\ "</table>"; *serialNum = QString("SerialNumber \t= %1").arg( devInfo[i].SerialNumber ); free( devInfo ); return deviceInfo; }
/** Create a list of all power meter devices on the bus. This function finds all power meter probes connected to your computer and creates a linked list of the devices. Note, that you have to deallocate the list with pm_list_free() after use. \param pm pointer to pm_context \param type the device type, either TYPE_PM_6006, TYPE_PM_6003 or TYPE_PM_ALL \param list a pointer to struct pm_list*, used to create the list \retval 0 - all fine \retval -1 - device list creation failed \retval -2 - out of memory \retval -3 - can not retrieve device info */ PM600X_EXPORT int pm_find_all(struct pm_context *pm, unsigned long type, struct pm_list **list) { int i; FT_STATUS ftstat; FT_DEVICE_LIST_INFO_NODE *devInfo = NULL; struct pm_list **curdev; curdev = list; *curdev = NULL; /* create device info list and get the number of connected devices */ unsigned long numDevs = 0; ftstat = FT_CreateDeviceInfoList(&numDevs); if (ftstat != FT_OK) pm_error_return(-1, "creation of device list failed"); /* get device info */ if (numDevs > 0) { devInfo = (FT_DEVICE_LIST_INFO_NODE*)malloc(numDevs * sizeof(FT_DEVICE_LIST_INFO_NODE)); if (!devInfo) pm_error_return(-2, "out of memory"); ftstat = FT_GetDeviceInfoList(devInfo,&numDevs); if (ftstat != FT_OK) pm_error_return(-3, "retrieving device info failed"); for (i = 0; i < numDevs; i++) { /* filter out all devices, that are not a PM 6006 or PM 6003 */ if ((type == TYPE_PM_ALL) && (devInfo[i].ID != TYPE_PM_6006 && devInfo[i].ID != TYPE_PM_6003)) continue; else if ((type == TYPE_PM_6006) && (devInfo[i].ID != TYPE_PM_6006)) continue; else if ((type == TYPE_PM_6003) && (devInfo[i].ID != TYPE_PM_6003)) continue; *curdev = (struct pm_list*) malloc(sizeof(struct pm_list)); if (!*curdev) pm_error_return(-2, "out of memory"); (*curdev)->next = NULL; (*curdev)->serial = atoi(devInfo[i].SerialNumber); (*curdev)->type = devInfo[i].ID; curdev = &(*curdev)->next; } } pm_error_return(0, "all fine"); }
BOOL InitializeForBitIO(void) { DWORD DeviceCount; FT_Status = FT_CreateDeviceInfoList(&DeviceCount); if (FT_Status) return printf("FT_CreateDeviceInfoList failed (%d)", FT_Status); if (DeviceCount == 0) return printf("No FTDI devices attached\n"); FT_Status = FT_Open(0, &FT_Handle); if (FT_Status) return printf("FT_Open failed (%d)", FT_Status); FT_Status = FT_SetBaudRate(FT_Handle, 921600); if (FT_Status) return printf("FT_SetBaudRate failed (%d)", FT_Status); FT_Status = FT_SetBitMode(FT_Handle, 1, SyncBitBang); if (FT_Status) return printf("FT_SetBitMode failed (%d)", FT_Status); return 0; }
bool CMmcUsbHndlBase::CreateDeviceInfoList(unsigned int *pdNbOfDevices) { if( !AreLibraryFunctionsLoaded() ) { perror("Library not loaded"); return false; } FT_STATUS ftStatus = FT_CreateDeviceInfoList((DWORD*)pdNbOfDevices); if( ftStatus != FT_OK ) { std::string errormsg = GetFtStatusDescription(ftStatus); errormsg += ":FT_CreateDeviceInfoList"; perror(errormsg.c_str()); } return (FT_OK == ftStatus); }
FT_STATUS Find(int vid, int pid) { FT_STATUS status; FT_SetVIDPID(vid, pid); DWORD numDevs = 0; status = FT_CreateDeviceInfoList(&numDevs); if (numDevs > 0) { // allocate storage for list based on numDevs FT_DEVICE_LIST_INFO_NODE *devInfo = new FT_DEVICE_LIST_INFO_NODE[numDevs]; memset(devInfo, 0, numDevs*sizeof(FT_DEVICE_LIST_INFO_NODE)); // get the device information list status = FT_GetDeviceInfoList(devInfo, &numDevs); printf("\nFound Devices: %d\r\n", numDevs); for(int i = 0; i < numDevs; i++) { // FT_HANDLE handy; // FT_GetDeviceInfoDetail (i, // &devInfo[i].Flags, // &devInfo[i].Type, // &devInfo[i].ID, // &devInfo[i].LocId, // devInfo[i].SerialNumber, // &devInfo[i].Description, // &handy); printf("%s\r\n", devInfo[i].Description); printf("%s\r\n", devInfo[i].SerialNumber); printf("Open: %d\n", devInfo[i].Flags & 0x1); } delete[] devInfo; } return status; }
static FT_HANDLE OpenUSBDevice( int nType, int nId ) { FT_HANDLE hndl = 0; unsigned i; DWORD dwDevs; FT_DEVICE_LIST_INFO_NODE *pNodes = 0; if( FT_CreateDeviceInfoList( &dwDevs) == FT_OK ) { pNodes = (FT_DEVICE_LIST_INFO_NODE *)calloc( sizeof(FT_DEVICE_LIST_INFO_NODE) , dwDevs ); if( FT_GetDeviceInfoList( pNodes, &dwDevs ) == FT_OK ) { for( i = 0; i < dwDevs; i++ ) { if( pNodes[i].Type == nType && pNodes[i].ID == nId ) { if( FT_OpenEx( pNodes[i].Description, FT_OPEN_BY_DESCRIPTION, &hndl ) != FT_OK ) { hndl = 0; goto cleanup; } /* if */ if( FT_SetLatencyTimer( hndl, s_nUsbLatency ) != FT_OK || FT_SetTimeouts( hndl, s_nReadTimeout, s_nWriteTimeout ) != FT_OK ) { FT_Close( s_hndl ); hndl = 0; goto cleanup; } break; } /* if */ } /* for */ } /* if */ } /* if */ cleanup: if( pNodes ) free( pNodes ); return hndl; }
void writebits(UCHAR Mask) { DWORD devIndex = 0; DWORD numDevs; UCHAR ucMask =0x0; ftStatus = FT_CreateDeviceInfoList(&numDevs); if (ftStatus == FT_OK) { // printf("Number of devices is %d\n",numDevs); } if (numDevs > 0) { // allocate storage for list based on numDevs devInfo = (FT_DEVICE_LIST_INFO_NODE*)malloc(sizeof(FT_DEVICE_LIST_INFO_NODE)*numDevs); // get the device information list ftStatus = FT_GetDeviceInfoList(devInfo,&numDevs); if (ftStatus == FT_OK) { /* for (i = 0; i < numDevs; i++) { printf("Dev %d:\n",i); printf(" Flags=0x%x\n",devInfo[i].Flags); printf(" Type=%s\n",devices[devInfo[i].Type]); printf(" ID=0x%x\n",devInfo[i].ID); printf(" LocId=0x%x\n",devInfo[i].LocId); printf(" SerialNumber=%s\n",devInfo[i].SerialNumber); printf(" Description=%s\n",devInfo[i].Description); printf(" ftHandle=0x%x\n",devInfo[i].ftHandle); } */ } else { } i=0; ftStatus = FT_Open(i,&ftHandle); if (ftStatus == FT_OK) { // printf("open OK\n"); } else { printf("Open failed! \n"); } ucMask = Mask; // Set CBUS pins states ftStatus = FT_SetBitMode(ftHandle,ucMask,0x20); // Check to see if write successful if (ftStatus == FT_OK) { printf("CBUS Write Succesful: 0x%02X\n",ucMask); } else { printf("CBUS write failed!\n"); } // Close device handle ftStatus = FT_Close(ftHandle); } }
mraa_result_t mraa_ftdi_ft4222_init() { mraa_result_t mraaStatus = MRAA_SUCCESS; FT_STATUS ftStatus; FT_DEVICE_LIST_INFO_NODE* devInfo = NULL; DWORD numDevs = 0; int i; int retCode = 0; ftStatus = FT_CreateDeviceInfoList(&numDevs); if (ftStatus != FT_OK) { syslog(LOG_ERR, "FT_CreateDeviceInfoList failed: error code %d\n", ftStatus); mraaStatus = MRAA_ERROR_NO_RESOURCES; goto init_exit; } if (numDevs == 0) { syslog(LOG_ERR, "No FT4222 devices connected.\n"); goto init_exit; } devInfo = calloc((size_t) numDevs, sizeof(FT_DEVICE_LIST_INFO_NODE)); if (devInfo == NULL) { syslog(LOG_ERR, "FT4222 allocation failure.\n"); mraaStatus = MRAA_ERROR_NO_RESOURCES; goto init_exit; } ftStatus = FT_GetDeviceInfoList(devInfo, &numDevs); if (ftStatus != FT_OK) { syslog(LOG_ERR, "FT_GetDeviceInfoList failed (error code %d)\n", (int) ftStatus); mraaStatus = MRAA_ERROR_NO_RESOURCES; goto init_exit; } /* FT4222_Version ft4222Version; FT4222_STATUS ft4222Status = FT4222_GetVersion(ftHandle, &ft4222Version); if (FT4222_OK == ft4222Status){ syslog(LOG_NOTICE, "FT4222_GetVersion %08X %08X\n", ft4222Version.chipVersion, ft4222Version.dllVersion); } else syslog(LOG_ERR, "FT4222_GetVersion failed with code %d", ft4222Status); */ syslog(LOG_NOTICE, "FT_GetDeviceInfoList returned %d devices\n", numDevs); DWORD locationId = 0; for (i = 0; i < numDevs && locationId == 0; ++i) { // printf("%d: type = %d, location = %d\n", i, devInfo[i].Type, devInfo[i].LocId); if (devInfo[i].Type == FT_DEVICE_4222H_0 || devInfo[i].Type == FT_DEVICE_4222H_3) locationId = devInfo[i].LocId; } if (locationId == 0) { syslog(LOG_ERR, "FT_GetDeviceInfoList contains no valid devices\n"); mraaStatus = MRAA_ERROR_NO_RESOURCES; goto init_exit; } ftStatus = FT_OpenEx((PVOID)(uintptr_t) locationId, FT_OPEN_BY_LOCATION, &ftHandle); if (ftStatus != FT_OK) { syslog(LOG_ERR, "FT_OpenEx failed (error %d)\n", (int) ftStatus); mraaStatus = MRAA_ERROR_NO_RESOURCES; goto init_exit; } // Tell the FT4222 to be an I2C Master. FT4222_STATUS ft4222Status = FT4222_I2CMaster_Init(ftHandle, bus_speed); if (FT4222_OK != ft4222Status) { syslog(LOG_ERR, "FT4222_I2CMaster_Init failed (error %d)!\n", ft4222Status); mraaStatus = MRAA_ERROR_NO_RESOURCES; goto init_exit; } // Reset the I2CM registers to a known state. ft4222Status = FT4222_I2CMaster_Reset(ftHandle); if (FT4222_OK != ft4222Status) { syslog(LOG_ERR, "FT4222_I2CMaster_Reset failed (error %d)!\n", ft4222Status); mraaStatus = MRAA_ERROR_NO_RESOURCES; goto init_exit; } init_exit: if (devInfo != NULL) ; free(devInfo); if (mraaStatus == MRAA_SUCCESS) syslog(LOG_NOTICE, "mraa_ftdi_ft4222_init completed successfully\n"); return mraaStatus; }
FT_STATUS GetComPort( LONG * comPort ) { //FTD2xx: // FT_GetDriverVersion , FT_GetLibraryVersion // FT_GetDeviceInfo , FT_CreateDeviceInfoList , FT_GetDeviceInfoDetail // FT_GetComPortNumber // FT_CyclePort , FT_ResetPort , FT_ResetDevice , FT_GetStatus FT_HANDLE ftHandle; FT_STATUS ftStatus; uint8_t * version; #define VER_BUILD 0 #define VER_MINOR 1 #define VER_MAJOR 2 #define VER_UNUSED 3 DWORD dwLibraryVer; // Get DLL version ftStatus = FT_GetLibraryVersion(&dwLibraryVer); if (ftStatus == FT_OK) { version = (uint8_t *)&dwLibraryVer; //ASSUMPTION: dwLibraryVer is little-endian std::cout << "FTD2xx Library " << int(version[VER_MAJOR]) << "." << int(version[VER_MINOR]) << " Build " << int(version[VER_BUILD]) << std::endl; } else { std::cerr << "ERROR: FT_GetLibraryVersion()" << std::endl; std::cerr << "ERROR: returning ftStatus" << std::endl; return ftStatus; } DWORD dwDriverVer; // Get driver version ftStatus = FT_Open(0, &ftHandle); if (ftStatus == FT_OK) { ftStatus = FT_GetDriverVersion(ftHandle, &dwDriverVer); if (ftStatus == FT_OK) { version = (uint8_t *)&dwDriverVer; //ASSUMPTION: dwLibraryVer is little-endian std::cout << "FTD2xx Driver " << int(version[VER_MAJOR]) << "." << int(version[VER_MINOR]) << " Build " << int(version[VER_BUILD]) << std::dec << std::endl; } else { std::cerr << "ERROR: FT_GetDriverVersion()" << std::endl; std::cerr << "ERROR: returning ftStatus" << std::endl; return ftStatus; } FT_Close(ftHandle); } else { std::cerr << "ERROR: FT_Open()" << std::endl; std::cerr << "ERROR: returning ftStatus" << std::endl; return ftStatus; } DWORD numDevs; ftStatus = FT_ListDevices(&numDevs, NULL, FT_LIST_NUMBER_ONLY); if (ftStatus == FT_OK) { // FT_ListDevices OK, number of devices connected is in numDevs } else { // FT_ListDevices failed std::cerr << "ERROR: FT_ListDevices()" << std::endl; std::cerr << "ERROR: returning ftStatus" << std::endl; return ftStatus; } DWORD numDevs2; // create the device information list ftStatus = FT_CreateDeviceInfoList(&numDevs2); if (ftStatus == FT_OK) { } else { // FT_CreateDeviceInfoList failed std::cerr << "ERROR: FT_CreateDeviceInfoList()" << std::endl; std::cerr << "ERROR: returning ftStatus" << std::endl; return ftStatus; } if (numDevs != numDevs2) { std::cerr << "ERROR: number of devices from FT_ListDevices() and FT_CreateDeviceInfoList() are different" << std::endl; return ftStatus; } if (numDevs == 0) { std::cerr << "ERROR: numDevs==0 ; ftStatus==FT_DEVICE_NOT_FOUND (2) ???" << std::endl; std::cerr << "ERROR: returning ftStatus" << std::endl; return ftStatus; } if (numDevs > 1) { std::cerr << "ERROR: numDevs > 1" << std::endl; std::cerr << "ERROR: returning numDevs" << std::endl; return numDevs; } std::cout << "1 FTDI device found" << std::endl; /* DWORD devIndex = 0; // first device char buffer[64]; // more than enough room! ftStatus = FT_ListDevices((PVOID)devIndex, buffer, FT_LIST_BY_INDEX | FT_OPEN_BY_SERIAL_NUMBER); if (ftStatus == FT_OK) { // FT_ListDevices OK, serial number is in Buffer } else { // FT_ListDevices failed std::cerr << "ERROR: FT_ListDevices()" << std::endl; std::cerr << "ERROR: returning ftStatus" << std::endl; return ftStatus; } std::cout << buffer << std::endl; */ //FT_DEVICE_LIST_INFO_NODE * devInfo; // allocate storage for list based on numDevs //devInfo = (FT_DEVICE_LIST_INFO_NODE*)malloc(sizeof(FT_DEVICE_LIST_INFO_NODE)*numDevs); FT_DEVICE_LIST_INFO_NODE devInfo[1]; // get the device information list ftStatus = FT_GetDeviceInfoList(devInfo, &numDevs); if (ftStatus == FT_OK) { //for (unsigned int i = 0; i < numDevs; i++) //{ unsigned int i = 0; //std::cout << "Dev " << i << ":" << std::endl; std::cout << std::hex; std::cout << " Flags=0x" << devInfo[i].Flags << std::endl; std::cout << " Type=0x" << devInfo[i].Type << std::endl; std::cout << " ID=0x" << devInfo[i].ID << std::endl; std::cout << " LocId=0x" << devInfo[i].LocId << std::endl; std::cout << " ftHandle=0x" << devInfo[i].ftHandle << std::endl; std::cout << std::dec; std::cout << " SerialNumber=" << devInfo[i].SerialNumber << std::endl; std::cout << " Desc=" << devInfo[i].Description << std::endl; //} } else { std::cerr << "ERROR: FT_GetDeviceInfoList()" << std::endl; std::cerr << "ERROR: returning ftStatus" << std::endl; return ftStatus; } ftStatus = FT_Open(0, &ftHandle); if (ftStatus == FT_OK) { ftStatus = FT_GetComPortNumber(ftHandle, comPort); if (ftStatus == FT_OK) { if(*comPort == -1) { // No COM port assigned } else { // COM port assigned with number held in *comPort } } else { // FT_GetComPortNumber FAILED! std::cerr << "ERROR: FT_GetComPortNumber()" << std::endl; std::cerr << "ERROR: returning ftStatus" << std::endl; return ftStatus; } FT_Close(ftHandle); if (ftStatus == FT_OK) { } else { std::cerr << "ERROR: FT_Close()" << std::endl; std::cerr << "ERROR: returning ftStatus" << std::endl; return ftStatus; } } else { std::cerr << "ERROR: FT_Open()" << std::endl; std::cerr << "ERROR: returning ftStatus" << std::endl; return ftStatus; } return FT_OK; }
mraa_result_t mraa_ftdi_ft4222_init() { mraa_result_t mraaStatus = MRAA_ERROR_NO_RESOURCES; FT_DEVICE_LIST_INFO_NODE* devInfo = NULL; FT_STATUS ftStatus; DWORD numDevs = 0; int i; int retCode = 0; ftStatus = FT_CreateDeviceInfoList(&numDevs); if (ftStatus != FT_OK) { syslog(LOG_ERR, "FT_CreateDeviceInfoList failed: error code %d\n", ftStatus); goto init_exit; } devInfo = calloc((size_t) numDevs, sizeof(FT_DEVICE_LIST_INFO_NODE)); if (devInfo == NULL) { syslog(LOG_ERR, "FT4222 allocation failure.\n"); goto init_exit; } ftStatus = FT_GetDeviceInfoList(devInfo, &numDevs); syslog(LOG_NOTICE, "FT_GetDeviceInfoList returned %d devices\n", numDevs); if (ftStatus != FT_OK) { syslog(LOG_ERR, "FT_GetDeviceInfoList failed (error code %d)\n", (int) ftStatus); goto init_exit; } if (numDevs < 2) { syslog(LOG_ERR, "No FT4222 devices connected.\n"); goto init_exit; } if(numDevs > 2) { syslog(LOG_ERR, "CNFMODE not supported. Valid modes are 0 or 3.\n"); goto init_exit; } // FIXME: Assumes just one physical FTDI device present DWORD locationIdI2c = 0; DWORD locationIdGpio = 0; if (devInfo[0].Type == FT_DEVICE_4222H_0) locationIdI2c = devInfo[0].LocId; if (devInfo[1].Type == FT_DEVICE_4222H_0) locationIdGpio = devInfo[1].LocId; if (locationIdI2c == 0) { syslog(LOG_ERR, "FT_GetDeviceInfoList contains no I2C controllers\n"); goto init_exit; } if (locationIdGpio == 0) { syslog(LOG_ERR, "FT_GetDeviceInfoList contains no GPIO controllers\n"); goto init_exit; } ftStatus = FT_OpenEx((PVOID)(uintptr_t) locationIdI2c, FT_OPEN_BY_LOCATION, &ftHandleI2c); if (ftStatus != FT_OK) { syslog(LOG_ERR, "FT_OpenEx failed (error %d)\n", (int) ftStatus); goto init_exit; } ftStatus = FT_OpenEx((PVOID)(uintptr_t) locationIdGpio, FT_OPEN_BY_LOCATION, &ftHandleGpio); if (ftStatus != FT_OK) { syslog(LOG_ERR, "FT_OpenEx failed (error %d)\n", (int) ftStatus); goto init_exit; } FT4222_SetSuspendOut(ftHandleGpio, 0); FT4222_SetWakeUpInterrupt(ftHandleGpio, 0); ftStatus = FT4222_GPIO_Init(ftHandleGpio, pinDirection); if (ftStatus != FT_OK) { syslog(LOG_ERR, "FT4222_GPIO_Init failed (error %d)\n", (int) ftStatus); mraaStatus = MRAA_ERROR_NO_RESOURCES; goto init_exit; } // Tell the FT4222 to be an I2C Master by default on init. FT4222_STATUS ft4222Status = FT4222_I2CMaster_Init(ftHandleI2c, bus_speed); if (FT4222_OK != ft4222Status) { syslog(LOG_ERR, "FT4222_I2CMaster_Init failed (error %d)!\n", ft4222Status); goto init_exit; } ft4222Status = FT4222_I2CMaster_Reset(ftHandleI2c); if (FT4222_OK != ft4222Status) { syslog(LOG_ERR, "FT4222_I2CMaster_Reset failed (error %d)!\n", ft4222Status); goto init_exit; } mraaStatus = MRAA_SUCCESS; init_exit: if (devInfo != NULL) free(devInfo); if (mraaStatus == MRAA_SUCCESS) syslog(LOG_NOTICE, "mraa_ftdi_ft4222_init completed successfully\n"); return mraaStatus; }
//***************************************************** //* Name: pindmdInit //* Purpose: initialize ftdi driver //* In: //* Out: //***************************************************** void pinddrvInit(void) { UINT8 deviceId; #ifdef PINDMD2 int ret = 0; enabled = 1; do16 = 1; //f = fopen("debug.txt","w"); //init usb library usb_init(); //find busses usb_find_busses(); //find devices usb_find_devices(); //try to open our device if( !( device = open_dev() ) ) { //if not successfull, print error message MessageBox(NULL, "PinDMD not found", "Error", MB_ICONERROR); enabled = 0; return; } //set configuration if( usb_set_configuration( device, MY_CONFIG ) < 0 ) { MessageBox(NULL, "PinDMD cannot configure", "Error", MB_ICONERROR); enabled = 0; usb_close( device ); return; } //try to claim interface for use if( usb_claim_interface( device, MY_INTF ) < 0 ) { MessageBox(NULL, "PinDMD cannot claim interface", "Error", MB_ICONERROR); enabled = 0; usb_close( device ); return; } // SETUP async ret = usb_bulk_setup_async( device, &asyncWriteContext, EP_OUT ); if( ret < 0 ) { MessageBox(NULL, "PinDMD cannot setup async", "Error", MB_ICONERROR); enabled = 0; //relese interface usb_release_interface( device, MY_INTF ); //close device and exit usb_close( device ); return; } //if(f) // fprintf(f,"all ok:%d \n",enabled); #else FT_DEVICE_LIST_INFO_NODE *devInfo; DWORD numDevs; UINT8 i; UINT8 BitMode; deviceId = 0; sendFrameCount=0; // create the device information list ftStatus = FT_CreateDeviceInfoList(&numDevs); enabled = 0; // ftdi devices found if (numDevs > 0) { // allocate storage for list based on numDevs devInfo = (FT_DEVICE_LIST_INFO_NODE*)malloc(sizeof(FT_DEVICE_LIST_INFO_NODE)*numDevs); // get the device information list ftStatus = FT_GetDeviceInfoList(devInfo,&numDevs); // info request successful if (ftStatus == FT_OK) { for (i = 0; i < numDevs; i++) { // search for pindmd board serial number if((strcmp(devInfo[i].SerialNumber,"DMD1000")==0) || (strcmp(devInfo[i].SerialNumber,"DMD1001")==0) || (strcmp(devInfo[i].SerialNumber,"DMD2000A")==0)){ // assign divice id (incase other ftdi devices are connected) deviceId=i; enabled = 1; } // pinDMD 2 //if(strcmp(devInfo[i].SerialNumber,"DMD2000A")==0) // pinDMD_Version = 2; // slow usb if(strcmp(devInfo[i].SerialNumber,"DMD1001")==0) slowUSB = 1; } } } else { enabled=0; return; } // get handle on device ftStatus = FT_Open(deviceId, &ftHandle); if(ftStatus != FT_OK){ // FT_Open failed return; enabled=0; return; } // check pinDMD firmware to see if its 16 colour (bit4=true) FT_SetBitMode(ftHandle, 0x0, 0x20); ftStatus = FT_GetBitMode(ftHandle, &BitMode); if (ftStatus == FT_OK) { // BitMode contains current value do16 = ((BitMode&0x08)==0x08); doOther = ((BitMode&0x04)==0x04); } // original pinDMD //if(pinDMD_Version==1){ // set Asynchronous Bit Bang Mode FT_SetBitMode(ftHandle, 0xff, 0x1); // set Baud FT_SetBaudRate(ftHandle, slowUSB?11000:12000); // Actually 10400 * 16 // new pinDMD 2 FPGA /*} else { do16 = 1; FT_SetBitMode(ftHandle, 0xff, 0); Sleep(10); FT_SetBitMode(ftHandle, 0xff, 0x40); FT_SetLatencyTimer(ftHandle, 16); FT_SetUSBParameters(ftHandle,0x10000, 0x10000); FT_SetFlowControl(ftHandle, FT_FLOW_RTS_CTS, 0x0, 0x0); FT_Purge(ftHandle, FT_PURGE_RX); Sleep(10); }*/ #endif }
int ftdi_init() { FT_DEVICE ftDevice; DWORD deviceID; char SerialNumber[16+1]; char Description[64+1]; // Does an FTDI device exist? printf("Checking for FTDI devices...\n"); ftStatus = FT_CreateDeviceInfoList(&dwNumDevs); // Get the number of FTDI devices if (ftStatus != FT_OK) // Did the command execute OK? { printf("Error in getting the number of devices\n"); return 1; // Exit with error } if (dwNumDevs < 1) // Exit if we don't see any { printf("There are no FTDI devices installed\n"); return 1; // Exist with error } printf("%d FTDI devices found - the count includes individual ports on a single chip\n", dwNumDevs); ftHandle=NULL; //go thru' list of devices for(int i=0; i<dwNumDevs; i++) { printf("Open port %d\n",i); ftStatus = FT_Open(i, &ftHandle); if (ftStatus != FT_OK) { printf("Open Failed with error %d\n", ftStatus); printf("If runing on Linux then try <rmmod ftdi_sio> first\n"); continue; } FT_PROGRAM_DATA ftData; char ManufacturerBuf[32]; char ManufacturerIdBuf[16]; char DescriptionBuf[64]; char SerialNumberBuf[16]; ftData.Signature1 = 0x00000000; ftData.Signature2 = 0xffffffff; ftData.Version = 0x00000003; //3 = FT2232H extensions ftData.Manufacturer = ManufacturerBuf; ftData.ManufacturerId = ManufacturerIdBuf; ftData.Description = DescriptionBuf; ftData.SerialNumber = SerialNumberBuf; ftStatus = FT_EE_Read(ftHandle,&ftData); if (ftStatus == FT_OK) { printf("\tDevice: %s\n\tSerial: %s\n", ftData.Description, ftData.SerialNumber); printf("\tDevice Type: %02X\n", ftData.IFAIsFifo7 ); break; } else { printf("\tCannot read ext flash\n"); } } if(ftHandle==NULL) { printf("NO FTDI chip with FIFO function\n"); return -1; } //ENABLE SYNC FIFO MODE ftStatus |= FT_SetBitMode(ftHandle, 0xFF, 0x00); ftStatus |= FT_SetBitMode(ftHandle, 0xFF, 0x40); if (ftStatus != FT_OK) { printf("Error in initializing1 %d\n", ftStatus); FT_Close(ftHandle); return 1; // Exit with error } UCHAR LatencyTimer = 2; //our default setting is 2 ftStatus |= FT_SetLatencyTimer(ftHandle, LatencyTimer); ftStatus |= FT_SetUSBParameters(ftHandle,0x10000,0x10000); ftStatus |= FT_SetFlowControl(ftHandle,FT_FLOW_RTS_CTS,0x10,0x13); if (ftStatus != FT_OK) { printf("Error in initializing2 %d\n", ftStatus); FT_Close(ftHandle); return 1; // Exit with error } //return with success return 0; }
int main(int argc, char **argv) { FILE *fd; FT_STATUS ftStatus = FT_OK; FT_HANDLE ftHandle; DWORD dwNumberOfDevices = 0; // int vid = 0x0403, pid = 0x6001; // int vid = 0x1781, pid = 0x0C31; int vid = 0x1781, pid = 0x0C30; if (argc < 2) { printf("Usage: %s filename\n", argv[0]); return 1; } FT_SetVIDPID(vid, pid); fd = fopen(argv[1], "r"); if (!fd) { fclose(fd); printf("Could not open file\n"); return 1; } ftStatus = FT_CreateDeviceInfoList(&dwNumberOfDevices); if (ftStatus == FT_OK) { bool found = false; for (int i = 0; i < (int)dwNumberOfDevices; i++) { FT_PROGRAM_DATA pData; char ManufacturerBuf[32]; char ManufacturerIdBuf[16]; char DescriptionBuf[64]; char SerialNumberBuf[16]; pData.Signature1 = 0x00000000; pData.Signature2 = 0xffffffff; pData.Version = 0x00000002; // EEPROM structure with FT232R extensions pData.Manufacturer = ManufacturerBuf; pData.ManufacturerId = ManufacturerIdBuf; pData.Description = DescriptionBuf; pData.SerialNumber = SerialNumberBuf; ftStatus = FT_Open(i, &ftHandle); ftStatus = FT_EE_Read(ftHandle, &pData); if(ftStatus == FT_OK){ if(pData.VendorId == vid && pData.ProductId == pid){ found = true; break; } } FT_Close(ftHandle); } if (!found) { printf("Could not find TellStick (Duo)\n"); return 1; } } if (pid == 0x0C31) { FT_SetBaudRate(ftHandle, 115200); } else { FT_SetBaudRate(ftHandle, 9600); } FT_SetFlowControl(ftHandle, FT_FLOW_NONE, 0, 0); std::string data = readHex(fd); FT_Purge(ftHandle, FT_PURGE_RX | FT_PURGE_TX); printf("Reboot TellStick..."); ftStatus = FT_SetBitMode(ftHandle, 0xff, 0x20); sleep(1); printf("Done\n"); ftStatus = FT_SetBitMode(ftHandle, 0xf0, 0x20); printf("Waiting for TellStick Duo Bootloader.\n"); waitFor(ftHandle, 'g'); send(ftHandle, 'r'); printf("Uploading hex-file\n"); uploadHex(ftHandle, data); printf("Rebooting TellStick\n"); waitFor(ftHandle, 'b'); send(ftHandle, 0x00); printf("Firmware updated!\n"); FT_Close(ftHandle); fclose(fd); }
int main() { char cBufWrite[BUF_SIZE]; char * pcBufRead = NULL; char * pcBufLD[MAX_DEVICES + 1]; char cBufLD[MAX_DEVICES][64]; DWORD dwRxSize = 0; DWORD dwBytesWritten, dwBytesRead; FT_STATUS ftStatus; FT_HANDLE ftHandle[MAX_DEVICES]; int iNumDevs = 0; int i, j; int iDevicesOpen; FT_DEVICE_LIST_INFO_NODE *devInfo; // // create the device information list // ftStatus = FT_CreateDeviceInfoList(&iNumDevs); if (ftStatus == FT_OK) { printf("Number of devices is %d\n",iNumDevs); } // // allocate storage for list based on numDevs // devInfo = (FT_DEVICE_LIST_INFO_NODE*)malloc(sizeof(FT_DEVICE_LIST_INFO_NODE)*iNumDevs); // // get the device information list // ftStatus = FT_GetDeviceInfoList(devInfo,&iNumDevs); if (ftStatus == FT_OK) { for (i = 0; i < iNumDevs; i++) { printf("Dev %d:\n",i); printf(" Flags=0x%x\n",devInfo[i].Flags); printf(" Type=0x%x\n",devInfo[i].Type); printf(" ID=0x%x\n",devInfo[i].ID); printf(" LocId=0x%x\n",devInfo[i].LocId); printf(" SerialNumber=%s\n",devInfo[i].SerialNumber); printf(" Description=%s\n",devInfo[i].Description); printf(" ftHandle=0x%x\n",devInfo[i].ftHandle); } } for(i = 0; i < MAX_DEVICES; i++) { pcBufLD[i] = cBufLD[i]; } pcBufLD[MAX_DEVICES] = NULL; ftStatus = FT_ListDevices(pcBufLD, &iNumDevs, FT_LIST_ALL | FT_OPEN_BY_SERIAL_NUMBER); // ftStatus = FT_ListDevices(pcBufLD, &iNumDevs, FT_LIST_ALL | FT_OPEN_BY_DESCRIPTION); if(ftStatus != FT_OK) { printf("Error: FT_ListDevices(%d)\n", ftStatus); return 1; } for(j = 0; j < BUF_SIZE; j++) { cBufWrite[j] = j; } for(i = 0; ( (i <MAX_DEVICES) && (i < iNumDevs) ); i++) { printf("Device %d Serial Number - %s\n", i, cBufLD[i]); } for(i = 0; ( (i <MAX_DEVICES) && (i < iNumDevs) ) ; i++) { /* Setup */ if((ftStatus = FT_OpenEx(cBufLD[i], FT_OPEN_BY_SERIAL_NUMBER, &ftHandle[i])) != FT_OK){ // if((ftStatus = FT_OpenEx(cBufLD[i], FT_OPEN_BY_DESCRIPTION, &ftHandle[i])) != FT_OK){ /* This can fail if the ftdi_sio driver is loaded use lsmod to check this and rmmod ftdi_sio to remove also rmmod usbserial */ printf("Error FT_OpenEx(%d), device\n", ftStatus, i); return 1; } // FT_SetDeadmanTimeout(ftHandle[i], 10000); iDevicesOpen++; if((ftStatus = FT_SetBaudRate(ftHandle[i], 9600)) != FT_OK) { printf("Error FT_SetBaudRate(%d), cBufLD[i] = %s\n", ftStatus, cBufLD[i]); break; } for(j = 0; j < BUF_SIZE; j++) { printf("cBufWrite[%d] = 0x%02X\n", j, cBufWrite[j]); } /* Write */ if((ftStatus = FT_Write(ftHandle[i], cBufWrite, BUF_SIZE, &dwBytesWritten)) != FT_OK) { printf("Error FT_Write(%d)\n", ftStatus); break; } sleep(1); /* Read */ dwRxSize = 0; while ((dwRxSize < BUF_SIZE) && (ftStatus == FT_OK)) { ftStatus = FT_GetQueueStatus(ftHandle[i], &dwRxSize); } if(ftStatus == FT_OK) { pcBufRead = (char*)realloc(pcBufRead, dwRxSize); memset(pcBufRead, 0xFF, dwRxSize); for(j = 0; j < dwRxSize; j++) { printf("b4 pcBufRead[%d] = 0x%02X\n", j, pcBufRead[j]); } if((ftStatus = FT_Read(ftHandle[i], pcBufRead, dwRxSize, &dwBytesRead)) != FT_OK) { printf("Error FT_Read(%d)\n", ftStatus); } else { printf("FT_Read = %d\n", dwBytesRead); for(j = 0; j < dwBytesRead; j++) { printf("aftr pcBufRead[%d] = 0x%02X\n", j, pcBufRead[j]); } } } else { printf("Error FT_GetQueueStatus(%d)\n", ftStatus); } } iDevicesOpen = i; /* Cleanup */ for(i = 0; i < iDevicesOpen; i++) { FT_Close(ftHandle[i]); printf("Closed device %s\n", cBufLD[i]); } if(pcBufRead) free(pcBufRead); return 0; }
int main(int argc, char* argv[]) { FT_HANDLE fthandle; FT_STATUS status; DWORD numdev = 0; // Open the first device connected to the system (which has index 0). You can use the various other // functions such as open_by_description to make this much more flexible and user friendly to let the user // choose which device to open. See the D2xx Programmers Guide for more information // Check how many FTDI devices are connected and installed. If one or more connected, open the first one status = FT_CreateDeviceInfoList(&numdev); if ((status == FT_OK) && (numdev > 0) ) { // Open the device now status = FT_Open(0, &fthandle); if(status != FT_OK) printf("status not ok %d\n", status); // Set the In transfer size. You can set up to 64K if required. Ideally, use a small value like this for // receiving a few bytes at a time or a larger value if you will be transferring large amounts of data status = FT_SetUSBParameters(fthandle, 256, 0); if(status != FT_OK) printf("status not ok %d\n", status); // Reset the device status = FT_ResetDevice(fthandle); if(status != FT_OK) printf("status not ok %d\n", status); // Set the handshaking mode in the driver, for I2C chips this has no affect on the external I2C interface // since it does not have handshake lines but this enables internal handshake in the driver status = FT_SetFlowControl(fthandle, FT_FLOW_RTS_CTS, FT_STOP_BITS_1, FT_PARITY_NONE); if(status != FT_OK) printf("status not ok %d\n", status); // Set Timeouts to ensure a Read or Write will return if unable to be completed // Setting both read and write timeouts to 5 seconds status = FT_SetTimeouts(fthandle, 5000, 5000); if(status != FT_OK) printf("status not ok %d\n", status); // Set Latency Timer (keeping it at default of 16ms here) status = FT_SetLatencyTimer(fthandle, 16); if(status != FT_OK) printf("status not ok %d\n", status); // Now write some data to the chips buffer char data_out[12] = "HELLO WORLD"; DWORD w_data_len = 12; DWORD data_written; status = FT_Write(fthandle, data_out, w_data_len, &data_written); if(status != FT_OK) printf("status not ok %d\n", status); else printf("12 Bytes Sent, waiting for bytes to come back\n"); /**********************************************************************/ // The I2C Master should now be able to read these 12 bytes from the FT-X over I2C. This example expects the // I2C Master to send the bytes back over I2C to the FT-X /**********************************************************************/ // Now read the data which the I2C master has written to the FT-X char data_in[12]; DWORD data_read; DWORD MyBytesReceived = 0; DWORD SoftwareTimeout = 0; // Wait for the FT-X to send our 12 bytes back to the PC while((MyBytesReceived <12) && (SoftwareTimeout < 500)) { FT_GetQueueStatus(fthandle, &MyBytesReceived); Sleep(1); SoftwareTimeout ++; } // Check if the loop exited due to timing out or receiving 12 bytes if(SoftwareTimeout == 500) { printf("Timed out waiting for data\n"); } else { // Now read the received bytes status = FT_Read(fthandle, data_in, MyBytesReceived, &data_read); if(status != FT_OK) printf("status not ok %d\n", status); else printf("data read %s\n", data_in); } // Close the device status = FT_Close(fthandle); } else { printf("No FTDI devices connected to the computer \n"); } printf("Press Return To End Program"); getchar(); printf("closed \n"); return 0; }
void get_info(void) { UCHAR Mask = 0xff; UCHAR Mode = 1; // Set asynchronous bit-bang mode LONG lComPortNumber; DWORD numDevs; //UCHAR BitMode; char ManufacturerBuf[32]; char ManufacturerIdBuf[16]; char DescriptionBuf[64]; char SerialNumberBuf[16]; ftData.Signature1 = 0x00000000; ftData.Signature2 = 0xffffffff; ftData.Version = 0x00000002; ftData.Manufacturer = ManufacturerBuf; ftData.ManufacturerId = ManufacturerIdBuf; ftData.Description = DescriptionBuf; ftData.SerialNumber = SerialNumberBuf; ftStatus = FT_CreateDeviceInfoList(&numDevs); if (ftStatus == FT_OK) { printf("Number of devices is %d\n",numDevs); } if (numDevs > 0) { // allocate storage for list based on numDevs devInfo = (FT_DEVICE_LIST_INFO_NODE*)malloc(sizeof(FT_DEVICE_LIST_INFO_NODE)*numDevs); // get the device information list ftStatus = FT_GetDeviceInfoList(devInfo,&numDevs); if (ftStatus == FT_OK) { for (i = 0; i < numDevs; i++) { printf("Dev %d:\n",i); printf(" Flags=0x%x\n",devInfo[i].Flags); printf(" Type=%s\n",devices[devInfo[i].Type]); printf(" ID=0x%x\n",devInfo[i].ID); printf(" LocId=0x%x\n",devInfo[i].LocId); printf(" SerialNumber=%s\n",devInfo[i].SerialNumber); printf(" Description=%s\n",devInfo[i].Description); // printf(" ftHandle=0x%x\n",devInfo[i].ftHandle); } } i=0; //open first device ftStatus = FT_Open(i,&ftHandle); if (ftStatus != FT_OK) { printf("Can't open %s device! \n",devInfo[i].Description); } else { printf("Successfully open %s device! \n",devInfo[i].Description); ftStatus = FT_GetComPortNumber(ftHandle,&lComPortNumber); if (ftStatus == FT_OK) { if (lComPortNumber == -1) { printf(" NO com port Assigned!\n"); } else { // COM port assigned with number held in lComPortNumber printf(" Current assigned COM Port: %d \n",lComPortNumber); } } else { printf(" Failed to get the COM Port!\n"); } ftStatus = FT_EE_Read(ftHandle, &ftData); if (ftStatus == FT_OK) { // FT_EE_Read OK, data is available in ftData printf(" EEPROM READ OK\n"); printf("Signature1 = 0x%04x\n", ftData.Signature1); printf("Signature2 = 0x%04x\n", ftData.Signature2); printf("Version = 0x%04x\n", ftData.Version); printf("VendorID = 0x%04x\n", ftData.VendorId); printf("ProductID = 0x%04x\n", ftData.ProductId); printf("Manufacturer = %s\n", ftData.Manufacturer); printf("ManufacturerID = %s\n", ftData.ManufacturerId); printf("Description = %s\n", ftData.Description); printf("SerialNumber = %s\n", ftData.SerialNumber); printf("MaxPower = %d\n", ftData.MaxPower); printf("PnP = %x\n", ftData.PnP); printf("SelfPowered = %x\n", ftData.SelfPowered); printf("RemoteWakeup = %x\n", ftData.RemoteWakeup); printf("Use Ext Osc = %x\n", ftData.UseExtOsc); printf("High Drives = %x\n", ftData.HighDriveIOs); printf("Endpoint Size = %x\n", ftData.EndpointSize); printf("Pull Down Enabled = %x\n", ftData.PullDownEnableR); printf("Serial Number Enabled = %x\n", ftData.SerNumEnableR); printf("Invert TXD = %x\n", ftData.InvertTXD); printf("Invert RXD = %x\n", ftData.InvertRXD); printf("Invert RTS = %x\n", ftData.InvertRTS); printf("Invert CTS = %x\n", ftData.InvertCTS); printf("Invert DTR = %x\n", ftData.InvertDTR); printf("Invert DSR = %x\n", ftData.InvertDSR); printf("Invert DCD = %x\n", ftData.InvertDCD); printf("Invert RI = %x\n", ftData.InvertRI); printf("CBUS0 = 0X%02X\n", ftData.Cbus0); printf("CBUS1 = 0X%02X\n", ftData.Cbus1); printf("CBUS2 = 0X%02X\n", ftData.Cbus2); printf("CBUS3 = 0X%02X\n", ftData.Cbus3); printf("CBUS4 = 0X%02X\n", ftData.Cbus4); } else { // FT_EE_Read FAILED! printf(" EEPROM READ FAILED\n"); } FT_Close(ftHandle); } } else { printf("No FT232 Device found! \n"); } }
int main(int argc, char *argv[]) { static const struct option long_opts[] = { {"prompt", no_argument, NULL, 'p'}, {"verbose", no_argument, NULL, 'v'}, {"help", no_argument, NULL, 'h'}, {NULL, no_argument, NULL, 0} }; opterr = 0; int c; int option_index = 0; while ((c = getopt_long(argc, argv, "vph", long_opts, &option_index)) != -1) switch (c) { case 'v': verbose++; break; case 'p': dont_prompt++; break; case 'h': print_usage(); return EXIT_SUCCESS; case '?': fprintf(stderr, "Unknown option `-%c'.\n", optopt); return EXIT_FAILURE; default: abort(); } DWORD num_devs; DWORD VID, PID; int iport = 0; /* See how many devices are plugged in, fail if greater than 1 */ if (verbose) printf("Creating device info list\n"); ft_status = FT_CreateDeviceInfoList(&num_devs); if (ft_status != FT_OK){ fprintf(stderr,"ERROR : Failed to create device info list, ft_status = %d\n",ft_status); return EXIT_FAILURE; } if (verbose) printf("Making sure only one FTDI device is plugged in\n"); /* Check that there aren't more than 1 device plugged in */ if (num_devs > 1){ fprintf(stderr,"ERROR : More than one FTDI device plugged in\n"); return EXIT_FAILURE; } /* Get VID/PID from FTDI device */ if (verbose) printf("Getting VID/PID from device\n"); ft_status = FT_GetVIDPID(&VID,&PID); if (ft_status != FT_OK){ fprintf(stderr,"ERROR : Failed to get VID and PID from FTDI device, ft_status = %d\n",ft_status); return EXIT_FAILURE; } if (verbose) printf(" VID = %04x, PID = %04x\n",VID,PID); /* Set the VID/PID found */ if (verbose) printf("Setting VID/PID\n"); ft_status = FT_SetVIDPID(VID,PID); if (ft_status != FT_OK){ fprintf(stderr,"ERROR : Failed to set VID and PID, ft_status = %d\n",ft_status); return EXIT_FAILURE; } /* Get info about the device and print to user */ //FT_GetDeviceInfoDetail seems to not work very reliably //DWORD lpdw_flags; //DWORD lpdw_type; //DWORD lpdw_id; //char pc_serial_number[16]; //char pc_description[64]; //ft_status = FT_GetDeviceInfoDetail(0,&lpdw_flags,&lpdw_type,&lpdw_id,NULL,pc_serial_number,pc_description,&ft_handle); //if (ft_status != FT_OK){ // fprintf(stderr,"ERROR : Failed to get device info, ft_status = %d\n",ft_status); // return EXIT_FAILURE; //} //if (verbose || !dont_prompt){ // printf("Device Information : \n"); // printf(" Description : %s\n", pc_description); // printf(" Serial Number : %s\n", pc_serial_number); // printf(" Flags : 0x%x\n", lpdw_flags); // printf(" Type : 0x%x\n", lpdw_type); // printf(" ID : 0x%x\n", lpdw_id); //} /* Ask user if this is the correct device */ if (!dont_prompt) { char correct_device; printf("Is this the correct device? (y/n) : "); scanf("%c",&correct_device); while ((correct_device != 'y') && (correct_device != 'n')) { printf("\rPlease enter y or n"); scanf("%c",&correct_device); } if (correct_device == 'n'){ printf("Exiting, since this is not the device we want to program\n"); return EXIT_SUCCESS; } } /* Open the device */ if (verbose) printf("Attempting to open device using read VID/PID..."); ft_status = FT_Open(iport, &ft_handle); /* If that didn't work, try some other likely VID/PID combos */ /* Try 0403:6014 */ if (ft_status != FT_OK){ if (verbose) printf("FAILED\nTrying VID=0x0403, PID=0x6014..."); ft_status = FT_SetVIDPID(0x0403,0x6014); if (ft_status != FT_OK){ fprintf(stderr,"ERROR : Failed to set VID and PID, ft_status = %d\n",ft_status); return EXIT_FAILURE; } ft_status = FT_Open(iport, &ft_handle); } /* Try 0403:8398 */ if (ft_status != FT_OK){ if (verbose) printf("FAILED\nTrying VID=0x0403, PID=0x8398..."); ft_status = FT_SetVIDPID(0x0403,0x8398); if (ft_status != FT_OK){ fprintf(stderr,"ERROR : Failed to set VID and PID, ft_status = %d\n",ft_status); return EXIT_FAILURE; } ft_status = FT_Open(iport, &ft_handle); } /* Exit program if we still haven't opened the device */ if (ft_status != FT_OK){ if (verbose) printf("FAILED\n"); fprintf(stderr,"ERROR : Failed to open device : ft_status = %d\nHave you tried (sudo rmmod ftdi_sio)?\n",ft_status); return EXIT_FAILURE; } if (verbose) printf("SUCCESS\n"); /* Erase the EEPROM */ ft_status = FT_EraseEE(ft_handle); if(ft_status != FT_OK) { fprintf(stderr, "ERROR: Device EEPROM could not be erased : ft_status = %d\n", ft_status); return EXIT_FAILURE; } if (verbose) printf("Erased device's EEPROM\n"); /* Assign appropriate values to eeprom data */ eeprom_data.Signature1 = 0x00000000; eeprom_data.Signature2 = 0xffffffff; eeprom_data.Version = 5; /* 5=FT232H */ eeprom_data.VendorId = USB_CUSTOM_VID; eeprom_data.ProductId = USB_CUSTOM_PID; eeprom_data.Manufacturer = "FTDI"; eeprom_data.ManufacturerId = "FT"; eeprom_data.Description = "Piksi Passthrough"; eeprom_data.IsFifoH = 1; /* needed for FIFO samples passthrough */ /* Program device EEPROM */ ft_status = FT_EE_Program(ft_handle, &eeprom_data); if (ft_status != FT_OK) { fprintf(stderr,"ERROR : Failed to program device EEPROM : ft_status = %d\n",ft_status); return EXIT_FAILURE; } if (verbose) printf("Programmed device's EEPROM\n"); /* Reset the device */ ft_status = FT_ResetDevice(ft_handle); if (ft_status != FT_OK) { fprintf(stderr, "ERROR: Device could not be reset : ft_status = %d\n", ft_status); return EXIT_FAILURE; } if (verbose) printf("Reset device\n"); /* Close the device */ if (verbose) printf("Closing device\n"); FT_Close(ft_handle); if(ft_status != FT_OK) { fprintf(stderr,"ERROR : Failed to close device : ft_status = %d\n",ft_status); return EXIT_FAILURE; } printf("Re-configuring for FIFO mode successful, please unplug and replug your device now\n"); return EXIT_SUCCESS; }
QList <DMXUSBWidget*> QLCFTDI::widgets() { QList <DMXUSBWidget*> widgetList; quint32 input_id = 0; quint32 output_id = 0; /* Find out the number of FTDI devices present */ DWORD num = 0; FT_STATUS status = FT_CreateDeviceInfoList(&num); if (status != FT_OK) { qWarning() << Q_FUNC_INFO << "CreateDeviceInfoList:" << status; return widgetList; } else if (num <= 0) { return widgetList; } // Allocate storage for list based on numDevices FT_DEVICE_LIST_INFO_NODE* devInfo = new FT_DEVICE_LIST_INFO_NODE[num]; // Get a map of user-forced serials and their types QMap <QString,QVariant> types(typeMap()); // Get the device information list if (FT_GetDeviceInfoList(devInfo, &num) == FT_OK) { for (DWORD i = 0; i < num; i++) { QString vendor, name, serial; FT_STATUS s = qlcftdi_get_strings(i, vendor, name, serial); if (s != FT_OK || name.isEmpty() || serial.isEmpty()) { // Seems that some otherwise working devices don't provide // FT_PROGRAM_DATA struct used by qlcftdi_get_strings(). name = QString(devInfo[i].Description); serial = QString(devInfo[i].SerialNumber); vendor = QString(); } qDebug() << "serial: " << serial << "name:" << name << "vendor:" << vendor; if (types.contains(serial) == true) { // Force a widget with a specific serial to either type DMXUSBWidget::Type type = (DMXUSBWidget::Type) types[serial].toInt(); switch (type) { case DMXUSBWidget::OpenTX: widgetList << new EnttecDMXUSBOpen(serial, name, vendor, output_id++, i); break; case DMXUSBWidget::ProMk2: { EnttecDMXUSBPro *promkii = new EnttecDMXUSBPro(serial, name, vendor, output_id, input_id, i); promkii->setOutputsNumber(2); promkii->setMidiPortsNumber(1, 1); output_id += 3; input_id += 2; widgetList << promkii; break; } case DMXUSBWidget::UltraPro: { EnttecDMXUSBPro *ultra = new EnttecDMXUSBPro(serial, name, vendor, output_id, input_id++, i); ultra->setOutputsNumber(2); ultra->setDMXKingMode(); output_id += 2; widgetList << ultra; break; } case DMXUSBWidget::VinceTX: widgetList << new VinceUSBDMX512(serial, name, vendor, output_id++, i); break; default: case DMXUSBWidget::ProRXTX: widgetList << new EnttecDMXUSBPro(serial, name, vendor, output_id++, input_id++, i); break; } } else if (name.toUpper().contains("PRO MK2") == true) { EnttecDMXUSBPro *promkii = new EnttecDMXUSBPro(serial, name, vendor, output_id, input_id, i); promkii->setOutputsNumber(2); promkii->setMidiPortsNumber(1, 1); output_id += 3; input_id += 2; widgetList << promkii; } else if (name.toUpper().contains("DMX USB PRO")) { /** Check if the device responds to label 77 and 78, so it might be a DMXking adapter */ int ESTAID = 0; int DEVID = 0; QString manName = readLabel(i, DMXKING_USB_DEVICE_MANUFACTURER, &ESTAID); qDebug() << "--------> Device Manufacturer: " << manName; QString devName = readLabel(i, DMXKING_USB_DEVICE_NAME, &DEVID); qDebug() << "--------> Device Name: " << devName; qDebug() << "--------> ESTA Code: " << QString::number(ESTAID, 16) << ", Device ID: " << QString::number(DEVID, 16); if (ESTAID == DMXKING_ESTA_ID) { if (DEVID == ULTRADMX_PRO_DEV_ID) { EnttecDMXUSBPro *ultra = new EnttecDMXUSBPro(serial, name, vendor, output_id, input_id++, i); ultra->setOutputsNumber(2); ultra->setDMXKingMode(); ultra->setRealName(devName); output_id += 2; widgetList << ultra; } else { EnttecDMXUSBPro *pro = new EnttecDMXUSBPro(serial, name, vendor, output_id++, 0, i); pro->setInputsNumber(0); pro->setRealName(devName); widgetList << pro; } } else { /* This is probably a Enttec DMX USB Pro widget */ EnttecDMXUSBPro *pro = new EnttecDMXUSBPro(serial, name, vendor, output_id++, input_id++, i); pro->setRealName(devName); widgetList << pro; } } else if (name.toUpper().contains("USB-DMX512 CONVERTER") == true) { widgetList << new VinceUSBDMX512(serial, name, vendor, output_id++, i); } else if (vendor.toUpper().contains("DMX4ALL") == true) { widgetList << new Stageprofi(serial, name, vendor, output_id++, i); } else { /* This is probably an Open DMX USB widget */ widgetList << new EnttecDMXUSBOpen(serial, name, vendor, output_id++, i); } } } delete [] devInfo; return widgetList; }
main (int argc, char *argv[]) { DWORD num; FT_CreateDeviceInfoList(&num); std::cout << num << " devices found" << std::endl; DWORD version; FT_GetLibraryVersion (&version); std::cout << "Version " << version << std::endl; FT_STATUS ftStatus; DWORD vid,pid; ftStatus = FT_GetVIDPID(&vid,&pid); if (ftStatus!= FT_OK) { std::cout << "Error " << ftStatus << std::endl; } std::cout << std::hex << "vid("<<vid<<") pid("<<pid<<")" << std::endl; std::cout << std::dec << "vid("<<vid<<") pid("<<pid<<")" << std::endl; FT_DEVICE_LIST_INFO_NODE devInfo[16]; ftStatus = FT_GetDeviceInfoList(devInfo, &num); if (ftStatus != FT_OK) { std::cout << "Error " << ftStatus << std::endl; } for (int i = 0; i < num; i++) { printf("Dev %d:\n",i); printf(" Flags=0x%x\n",devInfo[i].Flags); printf(" Type=0x%x\n",devInfo[i].Type); printf(" ID=0x%x\n",devInfo[i].ID); printf(" LocId=0x%x\n",devInfo[i].LocId); printf(" SerialNumber=%s\n",devInfo[i].SerialNumber); printf(" Description=%s\n",devInfo[i].Description); //printf(" ftHandle=0x%x\n",(unsigned int)devInfo[i].ftHandle); } FT_HANDLE h; ftStatus = FT_Open(0, &h); if (ftStatus != FT_OK) { std::cout << "Failed to open device - " << ftStatus << std::endl; } /* std::cout << "start" << std::endl; for(size_t i(0); i < 10; ++i) { FT_SetRts(h); FT_ClrDtr(h); sleep(1); FT_ClrRts(h); FT_SetDtr(h); sleep(1); } */ FT_Close(0); std::cout << "done" << std::endl; }