From: Soumen M. <ms...@so...> - 2007-07-31 03:42:00
|
The code you have posted uses D2XX direct driver APIs from FTDI, and not the APIs from LIBUSB as you have mentioned. I guess you need to paste the program which uses LIBUSB. Thanks, Soumen David Hooker wrote: >What error do you get when it fails to open the device? > >-----Original Message----- >From: lib...@li... >[mailto:lib...@li...]On Behalf Of Spippo >Sent: Friday, July 27, 2007 6:26 AM >To: lib...@li... >Subject: [Libusb-devel] Problems with re-opening USB-device > > > >Hi all, > >I'm using LibUSB in Linux (Ubuntu 7.04) and trying to write a driver for >serial USB communication. >While writing this, I've come upon a problem: > >When I run my program, it finds the USB-device, opens it, configures it, ... >, writes to the device and closes it. >But when I run it again, it can't open the device anymore. I have to pull >out the USB device, insert it again and then run the program. > >Here is my code: > >#include <stdio.h> >#include <stdlib.h> >#include <string.h> >#include "ftd2xx.h" > >FT_HANDLE ftHandle; >FT_STATUS ftStatus; > >UCHAR OUTPUTS = 0xff; >UCHAR Mode = 0x1; > >char TxBuffer[8] = {'s','a','k','i','y','a','m','a'}; >DWORD BytesWritten; > >void USB_open(); >void USB_close(); > >int main(int argc, char *argv[]) >{ > int i=0, j=0; > > USB_open(); > > ftStatus = FT_Write(ftHandle, TxBuffer, 8, &BytesWritten); > if(ftStatus != FT_OK) > printf("Failed to write\n"); > else > printf("Write one char\n"); > > USB_close(); > > return 0; >} > >void USB_open() >{ > ftStatus = FT_Open(0, &ftHandle); > if(ftStatus != FT_OK) > printf("Can not open device\n"); > else > printf("Device open\n"); > > ftStatus = FT_ResetDevice(ftHandle); > if(ftStatus != FT_OK) > printf("REset device failed\n"); > else > printf("Reset device ok\n"); > > ftStatus = FT_SetBaudRate(ftHandle, 9600); > if(ftStatus != FT_OK) > printf("Setting baudrate failed\n"); > else > printf("Baudrate set\n"); > > ftStatus = FT_SetBitMode(ftHandle, OUTPUTS, Mode); > if(ftStatus != FT_OK) > printf("Failed setting bit mode\n"); > > ftStatus = FT_Purge(ftHandle, FT_PURGE_RX || FT_PURGE_TX); > if(ftStatus != FT_OK) > printf("FT_Purge failed\n"); >} > >void USB_close() >{ > ftStatus = FT_ResetDevice(ftHandle); > if(ftStatus != FT_OK) > printf("Reset Device Failed\n"); > else > printf("Device reset\n"); > > ftStatus = FT_Close(ftHandle); > if(ftStatus != FT_OK) > printf("closing failed\n"); > else > printf("device closed\n"); >} > >I have tried some things to help it: >- set the bitmode as synochronized : FT_SetBitMode(ftHandle, OUTPUTS, 0x04); >- reset the bitmode (before i set it, and before i close the USB) : >FT_SetBitMode(ftHandle, OUTPUTS, 0x00); > >Both these methodes solved the problem of re-inserting the USB, but then I >couldn't send any data. > >Is there any way to solve this? > > >Greetz > >Tim > > |