Example #1
0
/**
 * @param readers Probably should be an empty list.
 */
list *find_all_readers(struct list *readers) {
  int rc;
  struct ftdi_device_list *devlist;
  struct ftdi_context ftdi;

  ftdi_init(&ftdi);
  rc = ftdi_usb_find_all(&ftdi, &devlist, RFID1_VID, RFID1_PID);
  ftdi_deinit(&ftdi);

  if(rc < 0) return NULL;

  struct ftdi_device_list *dp = devlist;
  while(dp){
    struct ftdi_context *c = malloc(sizeof(struct ftdi_context));
    if(c == NULL){
      // Out of memory !!
      // TODO: Clean up
      return NULL;
    }
    ftdi_init(c);

    struct reader *r = reader_create();
    reader_init(r, c, dp->dev);
    list_push(readers, r);

    dp = dp->next;
  }

  ftdi_list_free(&dp);

  return readers;
}
Example #2
0
/*
List connected TCTEC Relays
*/
void
listRelays()
{
	int             ret, i, bRelayStates;
	struct ftdi_device_list *devlist, *curdev;
	char            manufacturer[128], description[128], serial[128],
	                buf[1];
	if ((ret = ftdi_usb_find_all(&ftdic, &devlist, 0x0403, 0x6001)) < 0) {
		fprintf(stderr, "ftdi_usb_find_all failed: %d (%s)\n", ret, ftdi_get_error_string(&ftdic));
		return;
	}
	printf("Number of FTDI devices found: %d\n", ret);
	for (curdev = devlist; curdev != NULL; i++) {
		if ((ret = ftdi_usb_get_strings(&ftdic, curdev->dev, manufacturer, 128, description, 128, serial, 128)) < 0) {
			fprintf(stderr, "ftdi_usb_get_strings failed: %d (%s)\n", ret, ftdi_get_error_string(&ftdic));
			return;
		}
		if (strncmp(description, "TCTEC USB RELAY", 15) == 0) {
			printf("Manufacturer: %s, Description: %s, Serial: %s\n\n", manufacturer, description, serial);
		}
		curdev = curdev->next;
	}
	ftdi_list_free(&devlist);
	ftdi_deinit(&ftdic);
	return;
}
Example #3
0
/*
 * Return a list of devices found by libftdi together with a number of fields
 * describing the corresponding USB device.
 * The list is internally cached. To free it, call freeDeviceList().
 *
 * Returns: a vector pointer containing 0 or more devices, or NULL if an error
 * occured while retrieving the list. When NULL is returned, this is guaranteed
 * to be an ftdi error.
 */
const FtdiDevice::vec_deviceInfo* FtdiDevice::getDeviceList( ftdi_context* c )
{
	ftdi_context* context = c ? c : ftdi_new();
	if ( context == 0 ) return 0;
	
	if ( s_deviceList != 0 ) freeDeviceList();
	
	int r = ftdi_usb_find_all( context, &s_ftdiDeviceList, USB_VENDOR_ID, USB_PRODUCT_ID );
	s_deviceList = new vec_deviceInfo();
	if ( r >= 0 ) {
		struct ftdi_device_list* openDev = s_ftdiDeviceList;
		while ( openDev ) {
			struct deviceInfo info;
			info.ftdiDevice = openDev->dev;
			info.usbInfo = fetchUsbInformation( context, info.ftdiDevice );
			s_deviceList->push_back( info );
			
			openDev = openDev->next;
		}
	}
	
	//Only free the context if it has been allocated locally.
	if ( c == 0 ) ftdi_free( context );
	return s_deviceList;
}
Example #4
0
int main(int argc, char *argv[])
{
    int num_devs;
    struct ftdi_context *ctx;
    struct ftdi_device_list *devs = NULL;

    (void)argc;
    (void)argv;

    ctx = ftdi_new();
    if (!ctx) {
        printf("Initialization error.\n");
        return 1;
    }

    num_devs = ftdi_usb_find_all(ctx, &devs, 0, 0);
    if (num_devs < 0) {
        printf("Device list error: %s.\n", ftdi_get_error_string(ctx));
        ftdi_free(ctx);
        return 2;
    }

    printf("Found %d FTDI devices.\n", (int)num_devs);

    ftdi_list_free(&devs);

    ftdi_free(ctx);

    return 0;
}
Example #5
0
int nifalcon_open(falcon_device* dev, unsigned int device_index)
{
	unsigned int count, i, status;
	struct ftdi_device_list *dev_list, *current;
	if(!dev->is_initialized) nifalcon_error_return(NIFALCON_DEVICE_NOT_VALID_ERROR, "tried to open an uninitialized device");
	if(dev->is_open) nifalcon_close(dev);

	count = ftdi_usb_find_all(&(dev->falcon), &dev_list, NIFALCON_VENDOR_ID, NIFALCON_PRODUCT_ID);
	if(count <= 0 || device_index > count)
	{
		ftdi_list_free(&dev_list);
		if(count == 0) nifalcon_error_return(NIFALCON_DEVICE_NOT_FOUND_ERROR, "no devices connected to system");
		nifalcon_error_return(NIFALCON_DEVICE_INDEX_OUT_OF_RANGE_ERROR, "device index out of range");
	}
	for(i = 0, current = dev_list; current != NULL && i < device_index; current = dev_list->next, ++i);
	if((dev->falcon_status_code = ftdi_usb_open_dev(&(dev->falcon), current->dev)) < 0) return dev->falcon_status_code;
	ftdi_list_free(&dev_list);
	//VERY IMPORTANT
	//If we do not reset latency to 1ms, then we either have to fill the FTDI butter (64bytes) or wait 16ms
	//to get any data back. This is what was causing massive slowness in pre-1.0 releases
	if((dev->falcon_status_code = ftdi_set_latency_timer(&(dev->falcon), 1)) < 0) return dev->falcon_status_code;

	//Shift to full speed
	if((dev->falcon_status_code = ftdi_set_baudrate(&(dev->falcon), 1456312)) < 0) return dev->falcon_status_code;

	dev->is_open = 1;
	return 0;
}
Example #6
0
List* List::find_all(int vendor, int product)
{
    struct ftdi_device_list* dlist = 0;
    struct ftdi_context ftdi;
    ftdi_init(&ftdi);
    ftdi_usb_find_all(&ftdi, &dlist, vendor, product);
    ftdi_deinit(&ftdi);
    return new List(dlist);
}
Example #7
0
int nifalcon_get_count(falcon_device* dev)
{
	int count;
	struct ftdi_device_list* dev_list[128];
	if(!dev->is_initialized) nifalcon_error_return(NIFALCON_DEVICE_NOT_VALID_ERROR, "tried to get count on an uninitialized device");
	count = ftdi_usb_find_all(&(dev->falcon), dev_list, NIFALCON_VENDOR_ID, NIFALCON_PRODUCT_ID);
	ftdi_list_free(dev_list);
	return count;
}
Example #8
0
void list_devices() {
	struct ftdi_context *ftdi;
	struct ftdi_device_list *dev_list;
	struct ftdi_device_list *dev_current;
	int num_devices;

	ftdi = ftdi_new();
	if (!ftdi) {
		fprintf(stderr, "failed to initialize ftdi context\n");
		exit(1);
	}

	num_devices = ftdi_usb_find_all(ftdi, &dev_list, VID, PID);
	if (num_devices < 0) {
		fprintf(stderr, "ftdi error: %s\n",
			ftdi_get_error_string(ftdi));
		goto error;
	}

	if (!num_devices) {
		printf("unable to find saturn device!\n");
		goto done;
	}

	dev_current = dev_list;
	num_devices = 0;
	while (dev_current) {
		char manufacturer[255];
		char description[255];
		char serial[255];
		if (ftdi_usb_get_strings(ftdi, dev_current->dev,
					 manufacturer, 255,
					 description, 255,
					 serial, 255) < 0) {
			fprintf(stderr, "ftdi error: %s\n",
				ftdi_get_error_string(ftdi));
			goto done;
		}

		if (strcmp(DESCRIPTION, description) == 0)
			printf("%d: %s (%s, %s)\n", num_devices++, description,
			       manufacturer, serial);

		dev_current = dev_current->next;
	}

	if (!num_devices)
		printf("unable to find saturn device!\n");

done:
	ftdi_list_free(&dev_list);
error:
	ftdi_free(ftdi);
}
	bool FalconCommLibFTDI::getDeviceCount(int8_t& device_count)
	{
		if(!m_isInitialized)
		{
			m_errorCode = FALCON_COMM_NOT_INITIALIZED;
			return false;
		}
		struct ftdi_device_list* dev_list[128];
		device_count = ftdi_usb_find_all((m_falconDevice), dev_list, FALCON_VENDOR_ID, FALCON_PRODUCT_ID);
		ftdi_list_free(dev_list);
		return true;
	}
	bool FalconCommLibFTDI::open(uint8_t device_index)
	{
		LOG_INFO("Opening device " << device_index);
		if(!m_isInitialized)
		{
			LOG_ERROR("Device not initialized");
			m_errorCode = FALCON_COMM_NOT_INITIALIZED;
			return false;
		}
		unsigned int count, i, status;
		struct ftdi_device_list *dev_list, *current;
		if(m_isCommOpen) close();

		count = ftdi_usb_find_all((m_falconDevice), &dev_list, FALCON_VENDOR_ID, FALCON_PRODUCT_ID);
		if(count <= 0 || device_index > count)
		{
			ftdi_list_free(&dev_list);
			if(count == 0)
			{
				LOG_ERROR("No devices found");
				m_errorCode = FALCON_COMM_DEVICE_NOT_FOUND_ERROR;
				return false;
			}
			else if(device_index > count)
			{
				LOG_ERROR("Device index " << device_index << " out of range");
				m_errorCode = FALCON_COMM_DEVICE_INDEX_OUT_OF_RANGE_ERROR;
				return false;
			}
		}
		for(i = 0, current = dev_list; current != NULL && i < device_index; current = current->next, ++i);
		if(current==NULL)
		{
			LOG_ERROR("No devices found");
			m_errorCode = FALCON_COMM_DEVICE_NOT_FOUND_ERROR;
			return false;
		}
		if((m_deviceErrorCode = ftdi_usb_open_dev((m_falconDevice), current->dev)) < 0)
		{
			LOG_ERROR("Device error " << m_deviceErrorCode);
			m_errorCode = FALCON_COMM_DEVICE_ERROR;
			ftdi_list_free(&dev_list);
			return false;
		}
		ftdi_list_free(&dev_list);
		m_isCommOpen = true;
		//Purge buffers
		if((m_deviceErrorCode = ftdi_usb_purge_buffers((m_falconDevice))) < 0) return false;
		setNormalMode();
		return true;
	}
	bool FalconCommLibFTDI::getDeviceCount(int8_t& device_count)
	{
		LOG_INFO("Getting device count");
		if(!m_isInitialized)
		{
			LOG_ERROR("Device not initialized");
			m_errorCode = FALCON_COMM_NOT_INITIALIZED;
			return false;
		}
		struct ftdi_device_list* dev_list[128];
		device_count = ftdi_usb_find_all(m_falconDevice, dev_list, FALCON_VENDOR_ID, FALCON_PRODUCT_ID);
		ftdi_list_free(dev_list);
		return true;
	}
Example #12
0
int GetFTDIDevicePortNumUSingLibFTDI(UInt32 locationIDFromInterface)
{
    int ret, i;
    struct ftdi_context ftdic;
    struct ftdi_device_list *devlist, *curdev;
    char manufacturer[128], description[128];
    
    if (ftdi_init(&ftdic) < 0)
    {
        fprintf(stderr, "ftdi_init failed\n");
        return -1;
    }
    
    if ((ret = ftdi_usb_find_all(&ftdic, &devlist, 0x0403, 0x6001)) < 0)
    {
        fprintf(stderr, "ftdi_usb_find_all failed: %d (%s)\n", ret, ftdi_get_error_string(&ftdic));
        return -1;
    }
    
    printf("Number of FTDI devices found: %d\n", ret);
    
    i = 0;
    for (curdev = devlist; curdev != NULL; i++)
    {
        //printf("Checking device: %d\n", i);
        if ((ret = ftdi_usb_get_strings(&ftdic, curdev->dev, manufacturer, 128, description, 128, NULL, 0)) < 0)
        {
            fprintf(stderr, "ftdi_usb_get_strings failed: %d (%s)\n", ret, ftdi_get_error_string(&ftdic));
            return -1;
        }
        uint32_t *locationId = (uint32_t *)malloc(sizeof(uint32_t)); 
        
        xlibusb_get_device_location_id((struct libusb_device *)curdev->dev->dev,locationId);
        printf("Manufacturer: %s, Description: %s\n\n", manufacturer, description);
        if ((*locationId) == locationIDFromInterface) {
             free(locationId);
             return i;
        }
        
        free(locationId);
        //printf("0x%x deviceDesc[%d] %s",(unsigned int)&(deviceDesc[i]),i,deviceDesc[i]);
        curdev = curdev->next;
    }
    
    ftdi_list_free(&devlist);
    ftdi_deinit(&ftdic);
    
    return -1;
}
Example #13
0
int main(int argc, char **argv)
{

  int ret, i, no_devices;
  struct ftdi_context ftdic;
  struct ftdi_device_list *devlist, *curdev;
  char manufacturer[128], description[128];
  char serial[128];

  if (ftdi_init(&ftdic) < 0)
  {
    std::cerr << "ftdi_init failed" << std::endl;
    return EXIT_FAILURE;
  }

  if ((no_devices = ftdi_usb_find_all(&ftdic, &devlist, 0x0403, 0x6001)) < 0)
  {
    std::cerr << "ftdi_usb_find_all failed: " << ftdi_get_error_string(&ftdic) << std::endl;
    return EXIT_FAILURE;
  }

  std::cout << "Number of FTDI devices found: " << no_devices << std::endl;

  i = 0;
  for (curdev = devlist; curdev != NULL; i++)
  {
    std::cout << "Device #" << i << std::endl;
    if ((ret = ftdi_usb_get_strings(&ftdic, curdev->dev, manufacturer, 128, description, 128, serial, 128)) < 0)
    {
      std::cerr << "ftdi_usb_get_strings failed: " << ftdi_get_error_string(&ftdic) << std::endl;
      return EXIT_FAILURE;
    }
    std::cout << "  Manufacturer: " << manufacturer << std::endl;
    std::cout << "  Description : " << description << std::endl;
    std::cout << "  Serial Id   : " << serial << std::endl;
    curdev = curdev->next;
  }

  ftdi_list_free(&devlist);
  ftdi_deinit(&ftdic);

  return 0;
}
Example #14
0
File: spi.c Project: z80/bt-board
/* Fills spi_ports array with discovered devices, sets spi_nports */
static int spi_enumerate_ports(void)
{
    int id, rc;
    struct ftdi_device_list *ftdevlist, *ftdev;

    spi_nports = 0;

    for (id = 0; id < sizeof(ftdi_device_ids) / sizeof(ftdi_device_ids[0]) && spi_nports < SPI_MAX_PORTS; id++) {
        LOG(DEBUG, "find all: 0x%04x:0x%04x", ftdi_device_ids[id].vid, ftdi_device_ids[id].pid);
        rc = ftdi_usb_find_all(&ftdic, &ftdevlist, ftdi_device_ids[id].vid, ftdi_device_ids[id].pid);
        if (rc < 0) {
            SPI_ERR("FTDI: ftdi_usb_find_all() failed: %s", ftdi_get_error_string(&ftdic));
            return -1;
        }
        if (rc == 0)
            continue;

        for (ftdev = ftdevlist; ftdev && spi_nports < SPI_MAX_PORTS; ftdev = ftdev->next) {
            spi_ports[spi_nports].vid = ftdi_device_ids[id].vid;
            spi_ports[spi_nports].pid = ftdi_device_ids[id].pid;

            if (ftdi_usb_get_strings(&ftdic, ftdev->dev,
                        spi_ports[spi_nports].manuf, sizeof(spi_ports[spi_nports].manuf),
                        spi_ports[spi_nports].desc, sizeof(spi_ports[spi_nports].desc),
                        spi_ports[spi_nports].serial, sizeof(spi_ports[spi_nports].serial)) < 0)
            {
                SPI_ERR("FTDI: ftdi_usb_get_strings() failed: %s", ftdi_get_error_string(&ftdic));
                return -1;
            }
            snprintf(spi_ports[spi_nports].name, sizeof(spi_ports[spi_nports].name),
                    "%s %s", ftdi_device_ids[id].name, spi_ports[spi_nports].serial);
            LOG(INFO, "Found device: name=\"%s\", manuf=\"%s\", desc=\"%s\", serial=\"%s\", vid=0x%04x, pid=0x%04x",
                    spi_ports[spi_nports].name, spi_ports[spi_nports].manuf,
                    spi_ports[spi_nports].desc, spi_ports[spi_nports].serial,
                    ftdi_device_ids[id].vid, ftdi_device_ids[id].pid);

            spi_nports++;
        }
        ftdi_list_free(&ftdevlist);
    }

    return 0;
}
QList <EnttecDMXUSBWidget*> QLCFTDI::widgets()
{
    QList <EnttecDMXUSBWidget*> widgetList;
    struct ftdi_device_list* list = 0;
    struct ftdi_context ftdi;
    ftdi_init(&ftdi);
    ftdi_usb_find_all(&ftdi, &list, QLCFTDI::VID, QLCFTDI::PID);
    while (list != NULL)
    {
        struct usb_device* dev = list->dev;
        Q_ASSERT(dev != NULL);

        char serial[256];
        char name[256];
        char vendor[256];

        ftdi_usb_get_strings(&ftdi, dev,
                             vendor, sizeof(vendor),
                             name, sizeof(name),
                             serial, sizeof(serial));

        QString ser(serial);
        QString ven(vendor);
        QMap <QString,QVariant> types(typeMap());

        if (types.contains(ser) == true)
        {
            // Force a widget with a specific serial to either type
            EnttecDMXUSBWidget::Type type = (EnttecDMXUSBWidget::Type) types[ser].toInt();
            switch (type)
            {
            case EnttecDMXUSBWidget::OpenTX:
                widgetList << new EnttecDMXUSBOpen(serial, name);
                break;
            case EnttecDMXUSBWidget::ProRX:
            {
                EnttecDMXUSBProRX* prorx = new EnttecDMXUSBProRX(serial, name, widgetList.size());
                widgetList << prorx;
                break;
            }
            default:
            case EnttecDMXUSBWidget::ProTX:
                widgetList << new EnttecDMXUSBProTX(serial, name);
                break;
            }
        }
        else if (ven.toUpper().contains("FTDI") == true)
        {
            /* This is probably an Open DMX USB widget */
            widgetList << new EnttecDMXUSBOpen(serial, name, 0);
        }
        else
        {
            /* This is probably a DMX USB Pro widget in TX mode */
            widgetList << new EnttecDMXUSBProTX(serial, name);
        }

        list = list->next;
    }

    ftdi_deinit(&ftdi);
    return widgetList;
}
Example #16
0
int sys_init()
{
	int ret, i;
	struct ftdi_device_list *devlist, *curdev;
	char manufacturer[128], description[128], serialno[128];

	if (ftdi_init(&ux400_ftdic) < 0)
	{
		fprintf(stderr, "ftdi_init failed\n");
		return EXIT_FAILURE;
	}

#if 0
	if ((ret = ftdi_usb_find_all(&ux400_ftdic, &devlist, UX400VENDOR, UX400PRODUCT)) < 0)
	{
		fprintf(stderr, "ftdi_usb_find_all failed: %d (%s)\n", ret, ftdi_get_error_string(&ux400_ftdic));
		return EXIT_FAILURE;
	}

	printf("Number of FTDI devices found: %d\n", ret);

	i = 0;
	for (curdev = devlist; curdev != NULL; i++)
	{
		printf("Checking device: %d\n", i);
		if ((ret = ftdi_usb_get_strings(&ux400_ftdic, curdev->dev, manufacturer, 128, description, 128, serialno, 128)) < 0)
		{
		    fprintf(stderr, "ftdi_usb_get_strings failed: %d (%s)\n", ret, ftdi_get_error_string(&ux400_ftdic));
		    return EXIT_FAILURE;
		}
		printf("Manufacturer: %s, Description: %s, Serial number: %s\n\n", manufacturer, description, serialno);
		curdev = curdev->next;
	}

	ftdi_list_free(&devlist);
#endif

	if((ret = ftdi_usb_open_desc(&ux400_ftdic, UX400VENDOR, UX400PRODUCT, UX400DES, UX400_LOCAL_SN)) < 0)
	{
	    fprintf(stderr, "ftdi_usb_open_desc failed: %d (%s)\n", ret, ftdi_get_error_string(&ux400_ftdic));
	    return EXIT_FAILURE;
	}

	if((ret = ftdi_usb_reset(&ux400_ftdic)) < 0)
	{
	    fprintf(stderr, "ftdi_usb_reset failed: %d (%s)\n", ret, ftdi_get_error_string(&ux400_ftdic));
	    return EXIT_FAILURE;
	}

	if((ret = ftdi_set_baudrate(&ux400_ftdic, 9600)) < 0)
	{
	    fprintf(stderr, "ftdi_set_baudrate failed: %d (%s)\n", ret, ftdi_get_error_string(&ux400_ftdic));
	    return EXIT_FAILURE;
	}

	if((ret = ftdi_set_bitmode(&ux400_ftdic, 0x00, BITMODE_RESET)) < 0)
	{
	    fprintf(stderr, "ftdi_set_bitmode failed: %d (%s)\n", ret, ftdi_get_error_string(&ux400_ftdic));
	    return EXIT_FAILURE;
	}

	usleep(10000);

	if((ret = ftdi_set_bitmode(&ux400_ftdic, 0x00, BITMODE_MCU)) < 0)
	{
	    fprintf(stderr, "ftdi_set_bitmode failed: %d (%s)\n", ret, ftdi_get_error_string(&ux400_ftdic));
	    return EXIT_FAILURE;
	}

	return 0;
}
Example #17
0
bool CKMotionIO::RequestedDeviceAvail(char *Reason)
{
	int ftStatus, i, numDevs, list[MAX_BOARDS];
	struct ftdi_device_list *devlist, *curdev;
	bool error;
	char Manufacturer[128];
	//char SerialNumber[16];
	char Description[64]; 

	error = false;
	devlist = NULL;

	Mutex->Lock();

	// fill the list with -1 because driver
	// leaves the entries for open drivers unchanged

	for (i=0; i<MAX_BOARDS; i++) list[i]=-1;
	numDevs = ftStatus = ftdi_usb_find_all(ftdi, &devlist, VENDOR, PRODUCT );
	if (ftStatus < 0)
	{
		if (Reason) sprintf(Reason,"Failed to enumerate USB devices. %s(%d)",ftdi_get_error_string(ftdi), ftStatus);
		error = true;
	}
	else if (numDevs == 0)
	{
    error = true;
		if (Reason) strcpy(Reason,"No KMotion devices available");
	}
  else if (numDevs > MAX_BOARDS)
  {
    error = true;
    if (Reason) strcpy(Reason,"Too many KMotion devices available");
  }

	if(error){
	  if(devlist != NULL){
      ftdi_list_free(&devlist);
	  }
		Mutex->Unlock();
		return false;

	}
	// go through the list and remove any non-dynomotion boards
	i = 0;
	for (curdev = devlist; curdev != NULL; i++)
	{
		if ((ftStatus = ftdi_usb_get_strings(ftdi, curdev->dev, Manufacturer, 128, Description, 128, NULL, 0)) < 0)
		{
			log_info("ftdi_usb_get_strings failed: %d (%s)",ftStatus, ftdi_get_error_string(ftdi));
		   // FT_Open failed
		   list[i] = -1;  // mark as unusable
		}
		else
		{
		  debug("%s\n%s",Manufacturer, Description);
			if (strstr(Description,"KFLOP")!= NULL ||
				strstr(Description,"KMotion")!= NULL ||
				strstr(Description,"Dynomotion")!= NULL)
			{
				//save index
				list[i] = i;
			}
		}
		curdev = curdev->next;
	}

	ftdi_list_free(&devlist);

	// if USB Location is undefined select the first from
	// the list that is not already taken
	if (!BoardIDAssigned)
	{
		for (i=0; i<numDevs && !BoardIDAssigned; i++)
		{
			if (list[i] != -1)
			{
				int k;
				// make sure nobody is already using this one
				for (k=0; k<MAX_BOARDS; k++)
				{
					if (list[i]==KMotionLocal.KMotionIO[k].USB_Loc_ID)
						break;
				}
				if (k==MAX_BOARDS)
				{
					BoardIDAssigned=true;
					USB_Loc_ID=list[i];  // assign it
					debug("Board location %d", USB_Loc_ID);
				}
			}
		}
		if (!BoardIDAssigned)
		{
			Mutex->Unlock();
			if (Reason) strcpy(Reason,"No KMotion devices available");
			return false;
		}
	}

	// user wants a specific usb location
	// so see if it is available

	for (i=0; i<numDevs; i++)
	{
		if (list[i]==USB_Loc_ID)
			break;
	}

	if (i==numDevs)
	{
		Mutex->Unlock();
		if (Reason) sprintf(Reason,"KMotion not found on USB Location %08X\n"
								   "Unable to open device",USB_Loc_ID);
		return false;
	}

	Mutex->Unlock();
	return true;
}
Example #18
0
int main(int argc, char **argv)
{
    struct ftdi_context *ftdi;
    unsigned char buf[1024];
    int f = 0, i;
    int vid = 0x403;
    int pid = 0;
    int baudrate = 115200;
    int interface = INTERFACE_ANY;
    int do_write = 0;
    unsigned int pattern = 0xffff;
    int retval = EXIT_FAILURE;

    while ((i = getopt(argc, argv, "i:v:p:b:w::")) != -1)
    {
        switch (i)
        {
            case 'i': // 0=ANY, 1=A, 2=B, 3=C, 4=D
                interface = strtoul(optarg, NULL, 0);
                break;
            case 'v':
                vid = strtoul(optarg, NULL, 0);
                break;
            case 'p':
                pid = strtoul(optarg, NULL, 0);
                break;
            case 'b':
                baudrate = strtoul(optarg, NULL, 0);
                break;
            case 'w':
                do_write = 1;
                if (optarg)
                    pattern = strtoul(optarg, NULL, 0);
                if (pattern > 0xff)
                {
                    fprintf(stderr, "Please provide a 8 bit pattern\n");
                    exit(-1);
                }
                break;
            default:
                fprintf(stderr, "usage: %s [-i interface] [-v vid] [-p pid] [-b baudrate] [-w [pattern]]\n", *argv);
                exit(-1);
        }
    }

    // Init
    if ((ftdi = ftdi_new()) == 0)
    {
        fprintf(stderr, "ftdi_new failed\n");
        return EXIT_FAILURE;
    }

    if (!vid && !pid && (interface == INTERFACE_ANY))
    {
        ftdi_set_interface(ftdi, INTERFACE_ANY);
        struct ftdi_device_list *devlist;
        int res;
        if ((res = ftdi_usb_find_all(ftdi, &devlist, 0, 0)) < 0)
        {
            fprintf(stderr, "No FTDI with default VID/PID found\n");
            goto do_deinit;
        }
        if (res == 1)
        {
            f = ftdi_usb_open_dev(ftdi,  devlist[0].dev);
            if (f<0)
            {
                fprintf(stderr, "Unable to open device %d: (%s)",
                        i, ftdi_get_error_string(ftdi));
            }
        }
        ftdi_list_free(&devlist);
        if (res > 1)
        {
            fprintf(stderr, "%d Devices found, please select Device with VID/PID\n", res);
            /* TODO: List Devices*/
            goto do_deinit;
        }
        if (res == 0)
        {
            fprintf(stderr, "No Devices found with default VID/PID\n");
            goto do_deinit;
        }
    }
    else
    {
        // Select interface
        ftdi_set_interface(ftdi, interface);
        
        // Open device
        f = ftdi_usb_open(ftdi, vid, pid);
    }
    if (f < 0)
    {
        fprintf(stderr, "unable to open ftdi device: %d (%s)\n", f, ftdi_get_error_string(ftdi));
        exit(-1);
    }

    // Set baudrate
    f = ftdi_set_baudrate(ftdi, baudrate);
    if (f < 0)
    {
        fprintf(stderr, "unable to set baudrate: %d (%s)\n", f, ftdi_get_error_string(ftdi));
        exit(-1);
    }
    
    /* Set line parameters
     *
     * TODO: Make these parameters settable from the command line
     *
     * Parameters are choosen that sending a continous stream of 0x55 
     * should give a square wave
     *
     */
    f = ftdi_set_line_property(ftdi, 8, STOP_BIT_1, NONE);
    if (f < 0)
    {
        fprintf(stderr, "unable to set line parameters: %d (%s)\n", f, ftdi_get_error_string(ftdi));
        exit(-1);
    }
    
    if (do_write)
        for(i=0; i<1024; i++)
            buf[i] = pattern;

    signal(SIGINT, sigintHandler);
    while (!exitRequested)
    {
        if (do_write)
            f = ftdi_write_data(ftdi, buf, 
                                (baudrate/512 >sizeof(buf))?sizeof(buf):
                                (baudrate/512)?baudrate/512:1);
        else
            f = ftdi_read_data(ftdi, buf, sizeof(buf));
        if (f<0)
            sleep(1);
        else if(f> 0 && !do_write)
        {
            fprintf(stderr, "read %d bytes\n", f);
            fwrite(buf, f, 1, stdout);
            fflush(stderr);
            fflush(stdout);
        }
    }
    signal(SIGINT, SIG_DFL);
    retval =  EXIT_SUCCESS;
            
    ftdi_usb_close(ftdi);
    do_deinit:
    ftdi_free(ftdi);

    return retval;
}
Example #19
0
int spi_begin(uint8_t bus, uint8_t port)
{
	int ret;

	ftdi = ftdi_new();
	if (ftdi == 0) {
		fprintf(stderr, "ftdi_new failed\n");
		return -1;
	}

	if (bus > 0) {
		struct ftdi_device_list *list = NULL;
		struct ftdi_device_list *p;

		ret = ftdi_usb_find_all(ftdi, &list, 0, 0);
		if (ret < 0) {
			fprintf(stderr, "unable to list devices: %d (%s)\n",
					ret, ftdi_get_error_string(ftdi));
			ftdi_free(ftdi);
			return -2;
		}

		p = list;
		while (p) {
			if (bus == libusb_get_bus_number(p->dev) &&
				port == libusb_get_port_number(p->dev)) {
				ret = ftdi_usb_open_dev(ftdi, p->dev);
				break;
			}
			p = p->next;
		}

		ftdi_list_free(&list);

		if (!p) {
			fprintf(stderr, "dev on bus %i and port %i not found\n",
								bus, port);
			ftdi_free(ftdi);
			return -3;
		}
	} else
		ret = ftdi_usb_open(ftdi, 0x0403, 0x6001);

	if (ret < 0 && ret != -5) {
		fprintf(stderr, "unable to open ftdi device: %d (%s)\n", ret,
						ftdi_get_error_string(ftdi));
		ftdi_free(ftdi);
		return -4;
	}

	ret = ftdi_set_bitmode(ftdi, PINS_OUT, BITMODE_SYNCBB);
	if (ret != 0) {
		fprintf(stderr, "unable to set bitmode: %d (%s)\n", ret,
						ftdi_get_error_string(ftdi));
		ftdi_free(ftdi);
		return -5;
	}

	ret = ftdi_set_baudrate(ftdi, 57600);
	if (ret != 0) {
		fprintf(stderr, "unable to set baudrate: %d (%s)\n", ret,
						ftdi_get_error_string(ftdi));
		ftdi_disable_bitbang(ftdi);
		ftdi_free(ftdi);
		return -6;
	}

	digitalWrite(PIN_PROG, LOW);
	digitalWrite(PIN_FSCK, LOW);
	digitalWrite(PIN_FCSN, HIGH);
	digitalWrite(PIN_FMOSI, LOW);
	digitalWrite(PIN_RESET, HIGH);

	prog_begin();

	return 0;
}
int main(int argc, char *argv[])
{
    int ret, i;
    struct ftdi_device_list *devlist, *curdev;
    struct ftdi_context ftdic;
    struct ftdi_eeprom  eeprom;

    for (i = 0; i < CBUS_NUM; i++)
    {
        apcCBUS[i] = NULL;
    }

    {
        static struct option long_options[] =
        {

            {"help",                    no_argument,        NULL, 'h'},
            {"verbosity",               required_argument,  NULL, 'V'},

            {"vid",                     required_argument,  NULL, 'v'},
            {"pid",                     required_argument,  NULL, 'p'},

            {"manufacturer",            required_argument,  NULL, 'm'},
            {"description",             required_argument,  NULL, 'd'},

            {"serial",                  required_argument,  NULL, 's'},
            {"autoserial",              required_argument,  NULL, 'a'},

            {"C0",                      required_argument,  NULL, '0'},
            {"C1",                      required_argument,  NULL, '1'},
            {"C2",                      required_argument,  NULL, '2'},
            {"C3",                      required_argument,  NULL, '3'},
            {"C4",                      required_argument,  NULL, '4'},

            { NULL, 0, NULL, 0}
        };
        signed char opt;
        int option_index;

        while ((opt = getopt_long(argc, argv, "hV:v:p:m:d:s:a:0:1:2:3:4:", long_options, &option_index)) != -1)
        {
            switch (opt)
            {
            case 'h':
                print_usage_exit(argv);
                break;

            case 'V':
                if (iMyStrtoul(&u32Verbosity, optarg, "verbosity", 2))
                {
                    return EXIT_FAILURE;
                }
                break;

            case 'v':
                if (iMyStrtoul(&u32VID, optarg, "vendor id", 0xFFFF))
                {
                    return EXIT_FAILURE;
                }
                break;

            case 'p':
                if (iMyStrtoul(&u32PID, optarg, "product id", 0xFFFF))
                {
                    return EXIT_FAILURE;
                }
                break;

            case 'm':
                pcManufacturer = optarg;
                break;

            case 'd':
                pcDescription = optarg;
                break;

            case 's':
                pcSerial = optarg;
                break;

            case 'a':
                pcAutoSerial = optarg;
                break;

            case '0':
                apcCBUS[0] = optarg;
                break;

            case '1':
                apcCBUS[1] = optarg;
                break;

            case '2':
                apcCBUS[2] = optarg;
                break;

            case '3':
                apcCBUS[3] = optarg;
                break;

            case '4':
                apcCBUS[4] = optarg;
                break;

            default: /* '?' */
                print_usage_exit(argv);
            }
        }
    }

    printf("FTProg FTDI Programmer version %s\n\r", Version);

    /* Handle serial numbers */
    if (pcSerial && pcAutoSerial)
    {
        fprintf(stderr, "Please specify only one of serial number and autoserial\n\r");
        return EXIT_FAILURE;
    }

    if (pcSerial)
    {
        if (strlen(pcSerial) != 8)
        {
            fprintf(stderr, "Serial number must be 8 character string\n\r");
            return EXIT_FAILURE;
        }
    }

    if (pcAutoSerial)
    {
        int fd;
        if (strlen(pcAutoSerial) != 2)
        {
            fprintf(stderr, "Serial number prefix must be 2 character string\n\r");
            return EXIT_FAILURE;
        }

        pcSerial = malloc(sizeof(char) * 9);
        if (!pcSerial)
        {
            fprintf(stderr, "Memory error\n");
            return EXIT_FAILURE;
        }
        pcSerial[0] = pcAutoSerial[0];
        pcSerial[1] = pcAutoSerial[1];

        if ((fd = open("/dev/urandom", O_RDONLY)) < 0)
        {
            fprintf(stderr, "Could not open /dev/urandom (%s)\n\r", strerror(errno));
            return EXIT_FAILURE;
        }
        for (i = 2; i < 8; i++)
        {
            uint32_t j;
            read(fd, &j, 1);
            pcSerial[i] = "0123456789ABCDEF"[j % 16];
        }
        close(fd);

        pcSerial[8] = '\0';
        if (u32Verbosity > 0)
        {
            printf("Autogenerated serial number: '%s'\n", pcSerial);
        }
    }


    for (i = 0; i < CBUS_NUM; i++)
    {
        if (apcCBUS[i])
        {
            int j, iFound = 0;
            for (j = 0; j < (sizeof(asCBUSModeLookup)/sizeof(tsCBUSModeLookup)); j++)
            {
                if (strcmp(apcCBUS[i], asCBUSModeLookup[j].pcDescription) == 0)
                {
                    iFound = 1;
                    apsCBUS_Function[i] = &asCBUSModeLookup[j];
                }
            }
            if (!iFound)
            {
                fprintf(stderr, "Invalid C%d '%s'\n\r", i, apcCBUS[i]);
                return EXIT_FAILURE;
            }
        }
    }

    if (ftdi_init(&ftdic) < 0)
    {
        fprintf(stderr, "ftdi_init failed\n");
        return EXIT_FAILURE;
    }

    if ((ret = ftdi_usb_find_all(&ftdic, &devlist, u32VID, u32PID)) < 0)
    {
        fprintf(stderr, "ftdi_usb_find_all failed: %d (%s)\n", ret, ftdi_get_error_string(&ftdic));
        return EXIT_FAILURE;
    }

    printf("Number of FTDI devices found: %d\n", ret);

    for (i=0, curdev = devlist; curdev != NULL; i++, curdev = curdev->next)
    {
        printf(" Updating device: %d\n\r", i);

        if ((ret = ftdi_usb_open_dev(&ftdic, curdev->dev)) < 0)
        {
            fprintf(stderr, "ftdi_usb_open_dev failed: %d (%s)\n", ret, ftdi_get_error_string(&ftdic));
            return EXIT_FAILURE;
        }

        // Read out FTDIChip-ID of R type chips
        if (ftdic.type == TYPE_R)
        {
            unsigned char *pcEepromBuffer = NULL;
            unsigned int chipid;

            if ((ret = ftdi_read_chipid(&ftdic, &chipid)) < 0)
            {
                fprintf(stderr, "ftdi_read_chipid failed: %d (%s)\n", ret, ftdi_get_error_string(&ftdic));
                return EXIT_FAILURE;
            }

            printf("  FTDI chipid: %X\n", chipid);

            /* EEPROM is 160 bytes */
            ftdi_eeprom_setsize(&ftdic, &eeprom, 160);

            printf("  EEPROM size: %d bytes\n", ftdic.eeprom_size);
            pcEepromBuffer = malloc(ftdic.eeprom_size);
            if (!pcEepromBuffer)
            {
                fprintf(stderr, "Memory error!");
                return EXIT_FAILURE;
            }
            else
            {

                int i;
                if ((ret = ftdi_read_eeprom(&ftdic, pcEepromBuffer)) < 0)
                {
                    fprintf(stderr, "ftdi_read_eeprom failed: %d (%s)\n", ret, ftdi_get_error_string(&ftdic));
                    return EXIT_FAILURE;
                }
                if ((ret = ftdi_eeprom_decode(&eeprom, pcEepromBuffer, ftdic.eeprom_size)) < 0)
                {
                    if (ret != -1)
                    {
                        /* Avoid errors due to hard coded size causing checksum to fail. */
                        fprintf(stderr, "Error decoding eeprom buffer: %d (%s)\n", ret, ftdi_get_error_string(&ftdic));
                        return EXIT_FAILURE;
                    }
                }

                if (u32Verbosity > 0)
                {
                    printf("    Current Vendor: %d, %s\n", eeprom.vendor_id, eeprom.manufacturer);
                    printf("    Current Product: %d, %s\n", eeprom.product_id, eeprom.product);
                    printf("    Current Serial: %s\n", eeprom.serial);

                    if (u32Verbosity >= 2)
                    {
                        printf("      Current EEPROM Contents\n\r");
                        for (i = 0; i < ftdic.eeprom_size; i+=2)
                        {
                            if ((i % 16) == 0)
                            {
                                printf("        %04x:", i/2);
                            }
                            printf(" 0x%02x%02x", pcEepromBuffer[i],pcEepromBuffer[i+1]);
                            if ((i % 16) == 14)
                            {
                                printf("\n\r");
                            }
                        }
                    }
                }

                if (pcManufacturer)
                {
                    printf("  Setting manufacturer: '%s'\n\r", pcManufacturer);
                    free(eeprom.manufacturer);
                    eeprom.manufacturer     = pcManufacturer;
                }

                if (pcDescription)
                {
                    printf("  Setting description: '%s'\n\r", pcDescription);
                    free(eeprom.product);
                    eeprom.product          = pcDescription;
                }

                if (pcSerial)
                {
                    printf("  Setting serial number: '%s'\n\r", pcSerial);
                    free(eeprom.serial);
                    eeprom.serial           = pcSerial;
                }

                for (i = 0; i < CBUS_NUM; i++)
                {
                    if (apcCBUS[i])
                    {
                        /* Argument given */
                        printf("  Setting C%d: '%s' (%d)\n\r", i,
                               apsCBUS_Function[i]->pcDescription,
                               apsCBUS_Function[i]->iCBUSMode);

                        eeprom.cbus_function[i] = apsCBUS_Function[i]->iCBUSMode;
                    }
                }

                /* EEPROM is 160 bytes */
                ftdi_eeprom_setsize(&ftdic, &eeprom, 160);

                if ((ret = ftdi_eeprom_build(&eeprom, pcEepromBuffer)) < 0)
                {
                    fprintf(stderr, "ftdi_eeprom_build failed: %d (%s)\n\r", ret, ftdi_get_error_string(&ftdic));
                    return -1;
                }

                if ((ret = ftdi_write_eeprom(&ftdic, pcEepromBuffer)) < 0)
                {
                    fprintf(stderr, "ftdi_write_eeprom failed: %d (%s)\n", ret, ftdi_get_error_string(&ftdic));
                    return -1;
                }
                printf("  Wrote new EEPROM data successfully\n\r");
            }
        }

        if ((ret = ftdi_usb_close(&ftdic)) < 0)
        {
            fprintf(stderr, "ftdi_usb_close failed: %d (%s)\n\r", ret, ftdi_get_error_string(&ftdic));
            return EXIT_FAILURE;
        }
    }

    ftdi_list_free(&devlist);
    ftdi_deinit(&ftdic);
    return EXIT_SUCCESS;
}
Example #21
0
QList <DMXUSBWidget*> QLCFTDI::widgets()
{
    QList <DMXUSBWidget*> widgetList;
    quint32 input_id = 0;

    struct ftdi_device_list* list = 0;
    struct ftdi_context ftdi;
    ftdi_init(&ftdi);
    ftdi_usb_find_all(&ftdi, &list, QLCFTDI::VID, QLCFTDI::PID);
    while (list != NULL)
    {
#ifdef LIBFTDI1
        struct libusb_device* dev = list->dev;
#else
        struct usb_device* dev = list->dev;
#endif
        Q_ASSERT(dev != NULL);

        char serial[256];
        char name[256];
        char vendor[256];

        ftdi_usb_get_strings(&ftdi, dev,
                             vendor, sizeof(vendor),
                             name, sizeof(name),
                             serial, sizeof(serial));

        QString ser(serial);
        QString nme(name);
        QString ven(vendor);
        QMap <QString,QVariant> types(typeMap());

        qDebug() << "serial: " << ser << "name:" << nme << "vendor:" << ven;

        if (types.contains(ser) == true)
        {
            // Force a widget with a specific serial to either type
            DMXUSBWidget::Type type = (DMXUSBWidget::Type) types[ser].toInt();
            switch (type)
            {
            case DMXUSBWidget::OpenTX:
                widgetList << new EnttecDMXUSBOpen(serial, name, vendor);
                break;
            case DMXUSBWidget::ProRX:
            {
                EnttecDMXUSBProRX* prorx = new EnttecDMXUSBProRX(serial, name, vendor, input_id++);
                widgetList << prorx;
                break;
            }
            case DMXUSBWidget::ProMk2:
            {
                EnttecDMXUSBProTX* protx = new EnttecDMXUSBProTX(serial, name, vendor, 1);
                widgetList << protx;
                widgetList << new EnttecDMXUSBProTX(serial, name, vendor, 2, protx->ftdi());
                EnttecDMXUSBProRX* prorx = new EnttecDMXUSBProRX(serial, name, vendor, input_id++, protx->ftdi());
                widgetList << prorx;
                break;
            }
            case DMXUSBWidget::UltraProTx:
            {
                UltraDMXUSBProTx* protx = new UltraDMXUSBProTx(serial, name, vendor, 1);
                widgetList << protx;
                widgetList << new UltraDMXUSBProTx(serial, name, vendor, 2, protx->ftdi());
                EnttecDMXUSBProRX* prorx = new EnttecDMXUSBProRX(serial, name, vendor, input_id++, protx->ftdi());
                widgetList << prorx;
                break;
            }
            case DMXUSBWidget::VinceTX:
                widgetList << new VinceUSBDMX512TX(serial, name, vendor);
                break;
            default:
            case DMXUSBWidget::ProTX:
                widgetList << new EnttecDMXUSBProTX(serial, name, vendor);
                break;
            }
        }
        else if (nme.toUpper().contains("PRO MK2") == true)
        {
            EnttecDMXUSBProTX* protx = new EnttecDMXUSBProTX(serial, name, vendor, 1);
            widgetList << protx;
            widgetList << new EnttecDMXUSBProTX(serial, name, vendor, 2, protx->ftdi());
            EnttecDMXUSBProRX* prorx = new EnttecDMXUSBProRX(serial, name, vendor, input_id++, protx->ftdi());
            widgetList << prorx;
        }
        else if (nme.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(&ftdi, name, serial, USB_DEVICE_MANUFACTURER, &ESTAID);
            qDebug() << "--------> Device Manufacturer: " << manName;
            QString devName = readLabel(&ftdi, name, serial, 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)
                {
                    UltraDMXUSBProTx* protxP1 = new UltraDMXUSBProTx(serial, name, vendor, 1);
                    protxP1->setRealName(devName);
                    widgetList << protxP1;
                    UltraDMXUSBProTx* protxP2 = new UltraDMXUSBProTx(serial, name, vendor, 2, protxP1->ftdi());
                    protxP2->setRealName(devName);
                    widgetList << protxP2;
                    EnttecDMXUSBProRX* prorx = new EnttecDMXUSBProRX(serial, name, vendor, input_id++, protxP1->ftdi());
                    prorx->setRealName(devName);
                    widgetList << prorx;
                }
                else
                {
                    EnttecDMXUSBProTX* protx = new EnttecDMXUSBProTX(serial, name, vendor);
                    protx->setRealName(devName);
                    widgetList << protx;
                }
            }
            else
            {
                /* This is probably a Enttec DMX USB Pro widget */
                EnttecDMXUSBProTX* protx = new EnttecDMXUSBProTX(serial, name, vendor);
                widgetList << protx;
                EnttecDMXUSBProRX* prorx = new EnttecDMXUSBProRX(serial, name, vendor, input_id++, protx->ftdi());
                widgetList << prorx;
            }
        }
        else if (nme.toUpper().contains("USB-DMX512 CONVERTER") == true)
        {
            widgetList << new VinceUSBDMX512TX(serial, name, vendor);
        }
        else
        {
            /* This is probably an Open DMX USB widget */
            widgetList << new EnttecDMXUSBOpen(serial, name, vendor, 0);
        }

        list = list->next;
    }

    /* Search for DMX4ALL devices now */
    ftdi_usb_find_all(&ftdi, &list, QLCFTDI::VID, QLCFTDI::DMX4ALLPID);
    while (list != NULL)
    {
#ifdef LIBFTDI1
        struct libusb_device* dev = list->dev;
#else
        struct usb_device* dev = list->dev;
#endif
        Q_ASSERT(dev != NULL);

        char serial[256];
        char name[256];
        char vendor[256];

        ftdi_usb_get_strings(&ftdi, dev,
                             vendor, sizeof(vendor),
                             name, sizeof(name),
                             serial, sizeof(serial));

        QString ser(serial);
        QString nme(name);
        QString ven(vendor);

        qDebug() << "serial: " << ser << "name:" << nme << "vendor:" << ven;
        widgetList << new DMX4ALL(ser, nme, ven);

        list = list->next;
    }

    ftdi_deinit(&ftdi);
    return widgetList;
}
Example #22
0
static GSList *scan(struct sr_dev_driver *di, GSList *options)
{
	struct sr_dev_inst *sdi;
	struct drv_context *drvc;
	struct dev_context *devc;
	GSList *devices;
	struct ftdi_device_list *devlist;
	char serial_txt[10];
	uint32_t serial;
	int ret;
	unsigned int i;

	(void)options;

	drvc = di->context;

	devices = NULL;

	devc = g_malloc0(sizeof(struct dev_context));

	ftdi_init(&devc->ftdic);

	/* Look for SIGMAs. */

	if ((ret = ftdi_usb_find_all(&devc->ftdic, &devlist,
	    USB_VENDOR, USB_PRODUCT)) <= 0) {
		if (ret < 0)
			sr_err("ftdi_usb_find_all(): %d", ret);
		goto free;
	}

	/* Make sure it's a version 1 or 2 SIGMA. */
	ftdi_usb_get_strings(&devc->ftdic, devlist->dev, NULL, 0, NULL, 0,
			     serial_txt, sizeof(serial_txt));
	sscanf(serial_txt, "%x", &serial);

	if (serial < 0xa6010000 || serial > 0xa602ffff) {
		sr_err("Only SIGMA and SIGMA2 are supported "
		       "in this version of libsigrok.");
		goto free;
	}

	sr_info("Found ASIX SIGMA - Serial: %s", serial_txt);

	devc->cur_samplerate = samplerates[0];
	devc->period_ps = 0;
	devc->limit_msec = 0;
	devc->cur_firmware = -1;
	devc->num_channels = 0;
	devc->samples_per_event = 0;
	devc->capture_ratio = 50;
	devc->use_triggers = 0;

	/* Register SIGMA device. */
	sdi = g_malloc0(sizeof(struct sr_dev_inst));
	sdi->status = SR_ST_INITIALIZING;
	sdi->vendor = g_strdup(USB_VENDOR_NAME);
	sdi->model = g_strdup(USB_MODEL_NAME);
	sdi->driver = di;

	for (i = 0; i < ARRAY_SIZE(channel_names); i++)
		sr_channel_new(sdi, i, SR_CHANNEL_LOGIC, TRUE, channel_names[i]);

	devices = g_slist_append(devices, sdi);
	drvc->instances = g_slist_append(drvc->instances, sdi);
	sdi->priv = devc;

	/* We will open the device again when we need it. */
	ftdi_list_free(&devlist);

	return devices;

free:
	ftdi_deinit(&devc->ftdic);
	g_free(devc);
	return NULL;
}