X-Git-Url: http://developer.intra2net.com/git/?p=libftdi;a=blobdiff_plain;f=examples%2Fserial_test.c;h=0631504048a8d810cbb0f8a2ed5246eca1a87eca;hp=46599b83dafbd5adeda4d342f08f5180b5e7a8c3;hb=db9c7eba8ff28219a33b5494a3d60aa487d87ef1;hpb=53a561d380532adfd73159760681d8f2f91e2895 diff --git a/examples/serial_test.c b/examples/serial_test.c index 46599b8..0631504 100644 --- a/examples/serial_test.c +++ b/examples/serial_test.c @@ -28,8 +28,8 @@ int main(int argc, char **argv) { struct ftdi_context *ftdi; unsigned char buf[1024]; - int f, i; - int vid = 0; + int f = 0, i; + int vid = 0x403; int pid = 0; int baudrate = 115200; int interface = INTERFACE_ANY; @@ -130,6 +130,21 @@ int main(int argc, char **argv) exit(-1); } + /* Set line parameters + * + * TODO: Make these parameters settable from the command line + * + * Parameters are chosen that sending a continuous 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; @@ -138,11 +153,13 @@ int main(int argc, char **argv) while (!exitRequested) { if (do_write) - f = ftdi_write_data(ftdi, buf, sizeof(buf)); + 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); + usleep(1 * 1000000); else if(f> 0 && !do_write) { fprintf(stderr, "read %d bytes\n", f);