Thomas Jarosch wrote:
> On Sunday, 15. November 2009 12:51:27 Thomas Jarosch wrote:
> > Please give the attached patch a try. Works fine on my FT245BM type chip.
> 
> Anyone? :)

Hi, 

I finally got a chance to try this patch: "Determine maximum packet
size via usb config descriptor".  It works fine on:
  FT2232D, full speed
  FT2232H, high speed
  FT2232H, full speed (previously failed without the patch)

I wrote a small program to help with the testing, which might be
suitable as an example.  Patch attached.

-jim


--
libftdi - see http://www.intra2net.com/en/developer/libftdi for details.
To unsubscribe send a mail to [email protected]   
From d3b596de3140c21a7f4e438577ab8c7164b0b9f9 Mon Sep 17 00:00:00 2001
From: Jim Paris <[email protected]>
Date: Wed, 2 Dec 2009 18:13:44 -0500
Subject: [PATCH] examples: add sio example

Simple example to just receive and print data.
---
 examples/CMakeLists.txt |    2 +
 examples/Makefile.am    |    2 +
 examples/sio.c          |   81 +++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 85 insertions(+), 0 deletions(-)
 create mode 100644 examples/sio.c

diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt
index ccd2f89..b227115 100644
--- a/examples/CMakeLists.txt
+++ b/examples/CMakeLists.txt
@@ -13,6 +13,7 @@ add_executable(bitbang2 bitbang2.c)
 add_executable(bitbang_cbus bitbang_cbus.c)
 add_executable(bitbang_ft2232 bitbang_ft2232.c)
 add_executable(find_all find_all.c)
+add_executable(sio sio.c)
 
 # Linkage
 target_link_libraries(simple ftdi)
@@ -21,6 +22,7 @@ target_link_libraries(bitbang2 ftdi)
 target_link_libraries(bitbang_cbus ftdi)
 target_link_libraries(bitbang_ft2232 ftdi)
 target_link_libraries(find_all ftdi)
+target_link_libraries(sio ftdi)
 
 # libftdi++ examples
 if(FTDI_BUILD_CPP)
diff --git a/examples/Makefile.am b/examples/Makefile.am
index bcd50ec..0aca8a2 100644
--- a/examples/Makefile.am
+++ b/examples/Makefile.am
@@ -16,6 +16,7 @@ bin_PROGRAMS = simple \
 	bitbang_ft2232 \
 	bitbang_cbus \
 	find_all \
+	sio \
 	$(examples_libftdipp)
 
 # Don't install the example files
@@ -27,6 +28,7 @@ bitbang2_SOURCES = bitbang2.c
 bitbang_ft2232_SOURCES = bitbang_ft2232.c
 bitbang_cbus_SOURCES = bitbang_cbus.c
 find_all_SOURCES = find_all.c
+sio_SOURCES = sio.c
 
 if HAVE_LIBFTDIPP
 find_all_pp_SOURCES = find_all_pp.cpp
diff --git a/examples/sio.c b/examples/sio.c
new file mode 100644
index 0000000..3425ec7
--- /dev/null
+++ b/examples/sio.c
@@ -0,0 +1,81 @@
+/* sio.c
+
+   Read data via serial I/O
+
+   This program is distributed under the GPL, version 2
+*/
+
+#include <stdio.h>
+#include <unistd.h>
+#include <getopt.h>
+#include <ftdi.h>
+
+int main(int argc, char **argv)
+{
+    struct ftdi_context ftdic;
+    char buf[1024];
+    int f, i;
+    int vid = 0x0403;
+    int pid = 0x6001;
+    int baudrate = 115200;
+    int interface = INTERFACE_ANY;
+
+    while ((i = getopt(argc, argv, "i:v:p:b:")) != -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;
+	default:
+		fprintf(stderr, "usage: %s [-i interface] [-v vid] [-p pid] [-b baudrate]\n", *argv);
+		exit(-1);
+        }
+    }
+
+    // Init
+    if (ftdi_init(&ftdic) < 0)
+    {
+        fprintf(stderr, "ftdi_init failed\n");
+        return EXIT_FAILURE;
+    }
+
+    // Select first interface
+    ftdi_set_interface(&ftdic, interface);
+
+    // Open device
+    f = ftdi_usb_open(&ftdic, vid, pid);
+    if (f < 0)
+    {
+        fprintf(stderr, "unable to open ftdi device: %d (%s)\n", f, ftdi_get_error_string(&ftdic));
+        exit(-1);
+    }
+
+    // Set baudrate
+    f = ftdi_set_baudrate(&ftdic, 115200);
+    if (f < 0)
+    {
+        fprintf(stderr, "unable to set baudrate: %d (%s)\n", f, ftdi_get_error_string(&ftdic));
+        exit(-1);
+    }
+
+    // Read data forever
+    while ((f = ftdi_read_data(&ftdic, buf, sizeof(buf))) >= 0) {
+	    fprintf(stderr, "read %d bytes\n", f);
+	    fwrite(buf, f, 1, stdout);
+	    fflush(stderr);
+	    fflush(stdout);
+    }
+
+    ftdi_usb_close(&ftdic);
+    ftdi_deinit(&ftdic);
+}
-- 
1.5.6.5

Reply via email to