libftdi Archives

Subject: libftdi (serial_test) won't work on windows 7 64 bits bench

From: James Liu <jupiturliu@xxxxxxxxx>
To: libftdi@xxxxxxxxxxxxxxxxxxxxxxx
Date: Thu, 31 Oct 2013 11:24:04 -0700
Hi All,
   Here are more updated regarding to FTDI2232H test with libftdi on Windows 7 (32 bits and 64 bits)
  
Environment setsup:
   1. Zadig 2.0.1(Build 160) to install WinUSB(libusbx) driver.
   2. The Ftdi2232h controller was shown as two usb interface device
   3. Running both stream_test and serial_test as described in my first email.
   4. Running USBTRace 2.8.0.80 from sysnucleus.com to capture the usb traffic. I can see the data was written from serial_test to usb device, but there is no data was read from another terminal running serial_test.

I also use visual studio 2012 to compile the serial_test code with slightly modification, I  debugged it step by step and found there is never data read from usb interface A or B(In my setup, I am using interface A)
  
Could anybody here ever test the libftdi library on Windows 7 with read or stream read functions?   Any advice will be greatly appreciated.
   
Regards,
James


Appendix 1:

/* serial_test.c

   Read/write data via serial I/O

   This program is distributed under the GPL, version 2
*/

#include <stdio.h>
#include <stdlib.h>
//#include <unistd.h>
//#include <getopt.h>
//#include <signal.h>
#include "../libftdi/ftdi.h"

static int exitRequested = 0;
/*
 * sigintHandler --
 *
 *    SIGINT handler, so we can gracefully exit when the user hits ctrl-C.
 */
static void
sigintHandler(int signum)
{
    exitRequested = 1;
}

int main(int argc, char **argv)
{
    struct ftdi_context *ftdi;
    unsigned char buf[1024];
    int f = 0, i = 0;
    int vid = 0x403;
    int pid = 0x6010;
    int baudrate = 3000000;
    int iface = INTERFACE_A;
    int do_write = 0;
    unsigned int pattern = 0xffff;
    int retval = EXIT_FAILURE;
char *p = NULL;

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

iface  = strtol(argv[1], &p, 10);
do_write = strtol(argv[2], &p, 10);
    // Select interface
    ftdi_set_interface(ftdi, iface);
        
    // 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, 12000000);
    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);
    }


    // 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);
    }
  */  
     /* A timeout value of 1 results in may skipped blocks */
   if(ftdi_set_latency_timer(ftdi, 2))
   {
       fprintf(stderr,"Can't set latency, Error %s\n",ftdi_get_error_string(ftdi));
       ftdi_usb_close(ftdi);
       ftdi_free(ftdi);
       return EXIT_FAILURE;
   }
    
    if (do_write)
        for(i=0; i<1024; i++)
            buf[i] = 0x12;

    //signal(SIGINT, sigintHandler);
    while (1)
    {
        if (do_write)
{
            f = ftdi_write_data(ftdi, buf, sizeof(buf));
}
        else
            f = ftdi_read_data(ftdi, buf, sizeof(buf));
        
        Sleep(1 * 1000);
        if(f> 0 && !do_write)
        {
            printf("read %d bytes and first byte is %x\n", f, buf[0]);
          //  fwrite(buf, f, 1, stdout);
          //  fflush(stderr);
          //  fflush(stdout);
        } 
    }
    retval =  EXIT_SUCCESS;
            
    ftdi_usb_close(ftdi);
    do_deinit:
    ftdi_free(ftdi);

    return retval;
}

---------- Forwarded message ----------
From: James Liu <jupiturliu@xxxxxxxxx>
Date: Wed, Oct 30, 2013 at 12:04 PM
Subject: Fwd: Help: libftdi (serial_test) won't work on my windows 7 64 bits bench
To: libftdi+help@xxxxxxxxxxxxxxxxxxxxxxx



Hi All,
   We are right now running a project which need high speed usbserial controller. We are evaluating ft2232H chip with running several programs from the package libftdi1git_devkit_mingw64 Xiaofeng provided on Linux(Ubuntu 12.04) and Windows 7(64bits). Linux is totally fine and running very smoothly. However, We got several problems on Windows 7(64 bits):

1. Loopback tests:
   We connect port A to port B of controller to do loopback test.
    We ran below program for writing in one terminal
    E:\downloads\libftdi1git_devkit_mingw64\bin64>serial_test.exe -v0x403 -p0x6010 -i1 -w12
    However, when we ran below program in another terminal for reading , we always got below error
    E:\downloads\libftdi1git_devkit_mingw64\bin64>serial_test.exe -v0x403 -p0x6010 -
i2 
           unable to open ftdi device: -4 (usb_open() failed)
2. Then we did second test with two ft2232h connect with each other through port (interface) 2.
   We ran below program in one PC(windows 7) 
   E:\downloads\libftdi1git_devkit_mingw64\bin64>serial_test.exe -v0x403 -p0x6010 -i2 -w12
   and ran another program in another PC(windows)
   E:\downloads\libftdi1git_devkit_mingw64\bin64>serial_test.exe -v0x403 -p0x6010 -i2
   We can tell that data was written into port 2 of one controller through SysNucleus USBTrace tool.
   But we never receive any data from port 2 of controller in another PC.
3. The reason why I know the serial_test works on Linux because I can see print out from serial_test.Here are command I ran on Linux
  1. ./serial_test  -v0x403 -p0x6010 -i1 -w12  //write 0x0C into buffer
   2. ./serial_test  -v0x403 -p0x6010 -i1  //Read
  I can keep on reading the data from read side. I tried on Windows 7 32 bits system today and no lucky to get it works. I was wondering have the code been tested on windows before?


  Appreciate for any of your advice in advance. 

  Regards,
  James



--
********************************************************************************
The information contained in this communication is confidential, may be
attorney-client privileged, may constitute inside information, and is intended
only for the use of the addressee. It is the property of the
sender of this e-mail. Unauthorized use, disclosure, or copying of this
communication or any part thereof is strictly prohibited and may be unlawful.
If you have received this communication in error, please notify us immediately
by return e-mail and destroy this communication and all copies thereof,
including all attachments.
********************************************************************************



--
********************************************************************************
The information contained in this communication is confidential, may be
attorney-client privileged, may constitute inside information, and is intended
only for the use of the addressee. It is the property of the
sender of this e-mail. Unauthorized use, disclosure, or copying of this
communication or any part thereof is strictly prohibited and may be unlawful.
If you have received this communication in error, please notify us immediately
by return e-mail and destroy this communication and all copies thereof,
including all attachments.
********************************************************************************


libftdi - see http://www.intra2net.com/en/developer/libftdi for details.
To unsubscribe send a mail to libftdi+unsubscribe@xxxxxxxxxxxxxxxxxxxxxxx


Current Thread