Esempio n. 1
0
void TellStick::aquireTellStick() {
	char *tempSerial = new char[serial().size()+1];
#ifdef _WINDOWS
	strcpy_s(tempSerial, serial().size()+1, serial().toLocal8Bit());
#else
	strcpy(tempSerial, serial().toLocal8Bit());
	int pid = 0x0C30;
	if (type() == 2) {
		pid = 0x0C31;
	}
	FT_SetVIDPID(0x1781, pid);
#endif
	FT_STATUS ftStatus = FT_OpenEx(tempSerial, FT_OPEN_BY_SERIAL_NUMBER, &d->ftHandle);
	delete tempSerial;
	if (ftStatus != FT_OK) {
		return;
	}
	//open = true;

	if (type() == 2) {
		FT_SetBaudRate(d->ftHandle, 115200);
	} else {
		FT_SetBaudRate(d->ftHandle, 9600);
	}
	FT_SetFlowControl(d->ftHandle, FT_FLOW_NONE, 0, 0);
	FT_SetTimeouts(d->ftHandle,1000,0);

	setUpgradeStep(2);
	QTimer::singleShot(0, this, SLOT(enterBootloader()));
}
Esempio n. 2
0
FT_STATUS ftdimut_setup() {
  FT_STATUS ftStatus; 
  unsigned char timer;

	ftStatus = FT_SetVIDPID(USB_VID, USB_PID);
  if(ftStatus != FT_OK) return ftStatus;
	ftStatus = FT_Open(0, &ftHandle);
  if(ftStatus != FT_OK) return ftStatus;
  ftStatus = FT_ResetDevice(ftHandle);
  if(ftStatus != FT_OK) return ftStatus;
  ftStatus = FT_Purge(ftHandle, FT_PURGE_RX | FT_PURGE_TX);
  if(ftStatus != FT_OK) return ftStatus;
  ftStatus = FT_SetBaudRate(ftHandle, 15625);
  if(ftStatus != FT_OK) return ftStatus;
  ftStatus = FT_SetDataCharacteristics(ftHandle, FT_BITS_8, FT_STOP_BITS_1, FT_PARITY_NONE);
  if(ftStatus != FT_OK) return ftStatus;
  ftStatus = FT_SetFlowControl(ftHandle, FT_FLOW_NONE, 0, 0);
  if(ftStatus != FT_OK) return ftStatus;
  ftStatus = FT_SetTimeouts(ftHandle, 1000, 1000);
  if(ftStatus != FT_OK) return ftStatus;
  ftStatus = FT_GetLatencyTimer(ftHandle, &timer);
  if(ftStatus != FT_OK) return ftStatus;
  ftStatus = FT_SetLatencyTimer(ftHandle, 1);
  if(ftStatus != FT_OK) return ftStatus;

  return FT_OK;
}
Esempio n. 3
0
bool FTDXXDevice::connect (int baudrate) throw ()
{
#ifdef FOUND_ftd2xx

  disconnect();

  _status = FT_SetVIDPID(0x0403, 0x6001);
  FXXCHECK("Could not set IDs.");

  _status = FT_Open(0, &_handle);
  FXXCHECK("Could not open handle.");

  _status = FT_SetBaudRate(_handle, baudrate);
  FXXCHECK("Could not set baudrate.");

  _status = FT_SetLatencyTimer(_handle, 0);
  FXXCHECK("Unable to set latency timer.");

  _status = FT_Purge(_handle, FT_PURGE_RX | FT_PURGE_TX);
  FXXCHECK("Unable to purge buffers.");

  _initialized = true;
  FTDLOG("Connection successful.");
  return true;

#else

  _initialized = false;
  FTDERROR("cannot connect FTD2xx device: compiled without required libraries");
  return false;

#endif
}
Esempio n. 4
0
int nifalcon_open(falcon_device *dev, unsigned int device_index)
{
	unsigned int falcon_count = 0, device_count = 0, i = 0;
	char* pcBufLD[MAX_DEVICES + 1];
	char cBufLD[MAX_DEVICES][64];
	char serial[64];

	//If we're not using windows, we can set PID/VID to filter on. I have no idea why this isn't provided in the windows drivers.
#ifndef WIN32
	FT_SetVIDPID(0x0403, 0xCB48);
#endif

	for(i = 0; i < MAX_DEVICES; i++) {
		pcBufLD[i] = cBufLD[i];
	}
	if((dev->falcon_status_code = FT_ListDevices(pcBufLD, &device_count, FT_LIST_ALL | FT_OPEN_BY_DESCRIPTION)) != FT_OK) return -dev->falcon_status_code;
	for(i = 0; (i < device_count) && (falcon_count <= device_index); ++i)
	{
		if(!strcmp(cBufLD[i], NIFALCON_DESCRIPTION)) falcon_count++;
	}
	if(falcon_count == 0) nifalcon_error_return(NIFALCON_DEVICE_NOT_FOUND_ERROR, "no devices connected to system");
	if(device_index > falcon_count)	nifalcon_error_return(NIFALCON_DEVICE_INDEX_OUT_OF_RANGE_ERROR, "device index out of range");

	//Now that we know the index, get the serial number
	if((dev->falcon_status_code = FT_ListDevices((PVOID)(i-1), serial, FT_LIST_BY_INDEX | FT_OPEN_BY_SERIAL_NUMBER))) return -dev->falcon_status_code;

	//Open and reset device using serial number
	if((dev->falcon_status_code = FT_OpenEx(serial, FT_OPEN_BY_SERIAL_NUMBER, &(dev->falcon))) != FT_OK) return -dev->falcon_status_code;
	dev->is_open = 1;
	return FT_OK;
}
Esempio n. 5
0
FT_STATUS OpenDevice(DeviceParams_t* device)
{
	FT_STATUS status;
	FT_SetVIDPID(device->vid, device->pid);
	status = FT_OpenEx((PVOID) device->serial, FT_OPEN_BY_SERIAL_NUMBER, &(device->handle));
	
	if(status == FT_OK)
	{
		status = FT_SetDataCharacteristics(device->handle, FT_BITS_8, FT_STOP_BITS_1, FT_PARITY_NONE);
	}

	if(status == FT_OK)
	{
		status = FT_SetBaudRate(device->handle, device->baud);
	}

	if(status == FT_OK)
	{
		// pthread_mutex_init(&device->rxEvent.eMutex, NULL);
    // pthread_cond_init(&device->rxEvent.eCondVar, NULL);
    	
    // status = FT_SetEventNotification(device->handle, FT_EVENT_RXCHAR, (PVOID) &(device->rxEvent));
    
		// pthread_create(&(device->thread), NULL, ReadData, (void*)device);
	}

	printf ("Open state [%x]\r\n", status);
	return status;
}
Esempio n. 6
0
bool CUsb3003DF2ETInterface::OpenDevice(void)
{
    FT_STATUS ftStatus;
    int baudrate = 921600;
    
    //sets serial VID/PID for a Standard Device NOTE:  This is for legacy purposes only.  This can be ommitted.
    ftStatus = FT_SetVIDPID(m_uiVid, m_uiPid);
    if (ftStatus != FT_OK) {FTDI_Error((char *)"FT_SetVIDPID", ftStatus ); return false; }
    
    ftStatus = FT_OpenEx((PVOID)m_szDeviceSerial, FT_OPEN_BY_SERIAL_NUMBER, &m_FtdiHandle);
    if (ftStatus != FT_OK) { FTDI_Error((char *)"FT_OpenEx", ftStatus ); return false; }
    
    CTimePoint::TaskSleepFor(50);
    FT_Purge(m_FtdiHandle, FT_PURGE_RX | FT_PURGE_TX );
    CTimePoint::TaskSleepFor(50);
    
    ftStatus = FT_SetDataCharacteristics(m_FtdiHandle, FT_BITS_8, FT_STOP_BITS_1, FT_PARITY_NONE);
    if ( ftStatus != FT_OK ) { FTDI_Error((char *)"FT_SetDataCharacteristics", ftStatus ); return false; }
    
    ftStatus = FT_SetFlowControl(m_FtdiHandle, FT_FLOW_RTS_CTS, 0x11, 0x13);
    if (ftStatus != FT_OK) { FTDI_Error((char *)"FT_SetFlowControl", ftStatus ); return false; }
    
    ftStatus = FT_SetRts (m_FtdiHandle);
    if (ftStatus != FT_OK) { FTDI_Error((char *)"FT_SetRts", ftStatus ); return false; }
    
    // for DF2ET-3003 interface pull DTR low to take AMBE3003 out of reset.
    ftStatus = FT_SetDtr( m_FtdiHandle );
    CTimePoint::TaskSleepFor(50);
    if (ftStatus != FT_OK) { FTDI_Error((char *)"FT_SetDtr", ftStatus); return false; }
    
    ftStatus = FT_SetBaudRate(m_FtdiHandle, baudrate );
    if (ftStatus != FT_OK) { FTDI_Error((char *)"FT_SetBaudRate", ftStatus ); return false; }
    
    ftStatus = FT_SetLatencyTimer(m_FtdiHandle, 4);
    if (ftStatus != FT_OK) { FTDI_Error((char *)"FT_SetLatencyTimer", ftStatus ); return false; }
    
    ftStatus = FT_SetUSBParameters(m_FtdiHandle, USB3XXX_MAXPACKETSIZE, 0);
    if (ftStatus != FT_OK) { FTDI_Error((char *)"FT_SetUSBParameters", ftStatus ); return false; }
    
    ftStatus = FT_SetTimeouts(m_FtdiHandle, 200, 200 );
    if (ftStatus != FT_OK) { FTDI_Error((char *)"FT_SetTimeouts", ftStatus ); return false; }
    
    // done
    return true;
}
Esempio n. 7
0
CKMotionIO::CKMotionIO()
{
	ConsoleHandler=NULL;

	Mutex = new CMutex(FALSE,"KMotionIO",NULL);

	m_Connected=false;
	SendAbortOnConnect=true;
	FailMessageAlreadyShown=false;
	Token=0;
	NonRespondingCount=0;
	m_FirmwareVersion=2;
	USB_Loc_ID=-1;
    BoardIDAssigned=false;

#ifdef _KMOTIONX
    //FT_SetVIDPID(VENDOR, PRODUCT);
    FT_SetVIDPID(1027, 62001);
#endif
}
Esempio n. 8
0
int nifalcon_get_count(falcon_device* dev)
{
    unsigned int falcon_count = 0, device_count = 0, i = 0;
	char* pcBufLD[MAX_DEVICES + 1];
	char cBufLD[MAX_DEVICES][64];
	
	for(i = 0; i < MAX_DEVICES; i++) {
		pcBufLD[i] = cBufLD[i];
	}
	//If we're not using windows, we can set PID/VID to filter on. I have no idea why this isn't provided in the windows drivers.
#ifndef WIN32
	FT_SetVIDPID(0x0403, 0xCB48);
#endif
	if((dev->falcon_status_code = FT_ListDevices(pcBufLD, &device_count, FT_LIST_ALL | FT_OPEN_BY_DESCRIPTION)) != FT_OK) return -dev->falcon_status_code;
	for(i = 0; i < device_count; ++i)
	{
		if(!strcmp(cBufLD[i], NIFALCON_DESCRIPTION)) ++falcon_count;
	}
	return falcon_count;
}
Esempio n. 9
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;
  
}
Esempio n. 10
0
File: main.c Progetto: 0x6a77/JD2XX
int main(int argc, char *argv[])
{
	FT_STATUS	ftStatus;
	FT_HANDLE	ftHandle0;
	int iport;
	FT_PROGRAM_DATA Data;
	
	if(argc > 1) {
		sscanf(argv[1], "%d", &iport);
	}
	else {
		iport = 0;
	}
	printf("opening port %d\n", iport);
	FT_SetVIDPID(0x0403, 0x6011);
	ftStatus = FT_Open(iport, &ftHandle0);
	
	if(ftStatus != 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("FT_Open(%d) failed\n", iport);
		return 1;
	}

	printf("ftHandle0 = %p\n", ftHandle0);

#ifndef BM_DEVICE
	Data.Signature1 = 0x00000000;
	Data.Signature2 = 0xffffffff;
	Data.VendorId = 0x0403;				
	Data.ProductId = 0x6001;
	Data.Manufacturer =  "FTDI";
	Data.ManufacturerId = "FT";
	Data.Description = "USB <-> Serial";
	Data.SerialNumber = "FT000001";		// if fixed, or NULL
	
	Data.MaxPower = 44;
	Data.PnP = 1;
	Data.SelfPowered = 0;
	Data.RemoteWakeup = 1;
	Data.Rev4 = 1;
	Data.IsoIn = 0;
	Data.IsoOut = 0;
	Data.PullDownEnable = 1;
	Data.SerNumEnable = 1;
	Data.USBVersionEnable = 0;
	Data.USBVersion = 0x110;
#else // If 2232C	

	Data.Signature1 = 0x00000000;
	Data.Signature2 = 0xffffffff;
	Data.VendorId = 0x0403;				
	Data.ProductId = 0x6010;
	Data.Manufacturer =  "FTDI";
	Data.ManufacturerId = "FT";
	Data.Description = "SPI";
	Data.SerialNumber = "FT123452";		// if fixed, or NULL
	
	Data.MaxPower = 200;
	Data.PnP = 1;
	Data.SelfPowered = 0;
	Data.RemoteWakeup = 0;
	Data.Rev4 = 0;
	Data.IsoIn = 0;
	Data.IsoOut = 0;
	Data.PullDownEnable = 0;
	Data.SerNumEnable = 0;
	Data.USBVersionEnable = 0;
	Data.USBVersion = 0;

	Data.Rev5 = 1;					// non-zero if Rev5 chip, zero otherwise
	Data.IsoInA = 0;				// non-zero if in endpoint is isochronous
	Data.IsoInB = 0;				// non-zero if in endpoint is isochronous
	Data.IsoOutA = 0;				// non-zero if out endpoint is isochronous
	Data.IsoOutB = 0;				// non-zero if out endpoint is isochronous
	Data.PullDownEnable5 = 0;		// non-zero if pull down enabled
	Data.SerNumEnable5 = 1;			// non-zero if serial number to be used
	Data.USBVersionEnable5 = 0;		// non-zero if chip uses USBVersion
	Data.USBVersion5 = 0x0200;		// BCD (0x0200 => USB2)
	Data.AIsHighCurrent = 0;		// non-zero if interface is high current
	Data.BIsHighCurrent = 0;		// non-zero if interface is high current
	Data.IFAIsFifo = 1;				// non-zero if interface is 245 FIFO
	Data.IFAIsFifoTar = 0;			// non-zero if interface is 245 FIFO CPU target
	Data.IFAIsFastSer = 0;			// non-zero if interface is Fast serial
	Data.AIsVCP = 0;				// non-zero if interface is to use VCP drivers
	Data.IFBIsFifo = 1;				// non-zero if interface is 245 FIFO
	Data.IFBIsFifoTar = 0;			// non-zero if interface is 245 FIFO CPU target
	Data.IFBIsFastSer = 0;			// non-zero if interface is Fast serial
	Data.BIsVCP = 0;				// non-zero if interface is to use VCP drivers

#endif								

	ftStatus = FT_EE_Program(ftHandle0, &Data);
	if(ftStatus != FT_OK) {
		printf("FT_EE_Program failed (%d)\n", ftStatus);
		FT_Close(ftHandle0);
	}
	FT_Close(ftHandle0);
	return 0;
}
Esempio n. 11
0
int main(int argc, char *argv[])
{
	FT_STATUS	ftStatus;
	FT_HANDLE	ftHandle0;
	int iport;
	FT_PROGRAM_DATA Data;
	char *serialstr;
	if(argc == 3) {
		sscanf(argv[1], "%d", &iport);
		serialstr = argv[2];
	}
	else {
		fprintf(stderr, "syntax: %s iPort serialPrefix serialNumber\n", argv[0]);
		return -1;
	}
	//printf("opening port %d\n", iport);
	FT_SetVIDPID(0x0403, 0x6014);
	ftStatus = FT_Open(iport, &ftHandle0);
	if(ftStatus != 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("FT_Open port %d failed\n", iport);
		return 1;
	}

	Data.Signature1 = 0x00000000;
	Data.Signature2 = 0xffffffff;
	Data.Version = 5;	//FT232H
	Data.VendorId = 0x0403;
	Data.ProductId = 0x6014;
	Data.Manufacturer =  "DLRC";
	Data.ManufacturerId = "FT";
	Data.Description = "DLRC SNAPNODE Plus Rev 2.0";
	Data.SerialNumber = serialstr;		// if fixed, or NULL

	Data.MaxPower = 500;
	Data.PnP = 1;
	Data.SelfPowered = 0;
	Data.RemoteWakeup = 1;

	//FT232H
	Data.PullDownEnableH = 1;	// non-zero if pull down enabled
	Data.SerNumEnableH = 1;		// non-zero if serial number to be used
	Data.ACSlowSlewH = 0;		// non-zero if AC pins have slow slew
	Data.ACSchmittInputH = 0;	// non-zero if AC pins are Schmitt input
	Data.ACDriveCurrentH = 4;	// valid values are 4mA, 8mA, 12mA, 16mA
	Data.ADSlowSlewH = 0; 		// non-zero if AD pins have slow slew
	Data.ADSchmittInputH = 0;	// non-zero if AD pins are Schmitt input
	Data.ADDriveCurrentH = 4;	// valid values are 4mA, 8mA, 12mA, 16mA
	Data.Cbus0H = 0;			// Cbus Mux control
	Data.Cbus1H = 0;			// Cbus Mux control
	Data.Cbus2H = 0;			// Cbus Mux control
	Data.Cbus3H = 1;			// Cbus Mux control
	Data.Cbus4H = 2;			// Cbus Mux control
	Data.Cbus5H = 0;			// Cbus Mux control
	Data.Cbus6H = 0;			// Cbus Mux control
	Data.Cbus7H = 0;			// Cbus Mux control
	Data.Cbus8H = 0;			// Cbus Mux control
	Data.Cbus9H = 0;			// Cbus Mux control
	Data.IsFifoH = 0;			// non-zero if interface is 245 FIFO
	Data.IsFifoTarH = 0;		// non-zero if interface is 245 FIFO CPU target
	Data.IsFastSerH = 0;		// non-zero if interface is Fast serial
	Data.IsFT1248H = 0;			// non-zero if interface is FT1248
	Data.FT1248CpolH = 0;		// FT1248 clock polarity - clock idle high (1) or clock idle low (0)
	Data.FT1248LsbH = 0;		// FT1248 data is LSB (1) or MSB (0)
	Data.FT1248FlowControlH = 0;// FT1248 flow control enable
	Data.IsVCPH = 1;			// non-zero if interface is to use VCP drivers
	Data.PowerSaveEnableH = 1;	// non-zero if using ACBUS7 to save power for self-powered designs

#ifdef H2232_DEVICE // If 2232C

	Data.Signature1 = 0x00000000;
	Data.Signature2 = 0xffffffff;
	Data.VendorId = 0x0403;				
	Data.ProductId = 0x6010;
	Data.Manufacturer =  "FTDI";
	Data.ManufacturerId = "FT";
	Data.Description = "SPI";
	Data.SerialNumber = "FT123452";		// if fixed, or NULL
	
	Data.MaxPower = 200;
	Data.PnP = 1;
	Data.SelfPowered = 0;
	Data.RemoteWakeup = 0;
	Data.Rev4 = 0;
	Data.IsoIn = 0;
	Data.IsoOut = 0;
	Data.PullDownEnable = 0;
	Data.SerNumEnable = 0;
	Data.USBVersionEnable = 0;
	Data.USBVersion = 0;

	Data.Rev5 = 1;					// non-zero if Rev5 chip, zero otherwise
	Data.IsoInA = 0;				// non-zero if in endpoint is isochronous
	Data.IsoInB = 0;				// non-zero if in endpoint is isochronous
	Data.IsoOutA = 0;				// non-zero if out endpoint is isochronous
	Data.IsoOutB = 0;				// non-zero if out endpoint is isochronous
	Data.PullDownEnable5 = 0;		// non-zero if pull down enabled
	Data.SerNumEnable5 = 1;			// non-zero if serial number to be used
	Data.USBVersionEnable5 = 0;		// non-zero if chip uses USBVersion
	Data.USBVersion5 = 0x0200;		// BCD (0x0200 => USB2)
	Data.AIsHighCurrent = 0;		// non-zero if interface is high current
	Data.BIsHighCurrent = 0;		// non-zero if interface is high current
	Data.IFAIsFifo = 1;				// non-zero if interface is 245 FIFO
	Data.IFAIsFifoTar = 0;			// non-zero if interface is 245 FIFO CPU target
	Data.IFAIsFastSer = 0;			// non-zero if interface is Fast serial
	Data.AIsVCP = 0;				// non-zero if interface is to use VCP drivers
	Data.IFBIsFifo = 1;				// non-zero if interface is 245 FIFO
	Data.IFBIsFifoTar = 0;			// non-zero if interface is 245 FIFO CPU target
	Data.IFBIsFastSer = 0;			// non-zero if interface is Fast serial
	Data.BIsVCP = 0;				// non-zero if interface is to use VCP drivers

#endif								

	ftStatus = FT_EE_Program(ftHandle0, &Data);
	if(ftStatus != FT_OK) {
		printf("FT_EE_Program failed (%d)\n", (int)ftStatus);
		FT_Close(ftHandle0);
		return -1;
	}
	//FT_CyclePort(ftHandle0);
	FT_Close(ftHandle0);
	return 0;
}
Esempio n. 12
0
CMmcUsbHndlBase::CMmcUsbHndlBase()
{
	FT_SetVIDPID(0x403,0xa8b0);
}
Esempio n. 13
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);
}
Esempio n. 14
0
static int presto_open_ftd2xx(char *req_serial)
{
	uint32_t i;
	DWORD numdevs;
	DWORD vidpid;
	char devname[FT_DEVICE_NAME_LEN];
	FT_DEVICE device;

	BYTE presto_data;
	DWORD ftbytes;

	presto->handle = (FT_HANDLE)INVALID_HANDLE_VALUE;

#if IS_WIN32 == 0
	/* Add non-standard Vid/Pid to the linux driver */
	presto->status = FT_SetVIDPID(PRESTO_VID, PRESTO_PID);
	if (presto->status != FT_OK) {
		LOG_ERROR("couldn't add PRESTO VID/PID");
		exit(-1);
	}
#endif

	presto->status = FT_ListDevices(&numdevs, NULL, FT_LIST_NUMBER_ONLY);
	if (presto->status != FT_OK) {
		LOG_ERROR("FT_ListDevices failed: %s", ftd2xx_status_string(presto->status));
		return ERROR_JTAG_DEVICE_ERROR;
	}

	LOG_DEBUG("FTDI devices available: %" PRIu32, (uint32_t)numdevs);
	for (i = 0; i < numdevs; i++) {
		presto->status = FT_Open(i, &(presto->handle));
		if (presto->status != FT_OK) {
			/* this is not fatal, the device may be legitimately open by other process,
			 *hence debug message only */
			LOG_DEBUG("FT_Open failed: %s", ftd2xx_status_string(presto->status));
			continue;
		}
		LOG_DEBUG("FTDI device %i open", (int)i);

		presto->status = FT_GetDeviceInfo(presto->handle, &device,
				&vidpid, presto->serial, devname, NULL);
		if (presto->status == FT_OK) {
			if (vidpid == PRESTO_VID_PID && (req_serial == NULL ||
					!strcmp(presto->serial, req_serial)))
				break;
		} else
			LOG_DEBUG("FT_GetDeviceInfo failed: %s", ftd2xx_status_string(
					presto->status));

		LOG_DEBUG("FTDI device %i does not match, closing", (int)i);
		FT_Close(presto->handle);
		presto->handle = (FT_HANDLE)INVALID_HANDLE_VALUE;
	}

	if (presto->handle == (FT_HANDLE)INVALID_HANDLE_VALUE)
		return ERROR_JTAG_DEVICE_ERROR;	/* presto not open, return */

	presto->status = FT_SetLatencyTimer(presto->handle, 1);
	if (presto->status != FT_OK)
		return ERROR_JTAG_DEVICE_ERROR;

	presto->status = FT_SetTimeouts(presto->handle, 100, 0);
	if (presto->status != FT_OK)
		return ERROR_JTAG_DEVICE_ERROR;

	presto->status = FT_Purge(presto->handle, FT_PURGE_TX | FT_PURGE_RX);
	if (presto->status != FT_OK)
		return ERROR_JTAG_DEVICE_ERROR;

	presto_data = 0xD0;
	presto->status = FT_Write(presto->handle, &presto_data, 1, &ftbytes);
	if (presto->status != FT_OK)
		return ERROR_JTAG_DEVICE_ERROR;

	/* delay between first write/read turnaround (after purge?) necessary
	 * under Linux for unknown reason,
	 * probably a bug in library threading */
	usleep(100000);
	presto->status = FT_Read(presto->handle, &presto_data, 1, &ftbytes);
	if (presto->status != FT_OK)
		return ERROR_JTAG_DEVICE_ERROR;

	if (ftbytes != 1) {
		LOG_DEBUG("PRESTO reset");

		presto->status = FT_Purge(presto->handle, FT_PURGE_TX | FT_PURGE_RX);
		if (presto->status != FT_OK)
			return ERROR_JTAG_DEVICE_ERROR;
		presto->status = FT_SetBitMode(presto->handle, 0x80, 1);
		if (presto->status != FT_OK)
			return ERROR_JTAG_DEVICE_ERROR;
		presto->status = FT_SetBaudRate(presto->handle, 9600);
		if (presto->status != FT_OK)
			return ERROR_JTAG_DEVICE_ERROR;

		presto_data = 0;
		for (i = 0; i < 4 * 62; i++) {
			presto->status = FT_Write(presto->handle, &presto_data, 1, &ftbytes);
			if (presto->status != FT_OK)
				return ERROR_JTAG_DEVICE_ERROR;
		}
		usleep(100000);

		presto->status = FT_SetBitMode(presto->handle, 0x00, 0);
		if (presto->status != FT_OK)
			return ERROR_JTAG_DEVICE_ERROR;

		presto->status = FT_Purge(presto->handle, FT_PURGE_TX | FT_PURGE_RX);
		if (presto->status != FT_OK)
			return ERROR_JTAG_DEVICE_ERROR;

		presto_data = 0xD0;
		presto->status = FT_Write(presto->handle, &presto_data, 1, &ftbytes);
		if (presto->status != FT_OK)
			return ERROR_JTAG_DEVICE_ERROR;

		/* delay between first write/read turnaround (after purge?) necessary under Linux for unknown reason,
		   probably a bug in library threading */
		usleep(100000);
		presto->status = FT_Read(presto->handle, &presto_data, 1, &ftbytes);
		if (presto->status != FT_OK)
			return ERROR_JTAG_DEVICE_ERROR;

		if (ftbytes != 1) {
			LOG_DEBUG("PRESTO not responding");
			return ERROR_JTAG_DEVICE_ERROR;
		}
	}

	presto->status = FT_SetTimeouts(presto->handle, 0, 0);
	if (presto->status != FT_OK)
		return ERROR_JTAG_DEVICE_ERROR;

	presto->status = FT_Write(presto->handle, &presto_init_seq,
			sizeof(presto_init_seq), &ftbytes);

	if (presto->status != FT_OK || ftbytes != sizeof(presto_init_seq))
		return ERROR_JTAG_DEVICE_ERROR;

	return ERROR_OK;
}
Esempio n. 15
0
int main(int argc, char *argv[])
{
	FT_STATUS	ftStatus;
	FT_HANDLE	ftHandle0;
	int iport;
	FT_PROGRAM_DATA Data;
	FT_DEVICE	ftDevice; 
	
	if(argc > 1) {
		sscanf(argv[1], "%d", &iport);
	}
	else {
		iport = 0;
	}
	printf("opening port %d\n", iport);
	FT_SetVIDPID(0x0403, 0x6017);
	ftStatus = FT_Open(iport, &ftHandle0);
	
	if(ftStatus != 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("FT_Open(%d) failed\n", iport);
		return 1;
	}

	printf("ftHandle0 = %p\n", ftHandle0);

		ftStatus = FT_GetDeviceInfo( 
				ftHandle0, 
				&ftDevice, 
				NULL, 
				NULL, 
				NULL, 
				NULL 
				); 

	if (ftStatus != FT_OK) { 
		printf("FT_GetDeviceType FAILED!\n");
		return 1;
	}  

	if (ftDevice == FT_DEVICE_BM) {

		Data.Signature1 = 0x00000000;
		Data.Signature2 = 0xffffffff;
		Data.VendorId = 0x0403;				
		Data.ProductId = 0x6001;
		Data.Manufacturer =  "FTDI";
		Data.ManufacturerId = "FT";
		Data.Description = "USB <-> Srial";
		Data.SerialNumber = "FT000001";		// if fixed, or NULL
		
		Data.MaxPower = 44;
		Data.PnP = 1;
		Data.SelfPowered = 0;
		Data.RemoteWakeup = 1;
		Data.Rev4 = 1;
		Data.IsoIn = 0;
		Data.IsoOut = 0;
		Data.PullDownEnable = 1;
		Data.SerNumEnable = 1;
		Data.USBVersionEnable = 0;
		Data.USBVersion = 0x110;

	}
	else if (ftDevice == FT_DEVICE_232R) {

		Data.Signature1 = 0x00000000;
		Data.Signature2 = 0xffffffff;
		Data.Version = 2;
		Data.VendorId = 0x0403;				
		Data.ProductId = 0x6001 ;
		Data.Manufacturer =  "FTDI";
		Data.ManufacturerId = "FT";
		Data.Description = "USB <-> Serial";
		Data.SerialNumber = "FT000008";		// if fixed, or NULL
		
		Data.MaxPower = 100;
		Data.PnP = 1;
		Data.SelfPowered = 0;
		Data.RemoteWakeup = 1;
			
		Data.UseExtOsc = 0x00;			// Use External Oscillator
		Data.HighDriveIOs = 0x00;			// High Drive I/Os
		Data.EndpointSize = 0x40;			// Endpoint size

		Data.PullDownEnableR = 0x00;		// non-zero if pull down enabled
		Data.SerNumEnableR = 0x01;		// non-zero if serial number to be used

		Data.InvertTXD = 0x00;			// non-zero if invert TXD
		Data.InvertRXD = 0x00;			// non-zero if invert RXD
		Data.InvertRTS = 0x00;			// non-zero if invert RTS
		Data.InvertCTS = 0x00;			// non-zero if invert CTS
		Data.InvertDTR = 0x00;			// non-zero if invert DTR
		Data.InvertDSR = 0x00;			// non-zero if invert DSR
		Data.InvertDCD = 0x00;			// non-zero if invert DCD
		Data.InvertRI = 0x00;				// non-zero if invert RI

		Data.Cbus0 = 0x02;				// Cbus Mux control
		Data.Cbus1 = 0x03;				// Cbus Mux control
		Data.Cbus2 = 0x01;				// Cbus Mux control
		Data.Cbus3 = 0x01;				// Cbus Mux control
		Data.Cbus4 = 0x05;				// Cbus Mux control

		Data.RIsD2XX = 0;				// non-zero if using VCP drivers

	}
	else if (ftDevice == FT_DEVICE_2232C) {

		Data.Signature1 = 0x00000000;
		Data.Signature2 = 0xffffffff;
		Data.VendorId = 0x0403;				
		Data.ProductId = 0x6010;
		Data.Manufacturer =  "FTDI";
		Data.ManufacturerId = "FT";
		Data.Description = "USB <-> Serial";
		Data.SerialNumber = "FT123442";		// if fixed, or NULL
		
		Data.MaxPower = 200;
		Data.PnP = 1;
		Data.SelfPowered = 0;
		Data.RemoteWakeup = 0;

		Data.Rev5 = 1;					// non-zero if Rev5 chip, zero otherwise
		Data.IsoInA = 0;				// non-zero if in endpoint is isochronous
		Data.IsoInB = 0;				// non-zero if in endpoint is isochronous
		Data.IsoOutA = 0;				// non-zero if out endpoint is isochronous
		Data.IsoOutB = 0;				// non-zero if out endpoint is isochronous
		Data.PullDownEnable5 = 0;		// non-zero if pull down enabled
		Data.SerNumEnable5 = 1;			// non-zero if serial number to be used
		Data.USBVersionEnable5 = 0;		// non-zero if chip uses USBVersion
		Data.USBVersion5 = 0x0200;		// BCD (0x0200 => USB2)
		Data.AIsHighCurrent = 0;		// non-zero if interface is high current
		Data.BIsHighCurrent = 0;		// non-zero if interface is high current
		Data.IFAIsFifo = 0;				// non-zero if interface is 245 FIFO
		Data.IFAIsFifoTar = 0;			// non-zero if interface is 245 FIFO CPU target
		Data.IFAIsFastSer = 0;			// non-zero if interface is Fast serial
		Data.AIsVCP = 0;				// non-zero if interface is to use VCP drivers
		Data.IFBIsFifo = 0;				// non-zero if interface is 245 FIFO
		Data.IFBIsFifoTar = 0;			// non-zero if interface is 245 FIFO CPU target
		Data.IFBIsFastSer = 0;			// non-zero if interface is Fast serial
		Data.BIsVCP = 0;				// non-zero if interface is to use VCP drivers

	}								

	ftStatus = FT_EE_Program(ftHandle0, &Data);
	if(ftStatus != FT_OK) {
		printf("FT_EE_Program failed (%d)\n", ftStatus);
	}
	FT_Close(ftHandle0);
	return 0;
}
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;
}
Esempio n. 17
0
bool FTDIDMXDevice::open()
{
	// Change QString to char* (not const char* note)

	char *serial;
	QByteArray a = m_path.toLatin1();

	serial = (char*)malloc(sizeof(char) * (a.count() + 1));
	memcpy(serial, a.constData(), a.count());
	serial[a.count()] = 0;

#ifndef WIN32
	// Windows users cannot dynamiccaly set VID/PID of harward
	if (FT_SetVIDPID(m_vid, m_pid) == FT_OK && 
	    FT_OpenEx(serial, FT_OPEN_BY_SERIAL_NUMBER, &m_handle) == FT_OK)
	{
#else
	if (FT_OpenEx(serial, FT_OPEN_BY_SERIAL_NUMBER, &m_handle) == FT_OK)
	{
#endif
		free(serial);
		if (!FT_SUCCESS(FT_ResetDevice(m_handle)))
		{
			qWarning() << "Unable to reset FTDI device" << m_path;
			return false;
		}

		// Set the baud rate 12 will give us 250Kbits
		if (!FT_SUCCESS(FT_SetDivisor(m_handle, 12)))
		{
			qWarning() << "Unable to set divisor on FTDI device"
				   << m_path;
			return false;
		}

		// Set the data characteristics
		if (!FT_SUCCESS(FT_SetDataCharacteristics(m_handle,
							  FT_BITS_8,
							  FT_STOP_BITS_2,
							  FT_PARITY_NONE)))
		{
			qWarning() << "Unable to set data characteristics on"
				   << "FTDI device" << m_path;
			return false;
		}

		// Set flow control
	 	if (!FT_SUCCESS(FT_SetFlowControl(m_handle, FT_FLOW_NONE, 0, 0)))
	 	{
			qWarning() << "Unable to set flow control on"
				   << "FTDI device" << m_path;
			return false;
		}

		// set RS485 for sendin
		FT_ClrRts(m_handle);

		// Clear TX RX buffers
		FT_Purge(m_handle,FT_PURGE_TX | FT_PURGE_RX);

		m_threadRunning = true;
		start(QThread::TimeCriticalPriority);

		return true;
	}
	else
	{
		qWarning() << "Unable to open FTDIDMX"
			   << m_output << ":" << serial;
		free(serial);
		return false;
	}
}

bool FTDIDMXDevice::close()
{
	// Kill thread
	m_threadRunning = false;
	wait(500);

	FT_Close(m_handle);
	return true;
}
Esempio n. 18
0
static int ublast_ftd2xx_init(struct ublast_lowlevel *low)
{
	FT_STATUS status;
	FT_HANDLE *ftdih = ublast_getftdih(low);
	uint8_t latency_timer;

	LOG_INFO("usb blaster interface using FTD2XX");
	/* Open by device description */
	if (low->ublast_device_desc == NULL) {
		LOG_WARNING("no usb blaster device description specified, "
			    "using default 'USB-Blaster'");
		low->ublast_device_desc = "USB-Blaster";
	}

#if IS_WIN32 == 0
	/* Add non-standard Vid/Pid to the linux driver */
	status = FT_SetVIDPID(low->ublast_vid, low->ublast_pid);
	if (status != FT_OK) {
		LOG_WARNING("couldn't add %4.4x:%4.4x",
			    low->ublast_vid, low->ublast_pid);
	}
#endif
	status = FT_OpenEx(low->ublast_device_desc, FT_OPEN_BY_DESCRIPTION,
			   ftdih);
	if (status != FT_OK) {
		DWORD num_devices;

		LOG_ERROR("unable to open ftdi device: %s",
			  ftd2xx_status_string(status));
		status = FT_ListDevices(&num_devices, NULL, FT_LIST_NUMBER_ONLY);
		if (status == FT_OK) {
			char **desc_array =
				malloc(sizeof(char *) * (num_devices + 1));
			unsigned int i;

			for (i = 0; i < num_devices; i++)
				desc_array[i] = malloc(64);
			desc_array[num_devices] = NULL;

			status = FT_ListDevices(desc_array, &num_devices,
						FT_LIST_ALL | FT_OPEN_BY_DESCRIPTION);

			if (status == FT_OK) {
				LOG_ERROR("ListDevices: %" PRIu32, (uint32_t)num_devices);
				for (i = 0; i < num_devices; i++)
					LOG_ERROR("%i: %s", i, desc_array[i]);
			}

			for (i = 0; i < num_devices; i++)
				free(desc_array[i]);
			free(desc_array);
		} else {
			printf("ListDevices: NONE\n");
		}
		return ERROR_JTAG_INIT_FAILED;
	}

	status = FT_SetLatencyTimer(*ftdih, 2);
	if (status != FT_OK) {
		LOG_ERROR("unable to set latency timer: %s",
				ftd2xx_status_string(status));
		return ERROR_JTAG_INIT_FAILED;
	}

	status = FT_GetLatencyTimer(*ftdih, &latency_timer);
	if (status != FT_OK) {
		LOG_ERROR("unable to get latency timer: %s",
				ftd2xx_status_string(status));
		return ERROR_JTAG_INIT_FAILED;
	}
	LOG_DEBUG("current latency timer: %i", latency_timer);

	status = FT_SetBitMode(*ftdih, 0x00, 0);
	if (status != FT_OK) {
		LOG_ERROR("unable to disable bit i/o mode: %s",
				ftd2xx_status_string(status));
		return ERROR_JTAG_INIT_FAILED;
	}
	return ERROR_OK;
}
int main(int argc, char *argv[])
{

  static const struct option long_opts[] = {
    {"verbose",  no_argument,        NULL, 'v'},
    {"help",     no_argument,        NULL, 'h'},
    {"id",       required_argument,  NULL, 'i'},
    {NULL,       no_argument,        NULL, 0}
  };

  opterr = 0;
  int c;
  int option_index = 0;
  while ((c = getopt_long(argc, argv, "vhi:", long_opts, &option_index)) != -1)
    switch (c) {
      case 'v':
        verbose++;
        break;
      case 'h':
        print_usage();
        return EXIT_SUCCESS;
      case 'i': {
        pid = parse_pid(optarg);
        if (!pid) {
          fprintf(stderr, "Invalid ID argument.\n");
          return EXIT_FAILURE;
        }
        break;
      }
      case '?':
        if (optopt == 'i')
          fprintf(stderr, "ID argument requires an argument.\n");
        else
          fprintf(stderr, "Unknown option `-%c'.\n", optopt);
        return EXIT_FAILURE;
      default:
        abort();
     }

  int iport = 0;

  /* Try to open device using input PID, or our custom PID if no input. */
  if (verbose)
    printf("Trying to open with VID=0x%04x, PID=0x%04x...",USB_CUSTOM_VID,pid);
  ft_status = FT_SetVIDPID(USB_CUSTOM_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;
  }
  ft_status = FT_Open(iport, &ft_handle);

  /* Exit program if we 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\n",ft_status);
    return EXIT_FAILURE;
  }
  if (verbose)
    printf("SUCCESS\n");

  /* Erase the EEPROM to set the device to UART mode. */
  if (verbose)
    printf("Erasing device EEPROM\n");
  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;
  }

  /* Reset the device. */
  if (verbose)
    printf("Resetting device\n");
  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;
  }

  /* 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;
  }

  if (verbose)
    printf("Re-configuring for UART mode successful, please unplug and replug your device now\n");
  return EXIT_SUCCESS;
}
Esempio n. 20
0
int main() {
  unsigned char cBufWrite[BUF_SIZE];
  unsigned char * pcBufRead = NULL;
  char * pcBufLD[MAX_DEVICES + 1];
  char cBufLD[MAX_DEVICES][64];
  DWORD dwRxSize = 0, dwRxSizeTemp = 0;
  DWORD dwBytesWritten, dwBytesRead;
  FT_STATUS ftStatus;
  FT_HANDLE ftHandle[MAX_DEVICES];
  int iNumDevs = 0;
  int i, j;
  int iDevicesOpen = 0;

  printf("Program start.\n");


  for (i = 0; i < MAX_DEVICES; i++) {
    pcBufLD[i] = cBufLD[i];
  }
  pcBufLD[MAX_DEVICES] = NULL;

  FT_SetVIDPID(1027, 59530); // use our VID and PID
  ftStatus = FT_ListDevices(pcBufLD, &iNumDevs, FT_LIST_ALL | FT_OPEN_BY_SERIAL_NUMBER);

  if (ftStatus != FT_OK) {
    printf("Error: FT_ListDevices(%d)\n", (int) ftStatus);
    return 1;
  }

  for (i = 0; ((i < MAX_DEVICES) && (i < iNumDevs)); i++) {
    printf("Device %d Serial Number - %s\n", i, cBufLD[i]);
  }

  for (j = 0; j < BUF_SIZE; j++) {
    cBufWrite[j] = j;
  }

  printf("Number of devices: %d.\n", iNumDevs);


  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) {
      /*
              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 %d\n", (int) ftStatus, i);
      printf("Use lsmod to check if ftdi_sio (and usbserial) are present.\n");
      printf("If so, unload them using rmmod, as they conflict with ftd2xx.\n");
      return 1;
    }

    printf("Opened device %s\n", cBufLD[i]);

    iDevicesOpen++;
    if ((ftStatus = FT_SetBaudRate(ftHandle[i], 9600)) != FT_OK) {
      printf("Error FT_SetBaudRate(%d), cBufLD[i] = %s\n", (int) ftStatus, cBufLD[i]);
      break;
    }

    //		printf("Calling FT_Write with this write-buffer:\n");
    //		dumpBuffer(cBufWrite, BUF_SIZE, 1);

    /* Write */
    /*
    ftStatus = FT_Write(ftHandle[i], cBufWrite, BUF_SIZE, &dwBytesWritten);
    if (ftStatus != FT_OK) {
            printf("Error FT_Write(%d)\n", (int)ftStatus);
            break;
    }
    if (dwBytesWritten != (DWORD)BUF_SIZE) {
            printf("FT_Write only wrote %d (of %d) bytes\n",
                   (int)dwBytesWritten,
                   BUF_SIZE);
            break;
    }
    sleep(1);
     */

    /* Read */

    // load buffer
    dwRxSize = 0;
    dwRxSizeTemp = 0;
    printf("Fill Buffer (Size: %d)...\n", BUF_SIZE);
    while ((dwRxSize < BUF_SIZE) && (ftStatus == FT_OK)) {
      ftStatus = FT_GetQueueStatus(ftHandle[i], &dwRxSize);

      // show progress
      if (dwRxSize > dwRxSizeTemp) {
        dwRxSizeTemp = dwRxSize;
        printf("Buffer %d/%d\n", dwRxSize, BUF_SIZE);
      }
    }

    // buffer is filled
    if (ftStatus == FT_OK) {
      // preset buffer
      pcBufRead = realloc(pcBufRead, dwRxSize);
      memset(pcBufRead, 0xFF, dwRxSize);

      /*
      printf("Calling FT_Read with this read-buffer (prefilled, initializied):\n");
      dumpBuffer(pcBufRead, dwRxSize, 1);
       */

      ftStatus = FT_Read(ftHandle[i], pcBufRead, dwRxSize, &dwBytesRead);

      if (ftStatus != FT_OK) {
        printf("Error FT_Read(%d)\n", (int) ftStatus);
        break;
      }
      if (dwBytesRead != dwRxSize) {
        printf("FT_Read only read %d (of %d) bytes\n",
                (int) dwBytesRead,
                (int) dwRxSize);
        break;
      }
      printf("FT_Read read %d bytes.  Read-buffer is now:\n", (int) dwBytesRead);
      printf("list in hex");
      dumpBuffer(pcBufRead, (int) dwBytesRead, 1);
      
      printf("list in hex");
      dumpBuffer(pcBufRead, (int) dwBytesRead, 2);
      
      printf("list in dec");
      dumpBuffer(pcBufRead, (int) dwBytesRead, 3);
      
      printf("list in combined");
      dumpBuffer(pcBufRead, (int) dwBytesRead, 4);

      /*
      if (0 != memcmp(cBufWrite, pcBufRead, BUF_SIZE)) {
          printf("Error: read-buffer does not match write-buffer.\n");
          break;
      }
      printf("%s test passed.\n", cBufLD[i]);
       */
    } else {
      printf("Error FT_GetQueueStatus(%d)\n", (int) 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);


  printf("Program end.\n");

  return 0;
}