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;
}
Ejemplo n.º 2
0
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;
}
Ejemplo n.º 3
0
/**
 * Обзор всех портов микросхемы 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;
}
Ejemplo n.º 4
0
/**
	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");
}
Ejemplo n.º 5
0
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;
  
}
Ejemplo n.º 6
0
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;
}
Ejemplo n.º 7
0
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;
}
Ejemplo n.º 8
0
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;
}
Ejemplo n.º 9
0
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;
}
Ejemplo n.º 10
0
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;
}
Ejemplo n.º 11
0
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;
}
Ejemplo n.º 12
0
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;
}
Ejemplo n.º 13
0
//*****************************************************
//* 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
}
Ejemplo n.º 14
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");
	}
}
Ejemplo n.º 15
0
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);
	}
}