c - Libftdi usb_open() failed -
i’m working on project using iridium ptt. iridium hardware hooks satellite, , pc via usb.
the iridium hardware came software runs on ubuntu linux, runs in virtual box on pc. software written in c , runs in ubuntu. develop on windows, using visual studios.
the ubuntu version uses libftdi , libusb (from intra2net) talk hardware.
we got libftdi, libusb , created project in visual studios 2013 desktop express edition. (i downloaded zadig windows check make sure had right usb drivers. verified arrow driver green usb connections hardware.)
when iridium hardware connected computer 4 serial ports appear in device manager. i’m attempting open 1 of serial ports windows when run program. error when try open 1 (even though can open ubuntu, running in virtual box, on same pc).
i'm using sample code (from intra2net) called "simple.c" i’m running in visual studios. i’ve posted below:
/* simple.c simple libftdi usage example program distributed under gpl, version 2 */ #include <stdio.h> #include <stdlib.h> #include "ftdi.h" int main(void) { int ret; struct ftdi_context *ftdi; struct ftdi_version_info version; if ((ftdi = ftdi_new()) == 0) { fprintf(stderr, "ftdi_new failed\n"); return exit_failure; } version = ftdi_get_library_version(); printf("initialized libftdi %s (major: %d, minor: %d, micro: %d, snapshot ver: %s)\n", version.version_str, version.major, version.minor, version.micro, version.snapshot_str); if ((ret = ftdi_usb_open(ftdi, 0x403, 0x6011)) < 0) { fprintf(stderr, "unable open ftdi device: %d (%s)\n", ret, ftdi_get_error_string(ftdi)); ftdi_free(ftdi); return exit_failure; } // read out ftdichip-id of r type chips if (ftdi->type == type_r) { unsigned int chipid; printf("ftdi_read_chipid: %d\n", ftdi_read_chipid(ftdi, &chipid)); printf("ftdi chipid: %x\n", chipid); } if ((ret = ftdi_usb_close(ftdi)) < 0) { fprintf(stderr, "unable close ftdi device: %d (%s)\n", ret, ftdi_get_error_string(ftdi)); ftdi_free(ftdi); return exit_failure; } ftdi_free(ftdi); return exit_success; }
i’ve modified 2 lines intra2net's original simple.c:
- line 10: changed
#include <ftdi.h>
#include "ftdi.h"
- line 28: changed original hex numbers in
if ((ret = ftdi_usb_open(ftdi, 0x403, 0x6011)) < 0)
numbers used in ubuntu c code, hardware.
the error i’m getting when run simple.c unable open ftdi device: -4 (usb_open() failed)
happening right on line 28 in ftdi_usb_open
function.
i’m new low-level c programming , i’m not sure go here.
mean when encounter problem? how go solving issue? thanks!
your call ftdi_usb_open(ftdi_context, vendor, product)
opens first device given vendor , product ids.
nothing in code looks wrong, assuming providing correct vendor , product value.
some things worth checking if unable open device:
- windows can weird things on auto plug. try disabling serial enumerator on com port. can access option in device manager->port settings->advanced settings.
- in same advanced settings, remove
enable model ctrl @ startup
. devices monitor these signals can enter wrong state after unplug-replug cycle on usb. more on this ftdi chip vendor. - another program claimed chip's interface before yours. might have running connects automatically on usb devices.
Comments
Post a Comment