Android Question FTDI FT312 or FT311 USB host accessory operation

marcbu

Member
Licensed User
Longtime User
I'm using DIGITUS DA-70160 (see https://www.reichelt.de/USB-Konvert...dex.html?ACTION=3&GROUPID=6105&ARTICLE=136302) (FT312 inside) cable to communicate via USB with Android while loading my android device.
I have tried to do all like thread https://www.b4x.com/android/forum/threads/another-usbserial-baudrate-question.29984/#post-426919

Tests with UsbSerial or felUsbSerial have been not successful. In one case baudrate is not adjustable or in other case device not found.

I got it running partial with UsbAccessory. One problem is that when I read I get error messages. Second is that it seems there is no chance to change baudrate until unplug/plug usb cable and then start software again. (It seems that FTDI app "FTDI AOA HyperTerm v1.0" has same problem with change config after first start)
The read error (1) is: java.io.IOException: ioctl failed: EINVAL (Invalid argument) at line 53.

Problem (2) is how to check if FTDIDevice (UsbAccessory) is valid?

B4X:
Sub Activity_Pause (UserClosed As Boolean)
    If FT31xIn.IsInitialized And UserClosed Then
        FT31xIn.Close
        FT31xOut.Close
        FTDIDevice.Close  ' (2) How to test if FTDIDevice is assigned or isInitialised ??
        Log("FTDI closed")
    End If
End Sub

Sub ButtonSend_Click
    If FT31xOut.IsInitialized Then
        Dim buffer(2) As Byte
        buffer(0) = 0
        buffer(1) = Asc("U")
        FT31xOut.WriteBytes(buffer, 0, buffer.Length)
    End If
    If FT31xIn.IsInitialized Then
        Dim i As Int = FT31xIn.BytesAvailable  ' (1) Error: java.io.IOException: ioctl failed: EINVAL (Invalid argument)
        If i > 0 Then
            Dim inBuff(i) As Byte
            Log("FTDIread " & FT31xIn.ReadBytes(inBuff,0,i))
        End If
    End If
End Sub

You can see attached the values of my watches just before error (execute of FT31xIn.BytesAvailable)
 

Attachments

  • myUsbSerial.zip
    43.4 KB · Views: 470
  • watches.PNG
    watches.PNG
    17.8 KB · Views: 447
  • Logs.txt
    2.5 KB · Views: 464
Last edited:

JoanRPM

Active Member
Licensed User
Longtime User
Marcbu.

Here you are a simple example on how to comunicate with FT311-312 FTDI chip.

When you plug the USB connector into the android device, the program will automatically open.
To do this you must put the FTDI chip description:
B4X:
If ListaAccesorios(i).Description = "Vinculum Accessory Test" Then        'FT311 Dev. Board
'If ListaAccesorios(i).Description = "FTDI Android Accessory FT312D" Then    'chip FT312D
From FTDI, there is a program to configure the FT311-312 chip. Look for "AN_212 User Guide for FT311 Configuration Utility" guide.

Also, you need to put in the manifest:
B4X:
AddActivityText(main, <intent-filter>
<action android:name="android.hardware.usb.action.USB_ACCESSORY_ATTACHED" />
</intent-filter>
<meta-data android:name="android.hardware.usb.action.USB_ACCESSORY_ATTACHED"
android:resource="@xml/accessory_filter" />)

Hope this will help.
 

Attachments

  • USB_FT311.zip
    8.6 KB · Views: 479
Upvote 0

marcbu

Member
Licensed User
Longtime User
Thank you JoanRPM,
After 1st start of app it's running well. When I finish app and start it again it will never more work until I remove/plug again USB device.

From the second start of app I get the message inside "Sub AStreams_Error":
libcore.io.ErrnoException: write failed: ENODEV (No such device)

Do you have any idea how it will be possible to start app more times without unplug/plug usb device?
 
Last edited:
Upvote 0
Top