X-Git-Url: http://developer.intra2net.com/git/?p=libftdi;a=blobdiff_plain;f=examples%2Fbaud_test.c;h=32b9beb3492eb0ca14de694efd3df24dd75c17b3;hp=f6bcac9e6fe35e20d38a154c115ba53999fe7482;hb=579b006f4873fa72c73d372660d158061497bcc9;hpb=f44dbec230aaa0835be8be7d4581394ed4a92435 diff --git a/examples/baud_test.c b/examples/baud_test.c index f6bcac9..32b9beb 100644 --- a/examples/baud_test.c +++ b/examples/baud_test.c @@ -3,7 +3,13 @@ * test setting the baudrate and compare it with the expected runtime * * options: - * -p (vendor is fixed to ftdi / 0x0403) + * -p defaults to "i:0x0403:0x6001" (this is the first FT232R with default id) + * d: path of bus and device-node (e.g. "003/001") within usb device tree (usually at /proc/bus/usb/) + * i:: first device with given vendor and product id, + * ids can be decimal, octal (preceded by "0") or hex (preceded by "0x") + * i::: as above with index being the number of the device (starting with 0) + * if there are more than one + * s::: first device with given vendor id, product id and serial string * -d * -b (divides by 16 if bitbang as taken from the ftdi datasheets) * -m r: serial a: async bitbang s:sync bitbang @@ -25,6 +31,7 @@ #include #include +#include #include #include @@ -53,7 +60,9 @@ int main(int argc, char **argv) int baud=9600; int set_baud; int datasize=100000; - int product_id=0x6001; + + char default_devicedesc[] = "i:0x0403:0x6001"; + char *devicedesc=default_devicedesc; int txchunksize=256; enum ftdi_mpsse_mode test_mode=BITMODE_BITBANG; @@ -85,7 +94,7 @@ int main(int argc, char **argv) baud = atoi (optarg); break; case 'p': - sscanf(optarg,"0x%x",&product_id); + devicedesc=optarg; break; case 'c': txchunksize = atoi (optarg); @@ -107,7 +116,7 @@ int main(int argc, char **argv) return EXIT_FAILURE; } - if (ftdi_usb_open(&ftdic, 0x0403, product_id) < 0) + if (ftdi_usb_open_string(&ftdic, devicedesc) < 0) { fprintf(stderr,"Can't open ftdi device: %s\n",ftdi_get_error_string(&ftdic)); return EXIT_FAILURE; @@ -167,6 +176,10 @@ int main(int argc, char **argv) start=get_prec_time(); + // don't wait for more data to arrive, take what we get and keep on sending + // yes, we really would like to have libusb 1.0+ with async read/write... + ftdic.usb_read_timeout=1; + i=0; while(i < datasize) { @@ -186,12 +199,12 @@ int main(int argc, char **argv) if(test_mode==BITMODE_SYNCBB) { // read the same amount of data as sent - ftdi_read_data(&ftdic, rxbuf, txchunksize); + ftdi_read_data(&ftdic, rxbuf, sendsize); } } duration=get_prec_time()-start; - printf("and took %.4f seconds, this is factor %.3f\n",duration,plan/duration); + printf("and took %.4f seconds, this is %.0f baud or factor %.3f\n",duration,(plan*baud)/duration,plan/duration); ftdi_usb_close(&ftdic); ftdi_deinit(&ftdic);